Skip to content

Commit a66e597

Browse files
authored
Merge pull request #127 from TheBlueMatt/2018-08-fuzz-fixes-5
Fix several panics introduced by #125 (#114) and #124
2 parents dbff601 + 7ce13da commit a66e597

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/ln/channel.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,17 +1131,24 @@ impl Channel {
11311131
if htlc_id != 0 {
11321132
panic!("Duplicate HTLC payment_hash, you probably re-used payment preimages, NEVER DO THIS!");
11331133
}
1134-
htlc_id = htlc.htlc_id;
1135-
htlc_amount_msat += htlc.amount_msat;
11361134
if htlc.state == HTLCState::Committed {
11371135
htlc.state = HTLCState::LocalRemoved;
11381136
} 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+
}
11401145
} else if htlc.state == HTLCState::LocalRemoved || htlc.state == HTLCState::LocalRemovedAwaitingCommitment {
11411146
return Err(HandleError{err: "Unable to find a pending HTLC which matched the given payment preimage", action: None});
11421147
} else {
11431148
panic!("Have an inbound HTLC when not awaiting remote revoke that had a garbage state");
11441149
}
1150+
htlc_id = htlc.htlc_id;
1151+
htlc_amount_msat += htlc.amount_msat;
11451152
}
11461153
}
11471154
if htlc_amount_msat == 0 {

src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ impl ChannelManager {
829829
if !chan.is_live() {
830830
Some(("Forwarding channel is not in a ready state.", 0x1000 | 7, self.get_channel_update(chan).unwrap()))
831831
} 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 {
834834
Some(("Prior hop has deviated from specified fees parameters or origin node has obsolete ones", 0x1000 | 12, self.get_channel_update(chan).unwrap()))
835835
} else {
836836
if (msg.cltv_expiry as u64) < (*outgoing_cltv_value) as u64 + CLTV_EXPIRY_DELTA as u64 {

0 commit comments

Comments
 (0)