From 7b161f7b0feb0fbe7d6465eb1d705c5b1bddf554 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 2 Jul 2021 00:13:13 +0000 Subject: [PATCH] Move RBF-bump to start of update_claims_view to avoid double-bump `OnchainTx::update_claims_view` currently checks if there are packages which need to be RBF-bumped first, prior to adding new packages to the tracking map. This can, in some cases, cause us to RBF-bump a package which we only just added, at least in cases where we're skipping blocks being connected. Here we simply move the RBF-bump check to the top of `OnchainTx::update_claims_view`, avoiding any such cases (though there are still some cases where we may call `OnchainTx::update_claims_view` twice for the same block, which is resolved separately). --- lightning/src/chain/onchaintx.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index cd283146..1aff410d 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -389,6 +389,16 @@ impl OnchainTxHandler { let mut preprocessed_requests = Vec::with_capacity(requests.len()); let mut aggregated_request = None; + let mut bump_candidates = HashMap::new(); + // Check if any pending claim request must be rescheduled + for (first_claim_txid, ref request) in self.pending_claim_requests.iter() { + if let Some(h) = request.timer() { + if cur_height >= h { + bump_candidates.insert(*first_claim_txid, (*request).clone()); + } + } + } + // Try to aggregate outputs if their timelock expiration isn't imminent (package timelock // <= CLTV_SHARED_CLAIM_BUFFER) and they don't require an immediate nLockTime (aggregable). for req in requests { @@ -453,7 +463,6 @@ impl OnchainTxHandler { } } - let mut bump_candidates = HashMap::new(); for tx in txn_matched { // Scan all input to verify is one of the outpoint spent is of interest for us let mut claimed_outputs_material = Vec::new(); @@ -555,15 +564,6 @@ impl OnchainTxHandler { } } - // Check if any pending claim request must be rescheduled - for (first_claim_txid, ref request) in self.pending_claim_requests.iter() { - if let Some(h) = request.timer() { - if cur_height >= h { - bump_candidates.insert(*first_claim_txid, (*request).clone()); - } - } - } - // Build, bump and rebroadcast tx accordingly log_trace!(logger, "Bumping {} candidates", bump_candidates.len()); for (first_claim_txid, request) in bump_candidates.iter() { -- 2.30.2