Skip to content

Commit 9fcc9d2

Browse files
committed
Clean up get_broadcasted_holder_claims confirmation height param use
1 parent a4766dc commit 9fcc9d2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,13 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
13571357
// *we* sign a holder commitment transaction, not when e.g. a watchtower broadcasts one of our
13581358
// holder commitment transactions.
13591359
if self.broadcasted_holder_revokable_script.is_some() {
1360-
let (claim_reqs, _) = self.get_broadcasted_holder_claims(&self.current_holder_commitment_tx, 0);
1360+
// Assume that the broadcasted commitment transaction confirmed in the current best
1361+
// block. Even if not, its a reasonable metric for the bump criteria on the HTLC
1362+
// transactions.
1363+
let (claim_reqs, _) = self.get_broadcasted_holder_claims(&self.current_holder_commitment_tx, self.best_block.height());
13611364
self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
13621365
if let Some(ref tx) = self.prev_holder_signed_commitment_tx {
1363-
let (claim_reqs, _) = self.get_broadcasted_holder_claims(&tx, 0);
1366+
let (claim_reqs, _) = self.get_broadcasted_holder_claims(&tx, self.best_block.height());
13641367
self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, self.best_block.height(), self.best_block.height(), broadcaster, fee_estimator, logger);
13651368
}
13661369
}
@@ -1728,7 +1731,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17281731
// Returns (1) `PackageTemplate`s that can be given to the OnChainTxHandler, so that the handler can
17291732
// broadcast transactions claiming holder HTLC commitment outputs and (2) a holder revokable
17301733
// script so we can detect whether a holder transaction has been seen on-chain.
1731-
fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, height: u32) -> (Vec<PackageTemplate>, Option<(Script, PublicKey, PublicKey)>) {
1734+
fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, conf_height: u32) -> (Vec<PackageTemplate>, Option<(Script, PublicKey, PublicKey)>) {
17321735
let mut claim_requests = Vec::with_capacity(holder_tx.htlc_outputs.len());
17331736

17341737
let redeemscript = chan_utils::get_revokeable_redeemscript(&holder_tx.revocation_key, self.on_holder_tx_csv, &holder_tx.delayed_payment_key);
@@ -1747,7 +1750,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17471750
};
17481751
HolderHTLCOutput::build_accepted(payment_preimage, htlc.amount_msat)
17491752
};
1750-
let htlc_package = PackageTemplate::build_package(holder_tx.txid, transaction_output_index, PackageSolvingData::HolderHTLCOutput(htlc_output), height, false, height);
1753+
let htlc_package = PackageTemplate::build_package(holder_tx.txid, transaction_output_index, PackageSolvingData::HolderHTLCOutput(htlc_output), conf_height, false, conf_height);
17511754
claim_requests.push(htlc_package);
17521755
}
17531756
}
@@ -2043,6 +2046,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20432046
self.pending_monitor_events.push(MonitorEvent::CommitmentTxBroadcasted(self.funding_info.0));
20442047
let commitment_tx = self.onchain_tx_handler.get_fully_signed_holder_tx(&self.funding_redeemscript);
20452048
self.holder_tx_signed = true;
2049+
// Because we're building a new commitment transaction, we should construct the package
2050+
// assuming it gets confirmed in the next block. Sadly, we have code which considers
2051+
// "not yet confirmed" things as discardable, so we cannot do that here.
20462052
let (mut new_outpoints, _) = self.get_broadcasted_holder_claims(&self.current_holder_commitment_tx, self.best_block.height());
20472053
let new_outputs = self.get_broadcasted_holder_watch_outputs(&self.current_holder_commitment_tx, &commitment_tx);
20482054
if !new_outputs.is_empty() {

0 commit comments

Comments
 (0)