Skip to content

Commit de9ff8f

Browse files
committed
Track ChannelTransactionParameters in RevokedHTLCOutput
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 `RevokedHTLCOutput` 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 27bd2a0 commit de9ff8f

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,11 +3788,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37883788
return (claimable_outpoints, to_counterparty_output_info);
37893789
}
37903790
let revk_htlc_outp = RevokedHTLCOutput::build(
3791-
per_commitment_point,
3792-
self.counterparty_commitment_params.counterparty_delayed_payment_base_key,
3793-
self.counterparty_commitment_params.counterparty_htlc_base_key,
3794-
per_commitment_key, htlc.amount_msat / 1000, htlc.clone(),
3795-
self.channel_type_features(),
3791+
per_commitment_point, per_commitment_key, htlc.clone(),
3792+
self.funding.channel_parameters.clone(),
37963793
);
37973794
let counterparty_spendable_height = if htlc.offered {
37983795
htlc.cltv_expiry

lightning/src/chain/package.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,32 @@ pub(crate) struct RevokedHTLCOutput {
181181
weight: u64,
182182
amount: u64,
183183
htlc: HTLCOutputInCommitment,
184+
channel_parameters: Option<ChannelTransactionParameters>,
184185
}
185186

186187
impl RevokedHTLCOutput {
187-
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: DelayedPaymentBasepoint, counterparty_htlc_base_key: HtlcBasepoint, per_commitment_key: SecretKey, amount: u64, htlc: HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures) -> Self {
188-
let weight = if htlc.offered { weight_revoked_offered_htlc(channel_type_features) } else { weight_revoked_received_htlc(channel_type_features) };
188+
pub(crate) fn build(
189+
per_commitment_point: PublicKey, per_commitment_key: SecretKey,
190+
htlc: HTLCOutputInCommitment, channel_parameters: ChannelTransactionParameters,
191+
) -> Self {
192+
let weight = if htlc.offered {
193+
weight_revoked_offered_htlc(&channel_parameters.channel_type_features)
194+
} else {
195+
weight_revoked_received_htlc(&channel_parameters.channel_type_features)
196+
};
197+
let directed_params = channel_parameters.as_holder_broadcastable();
198+
let counterparty_keys = directed_params.countersignatory_pubkeys();
199+
let counterparty_delayed_payment_base_key = counterparty_keys.delayed_payment_basepoint;
200+
let counterparty_htlc_base_key = counterparty_keys.htlc_basepoint;
189201
RevokedHTLCOutput {
190202
per_commitment_point,
191203
counterparty_delayed_payment_base_key,
192204
counterparty_htlc_base_key,
193205
per_commitment_key,
194206
weight,
195-
amount,
196-
htlc
207+
amount: htlc.amount_msat / 1000,
208+
htlc,
209+
channel_parameters: Some(channel_parameters),
197210
}
198211
}
199212
}
@@ -206,6 +219,7 @@ impl_writeable_tlv_based!(RevokedHTLCOutput, {
206219
(8, weight, required),
207220
(10, amount, required),
208221
(12, htlc, required),
222+
(13, channel_parameters, (option: ReadableArgs, None)), // Added in 0.2.
209223
});
210224

211225
/// A struct to describe a HTLC output on a counterparty commitment transaction.
@@ -821,8 +835,8 @@ impl PackageSolvingData {
821835
} else { return false; }
822836
},
823837
PackageSolvingData::RevokedHTLCOutput(ref outp) => {
824-
let directed_parameters =
825-
&onchain_handler.channel_transaction_parameters.as_counterparty_broadcastable();
838+
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);
839+
let directed_parameters = channel_parameters.as_counterparty_broadcastable();
826840
debug_assert_eq!(
827841
directed_parameters.broadcaster_pubkeys().delayed_payment_basepoint,
828842
outp.counterparty_delayed_payment_base_key,
@@ -835,7 +849,11 @@ impl PackageSolvingData {
835849
&outp.per_commitment_point, directed_parameters.broadcaster_pubkeys(),
836850
directed_parameters.countersignatory_pubkeys(), &onchain_handler.secp_ctx,
837851
);
838-
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(&outp.htlc, &onchain_handler.channel_type_features(), &chan_keys.broadcaster_htlc_key, &chan_keys.countersignatory_htlc_key, &chan_keys.revocation_key);
852+
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(
853+
&outp.htlc, &channel_parameters.channel_type_features,
854+
&chan_keys.broadcaster_htlc_key, &chan_keys.countersignatory_htlc_key,
855+
&chan_keys.revocation_key,
856+
);
839857
//TODO: should we panic on signer failure ?
840858
if let Ok(sig) = onchain_handler.signer.sign_justice_revoked_htlc(channel_parameters, &bumped_tx, i, outp.amount, &outp.per_commitment_key, &outp.htlc, &onchain_handler.secp_ctx) {
841859
let mut ser_sig = sig.serialize_der().to_vec();
@@ -1670,7 +1688,12 @@ mod tests {
16701688
let dumb_point = PublicKey::from_secret_key(&secp_ctx, &dumb_scalar);
16711689
let hash = PaymentHash([1; 32]);
16721690
let htlc = HTLCOutputInCommitment { offered: false, amount_msat: 1_000_000, cltv_expiry: 0, payment_hash: hash, transaction_output_index: None };
1673-
PackageSolvingData::RevokedHTLCOutput(RevokedHTLCOutput::build(dumb_point, DelayedPaymentBasepoint::from(dumb_point), HtlcBasepoint::from(dumb_point), dumb_scalar, 1_000_000 / 1_000, htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies()))
1691+
let mut channel_parameters = ChannelTransactionParameters::dummy(0);
1692+
channel_parameters.channel_type_features =
1693+
ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
1694+
PackageSolvingData::RevokedHTLCOutput(RevokedHTLCOutput::build(
1695+
dumb_point, dumb_scalar, htlc, channel_parameters
1696+
))
16741697
}
16751698
}
16761699
}

0 commit comments

Comments
 (0)