From 4f77c812a4b0e42454cb92b8b460dfa1323016cb Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 24 Aug 2018 11:52:55 -0400 Subject: [PATCH 1/2] Fix crash introduced in #124 I'm rapidly starting to regret holding failed HTLCs in Channel, given we allow them to violate the no-duplicate-hashes precondition. Found by fuzzer --- src/ln/channel.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 47c05de2ab9..d6e23a28392 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -1018,10 +1018,13 @@ impl Channel { for (idx, htlc) in self.pending_htlcs.iter().enumerate() { if !htlc.outbound && htlc.payment_hash == payment_hash_calc && htlc.state != HTLCState::LocalRemoved && htlc.state != HTLCState::LocalRemovedAwaitingCommitment { - if pending_idx != std::usize::MAX { - panic!("Duplicate HTLC payment_hash, ChannelManager should have prevented this!"); + if let Some(PendingHTLCStatus::Fail(_)) = htlc.pending_forward_state { + } else { + if pending_idx != std::usize::MAX { + panic!("Duplicate HTLC payment_hash, ChannelManager should have prevented this!"); + } + pending_idx = idx; } - pending_idx = idx; } } if pending_idx == std::usize::MAX { From 32e2f7eef56bbeece93173a73564174c53edd88f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 24 Aug 2018 16:48:24 -0400 Subject: [PATCH 2/2] Remove unused node_id tracking in ChannelManager tests --- src/ln/channelmanager.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 20e6f3739ec..a360c376a16 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -2256,7 +2256,6 @@ mod tests { chain_monitor: Arc, tx_broadcaster: Arc, chan_monitor: Arc, - node_id: SecretKey, node: Arc, router: Router, } @@ -2803,7 +2802,7 @@ mod tests { }; let node = ChannelManager::new(node_id.clone(), 0, true, Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger)).unwrap(); let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &node_id), Arc::clone(&logger)); - nodes.push(Node { feeest, chain_monitor, tx_broadcaster, chan_monitor, node_id, node, router }); + nodes.push(Node { feeest, chain_monitor, tx_broadcaster, chan_monitor, node, router }); } nodes