]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Always pass height to OnchainTxHandler::update_claims_view
authorMatt Corallo <git@bluematt.me>
Wed, 19 May 2021 21:47:30 +0000 (21:47 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 28 May 2021 23:56:44 +0000 (23:56 +0000)
This simplifies logic somewhat and avoids duplicating the storage
of the current height in OnchainTxHandler.

lightning/src/chain/channelmonitor.rs
lightning/src/chain/onchaintx.rs

index 7fc512a5a1859429b265d2b7ffc967b92fec3f4b..f789b4a7ee7fc92a4ee547678419ee00071cd075 100644 (file)
@@ -1387,7 +1387,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                macro_rules! claim_htlcs {
                        ($commitment_number: expr, $txid: expr) => {
                                let htlc_claim_reqs = self.get_counterparty_htlc_output_claim_reqs($commitment_number, $txid, None);
-                               self.onchain_tx_handler.update_claims_view(&Vec::new(), htlc_claim_reqs, None, broadcaster, fee_estimator, logger);
+                               self.onchain_tx_handler.update_claims_view(&Vec::new(), htlc_claim_reqs, self.best_block.height(), broadcaster, fee_estimator, logger);
                        }
                }
                if let Some(txid) = self.current_counterparty_commitment_txid {
@@ -1410,10 +1410,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                // holder commitment transactions.
                if self.broadcasted_holder_revokable_script.is_some() {
                        let (claim_reqs, _) = self.get_broadcasted_holder_claims(&self.current_holder_commitment_tx, 0);
-                       self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, None, broadcaster, fee_estimator, logger);
+                       self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, self.best_block.height(), broadcaster, fee_estimator, logger);
                        if let Some(ref tx) = self.prev_holder_signed_commitment_tx {
                                let (claim_reqs, _) = self.get_broadcasted_holder_claims(&tx, 0);
-                               self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, None, broadcaster, fee_estimator, logger);
+                               self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, self.best_block.height(), broadcaster, fee_estimator, logger);
                        }
                }
        }
@@ -2144,7 +2144,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                        }
                }
 
-               self.onchain_tx_handler.update_claims_view(&txn_matched, claimable_outpoints, Some(height), &&*broadcaster, &&*fee_estimator, &&*logger);
+               self.onchain_tx_handler.update_claims_view(&txn_matched, claimable_outpoints, height, &&*broadcaster, &&*fee_estimator, &&*logger);
 
                // Determine new outputs to watch by comparing against previously known outputs to watch,
                // updating the latter in the process.
index 9bbc2a4abd2e3e9a852c71e5e1d700d043fd4472..fc4805b3391eba3b62a683e947918ca8bd6eab10 100644 (file)
@@ -167,7 +167,6 @@ pub struct OnchainTxHandler<ChannelSigner: Sign> {
 
        onchain_events_awaiting_threshold_conf: Vec<OnchainEventEntry>,
 
-       latest_height: u32,
 
        pub(super) secp_ctx: Secp256k1<secp256k1::All>,
 }
@@ -222,7 +221,6 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                                }
                        }
                }
-               self.latest_height.write(writer)?;
 
                write_tlv_fields!(writer, {}, {});
                Ok(())
@@ -289,7 +287,6 @@ impl<'a, K: KeysInterface> ReadableArgs<&'a K> for OnchainTxHandler<K::Signer> {
                        };
                        onchain_events_awaiting_threshold_conf.push(OnchainEventEntry { txid, height, event });
                }
-               let latest_height = Readable::read(reader)?;
 
                read_tlv_fields!(reader, {}, {});
 
@@ -307,7 +304,6 @@ impl<'a, K: KeysInterface> ReadableArgs<&'a K> for OnchainTxHandler<K::Signer> {
                        claimable_outpoints,
                        pending_claim_requests,
                        onchain_events_awaiting_threshold_conf,
-                       latest_height,
                        secp_ctx,
                })
        }
@@ -326,7 +322,6 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                        pending_claim_requests: HashMap::new(),
                        claimable_outpoints: HashMap::new(),
                        onchain_events_awaiting_threshold_conf: Vec::new(),
-                       latest_height: 0,
 
                        secp_ctx,
                }
@@ -370,15 +365,11 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
        /// for this channel, provide new relevant on-chain transactions and/or new claim requests.
        /// Formerly this was named `block_connected`, but it is now also used for claiming an HTLC output
        /// if we receive a preimage after force-close.
-       pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, latest_height: Option<u32>, broadcaster: &B, fee_estimator: &F, logger: &L)
+       pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, height: u32, broadcaster: &B, fee_estimator: &F, logger: &L)
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator,
                                        L::Target: Logger,
        {
-               let height = match latest_height {
-                       Some(h) => h,
-                       None => self.latest_height,
-               };
                log_trace!(logger, "Updating claims view at height {} with {} matched transactions and {} claim requests", height, txn_matched.len(), requests.len());
                let mut preprocessed_requests = Vec::with_capacity(requests.len());
                let mut aggregated_request = None;