@@ -27,7 +27,7 @@ use bitcoin::hashes::hmac::{Hmac, HmacEngine};
27
27
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
28
28
use bitcoin:: hashes:: sha256d:: Hash as Sha256dHash ;
29
29
use bitcoin:: hashes:: cmp:: fixed_time_eq;
30
- use bitcoin:: hash_types:: BlockHash ;
30
+ use bitcoin:: hash_types:: { BlockHash , Txid } ;
31
31
32
32
use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
33
33
use bitcoin:: secp256k1:: Secp256k1 ;
@@ -3314,7 +3314,7 @@ where
3314
3314
"Blocks must be disconnected in chain-order - the disconnected block must have the correct height" ) ;
3315
3315
* self . last_block_hash . write ( ) . unwrap ( ) = header. prev_blockhash ;
3316
3316
3317
- self . do_chain_event ( new_height, |channel| channel. update_best_block ( new_height, header. time ) ) ;
3317
+ self . do_chain_event ( Some ( new_height) , |channel| channel. update_best_block ( new_height, header. time ) ) ;
3318
3318
}
3319
3319
}
3320
3320
@@ -3326,7 +3326,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3326
3326
L :: Target : Logger ,
3327
3327
{
3328
3328
fn do_chain_event < FN : Fn ( & mut Channel < Signer > ) -> Result < ( Option < msgs:: FundingLocked > , Vec < ( HTLCSource , PaymentHash ) > ) , msgs:: ErrorMessage > >
3329
- ( & self , height : u32 , f : FN ) {
3329
+ ( & self , height_opt : Option < u32 > , f : FN ) {
3330
3330
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
3331
3331
// during initialization prior to the chain_monitor being fully configured in some cases.
3332
3332
// See the docs for `ChannelManagerReadArgs` for more.
@@ -3385,24 +3385,26 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3385
3385
true
3386
3386
} ) ;
3387
3387
3388
- channel_state. claimable_htlcs . retain ( |& ( ref payment_hash, _) , htlcs| {
3389
- htlcs. retain ( |htlc| {
3390
- // If height is approaching the number of blocks we think it takes us to get
3391
- // our commitment transaction confirmed before the HTLC expires, plus the
3392
- // number of blocks we generally consider it to take to do a commitment update,
3393
- // just give up on it and fail the HTLC.
3394
- if height >= htlc. cltv_expiry - HTLC_FAIL_BACK_BUFFER {
3395
- let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3396
- htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array ( height) ) ;
3397
- timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) , HTLCFailReason :: Reason {
3398
- failure_code : 0x4000 | 15 ,
3399
- data : htlc_msat_height_data
3400
- } ) ) ;
3401
- false
3402
- } else { true }
3388
+ if let Some ( height) = height_opt {
3389
+ channel_state. claimable_htlcs . retain ( |& ( ref payment_hash, _) , htlcs| {
3390
+ htlcs. retain ( |htlc| {
3391
+ // If height is approaching the number of blocks we think it takes us to get
3392
+ // our commitment transaction confirmed before the HTLC expires, plus the
3393
+ // number of blocks we generally consider it to take to do a commitment update,
3394
+ // just give up on it and fail the HTLC.
3395
+ if height >= htlc. cltv_expiry - HTLC_FAIL_BACK_BUFFER {
3396
+ let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3397
+ htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array ( height) ) ;
3398
+ timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) , HTLCFailReason :: Reason {
3399
+ failure_code : 0x4000 | 15 ,
3400
+ data : htlc_msat_height_data
3401
+ } ) ) ;
3402
+ false
3403
+ } else { true }
3404
+ } ) ;
3405
+ !htlcs. is_empty ( ) // Only retain this entry if htlcs has at least one entry.
3403
3406
} ) ;
3404
- !htlcs. is_empty ( ) // Only retain this entry if htlcs has at least one entry.
3405
- } ) ;
3407
+ }
3406
3408
}
3407
3409
3408
3410
self . handle_init_event_channel_failures ( failed_channels) ;
@@ -3438,7 +3440,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3438
3440
log_trace ! ( self . logger, "{} transactions included in block {} at height {} provided" , txdata. len( ) , block_hash, height) ;
3439
3441
3440
3442
let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
3441
- self . do_chain_event ( height, |channel| channel. transactions_confirmed ( & block_hash, height, txdata, & self . logger ) . map ( |a| ( a, Vec :: new ( ) ) ) ) ;
3443
+ self . do_chain_event ( Some ( height) , |channel| channel. transactions_confirmed ( & block_hash, height, txdata, & self . logger ) . map ( |a| ( a, Vec :: new ( ) ) ) ) ;
3442
3444
}
3443
3445
3444
3446
/// Updates channel state with the current best blockchain tip. You should attempt to call this
@@ -3467,7 +3469,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3467
3469
self . latest_block_height . store ( height as usize , Ordering :: Release ) ;
3468
3470
* self . last_block_hash . write ( ) . unwrap ( ) = block_hash;
3469
3471
3470
- self . do_chain_event ( height, |channel| channel. update_best_block ( height, header. time ) ) ;
3472
+ self . do_chain_event ( Some ( height) , |channel| channel. update_best_block ( height, header. time ) ) ;
3471
3473
3472
3474
loop {
3473
3475
// Update last_node_announcement_serial to be the max of its current value and the
@@ -3483,6 +3485,30 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3483
3485
}
3484
3486
}
3485
3487
3488
+ /// Gets the set of txids which should be monitored for their confirmation state. XXX: Docs
3489
+ pub fn get_relevant_txids ( & self ) -> Vec < Txid > {
3490
+ let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3491
+ let mut res = Vec :: with_capacity ( channel_state. short_to_id . len ( ) ) ;
3492
+ for chan in channel_state. by_id . values ( ) {
3493
+ if let Some ( funding_txo) = chan. get_funding_txo ( ) {
3494
+ res. push ( funding_txo. txid ) ;
3495
+ }
3496
+ }
3497
+ res
3498
+ }
3499
+
3500
+ /// Marks a transaction as having been reorganized out of the blockchain XXX: Docs
3501
+ pub fn transaction_unconfirmed ( & self , txid : & Txid ) {
3502
+ let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
3503
+ self . do_chain_event ( None , |channel| {
3504
+ if let Some ( funding_txo) = channel. get_funding_txo ( ) {
3505
+ if funding_txo. txid == * txid {
3506
+ channel. funding_transaction_unconfirmed ( ) . map ( |_| ( None , Vec :: new ( ) ) )
3507
+ } else { Ok ( ( None , Vec :: new ( ) ) ) }
3508
+ } else { Ok ( ( None , Vec :: new ( ) ) ) }
3509
+ } ) ;
3510
+ }
3511
+
3486
3512
/// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
3487
3513
/// indicating whether persistence is necessary. Only one listener on
3488
3514
/// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
0 commit comments