]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make ignoring duplicates `PackageTemplate` claims more robust
authorMatt Corallo <git@bluematt.me>
Sat, 7 Sep 2024 13:26:36 +0000 (13:26 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 18 Sep 2024 16:48:42 +0000 (16:48 +0000)
`update_claims_view_from_requests` assumes that any
`PackageTemplate`s passed to it will not be aggregated (i.e. have
only one input) and uses that assumption when skipping duplicates.

This is currently true, but dropping `PackateTemplate` claims
entirely based on only the first input is somewhat brittle so we
add a debug assertion here and update the logic to not spuriously
drop claims if they happen to come into the `OnChainTxHandler`
pre-aggregated.

lightning/src/chain/onchaintx.rs

index 9ebf022529ca53a2966a189ffcc0f0a94f8f831f..7919724672e803081328368f76bcf089b0a6c815 100644 (file)
@@ -739,7 +739,18 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
 
                // First drop any claims which are duplicate
                requests.retain(|req| {
-                       if self.claimable_outpoints.get(req.outpoints()[0]).is_some() {
+                       debug_assert_eq!(
+                               req.outpoints().len(),
+                               1,
+                               "Claims passed to `update_claims_view_from_requests` should not be aggregated"
+                       );
+                       let mut all_outpoints_claiming = true;
+                       for outpoint in req.outpoints() {
+                               if self.claimable_outpoints.get(&outpoint).is_none() {
+                                       all_outpoints_claiming = false;
+                               }
+                       }
+                       if all_outpoints_claiming {
                                log_info!(logger, "Ignoring second claim for outpoint {}:{}, already registered its claiming request", req.outpoints()[0].txid, req.outpoints()[0].vout);
                                false
                        } else {