@@ -77,7 +77,7 @@ pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &T
77
77
}
78
78
79
79
/// The possible ways we may notify a ChannelManager of a new block
80
- #[ derive( Clone , Copy , PartialEq ) ]
80
+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
81
81
pub enum ConnectStyle {
82
82
/// Calls best_block_updated first, detecting transactions in the block only after receiving the
83
83
/// header and height information.
@@ -102,6 +102,26 @@ pub enum ConnectStyle {
102
102
FullBlockViaListen ,
103
103
}
104
104
105
+ impl ConnectStyle {
106
+ fn random_style ( ) -> ConnectStyle {
107
+ use std:: hash:: { BuildHasher , Hasher } ;
108
+ // Get a random value using the only std AIP to do so - the DefaultHasher
109
+ let rand_val = std:: collections:: hash_map:: RandomState :: new ( ) . build_hasher ( ) . finish ( ) ;
110
+ let res = match rand_val % 7 {
111
+ 0 => ConnectStyle :: BestBlockFirst ,
112
+ 1 => ConnectStyle :: BestBlockFirstSkippingBlocks ,
113
+ 2 => ConnectStyle :: BestBlockFirstReorgsOnlyTip ,
114
+ 3 => ConnectStyle :: TransactionsFirst ,
115
+ 4 => ConnectStyle :: TransactionsFirstSkippingBlocks ,
116
+ 5 => ConnectStyle :: TransactionsFirstReorgsOnlyTip ,
117
+ 6 => ConnectStyle :: FullBlockViaListen ,
118
+ _ => unreachable ! ( ) ,
119
+ } ;
120
+ #[ cfg( feature = "std" ) ] { eprintln ! ( "Using Block Connection Style: {:?}" , res) ; }
121
+ res
122
+ }
123
+ }
124
+
105
125
pub fn connect_blocks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , depth : u32 ) -> BlockHash {
106
126
let skip_intermediaries = match * node. connect_style . borrow ( ) {
107
127
ConnectStyle :: BestBlockFirstSkippingBlocks |ConnectStyle :: TransactionsFirstSkippingBlocks |
@@ -142,6 +162,9 @@ fn call_claimable_balances<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>) {
142
162
fn do_connect_block < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , block : Block , skip_intermediaries : bool ) {
143
163
call_claimable_balances ( node) ;
144
164
let height = node. best_block_info ( ) . 1 + 1 ;
165
+ #[ cfg( feature = "std" ) ] {
166
+ eprintln ! ( "Connecting block using Block Connection Style: {:?}" , * node. connect_style. borrow( ) ) ;
167
+ }
145
168
if !skip_intermediaries {
146
169
let txdata: Vec < _ > = block. txdata . iter ( ) . enumerate ( ) . collect ( ) ;
147
170
match * node. connect_style . borrow ( ) {
@@ -172,6 +195,9 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
172
195
173
196
pub fn disconnect_blocks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , count : u32 ) {
174
197
call_claimable_balances ( node) ;
198
+ #[ cfg( feature = "std" ) ] {
199
+ eprintln ! ( "Disconnecting {} blocks using Block Connection Style: {:?}" , count, * node. connect_style. borrow( ) ) ;
200
+ }
175
201
for i in 0 ..count {
176
202
let orig = node. blocks . lock ( ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
177
203
assert ! ( orig. 1 > 0 ) ; // Cannot disconnect genesis
@@ -1904,7 +1930,7 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
1904
1930
let mut nodes = Vec :: new ( ) ;
1905
1931
let chan_count = Rc :: new ( RefCell :: new ( 0 ) ) ;
1906
1932
let payment_count = Rc :: new ( RefCell :: new ( 0 ) ) ;
1907
- let connect_style = Rc :: new ( RefCell :: new ( ConnectStyle :: FullBlockViaListen ) ) ;
1933
+ let connect_style = Rc :: new ( RefCell :: new ( ConnectStyle :: random_style ( ) ) ) ;
1908
1934
1909
1935
for i in 0 ..node_count {
1910
1936
let net_graph_msg_handler = NetGraphMsgHandler :: new ( cfgs[ i] . network_graph , None , cfgs[ i] . logger ) ;
0 commit comments