Skip to content

Commit 5d6c8d6

Browse files
committed
Add MAX_FUNDING_SATOSHIS constant.
This constants defines the maximum value of `open_channel.funding_satoshis`, currently it's defined to be 2^24 according to the BOLT lightningdevkit#2 specification. Also a test was added to check that the constant is never over 2,1x10^15 (maximum satoshis in bitcoin) if modified. Signed-off-by: Jean Pierre Dudey <[email protected]>
1 parent 5fa80d0 commit 5d6c8d6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/ln/channel.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl Channel {
355355

356356
/// panics if channel_value_satoshis is >= (1 << 24)
357357
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) {
358+
if channel_value_satoshis >= msgs::MAX_FUNDING_SATOSHIS {
359359
panic!("funding value > 2^24");
360360
}
361361

@@ -441,12 +441,9 @@ impl Channel {
441441
/// that we're rejecting the new channel.
442442
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> {
443443
// Check sanity of message fields:
444-
if msg.funding_satoshis >= (1 << 24) {
444+
if msg.funding_satoshis >= msgs::MAX_FUNDING_SATOSHIS {
445445
return Err(HandleError{err: "funding value > 2^24", msg: Some(msgs::ErrorAction::DisconnectPeer{})});
446446
}
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-
}
450447
if msg.channel_reserve_satoshis > msg.funding_satoshis {
451448
return Err(HandleError{err: "Bogus channel_reserve_satoshis", msg: Some(msgs::ErrorAction::DisconnectPeer{})});
452449
}

src/ln/msgs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ pub struct Pong {
148148
pub byteslen: u16,
149149
}
150150

151+
/// Maximmum `funding_satoshis` value, according to the BOLT #2 specification
152+
/// it's 2^24.
153+
pub const MAX_FUNDING_SATOSHIS: u64 = (1 << 24);
154+
155+
#[test]
156+
fn test_max_funding_satoshis() {
157+
assert!(MAX_FUNDING_SATOSHIS <= 21_000_000 * 100_000_000,
158+
"MAX_FUNDING_SATOSHIS is greater than all satoshis on existence");
159+
}
160+
151161
pub struct OpenChannel {
152162
pub chain_hash: Sha256dHash,
153163
pub temporary_channel_id: Uint256,

0 commit comments

Comments
 (0)