Skip to content

Commit c946edb

Browse files
committed
Fix REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH for contest delays >0x7fff
When contest delays are >= 0x8000, script pushes require an extra byte to avoid being interpreted as a negative int. Thus, for channels with CSV delays longer than ~7.5 months we may generate transactions with slightly too little fee. This isn't really a huge deal, but we should prefer to be conservative here, and slightly too high fee in the general case is better than slightly too little fee in other cases.
1 parent ddb54fc commit c946edb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,11 @@ impl TxCreationKeys {
485485
}
486486

487487
/// The maximum length of a script returned by get_revokeable_redeemscript.
488-
// Calculated as 6 bytes of opcodes, 1 byte push plus 2 bytes for contest_delay, and two public
489-
// keys of 33 bytes (+ 1 push).
490-
pub const REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = 6 + 3 + 34*2;
488+
// Calculated as 6 bytes of opcodes, 1 byte push plus 3 bytes for contest_delay, and two public
489+
// keys of 33 bytes (+ 1 push). Generally, pushes are only 2 bytes (for values below 0x7fff, i.e.
490+
// around 7 months), however, a 7 month contest delay shouldn't result in being unable to reclaim
491+
// on-chain funds.
492+
pub const REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = 6 + 4 + 34*2;
491493

492494
/// A script either spendable by the revocation
493495
/// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.

0 commit comments

Comments
 (0)