Skip to content

Commit ee34469

Browse files
committed
Split update_claims_view
Previously it was one, now it's two methods: `update_claims_view_from_matched_txn` and `update_claims_view_from_requests`.
1 parent 48b82b3 commit ee34469

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

lightning/src/chain/channelmonitor.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
21752175
macro_rules! claim_htlcs {
21762176
($commitment_number: expr, $txid: expr) => {
21772177
let (htlc_claim_reqs, _) = self.get_counterparty_output_claim_info($commitment_number, $txid, None);
2178-
self.onchain_tx_handler.update_claims_view(&Vec::new(), htlc_claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
2178+
self.onchain_tx_handler.update_claims_view_from_requests(htlc_claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
21792179
}
21802180
}
21812181
if let Some(txid) = self.current_counterparty_commitment_txid {
@@ -2201,10 +2201,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22012201
// block. Even if not, its a reasonable metric for the bump criteria on the HTLC
22022202
// transactions.
22032203
let (claim_reqs, _) = self.get_broadcasted_holder_claims(&self.current_holder_commitment_tx, self.best_block.height());
2204-
self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
2204+
self.onchain_tx_handler.update_claims_view_from_requests(claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
22052205
if let Some(ref tx) = self.prev_holder_signed_commitment_tx {
22062206
let (claim_reqs, _) = self.get_broadcasted_holder_claims(&tx, self.best_block.height());
2207-
self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
2207+
self.onchain_tx_handler.update_claims_view_from_requests(claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
22082208
}
22092209
}
22102210
}
@@ -2291,8 +2291,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22912291
PackageSolvingData::HolderFundingOutput(funding_output),
22922292
best_block_height, false, best_block_height,
22932293
);
2294-
self.onchain_tx_handler.update_claims_view(
2295-
&[], vec![commitment_package], best_block_height, best_block_height,
2294+
self.onchain_tx_handler.update_claims_view_from_requests(
2295+
vec![commitment_package], best_block_height, best_block_height,
22962296
broadcaster, &bounded_fee_estimator, logger,
22972297
);
22982298
}
@@ -2930,7 +2930,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29302930
/// Update state for new block(s)/transaction(s) confirmed. Note that the caller must update
29312931
/// `self.best_block` before calling if a new best blockchain tip is available. More
29322932
/// concretely, `self.best_block` must never be at a lower height than `conf_height`, avoiding
2933-
/// complexity especially in `OnchainTx::update_claims_view`.
2933+
/// complexity especially in
2934+
/// `OnchainTx::update_claims_view_from_requests`/`OnchainTx::update_claims_view_from_matched_txn`.
29342935
///
29352936
/// `conf_height` should be set to the height at which any new transaction(s)/block(s) were
29362937
/// confirmed at, even if it is not the current best height.
@@ -3053,7 +3054,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30533054
}
30543055
}
30553056

3056-
self.onchain_tx_handler.update_claims_view(&txn_matched, claimable_outpoints, conf_height, self.best_block.height(), broadcaster, fee_estimator, logger);
3057+
self.onchain_tx_handler.update_claims_view_from_requests(claimable_outpoints, conf_height, self.best_block.height(), broadcaster, fee_estimator, logger);
3058+
self.onchain_tx_handler.update_claims_view_from_matched_txn(&txn_matched, conf_height, conf_hash, self.best_block.height(), broadcaster, fee_estimator, logger);
30573059

30583060
// Determine new outputs to watch by comparing against previously known outputs to watch,
30593061
// updating the latter in the process.

lightning/src/chain/onchaintx.rs

+33-10
Original file line numberDiff line numberDiff line change
@@ -547,17 +547,22 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
547547

548548
/// Upon channelmonitor.block_connected(..) or upon provision of a preimage on the forward link
549549
/// for this channel, provide new relevant on-chain transactions and/or new claim requests.
550-
/// Formerly this was named `block_connected`, but it is now also used for claiming an HTLC output
551-
/// if we receive a preimage after force-close.
552-
/// `conf_height` represents the height at which the transactions in `txn_matched` were
553-
/// confirmed. This does not need to equal the current blockchain tip height, which should be
554-
/// provided via `cur_height`, however it must never be higher than `cur_height`.
555-
pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L)
556-
where B::Target: BroadcasterInterface,
557-
F::Target: FeeEstimator,
558-
L::Target: Logger,
550+
/// Together with `update_claims_view_from_matched_txn` this used to be named
551+
/// `block_connected`, but it is now also used for claiming an HTLC output if we receive a
552+
/// preimage after force-close.
553+
///
554+
/// `conf_height` represents the minimal height at which the request could get confirmed. This
555+
/// does not need to equal the current blockchain tip height, which should be provided via
556+
/// `cur_height`, however it must never be higher than `cur_height`.
557+
pub(crate) fn update_claims_view_from_requests<B: Deref, F: Deref, L: Deref>(
558+
&mut self, requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32,
559+
broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
560+
) where
561+
B::Target: BroadcasterInterface,
562+
F::Target: FeeEstimator,
563+
L::Target: Logger,
559564
{
560-
log_debug!(logger, "Updating claims view at height {} with {} matched transactions in block {} and {} claim requests", cur_height, txn_matched.len(), conf_height, requests.len());
565+
log_debug!(logger, "Updating claims view at height {} with {} claim requests", cur_height, requests.len());
561566
let mut preprocessed_requests = Vec::with_capacity(requests.len());
562567
let mut aggregated_request = None;
563568

@@ -637,7 +642,25 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
637642
self.pending_claim_requests.insert(txid, req);
638643
}
639644
}
645+
}
640646

647+
/// Upon channelmonitor.block_connected(..) or upon provision of a preimage on the forward link
648+
/// for this channel, provide new relevant on-chain transactions and/or new claim requests.
649+
/// Together with `update_claims_view_from_requests` this used to be named `block_connected`,
650+
/// but it is now also used for claiming an HTLC output if we receive a preimage after force-close.
651+
///
652+
/// `conf_height` represents the height at which the transactions in `txn_matched` were
653+
/// confirmed. This does not need to equal the current blockchain tip height, which should be
654+
/// provided via `cur_height`, however it must never be higher than `cur_height`.
655+
pub(crate) fn update_claims_view_from_matched_txn<B: Deref, F: Deref, L: Deref>(
656+
&mut self, txn_matched: &[&Transaction], conf_height: u32, conf_hash: BlockHash,
657+
cur_height: u32, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
658+
) where
659+
B::Target: BroadcasterInterface,
660+
F::Target: FeeEstimator,
661+
L::Target: Logger,
662+
{
663+
log_debug!(logger, "Updating claims view at height {} with {} matched transactions in block {}", cur_height, txn_matched.len(), conf_height);
641664
let mut bump_candidates = HashMap::new();
642665
for tx in txn_matched {
643666
// Scan all input to verify is one of the outpoint spent is of interest for us

0 commit comments

Comments
 (0)