@@ -44,23 +44,50 @@ use std::sync::Mutex;
44
44
use std:: mem;
45
45
use std:: collections:: HashMap ;
46
46
47
- pub const CHAN_CONFIRM_DEPTH : u32 = 100 ;
47
+ pub const CHAN_CONFIRM_DEPTH : u32 = 10 ;
48
48
49
49
pub fn confirm_transaction < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , tx : & Transaction ) {
50
- let dummy_tx = Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
51
- let dummy_tx_count = tx. version as usize ;
52
50
let mut block = Block {
53
- header : BlockHeader { version : 0x20000000 , prev_blockhash : genesis_block ( Network :: Testnet ) . header . block_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ,
54
- txdata : vec ! [ dummy_tx ; dummy_tx_count ] ,
51
+ header : BlockHeader { version : 0x20000000 , prev_blockhash : node . last_block . lock ( ) . unwrap ( ) . 0 , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ,
52
+ txdata : Vec :: new ( ) ,
55
53
} ;
56
54
block. txdata . push ( tx. clone ( ) ) ;
57
- connect_block ( node, & block, 1 ) ;
55
+ let height = node. last_block . lock ( ) . unwrap ( ) . 1 + 1 ;
56
+ connect_block ( node, & block, height) ;
58
57
for i in 2 ..CHAN_CONFIRM_DEPTH {
59
58
block = Block {
60
59
header : BlockHeader { version : 0x20000000 , prev_blockhash : block. header . block_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ,
61
60
txdata : vec ! [ ] ,
62
61
} ;
62
+ connect_block ( node, & block, i + height) ;
63
+ }
64
+ }
65
+ pub fn confirm_transaction_at < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , tx : & Transaction , conf_height : u32 ) {
66
+ let mut block = Block {
67
+ header : BlockHeader { version : 0x20000000 , prev_blockhash : node. last_block . lock ( ) . unwrap ( ) . 0 , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ,
68
+ txdata : Vec :: new ( ) ,
69
+ } ;
70
+ let height = node. last_block . lock ( ) . unwrap ( ) . 1 + 1 ;
71
+ assert ! ( height <= conf_height) ;
72
+ for i in height..conf_height {
63
73
connect_block ( node, & block, i) ;
74
+ block = Block {
75
+ header : BlockHeader { version : 0x20000000 , prev_blockhash : block. header . block_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ,
76
+ txdata : vec ! [ ] ,
77
+ } ;
78
+ }
79
+
80
+ for _ in 0 ..* node. network_chan_count . borrow ( ) { // Make sure we don't end up with channels at the same short id by offsetting by chan_count
81
+ block. txdata . push ( Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ) ;
82
+ }
83
+ block. txdata . push ( tx. clone ( ) ) ;
84
+ connect_block ( node, & block, conf_height) ;
85
+ for i in 1 ..CHAN_CONFIRM_DEPTH {
86
+ block = Block {
87
+ header : BlockHeader { version : 0x20000000 , prev_blockhash : block. header . block_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ,
88
+ txdata : vec ! [ ] ,
89
+ } ;
90
+ connect_block ( node, & block, i + conf_height) ;
64
91
}
65
92
}
66
93
@@ -85,14 +112,14 @@ pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block,
85
112
node. chain_monitor . chain_monitor . block_connected ( & block. header , & txdata, height) ;
86
113
node. node . block_connected ( & block. header , & txdata, height) ;
87
114
node. node . test_process_background_events ( ) ;
88
- * node. last_block_hash . lock ( ) . unwrap ( ) = block. header . block_hash ( ) ;
115
+ * node. last_block . lock ( ) . unwrap ( ) = ( block. header . block_hash ( ) , height ) ;
89
116
}
90
117
91
118
pub fn disconnect_block < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , header : & BlockHeader , height : u32 ) {
92
119
node. chain_monitor . chain_monitor . block_disconnected ( header, height) ;
93
120
node. node . block_disconnected ( header) ;
94
121
node. node . test_process_background_events ( ) ;
95
- * node. last_block_hash . lock ( ) . unwrap ( ) = header. prev_blockhash ;
122
+ * node. last_block . lock ( ) . unwrap ( ) = ( header. prev_blockhash , height - 1 ) ;
96
123
}
97
124
98
125
pub struct TestChanMonCfg {
@@ -125,7 +152,7 @@ pub struct Node<'a, 'b: 'a, 'c: 'b> {
125
152
pub network_payment_count : Rc < RefCell < u8 > > ,
126
153
pub network_chan_count : Rc < RefCell < u32 > > ,
127
154
pub logger : & ' c test_utils:: TestLogger ,
128
- pub last_block_hash : Mutex < BlockHash > ,
155
+ pub last_block : Mutex < ( BlockHash , u32 ) > ,
129
156
}
130
157
131
158
impl < ' a , ' b , ' c > Drop for Node < ' a , ' b , ' c > {
@@ -419,8 +446,8 @@ pub fn create_chan_between_nodes_with_value_init<'a, 'b, 'c>(node_a: &Node<'a, '
419
446
tx
420
447
}
421
448
422
- pub fn create_chan_between_nodes_with_value_confirm_first < ' a , ' b , ' c , ' d > ( node_recv : & ' a Node < ' b , ' c , ' c > , node_conf : & ' a Node < ' b , ' c , ' d > , tx : & Transaction ) {
423
- confirm_transaction ( node_conf, tx) ;
449
+ pub fn create_chan_between_nodes_with_value_confirm_first < ' a , ' b , ' c , ' d > ( node_recv : & ' a Node < ' b , ' c , ' c > , node_conf : & ' a Node < ' b , ' c , ' d > , tx : & Transaction , conf_height : u32 ) {
450
+ confirm_transaction_at ( node_conf, tx, conf_height ) ;
424
451
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( ) ) ) ;
425
452
}
426
453
@@ -445,8 +472,9 @@ pub fn create_chan_between_nodes_with_value_confirm_second<'a, 'b, 'c>(node_recv
445
472
}
446
473
447
474
pub fn create_chan_between_nodes_with_value_confirm < ' a , ' b , ' c , ' d > ( node_a : & ' a Node < ' b , ' c , ' d > , node_b : & ' a Node < ' b , ' c , ' d > , tx : & Transaction ) -> ( ( msgs:: FundingLocked , msgs:: AnnouncementSignatures ) , [ u8 ; 32 ] ) {
448
- create_chan_between_nodes_with_value_confirm_first ( node_a, node_b, tx) ;
449
- confirm_transaction ( node_a, tx) ;
475
+ let conf_height = std:: cmp:: max ( node_a. last_block . lock ( ) . unwrap ( ) . 1 + 1 , node_b. last_block . lock ( ) . unwrap ( ) . 1 + 1 ) ;
476
+ create_chan_between_nodes_with_value_confirm_first ( node_a, node_b, tx, conf_height) ;
477
+ confirm_transaction_at ( node_a, tx, conf_height) ;
450
478
create_chan_between_nodes_with_value_confirm_second ( node_b, node_a)
451
479
}
452
480
@@ -1023,7 +1051,7 @@ pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
1023
1051
claim_payment_along_route ( origin_node, expected_route, false , our_payment_preimage, expected_amount) ;
1024
1052
}
1025
1053
1026
- pub const TEST_FINAL_CLTV : u32 = 32 ;
1054
+ pub const TEST_FINAL_CLTV : u32 = 100 ;
1027
1055
1028
1056
pub fn route_payment < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_route : & [ & Node < ' a , ' b , ' c > ] , recv_value : u64 ) -> ( PaymentPreimage , PaymentHash ) {
1029
1057
let net_graph_msg_handler = & origin_node. net_graph_msg_handler ;
@@ -1192,14 +1220,15 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
1192
1220
keys_manager : & cfgs[ i] . keys_manager , node : & chan_mgrs[ i] , net_graph_msg_handler,
1193
1221
node_seed : cfgs[ i] . node_seed , network_chan_count : chan_count. clone ( ) ,
1194
1222
network_payment_count : payment_count. clone ( ) , logger : cfgs[ i] . logger ,
1195
- last_block_hash : Mutex :: new ( genesis_block ( Network :: Testnet ) . header . block_hash ( ) ) ,
1223
+ last_block : Mutex :: new ( ( genesis_block ( Network :: Testnet ) . header . block_hash ( ) , 0 ) ) ,
1196
1224
} )
1197
1225
}
1198
1226
1199
1227
nodes
1200
1228
}
1201
1229
1202
- pub const ACCEPTED_HTLC_SCRIPT_WEIGHT : usize = 138 ; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
1230
+ // Note that the following only works for CLTV values up to 128
1231
+ pub const ACCEPTED_HTLC_SCRIPT_WEIGHT : usize = 137 ; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
1203
1232
pub const OFFERED_HTLC_SCRIPT_WEIGHT : usize = 133 ;
1204
1233
1205
1234
#[ derive( PartialEq ) ]
0 commit comments