Skip to content

Commit da226cc

Browse files
committed
Watch all outputs irrespective of claimable outpoints.
This removes dependency of watched_outputs from per_commitment_claimable_outpoints, it is required since we will no longer have direct access to per_commitment_claimable_outpoints once we start publishing PersistClaimInfo as part of #3049.
1 parent 1690c66 commit da226cc

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,16 +3232,14 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32323232
/// height > height + CLTV_SHARED_CLAIM_BUFFER. In any case, will install monitoring for
32333233
/// HTLC-Success/HTLC-Timeout transactions.
32343234
///
3235-
/// Returns packages to claim the revoked output(s), as well as additional outputs to watch and
3236-
/// general information about the output that is to the counterparty in the commitment
3237-
/// transaction.
3235+
/// Returns packages to claim the revoked output(s) and general information about the output that
3236+
/// is to the counterparty in the commitment transaction.
32383237
fn check_spend_counterparty_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, block_hash: &BlockHash, logger: &L)
3239-
-> (Vec<PackageTemplate>, TransactionOutputs, CommitmentTxCounterpartyOutputInfo)
3238+
-> (Vec<PackageTemplate>, CommitmentTxCounterpartyOutputInfo)
32403239
where L::Target: Logger {
32413240
// Most secp and related errors trying to create keys means we have no hope of constructing
32423241
// a spend transaction...so we return no transactions to broadcast
32433242
let mut claimable_outpoints = Vec::new();
3244-
let mut watch_outputs = Vec::new();
32453243
let mut to_counterparty_output_info = None;
32463244

32473245
let commitment_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
@@ -3251,7 +3249,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32513249
( $thing : expr ) => {
32523250
match $thing {
32533251
Ok(a) => a,
3254-
Err(_) => return (claimable_outpoints, (commitment_txid, watch_outputs), to_counterparty_output_info)
3252+
Err(_) => return (claimable_outpoints, to_counterparty_output_info)
32553253
}
32563254
};
32573255
}
@@ -3285,8 +3283,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32853283
if transaction_output_index as usize >= tx.output.len() ||
32863284
tx.output[transaction_output_index as usize].value != htlc.amount_msat / 1000 {
32873285
// per_commitment_data is corrupt or our commitment signing key leaked!
3288-
return (claimable_outpoints, (commitment_txid, watch_outputs),
3289-
to_counterparty_output_info);
3286+
return (claimable_outpoints, to_counterparty_output_info);
32903287
}
32913288
let revk_htlc_outp = RevokedHTLCOutput::build(per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key, htlc.amount_msat / 1000, htlc.clone(), &self.onchain_tx_handler.channel_transaction_parameters.channel_type_features);
32923289
let justice_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::RevokedHTLCOutput(revk_htlc_outp), htlc.cltv_expiry, height);
@@ -3299,9 +3296,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32993296
if !claimable_outpoints.is_empty() || per_commitment_option.is_some() { // ie we're confident this is actually ours
33003297
// We're definitely a counterparty commitment transaction!
33013298
log_error!(logger, "Got broadcast of revoked counterparty commitment transaction, going to generate general spend tx with {} inputs", claimable_outpoints.len());
3302-
for (idx, outp) in tx.output.iter().enumerate() {
3303-
watch_outputs.push((idx as u32, outp.clone()));
3304-
}
33053299
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number);
33063300

33073301
if let Some(per_commitment_claimable_data) = per_commitment_option {
@@ -3327,9 +3321,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33273321
// already processed the block, resulting in the counterparty_commitment_txn_on_chain entry
33283322
// not being generated by the above conditional. Thus, to be safe, we go ahead and
33293323
// insert it here.
3330-
for (idx, outp) in tx.output.iter().enumerate() {
3331-
watch_outputs.push((idx as u32, outp.clone()));
3332-
}
33333324
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number);
33343325

33353326
log_info!(logger, "Got broadcast of non-revoked counterparty commitment transaction {}", commitment_txid);
@@ -3345,7 +3336,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33453336
}
33463337

33473338
}
3348-
(claimable_outpoints, (commitment_txid, watch_outputs), to_counterparty_output_info)
3339+
(claimable_outpoints, to_counterparty_output_info)
33493340
}
33503341

33513342
/// Returns the HTLC claim package templates and the counterparty output info
@@ -3777,24 +3768,25 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37773768
self.funding_spend_seen = true;
37783769
let mut commitment_tx_to_counterparty_output = None;
37793770
if (tx.input[0].sequence.0 >> 8*3) as u8 == 0x80 && (tx.lock_time.to_consensus_u32() >> 8*3) as u8 == 0x20 {
3780-
let (mut new_outpoints, new_outputs, counterparty_output_idx_sats) =
3781-
self.check_spend_counterparty_transaction(&tx, height, &block_hash, &logger);
3782-
commitment_tx_to_counterparty_output = counterparty_output_idx_sats;
3783-
if !new_outputs.1.is_empty() {
3784-
watch_outputs.push(new_outputs);
3785-
}
3786-
claimable_outpoints.append(&mut new_outpoints);
3787-
if new_outpoints.is_empty() {
3788-
if let Some((mut new_outpoints, new_outputs)) = self.check_spend_holder_transaction(&tx, height, &block_hash, &logger) {
3789-
#[cfg(not(fuzzing))]
3790-
debug_assert!(commitment_tx_to_counterparty_output.is_none(),
3791-
"A commitment transaction matched as both a counterparty and local commitment tx?");
3792-
if !new_outputs.1.is_empty() {
3793-
watch_outputs.push(new_outputs);
3794-
}
3795-
claimable_outpoints.append(&mut new_outpoints);
3796-
balance_spendable_csv = Some(self.on_holder_tx_csv);
3771+
if let Some((mut new_outpoints, new_outputs)) = self.check_spend_holder_transaction(&tx, height, &block_hash, &logger) {
3772+
if !new_outputs.1.is_empty() {
3773+
watch_outputs.push(new_outputs);
3774+
}
3775+
3776+
claimable_outpoints.append(&mut new_outpoints);
3777+
balance_spendable_csv = Some(self.on_holder_tx_csv);
3778+
} else {
3779+
let mut new_watch_outputs = Vec::new();
3780+
for (idx, outp) in tx.output.iter().enumerate() {
3781+
new_watch_outputs.push((idx as u32, outp.clone()));
37973782
}
3783+
watch_outputs.push((txid, new_watch_outputs));
3784+
3785+
let (mut new_outpoints, counterparty_output_idx_sats) =
3786+
self.check_spend_counterparty_transaction(&tx, height, &block_hash, &logger);
3787+
commitment_tx_to_counterparty_output = counterparty_output_idx_sats;
3788+
3789+
claimable_outpoints.append(&mut new_outpoints);
37983790
}
37993791
}
38003792
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {

0 commit comments

Comments
 (0)