Skip to content

Commit cff2061

Browse files
authored
Merge pull request #2610 from wpaulino/missing-htlc-claim-balance
Fix matching of second-stage HTLC claim in get_htlc_balance
2 parents f534ce2 + fd66a29 commit cff2061

File tree

3 files changed

+502
-172
lines changed

3 files changed

+502
-172
lines changed

lightning/src/chain/channelmonitor.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,19 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
17511751
},
17521752
OnchainEvent::MaturingOutput {
17531753
descriptor: SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) }
1754-
if descriptor.outpoint.index as u32 == htlc_commitment_tx_output_idx => {
1754+
if event.transaction.as_ref().map(|tx| tx.input.iter().enumerate()
1755+
.any(|(input_idx, inp)|
1756+
Some(inp.previous_output.txid) == confirmed_txid &&
1757+
inp.previous_output.vout == htlc_commitment_tx_output_idx &&
1758+
// A maturing output for an HTLC claim will always be at the same
1759+
// index as the HTLC input. This is true pre-anchors, as there's
1760+
// only 1 input and 1 output. This is also true post-anchors,
1761+
// because we have a SIGHASH_SINGLE|ANYONECANPAY signature from our
1762+
// channel counterparty.
1763+
descriptor.outpoint.index as usize == input_idx
1764+
))
1765+
.unwrap_or(false)
1766+
=> {
17551767
debug_assert!(holder_delayed_output_pending.is_none());
17561768
holder_delayed_output_pending = Some(event.confirmation_threshold());
17571769
},
@@ -1892,8 +1904,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
18921904
/// confirmations on the claim transaction.
18931905
///
18941906
/// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1895-
/// LDK prior to 0.0.111, balances may not be fully captured if our counterparty broadcasted
1896-
/// a revoked state.
1907+
/// LDK prior to 0.0.111, not all or excess balances may be included.
18971908
///
18981909
/// See [`Balance`] for additional details on the types of claimable balances which
18991910
/// may be returned here and their meanings.

lightning/src/ln/functional_test_utils.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::sign::EntropySource;
1515
use crate::chain::channelmonitor::ChannelMonitor;
1616
use crate::chain::transaction::OutPoint;
1717
use crate::events::{ClaimedHTLC, ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, PaymentFailureReason};
18-
use crate::events::bump_transaction::{BumpTransactionEventHandler, Wallet, WalletSource};
18+
use crate::events::bump_transaction::{BumpTransactionEvent, BumpTransactionEventHandler, Wallet, WalletSource};
1919
use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
2020
use crate::ln::channelmanager::{AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, PaymentId, MIN_CLTV_EXPIRY_DELTA};
2121
use crate::routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate};
@@ -1504,6 +1504,21 @@ macro_rules! check_closed_event {
15041504
}
15051505
}
15061506

1507+
pub fn handle_bump_htlc_event(node: &Node, count: usize) {
1508+
let events = node.chain_monitor.chain_monitor.get_and_clear_pending_events();
1509+
assert_eq!(events.len(), count);
1510+
for event in events {
1511+
match event {
1512+
Event::BumpTransaction(bump_event) => {
1513+
if let BumpTransactionEvent::HTLCResolution { .. } = &bump_event {}
1514+
else { panic!(); }
1515+
node.bump_tx_handler.handle_event(&bump_event);
1516+
},
1517+
_ => panic!(),
1518+
}
1519+
}
1520+
}
1521+
15071522
pub fn close_channel<'a, 'b, 'c>(outbound_node: &Node<'a, 'b, 'c>, inbound_node: &Node<'a, 'b, 'c>, channel_id: &ChannelId, funding_tx: Transaction, close_inbound_first: bool) -> (msgs::ChannelUpdate, msgs::ChannelUpdate, Transaction) {
15081523
let (node_a, broadcaster_a, struct_a) = if close_inbound_first { (&inbound_node.node, &inbound_node.tx_broadcaster, inbound_node) } else { (&outbound_node.node, &outbound_node.tx_broadcaster, outbound_node) };
15091524
let (node_b, broadcaster_b, struct_b) = if close_inbound_first { (&outbound_node.node, &outbound_node.tx_broadcaster, outbound_node) } else { (&inbound_node.node, &inbound_node.tx_broadcaster, inbound_node) };
@@ -2780,7 +2795,8 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
27802795
}
27812796

27822797
// Note that the following only works for CLTV values up to 128
2783-
pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 137; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
2798+
pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 137; // Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
2799+
pub const ACCEPTED_HTLC_SCRIPT_WEIGHT_ANCHORS: usize = 140; // Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
27842800

27852801
#[derive(PartialEq)]
27862802
pub enum HTLCType { NONE, TIMEOUT, SUCCESS }

0 commit comments

Comments
 (0)