Skip to content

Commit f76f60f

Browse files
committed
Mark failed counterparty-is-destination HTLCs retryable
When our counterparty is the payment destination and we receive an `HTLCFailReason::Reason` in `fail_htlc_backwards_internal` we currently always set `rejected_by_dest` in the `PaymentPathFailed` event, implying the HTLC should *not* be retried. There are a number of cases where we use `HTLCFailReason::Reason`, but most should reasonably be treated as retryable even if our counterparty was the destination (i.e. `!rejected_by_dest`): * If an HTLC times out on-chain, this doesn't imply that the payment is no longer retryable, though the peer may well be offline so retrying may not be very useful, * If a commitment transaction "containing" a dust HTLC is confirmed on-chain, this definitely does not imply the payment is no longer retryable * If the channel we intended to relay over was closed (or force-closed) we should retry over another path, * If the channel we intended to relay over did not have enough capacity we should retry over another path, * If we received a update_fail_malformed_htlc message from our peer, we likely should *not* retry, however this should be exceedingly rare, and appears to nearly never appear in practice Thus, this commit simply disables the behavior here, opting to treat all `HTLCFailReason::Reason` errors as retryable. Note that prior to 93e645d this change would not have made sense as it would have resulted in us retrying the payment over the same channel in some cases, however we now "blame" our own channel and will avoid it when routing for the same payment.
1 parent e45db2b commit f76f60f

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3990,7 +3990,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
39903990
events::Event::PaymentPathFailed {
39913991
payment_id: Some(payment_id),
39923992
payment_hash: payment_hash.clone(),
3993-
rejected_by_dest: path.len() == 1,
3993+
rejected_by_dest: false,
39943994
network_update: None,
39953995
all_paths_failed,
39963996
path: path.clone(),

lightning/src/ln/functional_tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ fn claim_htlc_outputs_shared_tx() {
25602560
// ANTI_REORG_DELAY confirmations.
25612561
mine_transaction(&nodes[1], &node_txn[0]);
25622562
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
2563-
expect_payment_failed!(nodes[1], payment_hash_2, true);
2563+
expect_payment_failed!(nodes[1], payment_hash_2, false);
25642564
}
25652565
get_announce_close_broadcast_events(&nodes, 0, 1);
25662566
assert_eq!(nodes[0].node.list_channels().len(), 0);
@@ -2642,7 +2642,7 @@ fn claim_htlc_outputs_single_tx() {
26422642
mine_transaction(&nodes[1], &node_txn[3]);
26432643
mine_transaction(&nodes[1], &node_txn[4]);
26442644
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
2645-
expect_payment_failed!(nodes[1], payment_hash_2, true);
2645+
expect_payment_failed!(nodes[1], payment_hash_2, false);
26462646
}
26472647
get_announce_close_broadcast_events(&nodes, 0, 1);
26482648
assert_eq!(nodes[0].node.list_channels().len(), 0);
@@ -4960,7 +4960,7 @@ fn test_static_spendable_outputs_timeout_tx() {
49604960
mine_transaction(&nodes[1], &node_txn[1]);
49614961
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
49624962
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
4963-
expect_payment_failed!(nodes[1], our_payment_hash, true);
4963+
expect_payment_failed!(nodes[1], our_payment_hash, false);
49644964

49654965
let spend_txn = check_spendable_outputs!(nodes[1], node_cfgs[1].keys_manager);
49664966
assert_eq!(spend_txn.len(), 3); // SpendableOutput: remote_commitment_tx.to_remote, timeout_tx.output
@@ -5818,7 +5818,7 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
58185818

58195819
mine_transaction(&nodes[0], &htlc_timeout);
58205820
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
5821-
expect_payment_failed!(nodes[0], our_payment_hash, true);
5821+
expect_payment_failed!(nodes[0], our_payment_hash, false);
58225822

58235823
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
58245824
let spend_txn = check_spendable_outputs!(nodes[0], node_cfgs[0].keys_manager);
@@ -5900,7 +5900,7 @@ fn test_key_derivation_params() {
59005900

59015901
mine_transaction(&nodes[0], &htlc_timeout);
59025902
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
5903-
expect_payment_failed!(nodes[0], our_payment_hash, true);
5903+
expect_payment_failed!(nodes[0], our_payment_hash, false);
59045904

59055905
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
59065906
let new_keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
@@ -7304,7 +7304,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
73047304
mine_transaction(&nodes[0], &as_commitment_tx[0]);
73057305
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
73067306
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
7307-
expect_payment_failed!(nodes[0], dust_hash, true);
7307+
expect_payment_failed!(nodes[0], dust_hash, false);
73087308

73097309
connect_blocks(&nodes[0], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS - ANTI_REORG_DELAY);
73107310
check_closed_broadcast!(nodes[0], true);
@@ -7316,7 +7316,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
73167316
assert_eq!(nodes[0].node.get_and_clear_pending_events().len(), 0);
73177317
mine_transaction(&nodes[0], &timeout_tx[0]);
73187318
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
7319-
expect_payment_failed!(nodes[0], non_dust_hash, true);
7319+
expect_payment_failed!(nodes[0], non_dust_hash, false);
73207320
} else {
73217321
// We fail dust-HTLC 1 by broadcast of remote commitment tx. If revoked, fail also non-dust HTLC
73227322
mine_transaction(&nodes[0], &bs_commitment_tx[0]);
@@ -7331,7 +7331,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
73317331
check_spends!(timeout_tx[0], bs_commitment_tx[0]);
73327332
// For both a revoked or non-revoked commitment transaction, after ANTI_REORG_DELAY the
73337333
// dust HTLC should have been failed.
7334-
expect_payment_failed!(nodes[0], dust_hash, true);
7334+
expect_payment_failed!(nodes[0], dust_hash, false);
73357335

73367336
if !revoked {
73377337
assert_eq!(timeout_tx[0].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
@@ -7342,7 +7342,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
73427342
mine_transaction(&nodes[0], &timeout_tx[0]);
73437343
assert_eq!(nodes[0].node.get_and_clear_pending_events().len(), 0);
73447344
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
7345-
expect_payment_failed!(nodes[0], non_dust_hash, true);
7345+
expect_payment_failed!(nodes[0], non_dust_hash, false);
73467346
}
73477347
}
73487348

@@ -9042,7 +9042,7 @@ fn test_htlc_no_detection() {
90429042
let header_201 = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
90439043
connect_block(&nodes[0], &Block { header: header_201, txdata: vec![htlc_timeout.clone()] });
90449044
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
9045-
expect_payment_failed!(nodes[0], our_payment_hash, true);
9045+
expect_payment_failed!(nodes[0], our_payment_hash, false);
90469046
}
90479047

90489048
fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain_before_fulfill: bool) {

lightning/src/ln/monitor_tests.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn revoked_output_htlc_resolution_timing() {
141141
assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
142142

143143
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
144-
expect_payment_failed!(nodes[1], payment_hash_1, true);
144+
expect_payment_failed!(nodes[1], payment_hash_1, false);
145145
}
146146

147147
#[test]
@@ -429,7 +429,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
429429
sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()));
430430

431431
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
432-
expect_payment_failed!(nodes[0], dust_payment_hash, true);
432+
expect_payment_failed!(nodes[0], dust_payment_hash, false);
433433
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
434434

435435
// After ANTI_REORG_DELAY, A will consider its balance fully spendable and generate a
@@ -509,7 +509,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
509509
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
510510
assert_eq!(Vec::<Balance>::new(),
511511
nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances());
512-
expect_payment_failed!(nodes[0], timeout_payment_hash, true);
512+
expect_payment_failed!(nodes[0], timeout_payment_hash, false);
513513

514514
test_spendable_output(&nodes[0], &a_broadcast_txn[2]);
515515

@@ -724,7 +724,7 @@ fn test_balances_on_local_commitment_htlcs() {
724724
// panicked as described in the test introduction. This will remove the "maybe claimable"
725725
// spendable output as nodes[1] has fully claimed the second HTLC.
726726
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
727-
expect_payment_failed!(nodes[0], payment_hash, true);
727+
expect_payment_failed!(nodes[0], payment_hash, false);
728728

729729
assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
730730
claimable_amount_satoshis: 1_000_000 - 10_000 - 20_000 - chan_feerate *
@@ -923,7 +923,7 @@ fn test_no_preimage_inbound_htlc_balances() {
923923
// Once as_htlc_timeout_claim[0] reaches ANTI_REORG_DELAY confirmations, we should get a
924924
// payment failure event.
925925
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 2);
926-
expect_payment_failed!(nodes[0], to_b_failed_payment_hash, true);
926+
expect_payment_failed!(nodes[0], to_b_failed_payment_hash, false);
927927

928928
connect_blocks(&nodes[0], 1);
929929
assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
@@ -972,7 +972,7 @@ fn test_no_preimage_inbound_htlc_balances() {
972972
sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()));
973973

974974
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 2);
975-
expect_payment_failed!(nodes[1], to_a_failed_payment_hash, true);
975+
expect_payment_failed!(nodes[1], to_a_failed_payment_hash, false);
976976

977977
assert_eq!(vec![Balance::MaybePreimageClaimableHTLC {
978978
claimable_amount_satoshis: 10_000,
@@ -1216,21 +1216,21 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12161216

12171217
let mut payment_failed_events = nodes[1].node.get_and_clear_pending_events();
12181218
expect_payment_failed_conditions_event(&nodes[1], payment_failed_events.pop().unwrap(),
1219-
dust_payment_hash, true, PaymentFailedConditions::new());
1219+
dust_payment_hash, false, PaymentFailedConditions::new());
12201220
expect_payment_failed_conditions_event(&nodes[1], payment_failed_events.pop().unwrap(),
1221-
missing_htlc_payment_hash, true, PaymentFailedConditions::new());
1221+
missing_htlc_payment_hash, false, PaymentFailedConditions::new());
12221222
assert!(payment_failed_events.is_empty());
12231223

12241224
connect_blocks(&nodes[1], 1);
12251225
test_spendable_output(&nodes[1], &claim_txn[if confirm_htlc_spend_first { 2 } else { 3 }]);
12261226
connect_blocks(&nodes[1], 1);
12271227
test_spendable_output(&nodes[1], &claim_txn[if confirm_htlc_spend_first { 3 } else { 2 }]);
1228-
expect_payment_failed!(nodes[1], live_payment_hash, true);
1228+
expect_payment_failed!(nodes[1], live_payment_hash, false);
12291229
connect_blocks(&nodes[1], 1);
12301230
test_spendable_output(&nodes[1], &claim_txn[0]);
12311231
connect_blocks(&nodes[1], 1);
12321232
test_spendable_output(&nodes[1], &claim_txn[1]);
1233-
expect_payment_failed!(nodes[1], timeout_payment_hash, true);
1233+
expect_payment_failed!(nodes[1], timeout_payment_hash, false);
12341234
assert_eq!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances(), Vec::new());
12351235
}
12361236

@@ -1626,7 +1626,7 @@ fn test_revoked_counterparty_aggregated_claims() {
16261626
assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); // We shouldn't fail the payment until we spend the output
16271627

16281628
connect_blocks(&nodes[1], 5);
1629-
expect_payment_failed!(nodes[1], revoked_payment_hash, true);
1629+
expect_payment_failed!(nodes[1], revoked_payment_hash, false);
16301630
test_spendable_output(&nodes[1], &claim_txn_2[0]);
16311631
assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
16321632
}

lightning/src/ln/payment_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co
894894
nodes[0].chain_monitor.chain_monitor.channel_monitor_updated(funding_txo, update).unwrap();
895895
}
896896
if payment_timeout {
897-
expect_payment_failed!(nodes[0], payment_hash, true);
897+
expect_payment_failed!(nodes[0], payment_hash, false);
898898
} else {
899899
expect_payment_sent!(nodes[0], payment_preimage);
900900
}
@@ -938,7 +938,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co
938938
if persist_manager_post_event {
939939
assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
940940
} else if payment_timeout {
941-
expect_payment_failed!(nodes[0], payment_hash, true);
941+
expect_payment_failed!(nodes[0], payment_hash, false);
942942
} else {
943943
expect_payment_sent!(nodes[0], payment_preimage);
944944
}

lightning/src/ln/reorg_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn test_counterparty_revoked_reorg() {
256256

257257
// Connect blocks to confirm the unrevoked commitment transaction
258258
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 2);
259-
expect_payment_failed!(nodes[1], payment_hash_4, true);
259+
expect_payment_failed!(nodes[1], payment_hash_4, false);
260260
}
261261

262262
fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_unconfirmed: bool, connect_style: ConnectStyle) {

0 commit comments

Comments
 (0)