Skip to content

Commit 451e096

Browse files
Enable wumbo channels to be created
We remove MAX_FUNDING_SATOSHIS const since we no longer do this check, and instead check that the funding amount is less than the total bitcoin supply. This adds a const that is used for the new wumbo feature as well as in closing_signed
1 parent 146f357 commit 451e096

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

lightning/src/ln/channel.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,8 @@ pub const COMMITMENT_TX_WEIGHT_PER_HTLC: u64 = 172;
734734

735735
pub const ANCHOR_OUTPUT_VALUE_SATOSHI: u64 = 330;
736736

737-
/// Maximum `funding_satoshis` value, according to the BOLT #2 specification
738-
/// it's 2^24.
739-
pub const MAX_FUNDING_SATOSHIS: u64 = 1 << 24;
737+
/// Total bitcoin supply in satoshis.
738+
pub const TOTAL_BITCOIN_SUPPLY_SATOSHIS: u64 = 21_000_000 * 1_0000_0000;
740739

741740
/// The maximum network dust limit for standard script formats. This currently represents the
742741
/// minimum output value for a P2SH output before Bitcoin Core 22 considers the entire
@@ -850,8 +849,8 @@ impl<Signer: Sign> Channel<Signer> {
850849
let holder_signer = keys_provider.get_channel_signer(false, channel_value_satoshis);
851850
let pubkeys = holder_signer.pubkeys().clone();
852851

853-
if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
854-
return Err(APIError::APIMisuseError{err: format!("funding_value must be smaller than {}, it was {}", MAX_FUNDING_SATOSHIS, channel_value_satoshis)});
852+
if channel_value_satoshis >= TOTAL_BITCOIN_SUPPLY_SATOSHIS {
853+
return Err(APIError::APIMisuseError { err: format!("funding_value must be smaller than the total bitcoin supply, it was {}", channel_value_satoshis) });
855854
}
856855
let channel_value_msat = channel_value_satoshis * 1000;
857856
if push_msat > channel_value_msat {
@@ -1076,8 +1075,11 @@ impl<Signer: Sign> Channel<Signer> {
10761075
}
10771076

10781077
// Check sanity of message fields:
1079-
if msg.funding_satoshis >= MAX_FUNDING_SATOSHIS {
1080-
return Err(ChannelError::Close(format!("Funding must be smaller than {}. It was {}", MAX_FUNDING_SATOSHIS, msg.funding_satoshis)));
1078+
if msg.funding_satoshis > config.peer_channel_config_limits.max_funding_satoshis {
1079+
return Err(ChannelError::Close(format!("Per our config, funding must be at most {}. It was {}", config.peer_channel_config_limits.max_funding_satoshis, msg.funding_satoshis)));
1080+
}
1081+
if msg.funding_satoshis >= TOTAL_BITCOIN_SUPPLY_SATOSHIS {
1082+
return Err(ChannelError::Close(format!("Funding must be smaller than the total bitcoin supply. It was {}", msg.funding_satoshis)));
10811083
}
10821084
if msg.channel_reserve_satoshis > msg.funding_satoshis {
10831085
return Err(ChannelError::Close(format!("Bogus channel_reserve_satoshis ({}). Must be not greater than funding_satoshis: {}", msg.channel_reserve_satoshis, msg.funding_satoshis)));
@@ -4110,7 +4112,7 @@ impl<Signer: Sign> Channel<Signer> {
41104112
if !self.pending_inbound_htlcs.is_empty() || !self.pending_outbound_htlcs.is_empty() {
41114113
return Err(ChannelError::Close("Remote end sent us a closing_signed while there were still pending HTLCs".to_owned()));
41124114
}
4113-
if msg.fee_satoshis > 21_000_000 * 1_0000_0000 { //this is required to stop potential overflow in build_closing_transaction
4115+
if msg.fee_satoshis > TOTAL_BITCOIN_SUPPLY_SATOSHIS { // this is required to stop potential overflow in build_closing_transaction
41144116
return Err(ChannelError::Close("Remote tried to send us a closing tx with > 21 million BTC fee".to_owned()));
41154117
}
41164118

@@ -6298,7 +6300,7 @@ mod tests {
62986300
use ln::PaymentHash;
62996301
use ln::channelmanager::{HTLCSource, PaymentId};
63006302
use ln::channel::{Channel, InboundHTLCOutput, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator};
6301-
use ln::channel::MAX_FUNDING_SATOSHIS;
6303+
use ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS;
63026304
use ln::features::InitFeatures;
63036305
use ln::msgs::{ChannelUpdate, DataLossProtect, DecodeError, OptionalField, UnsignedChannelUpdate};
63046306
use ln::script::ShutdownScript;
@@ -6334,9 +6336,8 @@ mod tests {
63346336
}
63356337

63366338
#[test]
6337-
fn test_max_funding_satoshis() {
6338-
assert!(MAX_FUNDING_SATOSHIS <= 21_000_000 * 100_000_000,
6339-
"MAX_FUNDING_SATOSHIS is greater than all satoshis in existence");
6339+
fn test_total_btc_supply_const() {
6340+
assert_eq!(TOTAL_BITCOIN_SUPPLY_SATOSHIS, 21_000_000 * 100_000_000);
63406341
}
63416342

63426343
#[test]

lightning/src/ln/functional_tests.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ use ln::chan_utils::CommitmentTransaction;
5858
#[test]
5959
fn test_insane_channel_opens() {
6060
// Stand up a network of 2 nodes
61+
use ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS;
62+
let mut cfg = UserConfig::default();
63+
cfg.peer_channel_config_limits.max_funding_satoshis = TOTAL_BITCOIN_SUPPLY_SATOSHIS + 1;
6164
let chanmon_cfgs = create_chanmon_cfgs(2);
6265
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
63-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
66+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(cfg)]);
6467
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
6568

6669
// Instantiate channel parameters where we push the maximum msats given our
@@ -92,11 +95,12 @@ fn test_insane_channel_opens() {
9295
} else { assert!(false); }
9396
};
9497

95-
use ln::channel::MAX_FUNDING_SATOSHIS;
9698
use ln::channelmanager::MAX_LOCAL_BREAKDOWN_TIMEOUT;
9799

98100
// Test all mutations that would make the channel open message insane
99-
insane_open_helper(format!("Funding must be smaller than {}. It was {}", MAX_FUNDING_SATOSHIS, MAX_FUNDING_SATOSHIS).as_str(), |mut msg| { msg.funding_satoshis = MAX_FUNDING_SATOSHIS; msg });
101+
insane_open_helper(format!("Per our config, funding must be at most {}. It was {}", TOTAL_BITCOIN_SUPPLY_SATOSHIS + 1, TOTAL_BITCOIN_SUPPLY_SATOSHIS + 2).as_str(), |mut msg| { msg.funding_satoshis = TOTAL_BITCOIN_SUPPLY_SATOSHIS + 2; msg });
102+
103+
insane_open_helper(format!("Funding must be smaller than the total bitcoin supply. It was {}", TOTAL_BITCOIN_SUPPLY_SATOSHIS).as_str(), |mut msg| { msg.funding_satoshis = TOTAL_BITCOIN_SUPPLY_SATOSHIS; msg });
100104

101105
insane_open_helper("Bogus channel_reserve_satoshis", |mut msg| { msg.channel_reserve_satoshis = msg.funding_satoshis + 1; msg });
102106

0 commit comments

Comments
 (0)