Skip to content

Commit 4e47542

Browse files
committed
Incorporate low-R values into estimate signature size
1 parent c182567 commit 4e47542

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ use crate::util::invoice::construct_invoice_preimage;
6060
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
6161
pub struct KeyMaterial(pub [u8; 32]);
6262

63+
#[cfg(feature = "grind_signatures")]
64+
const ECDSA_SIGNATURE_SIZE: usize = 72;
65+
#[cfg(not(feature = "grind_signatures"))]
66+
const ECDSA_SIGNATURE_SIZE: usize = 73;
67+
6368
/// Information about a spendable output to a P2WSH script.
6469
///
6570
/// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
@@ -85,9 +90,9 @@ pub struct DelayedPaymentOutputDescriptor {
8590
}
8691
impl DelayedPaymentOutputDescriptor {
8792
/// The maximum length a well-formed witness spending one of these should have.
88-
// Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus
93+
// Calculated as 1 byte length + ECDSA signature, 1 byte empty vec push, 1 byte length plus
8994
// redeemscript push length.
90-
pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH + 1;
95+
pub const MAX_WITNESS_LENGTH: usize = 1 + ECDSA_SIGNATURE_SIZE + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH + 1;
9196
}
9297

9398
impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
@@ -117,9 +122,9 @@ pub struct StaticPaymentOutputDescriptor {
117122
}
118123
impl StaticPaymentOutputDescriptor {
119124
/// The maximum length a well-formed witness spending one of these should have.
120-
// Calculated as 1 byte legnth + 73 byte signature, 1 byte empty vec push, 1 byte length plus
125+
// Calculated as 1 byte legnth + ECDSA signature, 1 byte empty vec push, 1 byte length plus
121126
// redeemscript push length.
122-
pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 34;
127+
pub const MAX_WITNESS_LENGTH: usize = 1 + ECDSA_SIGNATURE_SIZE + 34;
123128
}
124129
impl_writeable_tlv_based!(StaticPaymentOutputDescriptor, {
125130
(0, outpoint, required),
@@ -1209,7 +1214,7 @@ impl KeysManager {
12091214
sequence: Sequence::ZERO,
12101215
witness: Witness::new(),
12111216
});
1212-
witness_weight += 1 + 73 + 34;
1217+
witness_weight += 1 + ECDSA_SIGNATURE_SIZE + 34;
12131218
input_value += output.value;
12141219
if !output_set.insert(*outpoint) { return Err(()); }
12151220
}

0 commit comments

Comments
 (0)