@@ -339,6 +339,16 @@ pub enum UpdateFulfillCommitFetch {
339
339
DuplicateClaim { } ,
340
340
}
341
341
342
+ /// The return value of `revoke_and_ack` on success, primarily updates to other channels or HTLC
343
+ /// state.
344
+ pub ( super ) struct RAAUpdates {
345
+ pub commitment_update : Option < msgs:: CommitmentUpdate > ,
346
+ pub to_forward_htlcs : Vec < ( PendingHTLCInfo , u64 ) > ,
347
+ pub failed_htlcs : Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > ,
348
+ pub monitor_update : ChannelMonitorUpdate ,
349
+ pub holding_cell_failed_htlcs : Vec < ( HTLCSource , PaymentHash ) > ,
350
+ }
351
+
342
352
/// If the majority of the channels funds are to the fundee and the initiator holds only just
343
353
/// enough funds to cover their reserve value, channels are at risk of getting "stuck". Because the
344
354
/// initiator controls the feerate, if they then go to increase the channel fee, they may have no
@@ -2702,7 +2712,7 @@ impl<Signer: Sign> Channel<Signer> {
2702
2712
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
2703
2713
/// generating an appropriate error *after* the channel state has been updated based on the
2704
2714
/// revoke_and_ack message.
2705
- pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < ( Option < msgs :: CommitmentUpdate > , Vec < ( PendingHTLCInfo , u64 ) > , Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > , ChannelMonitorUpdate , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError >
2715
+ pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < RAAUpdates , ChannelError >
2706
2716
where L :: Target : Logger ,
2707
2717
{
2708
2718
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
@@ -2891,7 +2901,12 @@ impl<Signer: Sign> Channel<Signer> {
2891
2901
self . monitor_pending_forwards . append ( & mut to_forward_infos) ;
2892
2902
self . monitor_pending_failures . append ( & mut revoked_htlcs) ;
2893
2903
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply." , log_bytes!( self . channel_id( ) ) ) ;
2894
- return Ok ( ( None , Vec :: new ( ) , Vec :: new ( ) , monitor_update, Vec :: new ( ) ) )
2904
+ return Ok ( RAAUpdates {
2905
+ commitment_update : None ,
2906
+ to_forward_htlcs : Vec :: new ( ) , failed_htlcs : Vec :: new ( ) ,
2907
+ monitor_update,
2908
+ holding_cell_failed_htlcs : Vec :: new ( )
2909
+ } ) ;
2895
2910
}
2896
2911
2897
2912
match self . free_holding_cell_htlcs ( logger) ? {
@@ -2910,7 +2925,13 @@ impl<Signer: Sign> Channel<Signer> {
2910
2925
self . latest_monitor_update_id = monitor_update. update_id ;
2911
2926
monitor_update. updates . append ( & mut additional_update. updates ) ;
2912
2927
2913
- Ok ( ( Some ( commitment_update) , to_forward_infos, revoked_htlcs, monitor_update, htlcs_to_fail) )
2928
+ Ok ( RAAUpdates {
2929
+ commitment_update : Some ( commitment_update) ,
2930
+ to_forward_htlcs : to_forward_infos,
2931
+ failed_htlcs : revoked_htlcs,
2932
+ monitor_update,
2933
+ holding_cell_failed_htlcs : htlcs_to_fail
2934
+ } )
2914
2935
} ,
2915
2936
( None , htlcs_to_fail) => {
2916
2937
if require_commitment {
@@ -2923,17 +2944,25 @@ impl<Signer: Sign> Channel<Signer> {
2923
2944
2924
2945
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {}. Responding with a commitment update with {} HTLCs failed." ,
2925
2946
log_bytes!( self . channel_id( ) ) , update_fail_htlcs. len( ) + update_fail_malformed_htlcs. len( ) ) ;
2926
- Ok ( ( Some ( msgs:: CommitmentUpdate {
2927
- update_add_htlcs : Vec :: new ( ) ,
2928
- update_fulfill_htlcs : Vec :: new ( ) ,
2929
- update_fail_htlcs,
2930
- update_fail_malformed_htlcs,
2931
- update_fee : None ,
2932
- commitment_signed
2933
- } ) , to_forward_infos, revoked_htlcs, monitor_update, htlcs_to_fail) )
2947
+ Ok ( RAAUpdates {
2948
+ commitment_update : Some ( msgs:: CommitmentUpdate {
2949
+ update_add_htlcs : Vec :: new ( ) ,
2950
+ update_fulfill_htlcs : Vec :: new ( ) ,
2951
+ update_fail_htlcs,
2952
+ update_fail_malformed_htlcs,
2953
+ update_fee : None ,
2954
+ commitment_signed
2955
+ } ) ,
2956
+ to_forward_htlcs : to_forward_infos, failed_htlcs : revoked_htlcs,
2957
+ monitor_update, holding_cell_failed_htlcs : htlcs_to_fail
2958
+ } )
2934
2959
} else {
2935
2960
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} with no reply necessary." , log_bytes!( self . channel_id( ) ) ) ;
2936
- Ok ( ( None , to_forward_infos, revoked_htlcs, monitor_update, htlcs_to_fail) )
2961
+ Ok ( RAAUpdates {
2962
+ commitment_update : None ,
2963
+ to_forward_htlcs : to_forward_infos, failed_htlcs : revoked_htlcs,
2964
+ monitor_update, holding_cell_failed_htlcs : htlcs_to_fail
2965
+ } )
2937
2966
}
2938
2967
}
2939
2968
}
0 commit comments