Move RBF-bump to start of update_claims_view to avoid double-bump
[rust-lightning] / 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() {