Skip to content

Commit 3445214

Browse files
Enable wumbo channels to be created
1 parent ade12b1 commit 3445214

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lightning/src/ln/channel.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,11 @@ impl<Signer: Sign> Channel<Signer> {
854854
let holder_signer = keys_provider.get_channel_signer(false, channel_value_satoshis);
855855
let pubkeys = holder_signer.pubkeys().clone();
856856

857-
if channel_value_satoshis >= MAX_FUNDING_SATOSHIS_NO_WUMBO {
858-
return Err(APIError::APIMisuseError{err: format!("funding_value must be smaller than {}, it was {}", MAX_FUNDING_SATOSHIS_NO_WUMBO, channel_value_satoshis)});
857+
if !their_features.supports_wumbo() && channel_value_satoshis >= MAX_FUNDING_SATOSHIS_NO_WUMBO {
858+
return Err(APIError::APIMisuseError{err: format!("funding_value must be smaller than {}, it was {}", MAX_FUNDING_SATOSHIS_NO_WUMBO, channel_value_satoshis) });
859+
}
860+
if channel_value_satoshis >= TOTAL_BITCOIN_SUPPLY_SATOSHIS {
861+
return Err(APIError::APIMisuseError { err: format!("funding_value must be smaller than the total bitcoin supply, it was {}", channel_value_satoshis) });
859862
}
860863
let channel_value_msat = channel_value_satoshis * 1000;
861864
if push_msat > channel_value_msat {
@@ -1080,9 +1083,15 @@ impl<Signer: Sign> Channel<Signer> {
10801083
}
10811084

10821085
// Check sanity of message fields:
1083-
if msg.funding_satoshis >= MAX_FUNDING_SATOSHIS_NO_WUMBO {
1086+
if !their_features.supports_wumbo() && msg.funding_satoshis >= MAX_FUNDING_SATOSHIS_NO_WUMBO {
10841087
return Err(ChannelError::Close(format!("Funding must be smaller than {}. It was {}", MAX_FUNDING_SATOSHIS_NO_WUMBO, msg.funding_satoshis)));
10851088
}
1089+
if msg.funding_satoshis >= config.peer_channel_config_limits.max_funding_satoshis {
1090+
return Err(ChannelError::Close(format!("Per our config, funding must be smaller than {}. It was {}", config.peer_channel_config_limits.max_funding_satoshis, msg.funding_satoshis)));
1091+
}
1092+
if msg.funding_satoshis > TOTAL_BITCOIN_SUPPLY_SATOSHIS {
1093+
return Err(ChannelError::Close(format!("Funding must be smaller than the total bitcoin supply. It was {}", msg.funding_satoshis)));
1094+
}
10861095
if msg.channel_reserve_satoshis > msg.funding_satoshis {
10871096
return Err(ChannelError::Close(format!("Bogus channel_reserve_satoshis ({}). Must be not greater than funding_satoshis: {}", msg.channel_reserve_satoshis, msg.funding_satoshis)));
10881097
}

lightning/src/ln/features.rs

+9
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,15 @@ impl<T: sealed::ShutdownAnySegwit> Features<T> {
743743
self
744744
}
745745
}
746+
747+
impl<T: sealed::Wumbo> Features<T> {
748+
#[cfg(test)]
749+
pub(crate) fn clear_wumbo(mut self) -> Self {
750+
<T as sealed::Wumbo>::clear_bits(&mut self.flags);
751+
self
752+
}
753+
}
754+
746755
macro_rules! impl_feature_len_prefixed_write {
747756
($features: ident) => {
748757
impl Writeable for $features {

lightning/src/ln/functional_tests.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ fn test_insane_channel_opens() {
9797
use ln::channelmanager::MAX_LOCAL_BREAKDOWN_TIMEOUT;
9898

9999
// Test all mutations that would make the channel open message insane
100-
insane_open_helper(format!("Funding must be smaller than {}. It was {}", MAX_FUNDING_SATOSHIS_NO_WUMBO, MAX_FUNDING_SATOSHIS_NO_WUMBO).as_str(), |mut msg| { msg.funding_satoshis = MAX_FUNDING_SATOSHIS_NO_WUMBO; msg }, |f| f);
100+
insane_open_helper(
101+
format!("Funding must be smaller than {}. It was {}", MAX_FUNDING_SATOSHIS_NO_WUMBO, MAX_FUNDING_SATOSHIS_NO_WUMBO).as_str(),
102+
|mut msg| { msg.funding_satoshis = MAX_FUNDING_SATOSHIS_NO_WUMBO; msg },
103+
|features| features.clear_wumbo());
104+
105+
insane_open_helper(format!("Per our config, funding must be smaller than {}. It was {}", MAX_FUNDING_SATOSHIS_NO_WUMBO, MAX_FUNDING_SATOSHIS_NO_WUMBO).as_str(), |mut msg| { msg.funding_satoshis = MAX_FUNDING_SATOSHIS_NO_WUMBO; msg }, |f| f);
101106

102107
insane_open_helper("Bogus channel_reserve_satoshis", |mut msg| { msg.channel_reserve_satoshis = msg.funding_satoshis + 1; msg }, |f| f);
103108

0 commit comments

Comments
 (0)