@@ -47,7 +47,6 @@ pub(super) struct BitcoindChainSource {
4747 api_client : Arc < BitcoindClient > ,
4848 header_cache : tokio:: sync:: Mutex < BoundedHeaderCache > ,
4949 latest_chain_tip : RwLock < Option < ValidatedBlockHeader > > ,
50- onchain_wallet : Arc < Wallet > ,
5150 wallet_polling_status : Mutex < WalletSyncStatus > ,
5251 fee_estimator : Arc < OnchainFeeEstimator > ,
5352 kv_store : Arc < DynStore > ,
@@ -59,9 +58,8 @@ pub(super) struct BitcoindChainSource {
5958impl BitcoindChainSource {
6059 pub ( crate ) fn new_rpc (
6160 rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String ,
62- onchain_wallet : Arc < Wallet > , fee_estimator : Arc < OnchainFeeEstimator > ,
63- kv_store : Arc < DynStore > , config : Arc < Config > , logger : Arc < Logger > ,
64- node_metrics : Arc < RwLock < NodeMetrics > > ,
61+ fee_estimator : Arc < OnchainFeeEstimator > , kv_store : Arc < DynStore > , config : Arc < Config > ,
62+ logger : Arc < Logger > , node_metrics : Arc < RwLock < NodeMetrics > > ,
6563 ) -> Self {
6664 let api_client = Arc :: new ( BitcoindClient :: new_rpc (
6765 rpc_host. clone ( ) ,
@@ -77,7 +75,6 @@ impl BitcoindChainSource {
7775 api_client,
7876 header_cache,
7977 latest_chain_tip,
80- onchain_wallet,
8178 wallet_polling_status,
8279 fee_estimator,
8380 kv_store,
@@ -89,9 +86,9 @@ impl BitcoindChainSource {
8986
9087 pub ( crate ) fn new_rest (
9188 rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String ,
92- onchain_wallet : Arc < Wallet > , fee_estimator : Arc < OnchainFeeEstimator > ,
93- kv_store : Arc < DynStore > , config : Arc < Config > , rest_client_config : BitcoindRestClientConfig ,
94- logger : Arc < Logger > , node_metrics : Arc < RwLock < NodeMetrics > > ,
89+ fee_estimator : Arc < OnchainFeeEstimator > , kv_store : Arc < DynStore > , config : Arc < Config > ,
90+ rest_client_config : BitcoindRestClientConfig , logger : Arc < Logger > ,
91+ node_metrics : Arc < RwLock < NodeMetrics > > ,
9592 ) -> Self {
9693 let api_client = Arc :: new ( BitcoindClient :: new_rest (
9794 rest_client_config. rest_host ,
@@ -111,7 +108,6 @@ impl BitcoindChainSource {
111108 header_cache,
112109 latest_chain_tip,
113110 wallet_polling_status,
114- onchain_wallet,
115111 fee_estimator,
116112 kv_store,
117113 config,
@@ -126,8 +122,8 @@ impl BitcoindChainSource {
126122
127123 pub ( super ) async fn continuously_sync_wallets (
128124 & self , mut stop_sync_receiver : tokio:: sync:: watch:: Receiver < ( ) > ,
129- channel_manager : Arc < ChannelManager > , chain_monitor : Arc < ChainMonitor > ,
130- output_sweeper : Arc < Sweeper > ,
125+ onchain_wallet : Arc < Wallet > , channel_manager : Arc < ChannelManager > ,
126+ chain_monitor : Arc < ChainMonitor > , output_sweeper : Arc < Sweeper > ,
131127 ) {
132128 // First register for the wallet polling status to make sure `Node::sync_wallets` calls
133129 // wait on the result before proceeding.
@@ -155,14 +151,10 @@ impl BitcoindChainSource {
155151
156152 let channel_manager_best_block_hash = channel_manager. current_best_block ( ) . block_hash ;
157153 let sweeper_best_block_hash = output_sweeper. current_best_block ( ) . block_hash ;
158- let onchain_wallet_best_block_hash =
159- self . onchain_wallet . current_best_block ( ) . block_hash ;
154+ let onchain_wallet_best_block_hash = onchain_wallet. current_best_block ( ) . block_hash ;
160155
161156 let mut chain_listeners = vec ! [
162- (
163- onchain_wallet_best_block_hash,
164- & * self . onchain_wallet as & ( dyn Listen + Send + Sync ) ,
165- ) ,
157+ ( onchain_wallet_best_block_hash, & * onchain_wallet as & ( dyn Listen + Send + Sync ) ) ,
166158 ( channel_manager_best_block_hash, & * channel_manager as & ( dyn Listen + Send + Sync ) ) ,
167159 ( sweeper_best_block_hash, & * output_sweeper as & ( dyn Listen + Send + Sync ) ) ,
168160 ] ;
@@ -307,6 +299,7 @@ impl BitcoindChainSource {
307299 return ;
308300 }
309301 _ = self . poll_and_update_listeners(
302+ Arc :: clone( & onchain_wallet) ,
310303 Arc :: clone( & channel_manager) ,
311304 Arc :: clone( & chain_monitor) ,
312305 Arc :: clone( & output_sweeper)
@@ -337,8 +330,8 @@ impl BitcoindChainSource {
337330 }
338331
339332 pub ( super ) async fn poll_and_update_listeners (
340- & self , channel_manager : Arc < ChannelManager > , chain_monitor : Arc < ChainMonitor > ,
341- output_sweeper : Arc < Sweeper > ,
333+ & self , onchain_wallet : Arc < Wallet > , channel_manager : Arc < ChannelManager > ,
334+ chain_monitor : Arc < ChainMonitor > , output_sweeper : Arc < Sweeper > ,
342335 ) -> Result < ( ) , Error > {
343336 let receiver_res = {
344337 let mut status_lock = self . wallet_polling_status . lock ( ) . unwrap ( ) ;
@@ -355,7 +348,12 @@ impl BitcoindChainSource {
355348 }
356349
357350 let res = self
358- . poll_and_update_listeners_inner ( channel_manager, chain_monitor, output_sweeper)
351+ . poll_and_update_listeners_inner (
352+ onchain_wallet,
353+ channel_manager,
354+ chain_monitor,
355+ output_sweeper,
356+ )
359357 . await ;
360358
361359 self . wallet_polling_status . lock ( ) . unwrap ( ) . propagate_result_to_subscribers ( res) ;
@@ -364,8 +362,8 @@ impl BitcoindChainSource {
364362 }
365363
366364 async fn poll_and_update_listeners_inner (
367- & self , channel_manager : Arc < ChannelManager > , chain_monitor : Arc < ChainMonitor > ,
368- output_sweeper : Arc < Sweeper > ,
365+ & self , onchain_wallet : Arc < Wallet > , channel_manager : Arc < ChannelManager > ,
366+ chain_monitor : Arc < ChainMonitor > , output_sweeper : Arc < Sweeper > ,
369367 ) -> Result < ( ) , Error > {
370368 let latest_chain_tip_opt = self . latest_chain_tip . read ( ) . unwrap ( ) . clone ( ) ;
371369 let chain_tip = if let Some ( tip) = latest_chain_tip_opt {
@@ -386,7 +384,7 @@ impl BitcoindChainSource {
386384 let mut locked_header_cache = self . header_cache . lock ( ) . await ;
387385 let chain_poller = ChainPoller :: new ( Arc :: clone ( & self . api_client ) , self . config . network ) ;
388386 let chain_listener = ChainListener {
389- onchain_wallet : Arc :: clone ( & self . onchain_wallet ) ,
387+ onchain_wallet : Arc :: clone ( & onchain_wallet) ,
390388 channel_manager : Arc :: clone ( & channel_manager) ,
391389 chain_monitor : Arc :: clone ( & chain_monitor) ,
392390 output_sweeper,
@@ -422,7 +420,7 @@ impl BitcoindChainSource {
422420 let cur_height = channel_manager. current_best_block ( ) . height ;
423421
424422 let now = SystemTime :: now ( ) ;
425- let bdk_unconfirmed_txids = self . onchain_wallet . get_unconfirmed_txids ( ) ;
423+ let bdk_unconfirmed_txids = onchain_wallet. get_unconfirmed_txids ( ) ;
426424 match self
427425 . api_client
428426 . get_updated_mempool_transactions ( cur_height, bdk_unconfirmed_txids)
@@ -436,11 +434,11 @@ impl BitcoindChainSource {
436434 evicted_txids. len( ) ,
437435 now. elapsed( ) . unwrap( ) . as_millis( )
438436 ) ;
439- self . onchain_wallet
440- . apply_mempool_txs ( unconfirmed_txs, evicted_txids)
441- . unwrap_or_else ( |e| {
437+ onchain_wallet. apply_mempool_txs ( unconfirmed_txs, evicted_txids) . unwrap_or_else (
438+ |e| {
442439 log_error ! ( self . logger, "Failed to apply mempool transactions: {:?}" , e) ;
443- } ) ;
440+ } ,
441+ ) ;
444442 } ,
445443 Err ( e) => {
446444 log_error ! ( self . logger, "Failed to poll for mempool transactions: {:?}" , e) ;
0 commit comments