@@ -113,13 +113,29 @@ pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block,
113
113
node. node . block_connected ( & block. header , & txdata, height) ;
114
114
node. node . test_process_background_events ( ) ;
115
115
* node. last_block . lock ( ) . unwrap ( ) = ( block. header . block_hash ( ) , height) ;
116
+ node. blocks . lock ( ) . unwrap ( ) . push ( ( block. header , height) ) ;
116
117
}
117
118
118
119
pub fn disconnect_block < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , header : & BlockHeader , height : u32 ) {
119
120
node. chain_monitor . chain_monitor . block_disconnected ( header, height) ;
120
121
node. node . block_disconnected ( header) ;
121
122
node. node . test_process_background_events ( ) ;
122
123
* node. last_block . lock ( ) . unwrap ( ) = ( header. prev_blockhash , height - 1 ) ;
124
+ node. blocks . lock ( ) . unwrap ( ) . pop ( ) ;
125
+ }
126
+
127
+ pub fn disconnect_all_blocks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > ) {
128
+ let mut blocks_len = {
129
+ node. blocks . lock ( ) . unwrap ( ) . len ( )
130
+ } ;
131
+ while blocks_len > 0 {
132
+ let ( block_header, height) = {
133
+ let blocks = node. blocks . lock ( ) . unwrap ( ) ;
134
+ ( blocks[ blocks. len ( ) - 1 ] . 0 , blocks[ blocks. len ( ) - 1 ] . 1 )
135
+ } ;
136
+ disconnect_block ( & node, & block_header, height) ;
137
+ blocks_len = node. blocks . lock ( ) . unwrap ( ) . len ( ) ;
138
+ }
123
139
}
124
140
125
141
pub struct TestChanMonCfg {
@@ -153,6 +169,7 @@ pub struct Node<'a, 'b: 'a, 'c: 'b> {
153
169
pub network_chan_count : Rc < RefCell < u32 > > ,
154
170
pub logger : & ' c test_utils:: TestLogger ,
155
171
pub last_block : Mutex < ( BlockHash , u32 ) > ,
172
+ pub blocks : Mutex < Vec < ( BlockHeader , u32 ) > > ,
156
173
}
157
174
158
175
impl < ' a , ' b , ' c > Drop for Node < ' a , ' b , ' c > {
@@ -1221,6 +1238,7 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
1221
1238
node_seed : cfgs[ i] . node_seed , network_chan_count : chan_count. clone ( ) ,
1222
1239
network_payment_count : payment_count. clone ( ) , logger : cfgs[ i] . logger ,
1223
1240
last_block : Mutex :: new ( ( genesis_block ( Network :: Testnet ) . header . block_hash ( ) , 0 ) ) ,
1241
+ blocks : Mutex :: new ( Vec :: new ( ) )
1224
1242
} )
1225
1243
}
1226
1244
0 commit comments