Skip to content

Commit 23eb12e

Browse files
committed
Track ChannelTransactionParameters in RevokedOutput
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied together, often tracking some of the same state twice. As we introduce support for splices in the `ChannelMonitor`, we'd like to avoid leaking some of those details to the `OnchainTxHandler`. Ultimately, the `OnchainTxHandler` should stand on its own and support claiming funds from multiple `ChannelMonitor`s, allowing us to save on fees by batching aggregatable claims across multiple in-flight closing channels. Once splices are supported, we may run into cases where we are attempting to claim an output from a specific `FundingScope`, while also having an additional pending `FundingScope` for a splice. If the pending splice confirms over the output claim, we need to cancel the claim and re-offer it with the set of relevant parameters in the new `FundingScope`. This commit tracks the `ChannelTransactionParameters` for the specific `FundingScope` the `RevokedOutput` claim originated from. This allows us to remove the dependency on `OnchainTxHandler` when obtaining the current `ChannelTransactionParameters` and ensures any alternative state due to splicing does not leak into the `OnchainTxHandler`.
1 parent 97348c7 commit 23eb12e

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

Diff for: lightning/src/chain/channelmonitor.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -3734,12 +3734,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37343734
for (idx, outp) in tx.output.iter().enumerate() {
37353735
if outp.script_pubkey == revokeable_p2wsh {
37363736
let revk_outp = RevokedOutput::build(
3737-
per_commitment_point,
3738-
self.counterparty_commitment_params.counterparty_delayed_payment_base_key,
3739-
self.counterparty_commitment_params.counterparty_htlc_base_key,
3740-
per_commitment_key, outp.value,
3741-
self.counterparty_commitment_params.on_counterparty_tx_csv,
3742-
self.channel_type_features().supports_anchors_zero_fee_htlc_tx(),
3737+
per_commitment_point, per_commitment_key, outp.value,
3738+
self.funding.channel_parameters.channel_type_features.supports_anchors_zero_fee_htlc_tx(),
3739+
self.funding.channel_parameters.clone(),
37433740
);
37443741
let justice_package = PackageTemplate::build_package(
37453742
commitment_txid, idx as u32,
@@ -3936,10 +3933,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39363933
if input.previous_output.txid == *commitment_txid && input.witness.len() == 5 && tx.output.get(idx).is_some() {
39373934
log_error!(logger, "Got broadcast of revoked counterparty HTLC transaction, spending {}:{}", htlc_txid, idx);
39383935
let revk_outp = RevokedOutput::build(
3939-
per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key,
3940-
self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key,
3941-
tx.output[idx].value, self.counterparty_commitment_params.on_counterparty_tx_csv,
3942-
false
3936+
per_commitment_point, per_commitment_key, tx.output[idx].value, false,
3937+
self.funding.channel_parameters.clone(),
39433938
);
39443939
let justice_package = PackageTemplate::build_package(
39453940
htlc_txid, idx as u32, PackageSolvingData::RevokedOutput(revk_outp),

Diff for: lightning/src/chain/package.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,19 @@ pub(crate) struct RevokedOutput {
136136
amount: Amount,
137137
on_counterparty_tx_csv: u16,
138138
is_counterparty_balance_on_anchors: Option<()>,
139+
channel_parameters: Option<ChannelTransactionParameters>,
139140
}
140141

141142
impl RevokedOutput {
142-
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: DelayedPaymentBasepoint, counterparty_htlc_base_key: HtlcBasepoint, per_commitment_key: SecretKey, amount: Amount, on_counterparty_tx_csv: u16, is_counterparty_balance_on_anchors: bool) -> Self {
143+
pub(crate) fn build(
144+
per_commitment_point: PublicKey, per_commitment_key: SecretKey, amount: Amount,
145+
is_counterparty_balance_on_anchors: bool, channel_parameters: ChannelTransactionParameters,
146+
) -> Self {
147+
let directed_params = channel_parameters.as_counterparty_broadcastable();
148+
let counterparty_keys = directed_params.broadcaster_pubkeys();
149+
let counterparty_delayed_payment_base_key = counterparty_keys.delayed_payment_basepoint;
150+
let counterparty_htlc_base_key = counterparty_keys.htlc_basepoint;
151+
let on_counterparty_tx_csv = directed_params.contest_delay();
143152
RevokedOutput {
144153
per_commitment_point,
145154
counterparty_delayed_payment_base_key,
@@ -148,7 +157,8 @@ impl RevokedOutput {
148157
weight: WEIGHT_REVOKED_OUTPUT,
149158
amount,
150159
on_counterparty_tx_csv,
151-
is_counterparty_balance_on_anchors: if is_counterparty_balance_on_anchors { Some(()) } else { None }
160+
is_counterparty_balance_on_anchors: if is_counterparty_balance_on_anchors { Some(()) } else { None },
161+
channel_parameters: Some(channel_parameters),
152162
}
153163
}
154164
}
@@ -161,7 +171,8 @@ impl_writeable_tlv_based!(RevokedOutput, {
161171
(8, weight, required),
162172
(10, amount, required),
163173
(12, on_counterparty_tx_csv, required),
164-
(14, is_counterparty_balance_on_anchors, option)
174+
(14, is_counterparty_balance_on_anchors, option),
175+
(15, channel_parameters, (option: ReadableArgs, None)), // Added in 0.2.
165176
});
166177

167178
/// A struct to describe a revoked offered output and corresponding information to generate a
@@ -778,8 +789,8 @@ impl PackageSolvingData {
778789
let channel_parameters = &onchain_handler.channel_transaction_parameters;
779790
match self {
780791
PackageSolvingData::RevokedOutput(ref outp) => {
781-
let directed_parameters =
782-
&onchain_handler.channel_transaction_parameters.as_counterparty_broadcastable();
792+
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);
793+
let directed_parameters = channel_parameters.as_counterparty_broadcastable();
783794
debug_assert_eq!(
784795
directed_parameters.broadcaster_pubkeys().delayed_payment_basepoint,
785796
outp.counterparty_delayed_payment_base_key,
@@ -1589,7 +1600,6 @@ mod tests {
15891600
ChannelTransactionParameters, HolderCommitmentTransaction, HTLCOutputInCommitment,
15901601
};
15911602
use crate::types::payment::{PaymentPreimage, PaymentHash};
1592-
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint};
15931603
use crate::sign::{ChannelDerivationParameters, HTLCDescriptor};
15941604

15951605
use bitcoin::absolute::LockTime;
@@ -1627,7 +1637,11 @@ mod tests {
16271637
let secp_ctx = Secp256k1::new();
16281638
let dumb_scalar = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
16291639
let dumb_point = PublicKey::from_secret_key(&secp_ctx, &dumb_scalar);
1630-
PackageSolvingData::RevokedOutput(RevokedOutput::build(dumb_point, DelayedPaymentBasepoint::from(dumb_point), HtlcBasepoint::from(dumb_point), dumb_scalar, Amount::ZERO, 0, $is_counterparty_balance_on_anchors))
1640+
let channel_parameters = ChannelTransactionParameters::test_dummy(0);
1641+
PackageSolvingData::RevokedOutput(RevokedOutput::build(
1642+
dumb_point, dumb_scalar, Amount::ZERO, $is_counterparty_balance_on_anchors,
1643+
channel_parameters,
1644+
))
16311645
}
16321646
}
16331647
}

0 commit comments

Comments
 (0)