@@ -401,6 +401,17 @@ pub(super) struct MonitorRestoreUpdates {
401
401
pub funding_locked : Option < msgs:: FundingLocked > ,
402
402
}
403
403
404
+ /// The return value of `channel_reestablish`
405
+ pub ( super ) struct ReestablishResponses {
406
+ pub funding_locked : Option < msgs:: FundingLocked > ,
407
+ pub raa : Option < msgs:: RevokeAndACK > ,
408
+ pub commitment_update : Option < msgs:: CommitmentUpdate > ,
409
+ pub order : RAACommitmentOrder ,
410
+ pub mon_update : Option < ChannelMonitorUpdate > ,
411
+ pub holding_cell_failed_htlcs : Vec < ( HTLCSource , PaymentHash ) > ,
412
+ pub shutdown_msg : Option < msgs:: Shutdown > ,
413
+ }
414
+
404
415
/// If the majority of the channels funds are to the fundee and the initiator holds only just
405
416
/// enough funds to cover their reserve value, channels are at risk of getting "stuck". Because the
406
417
/// initiator controls the feerate, if they then go to increase the channel fee, they may have no
@@ -3501,7 +3512,7 @@ impl<Signer: Sign> Channel<Signer> {
3501
3512
3502
3513
/// May panic if some calls other than message-handling calls (which will all Err immediately)
3503
3514
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
3504
- pub fn channel_reestablish < L : Deref > ( & mut self , msg : & msgs:: ChannelReestablish , logger : & L ) -> Result < ( Option < msgs :: FundingLocked > , Option < msgs :: RevokeAndACK > , Option < msgs :: CommitmentUpdate > , Option < ChannelMonitorUpdate > , RAACommitmentOrder , Vec < ( HTLCSource , PaymentHash ) > , Option < msgs :: Shutdown > ) , ChannelError > where L :: Target : Logger {
3515
+ pub fn channel_reestablish < L : Deref > ( & mut self , msg : & msgs:: ChannelReestablish , logger : & L ) -> Result < ReestablishResponses , ChannelError > where L :: Target : Logger {
3505
3516
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == 0 {
3506
3517
// While BOLT 2 doesn't indicate explicitly we should error this channel here, it
3507
3518
// almost certainly indicates we are going to end up out-of-sync in some way, so we
@@ -3553,15 +3564,27 @@ impl<Signer: Sign> Channel<Signer> {
3553
3564
return Err ( ChannelError :: Close ( "Peer claimed they saw a revoke_and_ack but we haven't sent funding_locked yet" . to_owned ( ) ) ) ;
3554
3565
}
3555
3566
// Short circuit the whole handler as there is nothing we can resend them
3556
- return Ok ( ( None , None , None , None , RAACommitmentOrder :: CommitmentFirst , Vec :: new ( ) , shutdown_msg) ) ;
3567
+ return Ok ( ReestablishResponses {
3568
+ funding_locked : None ,
3569
+ raa : None , commitment_update : None , mon_update : None ,
3570
+ order : RAACommitmentOrder :: CommitmentFirst ,
3571
+ holding_cell_failed_htlcs : Vec :: new ( ) ,
3572
+ shutdown_msg
3573
+ } ) ;
3557
3574
}
3558
3575
3559
3576
// We have OurFundingLocked set!
3560
3577
let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
3561
- return Ok ( ( Some ( msgs:: FundingLocked {
3562
- channel_id : self . channel_id ( ) ,
3563
- next_per_commitment_point,
3564
- } ) , None , None , None , RAACommitmentOrder :: CommitmentFirst , Vec :: new ( ) , shutdown_msg) ) ;
3578
+ return Ok ( ReestablishResponses {
3579
+ funding_locked : Some ( msgs:: FundingLocked {
3580
+ channel_id : self . channel_id ( ) ,
3581
+ next_per_commitment_point,
3582
+ } ) ,
3583
+ raa : None , commitment_update : None , mon_update : None ,
3584
+ order : RAACommitmentOrder :: CommitmentFirst ,
3585
+ holding_cell_failed_htlcs : Vec :: new ( ) ,
3586
+ shutdown_msg
3587
+ } ) ;
3565
3588
}
3566
3589
3567
3590
let required_revoke = if msg. next_remote_commitment_number + 1 == INITIAL_COMMITMENT_NUMBER - self . cur_holder_commitment_transaction_number {
@@ -3585,7 +3608,7 @@ impl<Signer: Sign> Channel<Signer> {
3585
3608
// the corresponding revoke_and_ack back yet.
3586
3609
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self . cur_counterparty_commitment_transaction_number + if ( self . channel_state & ChannelState :: AwaitingRemoteRevoke as u32 ) != 0 { 1 } else { 0 } ;
3587
3610
3588
- let resend_funding_locked = if msg. next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self . cur_holder_commitment_transaction_number == 1 {
3611
+ let funding_locked = if msg. next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self . cur_holder_commitment_transaction_number == 1 {
3589
3612
// We should never have to worry about MonitorUpdateFailed resending FundingLocked
3590
3613
let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
3591
3614
Some ( msgs:: FundingLocked {
@@ -3607,18 +3630,39 @@ impl<Signer: Sign> Channel<Signer> {
3607
3630
// have received some updates while we were disconnected. Free the holding cell
3608
3631
// now!
3609
3632
match self . free_holding_cell_htlcs ( logger) {
3610
- Err ( ChannelError :: Close ( msg) ) => return Err ( ChannelError :: Close ( msg) ) ,
3633
+ Err ( ChannelError :: Close ( msg) ) => Err ( ChannelError :: Close ( msg) ) ,
3611
3634
Err ( ChannelError :: Warn ( _) ) | Err ( ChannelError :: Ignore ( _) ) | Err ( ChannelError :: CloseDelayBroadcast ( _) ) =>
3612
3635
panic ! ( "Got non-channel-failing result from free_holding_cell_htlcs" ) ,
3613
- Ok ( ( Some ( ( commitment_update, monitor_update) ) , htlcs_to_fail) ) => {
3614
- return Ok ( ( resend_funding_locked, required_revoke, Some ( commitment_update) , Some ( monitor_update) , self . resend_order . clone ( ) , htlcs_to_fail, shutdown_msg) ) ;
3636
+ Ok ( ( Some ( ( commitment_update, monitor_update) ) , holding_cell_failed_htlcs) ) => {
3637
+ Ok ( ReestablishResponses {
3638
+ funding_locked, shutdown_msg,
3639
+ raa : required_revoke,
3640
+ commitment_update : Some ( commitment_update) ,
3641
+ order : self . resend_order . clone ( ) ,
3642
+ mon_update : Some ( monitor_update) ,
3643
+ holding_cell_failed_htlcs,
3644
+ } )
3615
3645
} ,
3616
- Ok ( ( None , htlcs_to_fail) ) => {
3617
- return Ok ( ( resend_funding_locked, required_revoke, None , None , self . resend_order . clone ( ) , htlcs_to_fail, shutdown_msg) ) ;
3646
+ Ok ( ( None , holding_cell_failed_htlcs) ) => {
3647
+ Ok ( ReestablishResponses {
3648
+ funding_locked, shutdown_msg,
3649
+ raa : required_revoke,
3650
+ commitment_update : None ,
3651
+ order : self . resend_order . clone ( ) ,
3652
+ mon_update : None ,
3653
+ holding_cell_failed_htlcs,
3654
+ } )
3618
3655
} ,
3619
3656
}
3620
3657
} else {
3621
- return Ok ( ( resend_funding_locked, required_revoke, None , None , self . resend_order . clone ( ) , Vec :: new ( ) , shutdown_msg) ) ;
3658
+ Ok ( ReestablishResponses {
3659
+ funding_locked, shutdown_msg,
3660
+ raa : required_revoke,
3661
+ commitment_update : None ,
3662
+ order : self . resend_order . clone ( ) ,
3663
+ mon_update : None ,
3664
+ holding_cell_failed_htlcs : Vec :: new ( ) ,
3665
+ } )
3622
3666
}
3623
3667
} else if msg. next_local_commitment_number == next_counterparty_commitment_number - 1 {
3624
3668
if required_revoke. is_some ( ) {
@@ -3629,12 +3673,24 @@ impl<Signer: Sign> Channel<Signer> {
3629
3673
3630
3674
if self . channel_state & ( ChannelState :: MonitorUpdateFailed as u32 ) != 0 {
3631
3675
self . monitor_pending_commitment_signed = true ;
3632
- return Ok ( ( resend_funding_locked, None , None , None , self . resend_order . clone ( ) , Vec :: new ( ) , shutdown_msg) ) ;
3676
+ Ok ( ReestablishResponses {
3677
+ funding_locked, shutdown_msg,
3678
+ commitment_update : None , raa : None , mon_update : None ,
3679
+ order : self . resend_order . clone ( ) ,
3680
+ holding_cell_failed_htlcs : Vec :: new ( ) ,
3681
+ } )
3682
+ } else {
3683
+ Ok ( ReestablishResponses {
3684
+ funding_locked, shutdown_msg,
3685
+ raa : required_revoke,
3686
+ commitment_update : Some ( self . get_last_commitment_update ( logger) ) ,
3687
+ order : self . resend_order . clone ( ) ,
3688
+ mon_update : None ,
3689
+ holding_cell_failed_htlcs : Vec :: new ( ) ,
3690
+ } )
3633
3691
}
3634
-
3635
- return Ok ( ( resend_funding_locked, required_revoke, Some ( self . get_last_commitment_update ( logger) ) , None , self . resend_order . clone ( ) , Vec :: new ( ) , shutdown_msg) ) ;
3636
3692
} else {
3637
- return Err ( ChannelError :: Close ( "Peer attempted to reestablish channel with a very old remote commitment transaction" . to_owned ( ) ) ) ;
3693
+ Err ( ChannelError :: Close ( "Peer attempted to reestablish channel with a very old remote commitment transaction" . to_owned ( ) ) )
3638
3694
}
3639
3695
}
3640
3696
0 commit comments