From 3249894e5d563daf70f280092e9595a73da12aeb Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Wed, 12 Jun 2024 17:16:26 -1000 Subject: [PATCH] chain: send block over dialog --- src/chain/chain.rs | 11 ++++------- src/node/node.rs | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/chain/chain.rs b/src/chain/chain.rs index fe099ec..b7f6a24 100644 --- a/src/chain/chain.rs +++ b/src/chain/chain.rs @@ -571,12 +571,13 @@ impl Chain { // Scan an incoming block for transactions with our scripts pub(crate) async fn scan_block(&mut self, block: &Block) -> Result<(), BlockScanError> { self.block_queue.receive_one(); - let mut contains_relevant = false; match self.height_of_hash(block.block_hash()).await { Some(height) => { + self.dialog + .send_data(NodeMessage::Block(IndexedBlock::new(height, block.clone()))) + .await; for tx in &block.txdata { if self.scan_inputs(&tx.input) || self.scan_outputs(&tx.output) { - contains_relevant = true; self.dialog .send_data(NodeMessage::Transaction(IndexedTransaction::new( tx.clone(), @@ -589,11 +590,6 @@ impl Chain { .await; } } - if contains_relevant { - self.dialog - .send_data(NodeMessage::Block(IndexedBlock::new(height, block.clone()))) - .await; - } Ok(()) } None => Err(BlockScanError::NoBlockHash), @@ -612,6 +608,7 @@ impl Chain { .any(|out| self.scripts.contains(&out.script_pubkey)) } + // Add more scripts to our list pub(crate) fn put_scripts(&mut self, scripts: HashSet) { for script in scripts { self.scripts.insert(script); diff --git a/src/node/node.rs b/src/node/node.rs index 7c2ee9b..882cf09 100644 --- a/src/node/node.rs +++ b/src/node/node.rs @@ -173,6 +173,7 @@ impl Node { let mut node_map = PeerMap::new(mtx, self.network); let mut tx_broadcaster = Broadcaster::new(); loop { + // Try to advance the state of the node and remove old connections self.advance_state().await; node_map.clean().await; // Rehydrate on peers when lower than a threshold