From: Matt Corallo Date: Sat, 7 Sep 2024 13:26:36 +0000 (+0000) Subject: Make ignoring duplicates `PackageTemplate` claims more robust X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=eec6ca9887d0359cc9e3fe45dbc430793efa2336;p=rust-lightning Make ignoring duplicates `PackageTemplate` claims more robust `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. --- diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index 9ebf02252..791972467 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -739,7 +739,18 @@ impl OnchainTxHandler { // 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 {