@@ -106,19 +106,19 @@ enum OutboundHTLCState {
106
106
Committed ,
107
107
/// Remote removed this (outbound) HTLC. We're waiting on their commitment_signed to finalize
108
108
/// the change (though they'll need to revoke before we fail the payment).
109
- RemoteRemoved ,
109
+ RemoteRemoved ( Option < HTLCFailReason > ) ,
110
110
/// Remote removed this and sent a commitment_signed (implying we've revoke_and_ack'ed it), but
111
111
/// the remote side hasn't yet revoked their previous state, which we need them to do before we
112
112
/// can do any backwards failing. Implies AwaitingRemoteRevoke.
113
113
/// We also have not yet removed this HTLC in a commitment_signed message, and are waiting on a
114
114
/// remote revoke_and_ack on a previous state before we can do so.
115
- AwaitingRemoteRevokeToRemove ,
115
+ AwaitingRemoteRevokeToRemove ( Option < HTLCFailReason > ) ,
116
116
/// Remote removed this and sent a commitment_signed (implying we've revoke_and_ack'ed it), but
117
117
/// the remote side hasn't yet revoked their previous state, which we need them to do before we
118
118
/// can do any backwards failing. Implies AwaitingRemoteRevoke.
119
119
/// We have removed this HTLC in our latest commitment_signed and are now just waiting on a
120
120
/// revoke_and_ack to drop completely.
121
- AwaitingRemovedRemoteRevoke ,
121
+ AwaitingRemovedRemoteRevoke ( Option < HTLCFailReason > ) ,
122
122
}
123
123
124
124
struct OutboundHTLCOutput {
@@ -128,8 +128,6 @@ struct OutboundHTLCOutput {
128
128
payment_hash : PaymentHash ,
129
129
state : OutboundHTLCState ,
130
130
source : HTLCSource ,
131
- /// If we're in a removed state, set if they failed, otherwise None
132
- fail_reason : Option < HTLCFailReason > ,
133
131
}
134
132
135
133
/// See AwaitingRemoteRevoke ChannelState for more info
@@ -858,9 +856,9 @@ impl Channel {
858
856
let ( include, state_name) = match htlc. state {
859
857
OutboundHTLCState :: LocalAnnounced ( _) => ( generated_by_local, "LocalAnnounced" ) ,
860
858
OutboundHTLCState :: Committed => ( true , "Committed" ) ,
861
- OutboundHTLCState :: RemoteRemoved => ( generated_by_local, "RemoteRemoved" ) ,
862
- OutboundHTLCState :: AwaitingRemoteRevokeToRemove => ( generated_by_local, "AwaitingRemoteRevokeToRemove" ) ,
863
- OutboundHTLCState :: AwaitingRemovedRemoteRevoke => ( false , "AwaitingRemovedRemoteRevoke" ) ,
859
+ OutboundHTLCState :: RemoteRemoved ( _ ) => ( generated_by_local, "RemoteRemoved" ) ,
860
+ OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( _ ) => ( generated_by_local, "AwaitingRemoteRevokeToRemove" ) ,
861
+ OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( _ ) => ( false , "AwaitingRemovedRemoteRevoke" ) ,
864
862
} ;
865
863
866
864
if include {
@@ -869,13 +867,11 @@ impl Channel {
869
867
} else {
870
868
log_trace ! ( self , " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})" , htlc. htlc_id, log_bytes!( htlc. payment_hash. 0 ) , htlc. amount_msat, state_name) ;
871
869
match htlc. state {
872
- OutboundHTLCState :: AwaitingRemoteRevokeToRemove |OutboundHTLCState :: AwaitingRemovedRemoteRevoke => {
873
- if htlc. fail_reason . is_none ( ) {
874
- value_to_self_msat_offset -= htlc. amount_msat as i64 ;
875
- }
870
+ OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( None ) |OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( None ) => {
871
+ value_to_self_msat_offset -= htlc. amount_msat as i64 ;
876
872
} ,
877
- OutboundHTLCState :: RemoteRemoved => {
878
- if !generated_by_local && htlc . fail_reason . is_none ( ) {
873
+ OutboundHTLCState :: RemoteRemoved ( None ) => {
874
+ if !generated_by_local {
879
875
value_to_self_msat_offset -= htlc. amount_msat as i64 ;
880
876
}
881
877
} ,
@@ -1644,10 +1640,9 @@ impl Channel {
1644
1640
OutboundHTLCState :: LocalAnnounced ( _) =>
1645
1641
return Err ( ChannelError :: Close ( "Remote tried to fulfill/fail HTLC before it had been committed" ) ) ,
1646
1642
OutboundHTLCState :: Committed => {
1647
- htlc. state = OutboundHTLCState :: RemoteRemoved ;
1648
- htlc. fail_reason = fail_reason;
1643
+ htlc. state = OutboundHTLCState :: RemoteRemoved ( fail_reason) ;
1649
1644
} ,
1650
- OutboundHTLCState :: AwaitingRemoteRevokeToRemove | OutboundHTLCState :: AwaitingRemovedRemoteRevoke | OutboundHTLCState :: RemoteRemoved =>
1645
+ OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( _ ) | OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( _ ) | OutboundHTLCState :: RemoteRemoved ( _ ) =>
1651
1646
return Err ( ChannelError :: Close ( "Remote tried to fulfill/fail HTLC that they'd already fulfilled/failed" ) ) ,
1652
1647
}
1653
1648
return Ok ( & htlc. source ) ;
@@ -1800,8 +1795,10 @@ impl Channel {
1800
1795
}
1801
1796
}
1802
1797
for htlc in self . pending_outbound_htlcs . iter_mut ( ) {
1803
- if let OutboundHTLCState :: RemoteRemoved = htlc. state {
1804
- htlc. state = OutboundHTLCState :: AwaitingRemoteRevokeToRemove ;
1798
+ if let Some ( fail_reason) = if let & mut OutboundHTLCState :: RemoteRemoved ( ref mut fail_reason) = & mut htlc. state {
1799
+ Some ( fail_reason. take ( ) )
1800
+ } else { None } {
1801
+ htlc. state = OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( fail_reason) ;
1805
1802
need_our_commitment = true ;
1806
1803
}
1807
1804
}
@@ -2019,9 +2016,9 @@ impl Channel {
2019
2016
} else { true }
2020
2017
} ) ;
2021
2018
pending_outbound_htlcs. retain ( |htlc| {
2022
- if let OutboundHTLCState :: AwaitingRemovedRemoteRevoke = htlc. state {
2019
+ if let & OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( ref fail_reason ) = & htlc. state {
2023
2020
log_trace ! ( logger, " ...removing outbound AwaitingRemovedRemoteRevoke {}" , log_bytes!( htlc. payment_hash. 0 ) ) ;
2024
- if let Some ( reason) = htlc . fail_reason . clone ( ) { // We really want take() here, but, again, non-mut ref :(
2021
+ if let Some ( reason) = fail_reason. clone ( ) { // We really want take() here, but, again, non-mut ref :(
2025
2022
revoked_htlcs. push ( ( htlc. source . clone ( ) , htlc. payment_hash , reason) ) ;
2026
2023
} else {
2027
2024
// They fulfilled, so we sent them money
@@ -2072,9 +2069,12 @@ impl Channel {
2072
2069
if let OutboundHTLCState :: LocalAnnounced ( _) = htlc. state {
2073
2070
log_trace ! ( logger, " ...promoting outbound LocalAnnounced {} to Committed" , log_bytes!( htlc. payment_hash. 0 ) ) ;
2074
2071
htlc. state = OutboundHTLCState :: Committed ;
2075
- } else if let OutboundHTLCState :: AwaitingRemoteRevokeToRemove = htlc. state {
2072
+ }
2073
+ if let Some ( fail_reason) = if let & mut OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( ref mut fail_reason) = & mut htlc. state {
2074
+ Some ( fail_reason. take ( ) )
2075
+ } else { None } {
2076
2076
log_trace ! ( logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke" , log_bytes!( htlc. payment_hash. 0 ) ) ;
2077
- htlc. state = OutboundHTLCState :: AwaitingRemovedRemoteRevoke ;
2077
+ htlc. state = OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( fail_reason ) ;
2078
2078
require_commitment = true ;
2079
2079
}
2080
2080
}
@@ -2230,7 +2230,7 @@ impl Channel {
2230
2230
self . next_remote_htlc_id -= inbound_drop_count;
2231
2231
2232
2232
for htlc in self . pending_outbound_htlcs . iter_mut ( ) {
2233
- if let OutboundHTLCState :: RemoteRemoved = htlc. state {
2233
+ if let OutboundHTLCState :: RemoteRemoved ( _ ) = htlc. state {
2234
2234
// They sent us an update to remove this but haven't yet sent the corresponding
2235
2235
// commitment_signed, we need to move it back to Committed and they can re-send
2236
2236
// the update upon reconnection.
@@ -3248,7 +3248,6 @@ impl Channel {
3248
3248
cltv_expiry : cltv_expiry,
3249
3249
state : OutboundHTLCState :: LocalAnnounced ( Box :: new ( onion_routing_packet. clone ( ) ) ) ,
3250
3250
source,
3251
- fail_reason : None ,
3252
3251
} ) ;
3253
3252
3254
3253
let res = msgs:: UpdateAddHTLC {
@@ -3313,8 +3312,10 @@ impl Channel {
3313
3312
}
3314
3313
}
3315
3314
for htlc in self . pending_outbound_htlcs . iter_mut ( ) {
3316
- if let OutboundHTLCState :: AwaitingRemoteRevokeToRemove = htlc. state {
3317
- htlc. state = OutboundHTLCState :: AwaitingRemovedRemoteRevoke ;
3315
+ if let Some ( fail_reason) = if let & mut OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( ref mut fail_reason) = & mut htlc. state {
3316
+ Some ( fail_reason. take ( ) )
3317
+ } else { None } {
3318
+ htlc. state = OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( fail_reason) ;
3318
3319
}
3319
3320
}
3320
3321
@@ -3580,7 +3581,6 @@ impl Writeable for Channel {
3580
3581
htlc. cltv_expiry . write ( writer) ?;
3581
3582
htlc. payment_hash . write ( writer) ?;
3582
3583
htlc. source . write ( writer) ?;
3583
- write_option ! ( htlc. fail_reason) ;
3584
3584
match & htlc. state {
3585
3585
& OutboundHTLCState :: LocalAnnounced ( ref onion_packet) => {
3586
3586
0u8 . write ( writer) ?;
@@ -3589,14 +3589,17 @@ impl Writeable for Channel {
3589
3589
& OutboundHTLCState :: Committed => {
3590
3590
1u8 . write ( writer) ?;
3591
3591
} ,
3592
- & OutboundHTLCState :: RemoteRemoved => {
3592
+ & OutboundHTLCState :: RemoteRemoved ( ref fail_reason ) => {
3593
3593
2u8 . write ( writer) ?;
3594
+ write_option ! ( fail_reason) ;
3594
3595
} ,
3595
- & OutboundHTLCState :: AwaitingRemoteRevokeToRemove => {
3596
+ & OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( ref fail_reason ) => {
3596
3597
3u8 . write ( writer) ?;
3598
+ write_option ! ( fail_reason) ;
3597
3599
} ,
3598
- & OutboundHTLCState :: AwaitingRemovedRemoteRevoke => {
3600
+ & OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( ref fail_reason ) => {
3599
3601
4u8 . write ( writer) ?;
3602
+ write_option ! ( fail_reason) ;
3600
3603
} ,
3601
3604
}
3602
3605
}
@@ -3759,13 +3762,12 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
3759
3762
cltv_expiry : Readable :: read ( reader) ?,
3760
3763
payment_hash : Readable :: read ( reader) ?,
3761
3764
source : Readable :: read ( reader) ?,
3762
- fail_reason : Readable :: read ( reader) ?,
3763
3765
state : match <u8 as Readable < R > >:: read ( reader) ? {
3764
3766
0 => OutboundHTLCState :: LocalAnnounced ( Box :: new ( Readable :: read ( reader) ?) ) ,
3765
3767
1 => OutboundHTLCState :: Committed ,
3766
- 2 => OutboundHTLCState :: RemoteRemoved ,
3767
- 3 => OutboundHTLCState :: AwaitingRemoteRevokeToRemove ,
3768
- 4 => OutboundHTLCState :: AwaitingRemovedRemoteRevoke ,
3768
+ 2 => OutboundHTLCState :: RemoteRemoved ( Readable :: read ( reader ) ? ) ,
3769
+ 3 => OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( Readable :: read ( reader ) ? ) ,
3770
+ 4 => OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( Readable :: read ( reader ) ? ) ,
3769
3771
_ => return Err ( DecodeError :: InvalidValue ) ,
3770
3772
} ,
3771
3773
} ) ;
@@ -4158,7 +4160,6 @@ mod tests {
4158
4160
payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
4159
4161
state : OutboundHTLCState :: Committed ,
4160
4162
source : HTLCSource :: dummy ( ) ,
4161
- fail_reason : None ,
4162
4163
} ;
4163
4164
out. payment_hash . 0 = Sha256 :: hash ( & hex:: decode ( "0202020202020202020202020202020202020202020202020202020202020202" ) . unwrap ( ) ) . into_inner ( ) ;
4164
4165
out
@@ -4171,7 +4172,6 @@ mod tests {
4171
4172
payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
4172
4173
state : OutboundHTLCState :: Committed ,
4173
4174
source : HTLCSource :: dummy ( ) ,
4174
- fail_reason : None ,
4175
4175
} ;
4176
4176
out. payment_hash . 0 = Sha256 :: hash ( & hex:: decode ( "0303030303030303030303030303030303030303030303030303030303030303" ) . unwrap ( ) ) . into_inner ( ) ;
4177
4177
out
0 commit comments