@@ -34,27 +34,28 @@ use std::sync::{Arc, Mutex};
34
34
use std:: mem;
35
35
36
36
pub const CHAN_CONFIRM_DEPTH : u32 = 100 ;
37
- pub fn confirm_transaction ( chain : & chaininterface:: ChainWatchInterfaceUtil , tx : & Transaction , chan_id : u32 ) {
37
+ pub fn confirm_transaction ( notifier : & chaininterface :: BlockNotifier , chain : & chaininterface:: ChainWatchInterfaceUtil , tx : & Transaction , chan_id : u32 ) {
38
38
assert ! ( chain. does_match_tx( tx) ) ;
39
39
let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
40
- chain . block_connected_checked ( & header, 1 , & [ tx; 1 ] , & [ chan_id; 1 ] ) ;
40
+ notifier . block_connected_checked ( & header, 1 , & [ tx. clone ( ) ; 1 ] , & [ chan_id; 1 ] ) ;
41
41
for i in 2 ..CHAN_CONFIRM_DEPTH {
42
42
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
43
- chain . block_connected_checked ( & header, i, & [ tx ; 0 ] , & [ 0 ; 0 ] ) ;
43
+ notifier . block_connected_checked ( & header, i, & vec ! [ ] , & [ 0 ; 0 ] ) ;
44
44
}
45
45
}
46
46
47
- pub fn connect_blocks ( chain : & chaininterface:: ChainWatchInterfaceUtil , depth : u32 , height : u32 , parent : bool , prev_blockhash : Sha256d ) -> Sha256d {
47
+ pub fn connect_blocks ( notifier : & chaininterface:: BlockNotifier , depth : u32 , height : u32 , parent : bool , prev_blockhash : Sha256d ) -> Sha256d {
48
48
let mut header = BlockHeader { version : 0x2000000 , prev_blockhash : if parent { prev_blockhash } else { Default :: default ( ) } , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
49
- chain . block_connected_checked ( & header, height + 1 , & Vec :: new ( ) , & Vec :: new ( ) ) ;
49
+ notifier . block_connected_checked ( & header, height + 1 , & Vec :: new ( ) , & Vec :: new ( ) ) ;
50
50
for i in 2 ..depth + 1 {
51
51
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
52
- chain . block_connected_checked ( & header, height + i, & Vec :: new ( ) , & Vec :: new ( ) ) ;
52
+ notifier . block_connected_checked ( & header, height + i, & Vec :: new ( ) , & Vec :: new ( ) ) ;
53
53
}
54
54
header. bitcoin_hash ( )
55
55
}
56
56
57
57
pub struct Node {
58
+ pub block_notifier : Arc < chaininterface:: BlockNotifier > ,
58
59
pub chain_monitor : Arc < chaininterface:: ChainWatchInterfaceUtil > ,
59
60
pub tx_broadcaster : Arc < test_utils:: TestBroadcaster > ,
60
61
pub chan_monitor : Arc < test_utils:: TestChannelMonitor > ,
@@ -220,7 +221,7 @@ pub fn create_chan_between_nodes_with_value_init(node_a: &Node, node_b: &Node, c
220
221
}
221
222
222
223
pub fn create_chan_between_nodes_with_value_confirm_first ( node_recv : & Node , node_conf : & Node , tx : & Transaction ) {
223
- confirm_transaction ( & node_conf. chain_monitor , & tx, tx. version ) ;
224
+ confirm_transaction ( & node_conf. block_notifier , & node_conf . chain_monitor , & tx, tx. version ) ;
224
225
node_recv. node . handle_funding_locked ( & node_conf. node . get_our_node_id ( ) , & get_event_msg ! ( node_conf, MessageSendEvent :: SendFundingLocked , node_recv. node. get_our_node_id( ) ) ) . unwrap ( ) ;
225
226
}
226
227
@@ -246,7 +247,7 @@ pub fn create_chan_between_nodes_with_value_confirm_second(node_recv: &Node, nod
246
247
247
248
pub fn create_chan_between_nodes_with_value_confirm ( node_a : & Node , node_b : & Node , tx : & Transaction ) -> ( ( msgs:: FundingLocked , msgs:: AnnouncementSignatures ) , [ u8 ; 32 ] ) {
248
249
create_chan_between_nodes_with_value_confirm_first ( node_a, node_b, tx) ;
249
- confirm_transaction ( & node_a. chain_monitor , & tx, tx. version ) ;
250
+ confirm_transaction ( & node_a. block_notifier , & node_a . chain_monitor , & tx, tx. version ) ;
250
251
create_chan_between_nodes_with_value_confirm_second ( node_b, node_a)
251
252
}
252
253
@@ -836,6 +837,7 @@ pub fn create_network(node_count: usize, node_config: &[Option<UserConfig>]) ->
836
837
let logger: Arc < Logger > = Arc :: new ( test_utils:: TestLogger :: with_id ( format ! ( "node {}" , i) ) ) ;
837
838
let feeest = Arc :: new ( test_utils:: TestFeeEstimator { sat_per_kw : 253 } ) ;
838
839
let chain_monitor = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Network :: Testnet , Arc :: clone ( & logger) ) ) ;
840
+ let block_notifier = Arc :: new ( chaininterface:: BlockNotifier :: new ( chain_monitor. clone ( ) ) ) ;
839
841
let tx_broadcaster = Arc :: new ( test_utils:: TestBroadcaster { txn_broadcasted : Mutex :: new ( Vec :: new ( ) ) } ) ;
840
842
let mut seed = [ 0 ; 32 ] ;
841
843
rng. fill_bytes ( & mut seed) ;
@@ -853,6 +855,7 @@ pub fn create_network(node_count: usize, node_config: &[Option<UserConfig>]) ->
853
855
nodes. push ( Node { chain_monitor, tx_broadcaster, chan_monitor, node, router, keys_manager, node_seed : seed,
854
856
network_payment_count : payment_count. clone ( ) ,
855
857
network_chan_count : chan_count. clone ( ) ,
858
+ block_notifier,
856
859
} ) ;
857
860
}
858
861
0 commit comments