Skip to content

Commit 6f8f853

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 4b09913 commit 6f8f853

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Diff for: 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(())
@@ -5293,6 +5294,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
52935294
let mut holder_pays_commitment_tx_fee = None;
52945295
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
52955296
let mut first_confirmed_funding_txo = RequiredWrapper(None);
5297+
let mut channel_parameters = None;
52965298
read_tlv_fields!(reader, {
52975299
(1, funding_spend_confirmed, option),
52985300
(3, htlcs_resolved_on_chain, optional_vec),
@@ -5309,6 +5311,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53095311
(25, payment_preimages_with_info, option),
53105312
(27, first_confirmed_funding_txo, (default_value, outpoint)),
53115313
(29, initial_counterparty_commitment_tx, option),
5314+
(31, channel_parameters, (option: ReadableArgs, None)),
53125315
});
53135316
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
53145317
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5337,7 +5340,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53375340
}
53385341
}
53395342

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

53425347
// Monitors for anchor outputs channels opened in v0.0.116 suffered from a bug in which the
53435348
// 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
@@ -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.

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
) -> MaybeSignedTransaction {
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
let maybe_signed_tx = onchain_tx_handler.signer
@@ -831,7 +831,7 @@ impl PackageSolvingData {
831831
}
832832
}
833833
fn finalize_input<Signer: EcdsaChannelSigner>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> bool {
834-
let channel_parameters = &onchain_handler.channel_transaction_parameters;
834+
let channel_parameters = onchain_handler.channel_parameters();
835835
match self {
836836
PackageSolvingData::RevokedOutput(ref outp) => {
837837
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);

0 commit comments

Comments
 (0)