Skip to content

Commit fbaf2bc

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. This commit tracks the `ChannelTransactionParameters` for the specific `FundingScope` the `RevokedOutput` claim originated from. 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`.
1 parent de9ff8f commit fbaf2bc

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,12 +3760,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37603760
for (idx, outp) in tx.output.iter().enumerate() {
37613761
if outp.script_pubkey == revokeable_p2wsh {
37623762
let revk_outp = RevokedOutput::build(
3763-
per_commitment_point,
3764-
self.counterparty_commitment_params.counterparty_delayed_payment_base_key,
3765-
self.counterparty_commitment_params.counterparty_htlc_base_key,
3766-
per_commitment_key, outp.value,
3767-
self.counterparty_commitment_params.on_counterparty_tx_csv,
3768-
self.channel_type_features().supports_anchors_zero_fee_htlc_tx(),
3763+
per_commitment_point, per_commitment_key, outp.value,
3764+
self.funding.channel_parameters.channel_type_features.supports_anchors_zero_fee_htlc_tx(),
3765+
self.funding.channel_parameters.clone(),
37693766
);
37703767
let justice_package = PackageTemplate::build_package(
37713768
commitment_txid, idx as u32,
@@ -3962,10 +3959,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39623959
if input.previous_output.txid == *commitment_txid && input.witness.len() == 5 && tx.output.get(idx).is_some() {
39633960
log_error!(logger, "Got broadcast of revoked counterparty HTLC transaction, spending {}:{}", htlc_txid, idx);
39643961
let revk_outp = RevokedOutput::build(
3965-
per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key,
3966-
self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key,
3967-
tx.output[idx].value, self.counterparty_commitment_params.on_counterparty_tx_csv,
3968-
false
3962+
per_commitment_point, per_commitment_key, tx.output[idx].value, false,
3963+
self.funding.channel_parameters.clone(),
39693964
);
39703965
let justice_package = PackageTemplate::build_package(
39713966
htlc_txid, idx as u32, PackageSolvingData::RevokedOutput(revk_outp),

lightning/src/chain/package.rs

Lines changed: 21 additions & 7 deletions
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
@@ -810,8 +821,8 @@ impl PackageSolvingData {
810821
let channel_parameters = &onchain_handler.channel_transaction_parameters;
811822
match self {
812823
PackageSolvingData::RevokedOutput(ref outp) => {
813-
let directed_parameters =
814-
&onchain_handler.channel_transaction_parameters.as_counterparty_broadcastable();
824+
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);
825+
let directed_parameters = channel_parameters.as_counterparty_broadcastable();
815826
debug_assert_eq!(
816827
directed_parameters.broadcaster_pubkeys().delayed_payment_basepoint,
817828
outp.counterparty_delayed_payment_base_key,
@@ -1638,7 +1649,6 @@ mod tests {
16381649
ChannelTransactionParameters, HolderCommitmentTransaction, HTLCOutputInCommitment,
16391650
};
16401651
use crate::types::payment::{PaymentPreimage, PaymentHash};
1641-
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint};
16421652

16431653
use bitcoin::absolute::LockTime;
16441654
use bitcoin::amount::Amount;
@@ -1675,7 +1685,11 @@ mod tests {
16751685
let secp_ctx = Secp256k1::new();
16761686
let dumb_scalar = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
16771687
let dumb_point = PublicKey::from_secret_key(&secp_ctx, &dumb_scalar);
1678-
PackageSolvingData::RevokedOutput(RevokedOutput::build(dumb_point, DelayedPaymentBasepoint::from(dumb_point), HtlcBasepoint::from(dumb_point), dumb_scalar, Amount::ZERO, 0, $is_counterparty_balance_on_anchors))
1688+
let channel_parameters = ChannelTransactionParameters::dummy(0);
1689+
PackageSolvingData::RevokedOutput(RevokedOutput::build(
1690+
dumb_point, dumb_scalar, Amount::ZERO, $is_counterparty_balance_on_anchors,
1691+
channel_parameters,
1692+
))
16791693
}
16801694
}
16811695
}

0 commit comments

Comments
 (0)