Skip to content

Commit 97d6278

Browse files
committed
Track ChannelTransactionParameters in ChannelMonitor
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 current `FundingScope` of a `ChannelMonitor` and deprecates the one found in `OnchainTxHandler`.
1 parent 869bc13 commit 97d6278

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -5293,6 +5293,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
52935293
let mut holder_pays_commitment_tx_fee = None;
52945294
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
52955295
let mut first_confirmed_funding_txo = RequiredWrapper(None);
5296+
let mut channel_parameters = None;
52965297
read_tlv_fields!(reader, {
52975298
(1, funding_spend_confirmed, option),
52985299
(3, htlcs_resolved_on_chain, optional_vec),
@@ -5309,6 +5310,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53095310
(25, payment_preimages_with_info, option),
53105311
(27, first_confirmed_funding_txo, (default_value, outpoint)),
53115312
(29, initial_counterparty_commitment_tx, option),
5313+
(31, channel_parameters, (option: ReadableArgs, None)),
53125314
});
53135315
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
53145316
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5337,7 +5339,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53375339
}
53385340
}
53395341

5340-
let channel_parameters = onchain_tx_handler.channel_transaction_parameters.clone();
5342+
let channel_parameters = channel_parameters.unwrap_or_else(|| {
5343+
onchain_tx_handler.channel_parameters().clone()
5344+
});
53415345

53425346
// Monitors for anchor outputs channels opened in v0.0.116 suffered from a bug in which the
53435347
// wrong `counterparty_payment_script` was being tracked. Fix it now on deserialization to

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use core::cmp;
4242
use core::ops::Deref;
4343
use core::mem::replace;
4444
use core::mem::swap;
45-
use crate::types::features::ChannelTypeFeatures;
4645

4746
const MAX_ALLOC_SIZE: usize = 64*1024;
4847

@@ -220,14 +219,14 @@ pub(crate) enum FeerateStrategy {
220219
/// do RBF bumping if possible.
221220
#[derive(Clone)]
222221
pub struct OnchainTxHandler<ChannelSigner: EcdsaChannelSigner> {
223-
channel_value_satoshis: u64,
222+
channel_value_satoshis: u64, // Deprecated as of 0.2.
224223
channel_keys_id: [u8; 32], // Deprecated as of 0.2.
225224
destination_script: ScriptBuf, // Deprecated as of 0.2.
226225
holder_commitment: HolderCommitmentTransaction,
227226
prev_holder_commitment: Option<HolderCommitmentTransaction>,
228227

229228
pub(super) signer: ChannelSigner,
230-
pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
229+
channel_transaction_parameters: ChannelTransactionParameters, // Deprecated as of 0.2.
231230

232231
// Used to track claiming requests. If claim tx doesn't confirm before height timer expiration we need to bump
233232
// it (RBF or CPFP). If an input has been part of an aggregate tx at first claim try, we need to keep it within
@@ -675,7 +674,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
675674

676675
// We'll locate an anchor output we can spend within the commitment transaction.
677676
let channel_parameters = output.channel_parameters.as_ref()
678-
.unwrap_or(&self.channel_transaction_parameters);
677+
.unwrap_or(self.channel_parameters());
679678
let funding_pubkey = &channel_parameters.holder_pubkeys.funding_pubkey;
680679
match chan_utils::get_keyed_anchor_output(&tx, funding_pubkey) {
681680
// An anchor output was found, so we should yield a funding event externally.
@@ -1202,8 +1201,9 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
12021201
self.prev_holder_commitment = Some(replace(&mut self.holder_commitment, tx));
12031202
}
12041203

1205-
pub(crate) fn channel_type_features(&self) -> &ChannelTypeFeatures {
1206-
&self.channel_transaction_parameters.channel_type_features
1204+
// Deprecated as of 0.2, only use in cases where it was not previously available.
1205+
pub(crate) fn channel_parameters(&self) -> &ChannelTransactionParameters {
1206+
&self.channel_transaction_parameters
12071207
}
12081208

12091209
// Deprecated as of 0.2, only use in cases where it was not previously available.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl HolderHTLCOutput {
460460
) -> Option<MaybeSignedTransaction> {
461461
let channel_parameters = self.htlc_descriptor.as_ref()
462462
.map(|d| &d.channel_derivation_parameters.transaction_parameters)
463-
.unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
463+
.unwrap_or(onchain_tx_handler.channel_parameters());
464464

465465
let get_htlc_descriptor = |holder_commitment: &HolderCommitmentTransaction| {
466466
let trusted_tx = holder_commitment.trust();
@@ -533,7 +533,7 @@ impl HolderHTLCOutput {
533533
) -> Option<HTLCDescriptor> {
534534
let channel_parameters = self.htlc_descriptor.as_ref()
535535
.map(|d| &d.channel_derivation_parameters.transaction_parameters)
536-
.unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
536+
.unwrap_or(onchain_tx_handler.channel_parameters());
537537

538538
let get_htlc_descriptor = |holder_commitment: &HolderCommitmentTransaction| {
539539
let trusted_tx = holder_commitment.trust();
@@ -659,7 +659,7 @@ impl HolderFundingOutput {
659659
&self, onchain_tx_handler: &mut OnchainTxHandler<Signer>,
660660
) -> Option<Signature> {
661661
let channel_parameters = self.channel_parameters.as_ref().
662-
unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
662+
unwrap_or(onchain_tx_handler.channel_parameters());
663663
let commitment_tx = self.commitment_tx.as_ref()
664664
.unwrap_or(onchain_tx_handler.current_holder_commitment_tx());
665665
onchain_tx_handler.signer
@@ -825,7 +825,7 @@ impl PackageSolvingData {
825825
}
826826
}
827827
fn finalize_input<Signer: EcdsaChannelSigner>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> bool {
828-
let channel_parameters = &onchain_handler.channel_transaction_parameters;
828+
let channel_parameters = onchain_handler.channel_parameters();
829829
match self {
830830
PackageSolvingData::RevokedOutput(ref outp) => {
831831
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);

0 commit comments

Comments
 (0)