From: Elias Rohrer Date: Tue, 7 Nov 2023 08:21:40 +0000 (+0100) Subject: Move `sync_` methods to `SyncState` X-Git-Tag: v0.0.119~44^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=82f4c10e18f9cbe5359a20433fa7638a66c4f96f;p=rust-lightning Move `sync_` methods to `SyncState` --- diff --git a/lightning-transaction-sync/src/common.rs b/lightning-transaction-sync/src/common.rs index 45f18afb9..91a9c90b2 100644 --- a/lightning-transaction-sync/src/common.rs +++ b/lightning-transaction-sync/src/common.rs @@ -1,6 +1,6 @@ -use lightning::chain::WatchedOutput; +use lightning::chain::{Confirm, WatchedOutput}; use bitcoin::{Txid, BlockHash, Transaction, OutPoint}; -use bitcoin::blockdata::block::Header; +use bitcoin::block::Header; use std::collections::{HashSet, HashMap}; @@ -28,6 +28,39 @@ impl SyncState { pending_sync: false, } } + pub fn sync_unconfirmed_transactions( + &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + unconfirmed_txs: Vec, + ) { + for txid in unconfirmed_txs { + for c in confirmables { + c.transaction_unconfirmed(&txid); + } + + self.watched_transactions.insert(txid); + } + } + + pub fn sync_confirmed_transactions( + &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + confirmed_txs: Vec + ) { + for ctx in confirmed_txs { + for c in confirmables { + c.transactions_confirmed( + &ctx.block_header, + &[(ctx.pos, &ctx.tx)], + ctx.block_height, + ); + } + + self.watched_transactions.remove(&ctx.tx.txid()); + + for input in &ctx.tx.input { + self.watched_outputs.remove(&input.previous_output); + } + } + } } diff --git a/lightning-transaction-sync/src/esplora.rs b/lightning-transaction-sync/src/esplora.rs index 1a3ae2c22..3f0d48283 100644 --- a/lightning-transaction-sync/src/esplora.rs +++ b/lightning-transaction-sync/src/esplora.rs @@ -123,7 +123,7 @@ where continue; } num_unconfirmed += unconfirmed_txs.len(); - self.sync_unconfirmed_transactions(&mut sync_state, &confirmables, unconfirmed_txs); + sync_state.sync_unconfirmed_transactions(&confirmables, unconfirmed_txs); }, Err(err) => { // (Semi-)permanent failure, retry later. @@ -169,8 +169,7 @@ where } num_confirmed += confirmed_txs.len(); - self.sync_confirmed_transactions( - &mut sync_state, + sync_state.sync_confirmed_transactions( &confirmables, confirmed_txs, ); @@ -221,26 +220,6 @@ where Ok(()) } - fn sync_confirmed_transactions( - &self, sync_state: &mut SyncState, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, confirmed_txs: Vec, - ) { - for ctx in confirmed_txs { - for c in confirmables { - c.transactions_confirmed( - &ctx.block_header, - &[(ctx.pos, &ctx.tx)], - ctx.block_height, - ); - } - - sync_state.watched_transactions.remove(&ctx.tx.txid()); - - for input in &ctx.tx.input { - sync_state.watched_outputs.remove(&input.previous_output); - } - } - } - #[maybe_async] fn get_confirmed_transactions( &self, sync_state: &SyncState, @@ -360,18 +339,6 @@ where Ok(unconfirmed_txs) } - fn sync_unconfirmed_transactions( - &self, sync_state: &mut SyncState, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, unconfirmed_txs: Vec, - ) { - for txid in unconfirmed_txs { - for c in confirmables { - c.transaction_unconfirmed(&txid); - } - - sync_state.watched_transactions.insert(txid); - } - } - /// Returns a reference to the underlying esplora client. pub fn client(&self) -> &EsploraClientType { &self.client