Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the Warning type #278

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/core/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ pub enum Warning {
/// The headers in the database do not link together. Recoverable by deleting the database.
CorruptedHeaders,
/// A transaction got rejected, likely for being an insufficient fee or non-standard transaction.
TransactionRejected(RejectPayload),
TransactionRejected {
/// The transaction ID and reject reason, if it exists.
payload: RejectPayload,
},
/// A database failed to persist some data.
FailedPersistance {
/// Additional context for the persistance failure.
Expand Down Expand Up @@ -281,8 +284,8 @@ impl core::fmt::Display for Warning {
"The node has been running for a long duration without receiving new blocks."
)
}
Warning::TransactionRejected(r) => {
write!(f, "A transaction got rejected: TXID {}", r.txid)
Warning::TransactionRejected { payload } => {
write!(f, "A transaction got rejected: TXID {}", payload.txid)
}
Warning::FailedPersistance { warning } => {
write!(f, "A database failed to persist some data: {}", warning)
Expand Down
7 changes: 4 additions & 3 deletions src/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
}
PeerMessage::Reject(payload) => {
self.dialog
.send_warning(Warning::TransactionRejected(payload));
.send_warning(Warning::TransactionRejected { payload });
}
PeerMessage::FeeFilter(feerate) => {
let mut peer_map = self.peer_map.lock().await;
Expand Down Expand Up @@ -416,8 +416,9 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
if did_broadcast {
self.dialog.send_info(Log::TxSent(txid)).await;
} else {
self.dialog
.send_warning(Warning::TransactionRejected(RejectPayload::from_txid(txid)));
self.dialog.send_warning(Warning::TransactionRejected {
payload: RejectPayload::from_txid(txid),
});
}
}
}
Expand Down