Skip to content

Commit b99d819

Browse files
author
Antoine Riard
committed
Fix duplicata of adjusted justice tx generation in OnchainTxHandler
Adjusted tx occurs when a previous aggregated claim tx has seen one of its outpoint being partially claimed by a remote tx. To pursue claiming of the remaining outpoint a adjusted claim tx is generated with leftover of claimable outpoints. Previously, in case of block-rescan where a partial claim occurs, we would generate duplicated adjusted tx, wrongly inflating feerate for next bumps. At rescan, if input has already been dropped from outpoints map from a claiming request, don't regenerate again a adjuste tx.
1 parent 83c9eb4 commit b99d819

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4182,9 +4182,14 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() {
41824182
check_closed_broadcast!(nodes[1], false);
41834183

41844184
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
4185-
assert_eq!(node_txn.len(), 4 ); // ChannelMonitor: justice tx on revoked commitment, justice tx on revoked HTLC-timeout, adjusted justice tx, ChannelManager: local commitment tx
4185+
assert_eq!(node_txn.len(), 4); // ChannelMonitor: justice tx on revoked commitment, justice tx on revoked HTLC-timeout, adjusted justice tx, ChannelManager: local commitment tx
4186+
assert_eq!(node_txn[0].input.len(), 2);
4187+
check_spends!(node_txn[0], revoked_local_txn[0]);
4188+
check_spends!(node_txn[1], chan_1.3);
41864189
assert_eq!(node_txn[2].input.len(), 1);
41874190
check_spends!(node_txn[2], revoked_htlc_txn[0]);
4191+
assert_eq!(node_txn[3].input.len(), 1);
4192+
check_spends!(node_txn[3], revoked_local_txn[0]);
41884193

41894194
// Check B's ChannelMonitor was able to generate the right spendable output descriptor
41904195
let spend_txn = check_spendable_outputs!(nodes[1], 1);

lightning/src/ln/onchaintx.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,17 +573,21 @@ impl OnchainTxHandler {
573573
if set_equality {
574574
clean_claim_request_after_safety_delay!();
575575
} else { // If false, generate new claim request with update outpoint set
576+
let mut at_least_one_drop = false;
576577
for input in tx.input.iter() {
577578
if let Some(input_material) = claim_material.per_input_material.remove(&input.previous_output) {
578579
claimed_outputs_material.push((input.previous_output, input_material));
580+
at_least_one_drop = true;
579581
}
580582
// If there are no outpoints left to claim in this request, drop it entirely after ANTI_REORG_DELAY.
581583
if claim_material.per_input_material.is_empty() {
582584
clean_claim_request_after_safety_delay!();
583585
}
584586
}
585587
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
586-
bump_candidates.insert(first_claim_txid_height.0.clone());
588+
if at_least_one_drop {
589+
bump_candidates.insert(first_claim_txid_height.0.clone());
590+
}
587591
}
588592
break; //No need to iterate further, either tx is our or their
589593
} else {

0 commit comments

Comments
 (0)