Skip to content

Commit 63dd53b

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 eb37346 commit 63dd53b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lightning/src/chain/channelmonitor.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
13981398
(25, self.payment_preimages, required),
13991399
(27, self.first_confirmed_funding_txo, required),
14001400
(29, self.initial_counterparty_commitment_tx, option),
1401+
(31, self.funding.channel_parameters, required),
14011402
});
14021403

14031404
Ok(())
@@ -5278,6 +5279,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
52785279
let mut holder_pays_commitment_tx_fee = None;
52795280
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
52805281
let mut first_confirmed_funding_txo = RequiredWrapper(None);
5282+
let mut channel_parameters = None;
52815283
read_tlv_fields!(reader, {
52825284
(1, funding_spend_confirmed, option),
52835285
(3, htlcs_resolved_on_chain, optional_vec),
@@ -5294,6 +5296,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
52945296
(25, payment_preimages_with_info, option),
52955297
(27, first_confirmed_funding_txo, (default_value, outpoint)),
52965298
(29, initial_counterparty_commitment_tx, option),
5299+
(31, channel_parameters, (option: ReadableArgs, None)),
52975300
});
52985301
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
52995302
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5322,7 +5325,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53225325
}
53235326
}
53245327

5325-
let channel_parameters = onchain_tx_handler.channel_transaction_parameters.clone();
5328+
let channel_parameters = channel_parameters.unwrap_or_else(|| {
5329+
onchain_tx_handler.channel_parameters().clone()
5330+
});
53265331

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

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
@@ -676,7 +675,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
676675

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

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

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

lightning/src/chain/package.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl HolderHTLCOutput {
465465

466466
let channel_parameters = self.htlc_descriptor.as_ref()
467467
.map(|d| &d.channel_derivation_parameters.transaction_parameters)
468-
.unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
468+
.unwrap_or(onchain_tx_handler.channel_parameters());
469469

470470
let get_htlc_descriptor = |holder_commitment: &HolderCommitmentTransaction| {
471471
let trusted_tx = holder_commitment.trust();
@@ -616,7 +616,7 @@ impl HolderFundingOutput {
616616
&self, onchain_tx_handler: &mut OnchainTxHandler<Signer>,
617617
) -> MaybeSignedTransaction {
618618
let channel_parameters = self.channel_parameters.as_ref().
619-
unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
619+
unwrap_or(onchain_tx_handler.channel_parameters());
620620
let commitment_tx = self.commitment_tx.as_ref()
621621
.unwrap_or(onchain_tx_handler.current_holder_commitment_tx());
622622
let maybe_signed_tx = onchain_tx_handler.signer
@@ -788,7 +788,7 @@ impl PackageSolvingData {
788788
}
789789
}
790790
fn finalize_input<Signer: EcdsaChannelSigner>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> bool {
791-
let channel_parameters = &onchain_handler.channel_transaction_parameters;
791+
let channel_parameters = onchain_handler.channel_parameters();
792792
match self {
793793
PackageSolvingData::RevokedOutput(ref outp) => {
794794
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);

0 commit comments

Comments
 (0)