From 707448199a70c4101272a54c611136d1628cce48 Mon Sep 17 00:00:00 2001 From: Rob N Date: Wed, 22 Jan 2025 13:51:16 -1000 Subject: [PATCH 1/4] refactor!: add named field to `TransactionRejected` enum variant --- Cargo.lock | 2 +- src/core/messages.rs | 9 ++++++--- src/core/node.rs | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36a20f1..704d80d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1641,7 +1641,7 @@ dependencies = [ [[package]] name = "kyoto-cbf" -version = "0.7.0" +version = "0.8.0" dependencies = [ "arti-client", "bip324", diff --git a/src/core/messages.rs b/src/core/messages.rs index 83ba87d..9cd667f 100644 --- a/src/core/messages.rs +++ b/src/core/messages.rs @@ -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. @@ -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) diff --git a/src/core/node.rs b/src/core/node.rs index dd5a7e7..b0434e1 100644 --- a/src/core/node.rs +++ b/src/core/node.rs @@ -261,7 +261,7 @@ impl Node { } 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; @@ -416,8 +416,9 @@ impl Node { 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), + }); } } } From 3267625973b8e92b1269b90abd1d6f27e9896118 Mon Sep 17 00:00:00 2001 From: Rob N Date: Wed, 22 Jan 2025 14:01:52 -1000 Subject: [PATCH 2/4] fix: typo in persistence --- src/chain/chain.rs | 8 ++++---- src/core/messages.rs | 4 ++-- src/core/peer_map.rs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/chain/chain.rs b/src/chain/chain.rs index 884810f..b3c7a91 100644 --- a/src/chain/chain.rs +++ b/src/chain/chain.rs @@ -133,7 +133,7 @@ impl Chain { let header_opt = db.header_at(height).await; if header_opt.is_err() { self.dialog - .send_warning(Warning::FailedPersistance { + .send_warning(Warning::FailedPersistence { warning: format!( "Unexpected error fetching a header from the header store at height {height}" ), @@ -248,7 +248,7 @@ impl Chain { .write(self.header_chain.headers()) .await { - self.dialog.send_warning(Warning::FailedPersistance { + self.dialog.send_warning(Warning::FailedPersistence { warning: format!("Could not save headers to disk: {e}"), }); } @@ -263,7 +263,7 @@ impl Chain { .write_over(self.header_chain.headers(), height) .await { - self.dialog.send_warning(Warning::FailedPersistance { + self.dialog.send_warning(Warning::FailedPersistence { warning: format!("Could not save headers to disk: {e}"), }); } @@ -886,7 +886,7 @@ impl Chain { let mut db = self.db.lock().await; let range_opt = db.load(range).await; if range_opt.is_err() { - self.dialog.send_warning(Warning::FailedPersistance { + self.dialog.send_warning(Warning::FailedPersistence { warning: "Unexpected error fetching a range of headers from the header store" .to_string(), }); diff --git a/src/core/messages.rs b/src/core/messages.rs index 9cd667f..b8b3651 100644 --- a/src/core/messages.rs +++ b/src/core/messages.rs @@ -245,7 +245,7 @@ pub enum Warning { payload: RejectPayload, }, /// A database failed to persist some data. - FailedPersistance { + FailedPersistence { /// Additional context for the persistance failure. warning: String, }, @@ -287,7 +287,7 @@ impl core::fmt::Display for Warning { Warning::TransactionRejected { payload } => { write!(f, "A transaction got rejected: TXID {}", payload.txid) } - Warning::FailedPersistance { warning } => { + Warning::FailedPersistence { warning } => { write!(f, "A database failed to persist some data: {}", warning) } Warning::EvaluatingFork => write!(f, "Peer sent us a potential fork."), diff --git a/src/core/peer_map.rs b/src/core/peer_map.rs index 0ec275e..8d4b20c 100644 --- a/src/core/peer_map.rs +++ b/src/core/peer_map.rs @@ -334,7 +334,7 @@ impl PeerMap

{ )) .await { - self.dialog.send_warning(Warning::FailedPersistance { + self.dialog.send_warning(Warning::FailedPersistence { warning: format!( "Encountered an error adding {:?}:{} flags: {} ... {e}", peer.addr, peer.port, peer.services @@ -357,7 +357,7 @@ impl PeerMap

{ )) .await { - self.dialog.send_warning(Warning::FailedPersistance { + self.dialog.send_warning(Warning::FailedPersistence { warning: format!( "Encountered an error adding {:?}:{} flags: {} ... {e}", peer.address, peer.port, peer.service_flags @@ -380,7 +380,7 @@ impl PeerMap

{ )) .await { - self.dialog.send_warning(Warning::FailedPersistance { + self.dialog.send_warning(Warning::FailedPersistence { warning: format!( "Encountered an error adding {:?}:{} flags: {} ... {e}", peer.address, peer.port, peer.service_flags From 5d4c06dd394469aad360a1689a6d9b4a5fda1e3e Mon Sep 17 00:00:00 2001 From: Rob N Date: Wed, 22 Jan 2025 14:18:42 -1000 Subject: [PATCH 3/4] refactor!: rename `NotEnoughConnections` to `NeedConnections` and add connection details --- src/core/messages.rs | 18 +++++++++++++++--- src/core/node.rs | 9 +++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/core/messages.rs b/src/core/messages.rs index b8b3651..ac13fe8 100644 --- a/src/core/messages.rs +++ b/src/core/messages.rs @@ -223,7 +223,12 @@ impl BlockRequest { #[derive(Debug, Clone)] pub enum Warning { /// The node is looking for connections to peers. - NotEnoughConnections, + NeedConnections { + /// The number of live connections. + connected: usize, + /// The configured requirement. + required: usize, + }, /// A connection to a peer timed out. PeerTimedOut, /// The node was unable to connect to a peer in the database. @@ -265,8 +270,15 @@ pub enum Warning { impl core::fmt::Display for Warning { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - Warning::NotEnoughConnections => { - write!(f, "Looking for connections to peers.") + Warning::NeedConnections { + connected, + required, + } => { + write!( + f, + "Looking for connections to peers. Connected: {}, Required: {}", + connected, required + ) } Warning::UnlinkableAnchor => write!( f, diff --git a/src/core/node.rs b/src/core/node.rs index b0434e1..30d2df7 100644 --- a/src/core/node.rs +++ b/src/core/node.rs @@ -361,9 +361,14 @@ impl Node { async fn dispatch(&self) -> Result<(), NodeError> { let mut peer_map = self.peer_map.lock().await; peer_map.clean().await; + let live = peer_map.live(); + let required = self.next_required_peers().await; // Find more peers when lower than the desired threshold. - if peer_map.live() < self.next_required_peers().await { - self.dialog.send_warning(Warning::NotEnoughConnections); + if live < required { + self.dialog.send_warning(Warning::NeedConnections { + connected: live, + required, + }); let address = peer_map.next_peer().await?; if peer_map.dispatch(address).await.is_err() { self.dialog.send_warning(Warning::CouldNotConnect); From bb934c3d7ee4c179905e0cef4b61bea6d53322a1 Mon Sep 17 00:00:00 2001 From: Rob N Date: Thu, 23 Jan 2025 11:09:45 -1000 Subject: [PATCH 4/4] refactor!: rename `UnlinkableAnchor` to `InvalidStartHeight` --- src/chain/chain.rs | 2 +- src/core/messages.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chain/chain.rs b/src/chain/chain.rs index b3c7a91..831a877 100644 --- a/src/chain/chain.rs +++ b/src/chain/chain.rs @@ -280,7 +280,7 @@ impl Chain { .map_err(HeaderPersistenceError::Database)?; if let Some(first) = loaded_headers.values().next() { if first.prev_blockhash.ne(&self.tip()) { - self.dialog.send_warning(Warning::UnlinkableAnchor); + self.dialog.send_warning(Warning::InvalidStartHeight); // The header chain did not align, so just start from the anchor return Err(HeaderPersistenceError::CannotLocateHistory); } else if loaded_headers diff --git a/src/core/messages.rs b/src/core/messages.rs index ac13fe8..74fe0fd 100644 --- a/src/core/messages.rs +++ b/src/core/messages.rs @@ -241,7 +241,7 @@ pub enum Warning { UnsolicitedMessage, /// The provided anchor is deeper than the database history. /// Recoverable by deleting the headers from the database or starting from a higher point in the chain. - UnlinkableAnchor, + InvalidStartHeight, /// 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. @@ -280,7 +280,7 @@ impl core::fmt::Display for Warning { connected, required ) } - Warning::UnlinkableAnchor => write!( + Warning::InvalidStartHeight => write!( f, "The provided anchor is deeper than the database history." ),