@@ -316,6 +316,9 @@ const COMMITMENT_TX_BASE_WEIGHT: u64 = 724;
316
316
const COMMITMENT_TX_WEIGHT_PER_HTLC : u64 = 172 ;
317
317
const SPENDING_INPUT_FOR_A_OUTPUT_WEIGHT : u64 = 79 ; // prevout: 36, nSequence: 4, script len: 1, witness lengths: (3+1)/4, sig: 73/4, if-selector: 1, redeemScript: (6 ops + 2*33 pubkeys + 1*2 delay)/4
318
318
const B_OUTPUT_PLUS_SPENDING_INPUT_WEIGHT : u64 = 104 ; // prevout: 40, nSequence: 4, script len: 1, witness lengths: 3/4, sig: 73/4, pubkey: 33/4, output: 31 (TODO: Wrong? Useless?)
319
+ /// Maximmum `funding_satoshis` value, according to the BOLT #2 specification
320
+ /// it's 2^24.
321
+ pub const MAX_FUNDING_SATOSHIS : u64 = ( 1 << 24 ) ;
319
322
320
323
macro_rules! secp_call {
321
324
( $res: expr, $err: expr ) => {
@@ -353,9 +356,9 @@ impl Channel {
353
356
354
357
// Constructors:
355
358
356
- /// panics if channel_value_satoshis is >= (1 << 24)
359
+ /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`
357
360
pub fn new_outbound ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , channel_value_satoshis : u64 , announce_publicly : bool , user_id : u64 ) -> Channel {
358
- if channel_value_satoshis >= ( 1 << 24 ) {
361
+ if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
359
362
panic ! ( "funding value > 2^24" ) ;
360
363
}
361
364
@@ -441,12 +444,9 @@ impl Channel {
441
444
/// that we're rejecting the new channel.
442
445
pub fn new_from_req ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , msg : & msgs:: OpenChannel , user_id : u64 , announce_publicly : bool ) -> Result < Channel , HandleError > {
443
446
// Check sanity of message fields:
444
- if msg. funding_satoshis >= ( 1 << 24 ) {
447
+ if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
445
448
return Err ( HandleError { err : "funding value > 2^24" , msg : Some ( msgs:: ErrorAction :: DisconnectPeer { } ) } ) ;
446
449
}
447
- if msg. funding_satoshis > 21000000 * 100000000 {
448
- return Err ( HandleError { err : "More funding_satoshis than there are satoshis!" , msg : Some ( msgs:: ErrorAction :: DisconnectPeer { } ) } ) ;
449
- }
450
450
if msg. channel_reserve_satoshis > msg. funding_satoshis {
451
451
return Err ( HandleError { err : "Bogus channel_reserve_satoshis" , msg : Some ( msgs:: ErrorAction :: DisconnectPeer { } ) } ) ;
452
452
}
@@ -2328,6 +2328,7 @@ mod tests {
2328
2328
use bitcoin:: network:: serialize:: serialize;
2329
2329
use bitcoin:: blockdata:: transaction:: Transaction ;
2330
2330
use ln:: channel:: { Channel , ChannelKeys , HTLCOutput , HTLCState , HTLCOutputInCommitment , TxCreationKeys } ;
2331
+ use ln:: channel:: MAX_FUNDING_SATOSHIS ;
2331
2332
use ln:: chan_utils;
2332
2333
use chain:: chaininterface:: { FeeEstimator , ConfirmationTarget } ;
2333
2334
use chain:: transaction:: OutPoint ;
@@ -2345,6 +2346,12 @@ mod tests {
2345
2346
}
2346
2347
}
2347
2348
2349
+ #[ test]
2350
+ fn test_max_funding_satoshis ( ) {
2351
+ assert ! ( MAX_FUNDING_SATOSHIS <= 21_000_000 * 100_000_000 ,
2352
+ "MAX_FUNDING_SATOSHIS is greater than all satoshis on existence" ) ;
2353
+ }
2354
+
2348
2355
#[ test]
2349
2356
fn outbound_commitment_test ( ) {
2350
2357
// Test vectors from BOLT 3 Appendix C:
0 commit comments