Skip to content

Commit e3d7e64

Browse files
committed
Test that no Balance appears for missing HTLCs in revoked txn
This adds an additional test in `test_revoked_counterparty_commitment_balances` to ensure that an HTLC which is missing from a revoked commitment transaction does not appear as a `Balance` in `get_claimebla_balances`.
1 parent 5fa8a7c commit e3d7e64

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,13 +1485,11 @@ macro_rules! expect_payment_failed {
14851485
};
14861486
}
14871487

1488-
pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
1489-
node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_rejected_by_dest: bool,
1490-
conditions: PaymentFailedConditions<'e>
1488+
pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
1489+
node: &'a Node<'b, 'c, 'd>, payment_failed_event: Event, expected_payment_hash: PaymentHash,
1490+
expected_rejected_by_dest: bool, conditions: PaymentFailedConditions<'e>
14911491
) {
1492-
let mut events = node.node.get_and_clear_pending_events();
1493-
assert_eq!(events.len(), 1);
1494-
let expected_payment_id = match events.pop().unwrap() {
1492+
let expected_payment_id = match payment_failed_event {
14951493
Event::PaymentPathFailed { payment_hash, rejected_by_dest, path, retry, payment_id, network_update,
14961494
#[cfg(test)]
14971495
error_code,
@@ -1551,6 +1549,15 @@ pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
15511549
}
15521550
}
15531551

1552+
pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
1553+
node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_rejected_by_dest: bool,
1554+
conditions: PaymentFailedConditions<'e>
1555+
) {
1556+
let mut events = node.node.get_and_clear_pending_events();
1557+
assert_eq!(events.len(), 1);
1558+
expect_payment_failed_conditions_event(node, events.pop().unwrap(), expected_payment_hash, expected_rejected_by_dest, conditions);
1559+
}
1560+
15541561
pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId {
15551562
let payment_id = origin_node.node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap();
15561563
check_added_monitors!(origin_node, expected_paths.len());

lightning/src/ln/monitor_tests.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -775,12 +775,14 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
775775
let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 };
776776
assert_eq!(funding_outpoint.to_channel_id(), chan_id);
777777

778-
// We create four HTLCs for B to claim against A's revoked commitment transaction:
778+
// We create five HTLCs for B to claim against A's revoked commitment transaction:
779779
//
780780
// (1) one for which A is the originator and B knows the preimage
781781
// (2) one for which B is the originator where the HTLC has since timed-out
782782
// (3) one for which B is the originator but where the HTLC has not yet timed-out
783783
// (4) one dust HTLC which is lost in the channel closure
784+
// (5) one that actually isn't in the revoked commitment transaction at all, but was added in
785+
// later commitment transaction updates
784786
//
785787
// Though they could all be claimed in a single claim transaction, due to CLTV timeouts they
786788
// are all currently claimed in separate transactions, which helps us test as we can claim
@@ -804,16 +806,8 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
804806

805807
let chan_feerate = get_feerate!(nodes[0], chan_id) as u64;
806808

807-
{
808-
let mut feerate = chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap();
809-
*feerate += 1;
810-
}
811-
nodes[0].node.timer_tick_occurred();
812-
check_added_monitors!(nodes[0], 1);
813-
814-
let fee_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
815-
nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &fee_update.update_fee.unwrap());
816-
commitment_signed_dance!(nodes[1], nodes[0], fee_update.commitment_signed, false);
809+
let missing_htlc_cltv_timeout = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1; // Note ChannelManager adds one to CLTV timeouts for safety
810+
let missing_htlc_payment_hash = route_payment(&nodes[1], &[&nodes[0]], 2_000_000).1;
817811

818812
nodes[1].node.claim_funds(claimed_payment_preimage);
819813
expect_payment_claimed!(nodes[1], claimed_payment_hash, 3_000_000);
@@ -839,7 +833,10 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
839833
// Prior to channel closure, B considers the preimage HTLC as its own, and otherwise only
840834
// lists the two on-chain timeout-able HTLCs as claimable balances.
841835
assert_eq!(sorted_vec(vec![Balance::ClaimableOnChannelClose {
842-
claimable_amount_satoshis: 100_000 - 5_000 - 4_000 - 3 + 3_000,
836+
claimable_amount_satoshis: 100_000 - 5_000 - 4_000 - 3 - 2_000 + 3_000,
837+
}, Balance::MaybeClaimableHTLCAwaitingTimeout {
838+
claimable_amount_satoshis: 2_000,
839+
claimable_height: missing_htlc_cltv_timeout,
843840
}, Balance::MaybeClaimableHTLCAwaitingTimeout {
844841
claimable_amount_satoshis: 4_000,
845842
claimable_height: htlc_cltv_timeout,
@@ -958,7 +955,14 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
958955

959956
connect_blocks(&nodes[1], 1);
960957
test_spendable_output(&nodes[1], &as_revoked_txn[0]);
961-
expect_payment_failed!(nodes[1], dust_payment_hash, true);
958+
959+
let mut payment_failed_events = nodes[1].node.get_and_clear_pending_events();
960+
expect_payment_failed_conditions_event(&nodes[1], payment_failed_events.pop().unwrap(),
961+
dust_payment_hash, true, PaymentFailedConditions::new());
962+
expect_payment_failed_conditions_event(&nodes[1], payment_failed_events.pop().unwrap(),
963+
missing_htlc_payment_hash, true, PaymentFailedConditions::new());
964+
assert!(payment_failed_events.is_empty());
965+
962966
connect_blocks(&nodes[1], 1);
963967
test_spendable_output(&nodes[1], &claim_txn[if confirm_htlc_spend_first { 2 } else { 3 }]);
964968
connect_blocks(&nodes[1], 1);

0 commit comments

Comments
 (0)