Skip to content

Commit

Permalink
Add ChannelTransactionParameters::channel_type_features
Browse files Browse the repository at this point in the history
  • Loading branch information
tankyleo committed Jan 13, 2025
1 parent 1074a11 commit 0db5287
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ impl<Signer: ChannelSigner> OnchainTxHandler<Signer> {
}

pub(crate) fn channel_type_features(&self) -> &ChannelTypeFeatures {
&self.channel_transaction_parameters.channel_type_features
self.channel_transaction_parameters.channel_type_features()
}
}

Expand Down
4 changes: 4 additions & 0 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@ impl ChannelTransactionParameters {
channel_type_features: ChannelTypeFeatures::empty(),
}
}

pub(crate) fn channel_type_features(&self) -> &ChannelTypeFeatures {
&self.channel_type_features
}
}

impl_writeable_tlv_based!(CounterpartyChannelTransactionParameters, {
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3093,8 +3093,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
broadcaster_max_commitment_tx_output.1 = cmp::max(broadcaster_max_commitment_tx_output.1, value_to_remote_msat as u64);
}

let total_fee_sat = commit_tx_fee_sat(feerate_per_kw, included_non_dust_htlcs.len(), &self.channel_transaction_parameters.channel_type_features);
let anchors_val = if self.channel_transaction_parameters.channel_type_features.supports_anchors_zero_fee_htlc_tx() { ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 } as i64;
let total_fee_sat = commit_tx_fee_sat(feerate_per_kw, included_non_dust_htlcs.len(), self.channel_transaction_parameters.channel_type_features());
let anchors_val = if self.channel_transaction_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() { ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 } as i64;
let (value_to_self, value_to_remote) = if self.is_outbound() {
(value_to_self_msat / 1000 - anchors_val - total_fee_sat as i64, value_to_remote_msat / 1000)
} else {
Expand Down Expand Up @@ -3948,7 +3948,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
if self.channel_type.supports_anchors_zero_fee_htlc_tx() {
self.channel_type.clear_anchors_zero_fee_htlc_tx();
self.feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
assert!(!self.channel_transaction_parameters.channel_type_features.supports_anchors_nonzero_fee_htlc_tx());
assert!(!self.channel_transaction_parameters.channel_type_features().supports_anchors_nonzero_fee_htlc_tx());
} else if self.channel_type.supports_scid_privacy() {
self.channel_type.clear_scid_privacy();
} else {
Expand Down
18 changes: 9 additions & 9 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ impl HTLCDescriptor {
chan_utils::build_htlc_input(
&self.commitment_txid,
&self.htlc,
&self.channel_derivation_parameters.transaction_parameters.channel_type_features,
self.channel_derivation_parameters.transaction_parameters.channel_type_features(),
)
}

Expand All @@ -640,7 +640,7 @@ impl HTLCDescriptor {
chan_utils::build_htlc_output(
self.feerate_per_kw,
&self.htlc,
&self.channel_derivation_parameters.transaction_parameters.channel_type_features,
self.channel_derivation_parameters.transaction_parameters.channel_type_features(),
revokeable_spk,
)
}
Expand Down Expand Up @@ -685,7 +685,7 @@ impl HTLCDescriptor {
&self.counterparty_sig,
&self.preimage,
witness_script,
&self.channel_derivation_parameters.transaction_parameters.channel_type_features,
self.channel_derivation_parameters.transaction_parameters.channel_type_features(),
)
}

Expand Down Expand Up @@ -917,7 +917,7 @@ pub trait ChannelSigner {
/// Return the total weight of the witness required to spend the justice path of a HTLC output in a
/// commitment transaction.
fn get_htlc_punishment_witness_weight(&self, offered: bool) -> u64 {
let features = &self.get_channel_parameters().unwrap().channel_type_features;
let features = self.get_channel_parameters().unwrap().channel_type_features();
if offered {
weight_revoked_offered_htlc(features)
} else {
Expand All @@ -935,7 +935,7 @@ pub trait ChannelSigner {

/// Weight of the witness that sweeps htlc outputs in counterparty commitment transactions
fn counterparty_htlc_output_witness_weight(&self, offered: bool) -> u64 {
let features = &self.get_channel_parameters().unwrap().channel_type_features;
let features = self.get_channel_parameters().unwrap().channel_type_features();
if offered {
weight_offered_htlc(features)
} else {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ pub trait ChannelSigner {
/// Get the anchor output of a commit tx
fn get_anchor_txout(&self, is_holder_tx: bool, is_broadcaster_anchor: bool) -> Option<TxOut> {
let channel_parameters = self.get_channel_parameters().unwrap();
if channel_parameters.channel_type_features.supports_anchors_zero_fee_htlc_tx() {
if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
let params = if is_holder_tx {
channel_parameters.as_holder_broadcastable()
} else {
Expand Down Expand Up @@ -1432,7 +1432,7 @@ impl InMemorySigner {
/// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
/// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
pub fn channel_type_features(&self) -> Option<&ChannelTypeFeatures> {
self.get_channel_parameters().map(|params| &params.channel_type_features)
self.get_channel_parameters().map(|params| params.channel_type_features())
}

/// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
Expand Down Expand Up @@ -1805,7 +1805,7 @@ impl ChannelSigner for InMemorySigner {
let sighash = hash_to_message!(sighash.as_byte_array());
let sig = sign_with_aux_rand(&secp_ctx, &sighash, &our_htlc_private_key, &self);

let features = &self.channel_parameters.as_ref().unwrap().channel_type_features;
let features = self.channel_parameters.as_ref().unwrap().channel_type_features();
let witness = chan_utils::build_htlc_input_witness(
&sig,
&htlc_descriptor.counterparty_sig,
Expand Down Expand Up @@ -1866,7 +1866,7 @@ impl EcdsaChannelSigner for InMemorySigner {
);
for htlc in commitment_tx.htlcs() {
let channel_parameters = self.get_channel_parameters().expect(MISSING_PARAMS_ERR);
let chan_type = &channel_parameters.channel_type_features;
let chan_type = channel_parameters.channel_type_features();
let htlc_tx = chan_utils::build_htlc_transaction(
&commitment_txid,
commitment_tx.feerate_per_kw(),
Expand Down

0 comments on commit 0db5287

Please sign in to comment.