@@ -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,31 @@ pub enum ConnectStyle {
102
102
FullBlockViaListen ,
103
103
}
104
104
105
+ impl ConnectStyle {
106
+ fn random_style ( ) -> ConnectStyle {
107
+ #[ cfg( feature = "std" ) ] {
108
+ use core:: hash:: { BuildHasher , Hasher } ;
109
+ // Get a random value using the only std AIP to do so - the DefaultHasher
110
+ let rand_val = std:: collections:: hash_map:: RandomState :: new ( ) . build_hasher ( ) . finish ( ) ;
111
+ let res = match rand_val % 7 {
112
+ 0 => ConnectStyle :: BestBlockFirst ,
113
+ 1 => ConnectStyle :: BestBlockFirstSkippingBlocks ,
114
+ 2 => ConnectStyle :: BestBlockFirstReorgsOnlyTip ,
115
+ 3 => ConnectStyle :: TransactionsFirst ,
116
+ 4 => ConnectStyle :: TransactionsFirstSkippingBlocks ,
117
+ 5 => ConnectStyle :: TransactionsFirstReorgsOnlyTip ,
118
+ 6 => ConnectStyle :: FullBlockViaListen ,
119
+ _ => unreachable ! ( ) ,
120
+ } ;
121
+ eprintln ! ( "Using Block Connection Style: {:?}" , res) ;
122
+ res
123
+ }
124
+ #[ cfg( not( feature = "std" ) ) ] {
125
+ ConnectStyle :: FullBlockViaListen
126
+ }
127
+ }
128
+ }
129
+
105
130
pub fn connect_blocks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , depth : u32 ) -> BlockHash {
106
131
let skip_intermediaries = match * node. connect_style . borrow ( ) {
107
132
ConnectStyle :: BestBlockFirstSkippingBlocks |ConnectStyle :: TransactionsFirstSkippingBlocks |
@@ -142,6 +167,9 @@ fn call_claimable_balances<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>) {
142
167
fn do_connect_block < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , block : Block , skip_intermediaries : bool ) {
143
168
call_claimable_balances ( node) ;
144
169
let height = node. best_block_info ( ) . 1 + 1 ;
170
+ #[ cfg( feature = "std" ) ] {
171
+ eprintln ! ( "Connecting block using Block Connection Style: {:?}" , * node. connect_style. borrow( ) ) ;
172
+ }
145
173
if !skip_intermediaries {
146
174
let txdata: Vec < _ > = block. txdata . iter ( ) . enumerate ( ) . collect ( ) ;
147
175
match * node. connect_style . borrow ( ) {
@@ -172,6 +200,9 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
172
200
173
201
pub fn disconnect_blocks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , count : u32 ) {
174
202
call_claimable_balances ( node) ;
203
+ #[ cfg( feature = "std" ) ] {
204
+ eprintln ! ( "Disconnecting {} blocks using Block Connection Style: {:?}" , count, * node. connect_style. borrow( ) ) ;
205
+ }
175
206
for i in 0 ..count {
176
207
let orig = node. blocks . lock ( ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
177
208
assert ! ( orig. 1 > 0 ) ; // Cannot disconnect genesis
@@ -1904,7 +1935,7 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
1904
1935
let mut nodes = Vec :: new ( ) ;
1905
1936
let chan_count = Rc :: new ( RefCell :: new ( 0 ) ) ;
1906
1937
let payment_count = Rc :: new ( RefCell :: new ( 0 ) ) ;
1907
- let connect_style = Rc :: new ( RefCell :: new ( ConnectStyle :: FullBlockViaListen ) ) ;
1938
+ let connect_style = Rc :: new ( RefCell :: new ( ConnectStyle :: random_style ( ) ) ) ;
1908
1939
1909
1940
for i in 0 ..node_count {
1910
1941
let net_graph_msg_handler = NetGraphMsgHandler :: new ( cfgs[ i] . network_graph , None , cfgs[ i] . logger ) ;
0 commit comments