File tree 2 files changed +12
-5
lines changed 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -1131,17 +1131,24 @@ impl Channel {
1131
1131
if htlc_id != 0 {
1132
1132
panic ! ( "Duplicate HTLC payment_hash, you probably re-used payment preimages, NEVER DO THIS!" ) ;
1133
1133
}
1134
- htlc_id = htlc. htlc_id ;
1135
- htlc_amount_msat += htlc. amount_msat ;
1136
1134
if htlc. state == HTLCState :: Committed {
1137
1135
htlc. state = HTLCState :: LocalRemoved ;
1138
1136
} else if htlc. state == HTLCState :: RemoteAnnounced {
1139
- panic ! ( "Somehow forwarded HTLC prior to remote revocation!" ) ;
1137
+ if let Some ( PendingHTLCStatus :: Forward ( _) ) = htlc. pending_forward_state {
1138
+ panic ! ( "Somehow forwarded HTLC prior to remote revocation!" ) ;
1139
+ } else {
1140
+ // We have to pretend this isn't here - we're probably a duplicate with the
1141
+ // same payment_hash as some other HTLC, and the other is getting failed,
1142
+ // we'll fail this one as soon as remote commits to it.
1143
+ continue ;
1144
+ }
1140
1145
} else if htlc. state == HTLCState :: LocalRemoved || htlc. state == HTLCState :: LocalRemovedAwaitingCommitment {
1141
1146
return Err ( HandleError { err : "Unable to find a pending HTLC which matched the given payment preimage" , action : None } ) ;
1142
1147
} else {
1143
1148
panic ! ( "Have an inbound HTLC when not awaiting remote revoke that had a garbage state" ) ;
1144
1149
}
1150
+ htlc_id = htlc. htlc_id ;
1151
+ htlc_amount_msat += htlc. amount_msat ;
1145
1152
}
1146
1153
}
1147
1154
if htlc_amount_msat == 0 {
Original file line number Diff line number Diff line change @@ -829,8 +829,8 @@ impl ChannelManager {
829
829
if !chan. is_live ( ) {
830
830
Some ( ( "Forwarding channel is not in a ready state." , 0x1000 | 7 , self . get_channel_update ( chan) . unwrap ( ) ) )
831
831
} else {
832
- let fee = chan . get_our_fee_base_msat ( & * self . fee_estimator ) + ( * amt_to_forward * self . fee_proportional_millionths as u64 / 1000000 ) as u32 ;
833
- if msg. amount_msat < fee as u64 || ( msg. amount_msat - fee as u64 ) < * amt_to_forward {
832
+ let fee = amt_to_forward . checked_mul ( self . fee_proportional_millionths as u64 ) . and_then ( |prop_fee| { ( prop_fee / 1000000 ) . checked_add ( chan . get_our_fee_base_msat ( & * self . fee_estimator ) as u64 ) } ) ;
833
+ if fee . is_none ( ) || msg. amount_msat < fee. unwrap ( ) || ( msg. amount_msat - fee. unwrap ( ) ) < * amt_to_forward {
834
834
Some ( ( "Prior hop has deviated from specified fees parameters or origin node has obsolete ones" , 0x1000 | 12 , self . get_channel_update ( chan) . unwrap ( ) ) )
835
835
} else {
836
836
if ( msg. cltv_expiry as u64 ) < ( * outgoing_cltv_value) as u64 + CLTV_EXPIRY_DELTA as u64 {
You can’t perform that action at this time.
0 commit comments