@@ -410,17 +410,6 @@ pub enum UpdateFulfillCommitFetch {
410
410
DuplicateClaim { } ,
411
411
}
412
412
413
- /// The return value of `revoke_and_ack` on success, primarily updates to other channels or HTLC
414
- /// state.
415
- pub ( super ) struct RAAUpdates {
416
- pub commitment_update : Option < msgs:: CommitmentUpdate > ,
417
- pub accepted_htlcs : Vec < ( PendingHTLCInfo , u64 ) > ,
418
- pub failed_htlcs : Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > ,
419
- pub finalized_claimed_htlcs : Vec < HTLCSource > ,
420
- pub monitor_update : ChannelMonitorUpdate ,
421
- pub holding_cell_failed_htlcs : Vec < ( HTLCSource , PaymentHash ) > ,
422
- }
423
-
424
413
/// The return value of `monitor_updating_restored`
425
414
pub ( super ) struct MonitorRestoreUpdates {
426
415
pub raa : Option < msgs:: RevokeAndACK > ,
@@ -3003,17 +2992,17 @@ impl<Signer: Sign> Channel<Signer> {
3003
2992
Ok ( ( ) )
3004
2993
}
3005
2994
3006
- pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < ( msgs :: RevokeAndACK , Option < msgs :: CommitmentSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
2995
+ pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < & ChannelMonitorUpdate , ChannelError >
3007
2996
where L :: Target : Logger
3008
2997
{
3009
2998
if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
3010
- return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ) ;
2999
+ return Err ( ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ;
3011
3000
}
3012
3001
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
3013
- return Err ( ( None , ChannelError :: Close ( "Peer sent commitment_signed when we needed a channel_reestablish" . to_owned ( ) ) ) ) ;
3002
+ return Err ( ChannelError :: Close ( "Peer sent commitment_signed when we needed a channel_reestablish" . to_owned ( ) ) ) ;
3014
3003
}
3015
3004
if self . channel_state & BOTH_SIDES_SHUTDOWN_MASK == BOTH_SIDES_SHUTDOWN_MASK && self . last_sent_closing_fee . is_some ( ) {
3016
- return Err ( ( None , ChannelError :: Close ( "Peer sent commitment_signed after we'd started exchanging closing_signeds" . to_owned ( ) ) ) ) ;
3005
+ return Err ( ChannelError :: Close ( "Peer sent commitment_signed after we'd started exchanging closing_signeds" . to_owned ( ) ) ) ;
3017
3006
}
3018
3007
3019
3008
let funding_script = self . get_funding_redeemscript ( ) ;
@@ -3031,7 +3020,7 @@ impl<Signer: Sign> Channel<Signer> {
3031
3020
log_bytes!( self . counterparty_funding_pubkey( ) . serialize( ) ) , encode:: serialize_hex( & bitcoin_tx. transaction) ,
3032
3021
log_bytes!( sighash[ ..] ) , encode:: serialize_hex( & funding_script) , log_bytes!( self . channel_id( ) ) ) ;
3033
3022
if let Err ( _) = self . secp_ctx . verify_ecdsa ( & sighash, & msg. signature , & self . counterparty_funding_pubkey ( ) ) {
3034
- return Err ( ( None , ChannelError :: Close ( "Invalid commitment tx signature from peer" . to_owned ( ) ) ) ) ;
3023
+ return Err ( ChannelError :: Close ( "Invalid commitment tx signature from peer" . to_owned ( ) ) ) ;
3035
3024
}
3036
3025
bitcoin_tx. txid
3037
3026
} ;
@@ -3046,7 +3035,7 @@ impl<Signer: Sign> Channel<Signer> {
3046
3035
debug_assert ! ( !self . is_outbound( ) ) ;
3047
3036
let counterparty_reserve_we_require_msat = self . holder_selected_channel_reserve_satoshis * 1000 ;
3048
3037
if commitment_stats. remote_balance_msat < commitment_stats. total_fee_sat * 1000 + counterparty_reserve_we_require_msat {
3049
- return Err ( ( None , ChannelError :: Close ( "Funding remote cannot afford proposed new fee" . to_owned ( ) ) ) ) ;
3038
+ return Err ( ChannelError :: Close ( "Funding remote cannot afford proposed new fee" . to_owned ( ) ) ) ;
3050
3039
}
3051
3040
}
3052
3041
#[ cfg( any( test, fuzzing) ) ]
@@ -3068,7 +3057,7 @@ impl<Signer: Sign> Channel<Signer> {
3068
3057
}
3069
3058
3070
3059
if msg. htlc_signatures . len ( ) != commitment_stats. num_nondust_htlcs {
3071
- return Err ( ( None , ChannelError :: Close ( format ! ( "Got wrong number of HTLC signatures ({}) from remote. It must be {}" , msg. htlc_signatures. len( ) , commitment_stats. num_nondust_htlcs) ) ) ) ;
3060
+ return Err ( ChannelError :: Close ( format ! ( "Got wrong number of HTLC signatures ({}) from remote. It must be {}" , msg. htlc_signatures. len( ) , commitment_stats. num_nondust_htlcs) ) ) ;
3072
3061
}
3073
3062
3074
3063
// TODO: Sadly, we pass HTLCs twice to ChannelMonitor: once via the HolderCommitmentTransaction and once via the update
@@ -3086,7 +3075,7 @@ impl<Signer: Sign> Channel<Signer> {
3086
3075
log_bytes!( msg. htlc_signatures[ idx] . serialize_compact( ) [ ..] ) , log_bytes!( keys. countersignatory_htlc_key. serialize( ) ) ,
3087
3076
encode:: serialize_hex( & htlc_tx) , log_bytes!( htlc_sighash[ ..] ) , encode:: serialize_hex( & htlc_redeemscript) , log_bytes!( self . channel_id( ) ) ) ;
3088
3077
if let Err ( _) = self . secp_ctx . verify_ecdsa ( & htlc_sighash, & msg. htlc_signatures [ idx] , & keys. countersignatory_htlc_key ) {
3089
- return Err ( ( None , ChannelError :: Close ( "Invalid HTLC tx signature from peer" . to_owned ( ) ) ) ) ;
3078
+ return Err ( ChannelError :: Close ( "Invalid HTLC tx signature from peer" . to_owned ( ) ) ) ;
3090
3079
}
3091
3080
htlcs_and_sigs. push ( ( htlc, Some ( msg. htlc_signatures [ idx] ) , source) ) ;
3092
3081
} else {
@@ -3102,10 +3091,8 @@ impl<Signer: Sign> Channel<Signer> {
3102
3091
self . counterparty_funding_pubkey ( )
3103
3092
) ;
3104
3093
3105
- let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number - 1 , & self . secp_ctx ) ;
3106
3094
self . holder_signer . validate_holder_commitment ( & holder_commitment_tx, commitment_stats. preimages )
3107
- . map_err ( |_| ( None , ChannelError :: Close ( "Failed to validate our commitment" . to_owned ( ) ) ) ) ?;
3108
- let per_commitment_secret = self . holder_signer . release_commitment_secret ( self . cur_holder_commitment_transaction_number + 1 ) ;
3095
+ . map_err ( |_| ChannelError :: Close ( "Failed to validate our commitment" . to_owned ( ) ) ) ?;
3109
3096
3110
3097
// Update state now that we've passed all the can-fail calls...
3111
3098
let mut need_commitment = false ;
@@ -3150,7 +3137,7 @@ impl<Signer: Sign> Channel<Signer> {
3150
3137
3151
3138
self . cur_holder_commitment_transaction_number -= 1 ;
3152
3139
// Note that if we need_commitment & !AwaitingRemoteRevoke we'll call
3153
- // send_commitment_no_status_check () next which will reset this to RAAFirst.
3140
+ // build_commitment_no_status_check () next which will reset this to RAAFirst.
3154
3141
self . resend_order = RAACommitmentOrder :: CommitmentFirst ;
3155
3142
3156
3143
if ( self . channel_state & ChannelState :: MonitorUpdateInProgress as u32 ) != 0 {
@@ -3162,37 +3149,35 @@ impl<Signer: Sign> Channel<Signer> {
3162
3149
// the corresponding HTLC status updates so that get_last_commitment_update
3163
3150
// includes the right HTLCs.
3164
3151
self . monitor_pending_commitment_signed = true ;
3165
- let ( _ , mut additional_update) = self . send_commitment_no_status_check ( logger) . map_err ( |e| ( None , e ) ) ? ;
3166
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3152
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3153
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3167
3154
// strictly increasing by one, so decrement it here.
3168
3155
self . latest_monitor_update_id = monitor_update. update_id ;
3169
3156
monitor_update. updates . append ( & mut additional_update. updates ) ;
3170
3157
}
3171
3158
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updated HTLC state but awaiting a monitor update resolution to reply." ,
3172
3159
log_bytes!( self . channel_id) ) ;
3173
- return Err ( ( Some ( monitor_update) , ChannelError :: Ignore ( "Previous monitor update failure prevented generation of RAA" . to_owned ( ) ) ) ) ;
3160
+ self . pending_monitor_updates . push ( monitor_update) ;
3161
+ return Ok ( self . pending_monitor_updates . last ( ) . unwrap ( ) ) ;
3174
3162
}
3175
3163
3176
- let commitment_signed = if need_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
3164
+ let need_commitment_signed = if need_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
3177
3165
// If we're AwaitingRemoteRevoke we can't send a new commitment here, but that's ok -
3178
3166
// we'll send one right away when we get the revoke_and_ack when we
3179
3167
// free_holding_cell_htlcs().
3180
- let ( msg , mut additional_update) = self . send_commitment_no_status_check ( logger) . map_err ( |e| ( None , e ) ) ? ;
3181
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3168
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3169
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3182
3170
// strictly increasing by one, so decrement it here.
3183
3171
self . latest_monitor_update_id = monitor_update. update_id ;
3184
3172
monitor_update. updates . append ( & mut additional_update. updates ) ;
3185
- Some ( msg )
3186
- } else { None } ;
3173
+ true
3174
+ } else { false } ;
3187
3175
3188
3176
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updating HTLC state and responding with{} a revoke_and_ack." ,
3189
- log_bytes!( self . channel_id( ) ) , if commitment_signed. is_some( ) { " our own commitment_signed and" } else { "" } ) ;
3190
-
3191
- Ok ( ( msgs:: RevokeAndACK {
3192
- channel_id : self . channel_id ,
3193
- per_commitment_secret,
3194
- next_per_commitment_point,
3195
- } , commitment_signed, monitor_update) )
3177
+ log_bytes!( self . channel_id( ) ) , if need_commitment_signed { " our own commitment_signed and" } else { "" } ) ;
3178
+ self . pending_monitor_updates . push ( monitor_update) ;
3179
+ self . monitor_updating_paused ( true , need_commitment_signed, false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
3180
+ return Ok ( self . pending_monitor_updates . last ( ) . unwrap ( ) ) ;
3196
3181
}
3197
3182
3198
3183
/// Public version of the below, checking relevant preconditions first.
@@ -3324,7 +3309,7 @@ impl<Signer: Sign> Channel<Signer> {
3324
3309
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
3325
3310
/// generating an appropriate error *after* the channel state has been updated based on the
3326
3311
/// revoke_and_ack message.
3327
- pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < RAAUpdates , ChannelError >
3312
+ pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < ( Vec < ( HTLCSource , PaymentHash ) > , & ChannelMonitorUpdate ) , ChannelError >
3328
3313
where L :: Target : Logger ,
3329
3314
{
3330
3315
if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
@@ -3511,8 +3496,8 @@ impl<Signer: Sign> Channel<Signer> {
3511
3496
// When the monitor updating is restored we'll call get_last_commitment_update(),
3512
3497
// which does not update state, but we're definitely now awaiting a remote revoke
3513
3498
// before we can step forward any more, so set it here.
3514
- let ( _ , mut additional_update) = self . send_commitment_no_status_check ( logger) ? ;
3515
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3499
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3500
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3516
3501
// strictly increasing by one, so decrement it here.
3517
3502
self . latest_monitor_update_id = monitor_update. update_id ;
3518
3503
monitor_update. updates . append ( & mut additional_update. updates ) ;
@@ -3521,12 +3506,8 @@ impl<Signer: Sign> Channel<Signer> {
3521
3506
self . monitor_pending_failures . append ( & mut revoked_htlcs) ;
3522
3507
self . monitor_pending_finalized_fulfills . append ( & mut finalized_claimed_htlcs) ;
3523
3508
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply." , log_bytes!( self . channel_id( ) ) ) ;
3524
- return Ok ( RAAUpdates {
3525
- commitment_update : None , finalized_claimed_htlcs : Vec :: new ( ) ,
3526
- accepted_htlcs : Vec :: new ( ) , failed_htlcs : Vec :: new ( ) ,
3527
- monitor_update,
3528
- holding_cell_failed_htlcs : Vec :: new ( )
3529
- } ) ;
3509
+ self . pending_monitor_updates . push ( monitor_update) ;
3510
+ return Ok ( ( Vec :: new ( ) , self . pending_monitor_updates . last ( ) . unwrap ( ) ) ) ;
3530
3511
}
3531
3512
3532
3513
match self . free_holding_cell_htlcs ( logger) ? {
@@ -3545,47 +3526,29 @@ impl<Signer: Sign> Channel<Signer> {
3545
3526
self . latest_monitor_update_id = monitor_update. update_id ;
3546
3527
monitor_update. updates . append ( & mut additional_update. updates ) ;
3547
3528
3548
- Ok ( RAAUpdates {
3549
- commitment_update : Some ( commitment_update) ,
3550
- finalized_claimed_htlcs,
3551
- accepted_htlcs : to_forward_infos,
3552
- failed_htlcs : revoked_htlcs,
3553
- monitor_update,
3554
- holding_cell_failed_htlcs : htlcs_to_fail
3555
- } )
3529
+ self . monitor_updating_paused ( false , true , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3530
+ self . pending_monitor_updates . push ( monitor_update) ;
3531
+ Ok ( ( htlcs_to_fail, self . pending_monitor_updates . last ( ) . unwrap ( ) ) )
3556
3532
} ,
3557
3533
( None , htlcs_to_fail) => {
3558
3534
if require_commitment {
3559
- let ( commitment_signed , mut additional_update) = self . send_commitment_no_status_check ( logger) ? ;
3535
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3560
3536
3561
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3537
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3562
3538
// strictly increasing by one, so decrement it here.
3563
3539
self . latest_monitor_update_id = monitor_update. update_id ;
3564
3540
monitor_update. updates . append ( & mut additional_update. updates ) ;
3565
3541
3566
3542
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {}. Responding with a commitment update with {} HTLCs failed." ,
3567
3543
log_bytes!( self . channel_id( ) ) , update_fail_htlcs. len( ) + update_fail_malformed_htlcs. len( ) ) ;
3568
- Ok ( RAAUpdates {
3569
- commitment_update : Some ( msgs:: CommitmentUpdate {
3570
- update_add_htlcs : Vec :: new ( ) ,
3571
- update_fulfill_htlcs : Vec :: new ( ) ,
3572
- update_fail_htlcs,
3573
- update_fail_malformed_htlcs,
3574
- update_fee : None ,
3575
- commitment_signed
3576
- } ) ,
3577
- finalized_claimed_htlcs,
3578
- accepted_htlcs : to_forward_infos, failed_htlcs : revoked_htlcs,
3579
- monitor_update, holding_cell_failed_htlcs : htlcs_to_fail
3580
- } )
3544
+ self . monitor_updating_paused ( false , true , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3545
+ self . pending_monitor_updates . push ( monitor_update) ;
3546
+ Ok ( ( htlcs_to_fail, self . pending_monitor_updates . last ( ) . unwrap ( ) ) )
3581
3547
} else {
3582
3548
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} with no reply necessary." , log_bytes!( self . channel_id( ) ) ) ;
3583
- Ok ( RAAUpdates {
3584
- commitment_update : None ,
3585
- finalized_claimed_htlcs,
3586
- accepted_htlcs : to_forward_infos, failed_htlcs : revoked_htlcs,
3587
- monitor_update, holding_cell_failed_htlcs : htlcs_to_fail
3588
- } )
3549
+ self . monitor_updating_paused ( false , false , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3550
+ self . pending_monitor_updates . push ( monitor_update) ;
3551
+ Ok ( ( htlcs_to_fail, self . pending_monitor_updates . last ( ) . unwrap ( ) ) )
3589
3552
}
3590
3553
}
3591
3554
}
@@ -3765,6 +3728,7 @@ impl<Signer: Sign> Channel<Signer> {
3765
3728
pub fn monitor_updating_restored < L : Deref > ( & mut self , logger : & L , node_pk : PublicKey , genesis_block_hash : BlockHash , user_config : & UserConfig , best_block_height : u32 ) -> MonitorRestoreUpdates where L :: Target : Logger {
3766
3729
assert_eq ! ( self . channel_state & ChannelState :: MonitorUpdateInProgress as u32 , ChannelState :: MonitorUpdateInProgress as u32 ) ;
3767
3730
self . channel_state &= !( ChannelState :: MonitorUpdateInProgress as u32 ) ;
3731
+ self . pending_monitor_updates . clear ( ) ;
3768
3732
3769
3733
// If we're past (or at) the FundingSent stage on an outbound channel, try to
3770
3734
// (re-)broadcast the funding transaction as we may have declined to broadcast it when we
0 commit comments