]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move RBF-bump to start of update_claims_view to avoid double-bump 2021-07-no-instant-rbf
authorMatt Corallo <git@bluematt.me>
Fri, 2 Jul 2021 00:13:13 +0000 (00:13 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 2 Jul 2021 17:55:47 +0000 (17:55 +0000)
`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

index cd28314651057d3659ee64dc5f2141935595b96b..1aff410dc696c4bb9a9093be931004d19983d6cb 100644 (file)
@@ -389,6 +389,16 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                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<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                        }
                }
 
-               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<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                        }
                }
 
-               // 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() {