@@ -3477,7 +3477,11 @@ impl<Signer: Sign> Channel<Signer> {
3477
3477
self . network_sync == UpdateStatus :: DisabledMarked
3478
3478
}
3479
3479
3480
- pub fn transactions_confirmed ( & mut self , block_hash : & BlockHash , height : u32 , txdata : & TransactionData ) -> Result < ( ) , msgs:: ErrorMessage > {
3480
+ /// When a transaction is confirmed, we check whether it is or spends the funding transaction
3481
+ /// In the first case, we store the confirmation height and calculating the short channel id.
3482
+ /// In the second, we simply return an Err indicating we need to be force-closed now.
3483
+ pub fn transactions_confirmed < L : Deref > ( & mut self , block_hash : & BlockHash , height : u32 , txdata : & TransactionData , logger : & L )
3484
+ -> Result < ( ) , msgs:: ErrorMessage > where L :: Target : Logger {
3481
3485
let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
3482
3486
if non_shutdown_state & !( ChannelState :: TheirFundingLocked as u32 ) == ChannelState :: FundingSent as u32 {
3483
3487
for & ( index_in_block, tx) in txdata. iter ( ) {
@@ -3523,6 +3527,15 @@ impl<Signer: Sign> Channel<Signer> {
3523
3527
( ( txo_idx as u64 ) << ( 0 * 8 ) ) ) ;
3524
3528
}
3525
3529
}
3530
+ for inp in tx. input . iter ( ) {
3531
+ if inp. previous_output == funding_txo. into_bitcoin_outpoint ( ) {
3532
+ log_trace ! ( logger, "Detected channel-closing tx {} spending {}:{}, closing channel {}" , tx. txid( ) , inp. previous_output. txid, inp. previous_output. vout, log_bytes!( self . channel_id( ) ) ) ;
3533
+ return Err ( msgs:: ErrorMessage {
3534
+ channel_id : self . channel_id ( ) ,
3535
+ data : "Commitment transaction was confirmed on chain." . to_owned ( )
3536
+ } ) ;
3537
+ }
3538
+ }
3526
3539
}
3527
3540
}
3528
3541
Ok ( ( ) )
@@ -3612,25 +3625,6 @@ impl<Signer: Sign> Channel<Signer> {
3612
3625
Ok ( ( None , timed_out_htlcs) )
3613
3626
}
3614
3627
3615
- /// When we receive a new block, we (a) check whether the block contains the funding
3616
- /// transaction (which would start us counting blocks until we send the funding_signed), and
3617
- /// (b) check the height of the block against outbound holding cell HTLCs in case we need to
3618
- /// give up on them prematurely and time them out. Everything else (e.g. commitment
3619
- /// transaction broadcasts, channel closure detection, HTLC transaction broadcasting, etc) is
3620
- /// handled by the ChannelMonitor.
3621
- ///
3622
- /// If we return Err, the channel may have been closed, at which point the standard
3623
- /// requirements apply - no calls may be made except those explicitly stated to be allowed
3624
- /// post-shutdown.
3625
- /// Only returns an ErrorAction of DisconnectPeer, if Err.
3626
- ///
3627
- /// May return some HTLCs (and their payment_hash) which have timed out and should be failed
3628
- /// back.
3629
- pub fn block_connected ( & mut self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) -> Result < ( Option < msgs:: FundingLocked > , Vec < ( HTLCSource , PaymentHash ) > ) , msgs:: ErrorMessage > {
3630
- self . transactions_confirmed ( & header. block_hash ( ) , height, txdata) ?;
3631
- self . update_best_block ( height, header. time )
3632
- }
3633
-
3634
3628
/// Called by channelmanager based on chain blocks being disconnected.
3635
3629
/// Returns true if we need to close the channel now due to funding transaction
3636
3630
/// unconfirmation/reorg.
0 commit comments