Skip to content

Commit 07535a8

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 fbaf2bc commit 07535a8

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5300,6 +5300,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53005300
let mut holder_pays_commitment_tx_fee = None;
53015301
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
53025302
let mut first_confirmed_funding_txo = RequiredWrapper(None);
5303+
let mut channel_parameters = None;
53035304
read_tlv_fields!(reader, {
53045305
(1, funding_spend_confirmed, option),
53055306
(3, htlcs_resolved_on_chain, optional_vec),
@@ -5316,6 +5317,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53165317
(25, payment_preimages_with_info, option),
53175318
(27, first_confirmed_funding_txo, (default_value, outpoint)),
53185319
(29, initial_counterparty_commitment_tx, option),
5320+
(31, channel_parameters, (option: ReadableArgs, None)),
53195321
});
53205322
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
53215323
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5344,7 +5346,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
53445346
}
53455347
}
53465348

5347-
let channel_parameters = onchain_tx_handler.channel_transaction_parameters.clone();
5349+
let channel_parameters = channel_parameters.unwrap_or_else(|| {
5350+
onchain_tx_handler.channel_parameters().clone()
5351+
});
53485352

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

lightning/src/chain/onchaintx.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use core::cmp;
4444
use core::ops::Deref;
4545
use core::mem::replace;
4646
use core::mem::swap;
47-
use crate::types::features::ChannelTypeFeatures;
4847

4948
const MAX_ALLOC_SIZE: usize = 64*1024;
5049

@@ -233,14 +232,14 @@ pub(crate) enum FeerateStrategy {
233232
/// do RBF bumping if possible.
234233
#[derive(Clone)]
235234
pub struct OnchainTxHandler<ChannelSigner: EcdsaChannelSigner> {
236-
channel_value_satoshis: u64,
235+
channel_value_satoshis: u64, // Deprecated as of 0.2.
237236
channel_keys_id: [u8; 32], // Deprecated as of 0.2.
238237
destination_script: ScriptBuf, // Deprecated as of 0.2.
239238
holder_commitment: HolderCommitmentTransaction,
240239
prev_holder_commitment: Option<HolderCommitmentTransaction>,
241240

242241
pub(super) signer: ChannelSigner,
243-
pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
242+
channel_transaction_parameters: ChannelTransactionParameters, // Deprecated as of 0.2.
244243

245244
// Used to track claiming requests. If claim tx doesn't confirm before height timer expiration we need to bump
246245
// 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.0, &funding_pubkey) {
682681
// An anchor output was found, so we should yield a funding event externally.
@@ -1204,8 +1203,9 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
12041203
self.prev_holder_commitment = Some(replace(&mut self.holder_commitment, tx));
12051204
}
12061205

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

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

lightning/src/chain/package.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl HolderHTLCOutput {
479479
preimage: &Option<PaymentPreimage>,
480480
) -> Option<MaybeSignedTransaction> {
481481
let channel_parameters = self.channel_parameters.as_ref()
482-
.unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
482+
.unwrap_or(onchain_tx_handler.channel_parameters());
483483
let channel_keys_id = self.channel_keys_id
484484
.unwrap_or(onchain_tx_handler.channel_keys_id());
485485
let get_signed_htlc_tx = |holder_commitment: &HolderCommitmentTransaction| {
@@ -534,7 +534,7 @@ impl HolderHTLCOutput {
534534
preimage: &Option<PaymentPreimage>
535535
) -> Option<ExternalHTLCClaim> {
536536
let channel_parameters = self.channel_parameters.as_ref()
537-
.unwrap_or(&onchain_tx_handler.channel_transaction_parameters);
537+
.unwrap_or(onchain_tx_handler.channel_parameters());
538538
let find_htlc = |holder_commitment: &HolderCommitmentTransaction| -> Option<ExternalHTLCClaim> {
539539
let trusted_tx = holder_commitment.trust();
540540
if outp.txid != trusted_tx.txid() {
@@ -818,7 +818,7 @@ impl PackageSolvingData {
818818
}
819819
}
820820
fn finalize_input<Signer: EcdsaChannelSigner>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> bool {
821-
let channel_parameters = &onchain_handler.channel_transaction_parameters;
821+
let channel_parameters = onchain_handler.channel_parameters();
822822
match self {
823823
PackageSolvingData::RevokedOutput(ref outp) => {
824824
let channel_parameters = outp.channel_parameters.as_ref().unwrap_or(channel_parameters);
@@ -945,7 +945,7 @@ impl PackageSolvingData {
945945
}
946946
PackageSolvingData::HolderFundingOutput(ref outp) => {
947947
let channel_parameters = outp.channel_parameters.as_ref()
948-
.unwrap_or(&onchain_handler.channel_transaction_parameters);
948+
.unwrap_or(onchain_handler.channel_parameters());
949949
let commitment_tx = outp.commitment_tx.as_ref()
950950
.unwrap_or(&onchain_handler.current_holder_commitment_tx());
951951
let maybe_signed_commitment_tx = onchain_handler.signer

0 commit comments

Comments
 (0)