@@ -17,7 +17,7 @@ use crate::chain::transaction::OutPoint;
17
17
use crate :: events:: { ClaimedHTLC , ClosureReason , Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider , PathFailure , PaymentPurpose , PaymentFailureReason } ;
18
18
use crate :: events:: bump_transaction:: { BumpTransactionEventHandler , Wallet , WalletSource } ;
19
19
use crate :: ln:: { ChannelId , PaymentPreimage , PaymentHash , PaymentSecret } ;
20
- use crate :: ln:: channelmanager:: { self , AChannelManager , ChainParameters , ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure , RecipientOnionFields , PaymentId , MIN_CLTV_EXPIRY_DELTA } ;
20
+ use crate :: ln:: channelmanager:: { AChannelManager , ChainParameters , ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure , RecipientOnionFields , PaymentId , MIN_CLTV_EXPIRY_DELTA } ;
21
21
use crate :: routing:: gossip:: { P2PGossipSync , NetworkGraph , NetworkUpdate } ;
22
22
use crate :: routing:: router:: { self , PaymentParameters , Route } ;
23
23
use crate :: ln:: features:: InitFeatures ;
@@ -73,6 +73,20 @@ pub fn mine_transactions<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, txn: &[&Tra
73
73
let height = node. best_block_info ( ) . 1 + 1 ;
74
74
confirm_transactions_at ( node, txn, height) ;
75
75
}
76
+ /// Mine a single block containing the given transaction without extra consistency checks which may
77
+ /// impact ChannelManager state.
78
+ pub fn mine_transaction_without_consistency_checks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , tx : & Transaction ) {
79
+ let height = node. best_block_info ( ) . 1 + 1 ;
80
+ let mut block = Block {
81
+ header : BlockHeader { version : 0x20000000 , prev_blockhash : node. best_block_hash ( ) , merkle_root : TxMerkleNode :: all_zeros ( ) , time : height, bits : 42 , nonce : 42 } ,
82
+ txdata : Vec :: new ( ) ,
83
+ } ;
84
+ 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
85
+ block. txdata . push ( Transaction { version : 0 , lock_time : PackedLockTime :: ZERO , input : Vec :: new ( ) , output : Vec :: new ( ) } ) ;
86
+ }
87
+ block. txdata . push ( ( * tx) . clone ( ) ) ;
88
+ do_connect_block_without_consistency_checks ( node, block, false ) ;
89
+ }
76
90
/// Mine the given transaction at the given height, mining blocks as required to build to that
77
91
/// height
78
92
///
@@ -211,16 +225,16 @@ pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) ->
211
225
assert ! ( depth >= 1 ) ;
212
226
for i in 1 ..depth {
213
227
let prev_blockhash = block. header . block_hash ( ) ;
214
- do_connect_block ( node, block, skip_intermediaries) ;
228
+ do_connect_block_with_consistency_checks ( node, block, skip_intermediaries) ;
215
229
block = create_dummy_block ( prev_blockhash, height + i, Vec :: new ( ) ) ;
216
230
}
217
231
let hash = block. header . block_hash ( ) ;
218
- do_connect_block ( node, block, false ) ;
232
+ do_connect_block_with_consistency_checks ( node, block, false ) ;
219
233
hash
220
234
}
221
235
222
236
pub fn connect_block < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , block : & Block ) {
223
- do_connect_block ( node, block. clone ( ) , false ) ;
237
+ do_connect_block_with_consistency_checks ( node, block. clone ( ) , false ) ;
224
238
}
225
239
226
240
fn call_claimable_balances < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > ) {
@@ -230,8 +244,14 @@ fn call_claimable_balances<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>) {
230
244
}
231
245
}
232
246
233
- fn do_connect_block < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , block : Block , skip_intermediaries : bool ) {
247
+ fn do_connect_block_with_consistency_checks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , block : Block , skip_intermediaries : bool ) {
248
+ call_claimable_balances ( node) ;
249
+ do_connect_block_without_consistency_checks ( node, block, skip_intermediaries) ;
234
250
call_claimable_balances ( node) ;
251
+ node. node . test_process_background_events ( ) ;
252
+ }
253
+
254
+ fn do_connect_block_without_consistency_checks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , block : Block , skip_intermediaries : bool ) {
235
255
let height = node. best_block_info ( ) . 1 + 1 ;
236
256
#[ cfg( feature = "std" ) ] {
237
257
eprintln ! ( "Connecting block using Block Connection Style: {:?}" , * node. connect_style. borrow( ) ) ;
@@ -286,8 +306,6 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
286
306
}
287
307
}
288
308
}
289
- call_claimable_balances ( node) ;
290
- node. node . test_process_background_events ( ) ;
291
309
292
310
for tx in & block. txdata {
293
311
for input in & tx. input {
0 commit comments