Skip to content

Commit 5ef0795

Browse files
committed
Add ChannelSigner::get_to_local_witness_weight
1 parent 079626e commit 5ef0795

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,6 +4631,7 @@ impl<Signer: ChannelSigner> ChannelMonitorImpl<Signer> {
46314631
channel_keys_id: self.channel_keys_id,
46324632
channel_value_satoshis: self.channel_value_satoshis,
46334633
channel_transaction_parameters: Some(self.onchain_tx_handler.channel_transaction_parameters.clone()),
4634+
witness_weight: signer.get_to_local_witness_weight(),
46344635
}));
46354636
}
46364637
}

lightning/src/sign/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,8 @@ pub struct DelayedPaymentOutputDescriptor {
115115
///
116116
/// Added as optional, but always `Some` if the descriptor was produced in v0.0.123 or later.
117117
pub channel_transaction_parameters: Option<ChannelTransactionParameters>,
118-
}
119-
120-
impl DelayedPaymentOutputDescriptor {
121-
/// The maximum length a well-formed witness spending one of these should have.
122-
/// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
123-
/// shorter.
124-
// Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus
125-
// redeemscript push length.
126-
pub const MAX_WITNESS_LENGTH: u64 =
127-
1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH as u64 + 1;
118+
/// Witness weight
119+
pub witness_weight: u64,
128120
}
129121

130122
impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
@@ -136,6 +128,8 @@ impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
136128
(10, channel_keys_id, required),
137129
(12, channel_value_satoshis, required),
138130
(13, channel_transaction_parameters, option),
131+
// Don't break downgrades ?
132+
(15, witness_weight, (default_value, 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH as u64 + 1)),
139133
});
140134

141135
pub(crate) const P2WPKH_WITNESS_WEIGHT: u64 = 1 /* num stack items */ +
@@ -483,7 +477,7 @@ impl SpendableOutputDescriptor {
483477
sequence: Sequence(descriptor.to_self_delay as u32),
484478
witness: Witness::new(),
485479
});
486-
witness_weight += DelayedPaymentOutputDescriptor::MAX_WITNESS_LENGTH;
480+
witness_weight += descriptor.witness_weight;
487481
#[cfg(feature = "grind_signatures")]
488482
{
489483
// Guarantees a low R signature
@@ -1100,6 +1094,16 @@ pub trait ChannelSigner {
11001094
P2WPKH_WITNESS_WEIGHT
11011095
}
11021096
}
1097+
1098+
/// Gets the weight of the witness that spends a `to_local` output
1099+
fn get_to_local_witness_weight(&self) -> u64 {
1100+
// The maximum length a well-formed witness spending one of these should have.
1101+
// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
1102+
// shorter.
1103+
// Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus
1104+
// redeemscript push length.
1105+
1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH as u64 + 1
1106+
}
11031107
}
11041108

11051109
/// Specifies the recipient of an invoice.

0 commit comments

Comments
 (0)