Skip to content

Commit 9bd8557

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 23eb12e commit 9bd8557

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
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(())
@@ -5271,6 +5272,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
52715272
let mut holder_pays_commitment_tx_fee = None;
52725273
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
52735274
let mut first_confirmed_funding_txo = RequiredWrapper(None);
5275+
let mut channel_parameters = None;
52745276
read_tlv_fields!(reader, {
52755277
(1, funding_spend_confirmed, option),
52765278
(3, htlcs_resolved_on_chain, optional_vec),
@@ -5287,6 +5289,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
52875289
(25, payment_preimages_with_info, option),
52885290
(27, first_confirmed_funding_txo, (default_value, outpoint)),
52895291
(29, initial_counterparty_commitment_tx, option),
5292+
(31, channel_parameters, (option: ReadableArgs, None)),
52905293
});
52915294
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
52925295
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5315,7 +5318,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53155318
}
53165319
}
53175320

5318-
let channel_parameters = onchain_tx_handler.channel_transaction_parameters.clone();
5321+
let channel_parameters = channel_parameters.unwrap_or_else(|| {
5322+
onchain_tx_handler.channel_parameters().clone()
5323+
});
53195324

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl HolderHTLCOutput {
463463
return Some(htlc_descriptor.clone());
464464
}
465465

466-
let channel_parameters = &onchain_tx_handler.channel_transaction_parameters;
466+
let channel_parameters = onchain_tx_handler.channel_parameters();
467467

468468
let get_htlc_descriptor = |holder_commitment: &HolderCommitmentTransaction| {
469469
let trusted_tx = holder_commitment.trust();
@@ -614,7 +614,7 @@ impl HolderFundingOutput {
614614
&self, onchain_tx_handler: &mut OnchainTxHandler<Signer>,
615615
) -> MaybeSignedTransaction {
616616
let channel_parameters = self.channel_parameters.as_ref()
617-
.unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
617+
.unwrap_or(onchain_tx_handler.channel_parameters());
618618
let commitment_tx = self.commitment_tx.as_ref()
619619
.unwrap_or(onchain_tx_handler.current_holder_commitment_tx());
620620
let maybe_signed_tx = onchain_tx_handler.signer
@@ -786,7 +786,7 @@ impl PackageSolvingData {
786786
}
787787
}
788788
fn finalize_input<Signer: EcdsaChannelSigner>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> bool {
789-
let channel_parameters = &onchain_handler.channel_transaction_parameters;
789+
let channel_parameters = onchain_handler.channel_parameters();
790790
match self {
791791
PackageSolvingData::RevokedOutput(ref outp) => {
792792
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);

0 commit comments

Comments
 (0)