@@ -411,17 +411,6 @@ pub enum UpdateFulfillCommitFetch {
411
411
DuplicateClaim { } ,
412
412
}
413
413
414
- /// The return value of `revoke_and_ack` on success, primarily updates to other channels or HTLC
415
- /// state.
416
- pub ( super ) struct RAAUpdates {
417
- pub commitment_update : Option < msgs:: CommitmentUpdate > ,
418
- pub accepted_htlcs : Vec < ( PendingHTLCInfo , u64 ) > ,
419
- pub failed_htlcs : Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > ,
420
- pub finalized_claimed_htlcs : Vec < HTLCSource > ,
421
- pub monitor_update : ChannelMonitorUpdate ,
422
- pub holding_cell_failed_htlcs : Vec < ( HTLCSource , PaymentHash ) > ,
423
- }
424
-
425
414
/// The return value of `monitor_updating_restored`
426
415
pub ( super ) struct MonitorRestoreUpdates {
427
416
pub raa : Option < msgs:: RevokeAndACK > ,
@@ -3049,17 +3038,17 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3049
3038
Ok ( ( ) )
3050
3039
}
3051
3040
3052
- pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < ( msgs :: RevokeAndACK , Option < msgs :: CommitmentSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
3041
+ pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < & ChannelMonitorUpdate , ChannelError >
3053
3042
where L :: Target : Logger
3054
3043
{
3055
3044
if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
3056
- return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ) ;
3045
+ return Err ( ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ;
3057
3046
}
3058
3047
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
3059
- return Err ( ( None , ChannelError :: Close ( "Peer sent commitment_signed when we needed a channel_reestablish" . to_owned ( ) ) ) ) ;
3048
+ return Err ( ChannelError :: Close ( "Peer sent commitment_signed when we needed a channel_reestablish" . to_owned ( ) ) ) ;
3060
3049
}
3061
3050
if self . channel_state & BOTH_SIDES_SHUTDOWN_MASK == BOTH_SIDES_SHUTDOWN_MASK && self . last_sent_closing_fee . is_some ( ) {
3062
- return Err ( ( None , ChannelError :: Close ( "Peer sent commitment_signed after we'd started exchanging closing_signeds" . to_owned ( ) ) ) ) ;
3051
+ return Err ( ChannelError :: Close ( "Peer sent commitment_signed after we'd started exchanging closing_signeds" . to_owned ( ) ) ) ;
3063
3052
}
3064
3053
3065
3054
let funding_script = self . get_funding_redeemscript ( ) ;
@@ -3077,7 +3066,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3077
3066
log_bytes!( self . counterparty_funding_pubkey( ) . serialize( ) ) , encode:: serialize_hex( & bitcoin_tx. transaction) ,
3078
3067
log_bytes!( sighash[ ..] ) , encode:: serialize_hex( & funding_script) , log_bytes!( self . channel_id( ) ) ) ;
3079
3068
if let Err ( _) = self . secp_ctx . verify_ecdsa ( & sighash, & msg. signature , & self . counterparty_funding_pubkey ( ) ) {
3080
- return Err ( ( None , ChannelError :: Close ( "Invalid commitment tx signature from peer" . to_owned ( ) ) ) ) ;
3069
+ return Err ( ChannelError :: Close ( "Invalid commitment tx signature from peer" . to_owned ( ) ) ) ;
3081
3070
}
3082
3071
bitcoin_tx. txid
3083
3072
} ;
@@ -3092,7 +3081,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3092
3081
debug_assert ! ( !self . is_outbound( ) ) ;
3093
3082
let counterparty_reserve_we_require_msat = self . holder_selected_channel_reserve_satoshis * 1000 ;
3094
3083
if commitment_stats. remote_balance_msat < commitment_stats. total_fee_sat * 1000 + counterparty_reserve_we_require_msat {
3095
- return Err ( ( None , ChannelError :: Close ( "Funding remote cannot afford proposed new fee" . to_owned ( ) ) ) ) ;
3084
+ return Err ( ChannelError :: Close ( "Funding remote cannot afford proposed new fee" . to_owned ( ) ) ) ;
3096
3085
}
3097
3086
}
3098
3087
#[ cfg( any( test, fuzzing) ) ]
@@ -3114,7 +3103,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3114
3103
}
3115
3104
3116
3105
if msg. htlc_signatures . len ( ) != commitment_stats. num_nondust_htlcs {
3117
- 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) ) ) ) ;
3106
+ 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) ) ) ;
3118
3107
}
3119
3108
3120
3109
// TODO: Sadly, we pass HTLCs twice to ChannelMonitor: once via the HolderCommitmentTransaction and once via the update
@@ -3132,7 +3121,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3132
3121
log_bytes!( msg. htlc_signatures[ idx] . serialize_compact( ) [ ..] ) , log_bytes!( keys. countersignatory_htlc_key. serialize( ) ) ,
3133
3122
encode:: serialize_hex( & htlc_tx) , log_bytes!( htlc_sighash[ ..] ) , encode:: serialize_hex( & htlc_redeemscript) , log_bytes!( self . channel_id( ) ) ) ;
3134
3123
if let Err ( _) = self . secp_ctx . verify_ecdsa ( & htlc_sighash, & msg. htlc_signatures [ idx] , & keys. countersignatory_htlc_key ) {
3135
- return Err ( ( None , ChannelError :: Close ( "Invalid HTLC tx signature from peer" . to_owned ( ) ) ) ) ;
3124
+ return Err ( ChannelError :: Close ( "Invalid HTLC tx signature from peer" . to_owned ( ) ) ) ;
3136
3125
}
3137
3126
htlcs_and_sigs. push ( ( htlc, Some ( msg. htlc_signatures [ idx] ) , source) ) ;
3138
3127
} else {
@@ -3148,10 +3137,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3148
3137
self . counterparty_funding_pubkey ( )
3149
3138
) ;
3150
3139
3151
- let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number - 1 , & self . secp_ctx ) ;
3152
3140
self . holder_signer . validate_holder_commitment ( & holder_commitment_tx, commitment_stats. preimages )
3153
- . map_err ( |_| ( None , ChannelError :: Close ( "Failed to validate our commitment" . to_owned ( ) ) ) ) ?;
3154
- let per_commitment_secret = self . holder_signer . release_commitment_secret ( self . cur_holder_commitment_transaction_number + 1 ) ;
3141
+ . map_err ( |_| ChannelError :: Close ( "Failed to validate our commitment" . to_owned ( ) ) ) ?;
3155
3142
3156
3143
// Update state now that we've passed all the can-fail calls...
3157
3144
let mut need_commitment = false ;
@@ -3196,7 +3183,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3196
3183
3197
3184
self . cur_holder_commitment_transaction_number -= 1 ;
3198
3185
// Note that if we need_commitment & !AwaitingRemoteRevoke we'll call
3199
- // send_commitment_no_status_check () next which will reset this to RAAFirst.
3186
+ // build_commitment_no_status_check () next which will reset this to RAAFirst.
3200
3187
self . resend_order = RAACommitmentOrder :: CommitmentFirst ;
3201
3188
3202
3189
if ( self . channel_state & ChannelState :: MonitorUpdateInProgress as u32 ) != 0 {
@@ -3208,37 +3195,35 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3208
3195
// the corresponding HTLC status updates so that get_last_commitment_update
3209
3196
// includes the right HTLCs.
3210
3197
self . monitor_pending_commitment_signed = true ;
3211
- let ( _ , mut additional_update) = self . send_commitment_no_status_check ( logger) . map_err ( |e| ( None , e ) ) ? ;
3212
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3198
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3199
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3213
3200
// strictly increasing by one, so decrement it here.
3214
3201
self . latest_monitor_update_id = monitor_update. update_id ;
3215
3202
monitor_update. updates . append ( & mut additional_update. updates ) ;
3216
3203
}
3217
3204
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updated HTLC state but awaiting a monitor update resolution to reply." ,
3218
3205
log_bytes!( self . channel_id) ) ;
3219
- return Err ( ( Some ( monitor_update) , ChannelError :: Ignore ( "Previous monitor update failure prevented generation of RAA" . to_owned ( ) ) ) ) ;
3206
+ self . pending_monitor_updates . push ( monitor_update) ;
3207
+ return Ok ( self . pending_monitor_updates . last ( ) . unwrap ( ) ) ;
3220
3208
}
3221
3209
3222
- let commitment_signed = if need_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
3210
+ let need_commitment_signed = if need_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
3223
3211
// If we're AwaitingRemoteRevoke we can't send a new commitment here, but that's ok -
3224
3212
// we'll send one right away when we get the revoke_and_ack when we
3225
3213
// free_holding_cell_htlcs().
3226
- let ( msg , mut additional_update) = self . send_commitment_no_status_check ( logger) . map_err ( |e| ( None , e ) ) ? ;
3227
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3214
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3215
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3228
3216
// strictly increasing by one, so decrement it here.
3229
3217
self . latest_monitor_update_id = monitor_update. update_id ;
3230
3218
monitor_update. updates . append ( & mut additional_update. updates ) ;
3231
- Some ( msg )
3232
- } else { None } ;
3219
+ true
3220
+ } else { false } ;
3233
3221
3234
3222
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updating HTLC state and responding with{} a revoke_and_ack." ,
3235
- log_bytes!( self . channel_id( ) ) , if commitment_signed. is_some( ) { " our own commitment_signed and" } else { "" } ) ;
3236
-
3237
- Ok ( ( msgs:: RevokeAndACK {
3238
- channel_id : self . channel_id ,
3239
- per_commitment_secret,
3240
- next_per_commitment_point,
3241
- } , commitment_signed, monitor_update) )
3223
+ log_bytes!( self . channel_id( ) ) , if need_commitment_signed { " our own commitment_signed and" } else { "" } ) ;
3224
+ self . pending_monitor_updates . push ( monitor_update) ;
3225
+ self . monitor_updating_paused ( true , need_commitment_signed, false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
3226
+ return Ok ( self . pending_monitor_updates . last ( ) . unwrap ( ) ) ;
3242
3227
}
3243
3228
3244
3229
/// Public version of the below, checking relevant preconditions first.
@@ -3370,7 +3355,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3370
3355
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
3371
3356
/// generating an appropriate error *after* the channel state has been updated based on the
3372
3357
/// revoke_and_ack message.
3373
- pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < RAAUpdates , ChannelError >
3358
+ pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < ( Vec < ( HTLCSource , PaymentHash ) > , & ChannelMonitorUpdate ) , ChannelError >
3374
3359
where L :: Target : Logger ,
3375
3360
{
3376
3361
if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
@@ -3557,8 +3542,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3557
3542
// When the monitor updating is restored we'll call get_last_commitment_update(),
3558
3543
// which does not update state, but we're definitely now awaiting a remote revoke
3559
3544
// before we can step forward any more, so set it here.
3560
- let ( _ , mut additional_update) = self . send_commitment_no_status_check ( logger) ? ;
3561
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3545
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3546
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3562
3547
// strictly increasing by one, so decrement it here.
3563
3548
self . latest_monitor_update_id = monitor_update. update_id ;
3564
3549
monitor_update. updates . append ( & mut additional_update. updates ) ;
@@ -3567,12 +3552,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3567
3552
self . monitor_pending_failures . append ( & mut revoked_htlcs) ;
3568
3553
self . monitor_pending_finalized_fulfills . append ( & mut finalized_claimed_htlcs) ;
3569
3554
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply." , log_bytes!( self . channel_id( ) ) ) ;
3570
- return Ok ( RAAUpdates {
3571
- commitment_update : None , finalized_claimed_htlcs : Vec :: new ( ) ,
3572
- accepted_htlcs : Vec :: new ( ) , failed_htlcs : Vec :: new ( ) ,
3573
- monitor_update,
3574
- holding_cell_failed_htlcs : Vec :: new ( )
3575
- } ) ;
3555
+ self . pending_monitor_updates . push ( monitor_update) ;
3556
+ return Ok ( ( Vec :: new ( ) , self . pending_monitor_updates . last ( ) . unwrap ( ) ) ) ;
3576
3557
}
3577
3558
3578
3559
match self . free_holding_cell_htlcs ( logger) ? {
@@ -3591,47 +3572,29 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3591
3572
self . latest_monitor_update_id = monitor_update. update_id ;
3592
3573
monitor_update. updates . append ( & mut additional_update. updates ) ;
3593
3574
3594
- Ok ( RAAUpdates {
3595
- commitment_update : Some ( commitment_update) ,
3596
- finalized_claimed_htlcs,
3597
- accepted_htlcs : to_forward_infos,
3598
- failed_htlcs : revoked_htlcs,
3599
- monitor_update,
3600
- holding_cell_failed_htlcs : htlcs_to_fail
3601
- } )
3575
+ self . monitor_updating_paused ( false , true , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3576
+ self . pending_monitor_updates . push ( monitor_update) ;
3577
+ Ok ( ( htlcs_to_fail, self . pending_monitor_updates . last ( ) . unwrap ( ) ) )
3602
3578
} ,
3603
3579
( None , htlcs_to_fail) => {
3604
3580
if require_commitment {
3605
- let ( commitment_signed , mut additional_update) = self . send_commitment_no_status_check ( logger) ? ;
3581
+ let mut additional_update = self . build_commitment_no_status_check ( logger) ;
3606
3582
3607
- // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
3583
+ // build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3608
3584
// strictly increasing by one, so decrement it here.
3609
3585
self . latest_monitor_update_id = monitor_update. update_id ;
3610
3586
monitor_update. updates . append ( & mut additional_update. updates ) ;
3611
3587
3612
3588
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {}. Responding with a commitment update with {} HTLCs failed." ,
3613
3589
log_bytes!( self . channel_id( ) ) , update_fail_htlcs. len( ) + update_fail_malformed_htlcs. len( ) ) ;
3614
- Ok ( RAAUpdates {
3615
- commitment_update : Some ( msgs:: CommitmentUpdate {
3616
- update_add_htlcs : Vec :: new ( ) ,
3617
- update_fulfill_htlcs : Vec :: new ( ) ,
3618
- update_fail_htlcs,
3619
- update_fail_malformed_htlcs,
3620
- update_fee : None ,
3621
- commitment_signed
3622
- } ) ,
3623
- finalized_claimed_htlcs,
3624
- accepted_htlcs : to_forward_infos, failed_htlcs : revoked_htlcs,
3625
- monitor_update, holding_cell_failed_htlcs : htlcs_to_fail
3626
- } )
3590
+ self . monitor_updating_paused ( false , true , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3591
+ self . pending_monitor_updates . push ( monitor_update) ;
3592
+ Ok ( ( htlcs_to_fail, self . pending_monitor_updates . last ( ) . unwrap ( ) ) )
3627
3593
} else {
3628
3594
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} with no reply necessary." , log_bytes!( self . channel_id( ) ) ) ;
3629
- Ok ( RAAUpdates {
3630
- commitment_update : None ,
3631
- finalized_claimed_htlcs,
3632
- accepted_htlcs : to_forward_infos, failed_htlcs : revoked_htlcs,
3633
- monitor_update, holding_cell_failed_htlcs : htlcs_to_fail
3634
- } )
3595
+ self . monitor_updating_paused ( false , false , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3596
+ self . pending_monitor_updates . push ( monitor_update) ;
3597
+ Ok ( ( htlcs_to_fail, self . pending_monitor_updates . last ( ) . unwrap ( ) ) )
3635
3598
}
3636
3599
}
3637
3600
}
@@ -3818,6 +3781,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3818
3781
{
3819
3782
assert_eq ! ( self . channel_state & ChannelState :: MonitorUpdateInProgress as u32 , ChannelState :: MonitorUpdateInProgress as u32 ) ;
3820
3783
self . channel_state &= !( ChannelState :: MonitorUpdateInProgress as u32 ) ;
3784
+ self . pending_monitor_updates . clear ( ) ;
3821
3785
3822
3786
// If we're past (or at) the FundingSent stage on an outbound channel, try to
3823
3787
// (re-)broadcast the funding transaction as we may have declined to broadcast it when we
0 commit comments