@@ -25,7 +25,7 @@ use bitcoin::secp256k1;
2525use crate :: ln:: { PaymentPreimage , PaymentHash } ;
2626use crate :: ln:: features:: { ChannelTypeFeatures , InitFeatures } ;
2727use crate :: ln:: msgs;
28- use crate :: ln:: msgs:: { DecodeError , OptionalField , DataLossProtect } ;
28+ use crate :: ln:: msgs:: { DecodeError , OptionalField , DataLossProtect , MAX_VALUE_MSAT } ;
2929use crate :: ln:: script:: { self , ShutdownScript } ;
3030use crate :: ln:: channelmanager:: { self , CounterpartyForwardingInfo , PendingHTLCStatus , HTLCSource , HTLCFailReason , HTLCFailureMsg , PendingHTLCInfo , RAACommitmentOrder , BREAKDOWN_TIMEOUT , MIN_CLTV_EXPIRY_DELTA , MAX_LOCAL_BREAKDOWN_TIMEOUT } ;
3131use crate :: ln:: chan_utils:: { CounterpartyCommitmentSecrets , TxCreationKeys , HTLCOutputInCommitment , htlc_success_tx_weight, htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys , CommitmentTransaction , HolderCommitmentTransaction , ChannelTransactionParameters , CounterpartyChannelTransactionParameters , MAX_HTLCS , get_commitment_transaction_number_obscure_factor, ClosingTransaction } ;
@@ -776,9 +776,6 @@ pub const MAX_IN_FLIGHT_PERCENT_LEGACY: u8 = 10;
776776/// It's 2^24 - 1.
777777pub const MAX_FUNDING_SATOSHIS_NO_WUMBO : u64 = ( 1 << 24 ) - 1 ;
778778
779- /// Total bitcoin supply in satoshis.
780- pub const TOTAL_BITCOIN_SUPPLY_SATOSHIS : u64 = 21_000_000 * 1_0000_0000 ;
781-
782779/// The maximum network dust limit for standard script formats. This currently represents the
783780/// minimum output value for a P2SH output before Bitcoin Core 22 considers the entire
784781/// transaction non-standard and thus refuses to relay it.
@@ -917,7 +914,7 @@ impl<Signer: Sign> Channel<Signer> {
917914 if !their_features. supports_wumbo ( ) && channel_value_satoshis > MAX_FUNDING_SATOSHIS_NO_WUMBO {
918915 return Err ( APIError :: APIMisuseError { err : format ! ( "funding_value must not exceed {}, it was {}" , MAX_FUNDING_SATOSHIS_NO_WUMBO , channel_value_satoshis) } ) ;
919916 }
920- if channel_value_satoshis >= TOTAL_BITCOIN_SUPPLY_SATOSHIS {
917+ if channel_value_satoshis >= MAX_VALUE_MSAT {
921918 return Err ( APIError :: APIMisuseError { err : format ! ( "funding_value must be smaller than the total bitcoin supply, it was {}" , channel_value_satoshis) } ) ;
922919 }
923920 let channel_value_msat = channel_value_satoshis * 1000 ;
@@ -1163,7 +1160,7 @@ impl<Signer: Sign> Channel<Signer> {
11631160 if msg. funding_satoshis > config. channel_handshake_limits . max_funding_satoshis {
11641161 return Err ( ChannelError :: Close ( format ! ( "Per our config, funding must be at most {}. It was {}" , config. channel_handshake_limits. max_funding_satoshis, msg. funding_satoshis) ) ) ;
11651162 }
1166- if msg. funding_satoshis >= TOTAL_BITCOIN_SUPPLY_SATOSHIS {
1163+ if msg. funding_satoshis >= MAX_VALUE_MSAT {
11671164 return Err ( ChannelError :: Close ( format ! ( "Funding must be smaller than the total bitcoin supply. It was {}" , msg. funding_satoshis) ) ) ;
11681165 }
11691166 if msg. channel_reserve_satoshis > msg. funding_satoshis {
@@ -4332,7 +4329,7 @@ impl<Signer: Sign> Channel<Signer> {
43324329 if !self . pending_inbound_htlcs . is_empty ( ) || !self . pending_outbound_htlcs . is_empty ( ) {
43334330 return Err ( ChannelError :: Close ( "Remote end sent us a closing_signed while there were still pending HTLCs" . to_owned ( ) ) ) ;
43344331 }
4335- if msg. fee_satoshis > TOTAL_BITCOIN_SUPPLY_SATOSHIS { // this is required to stop potential overflow in build_closing_transaction
4332+ if msg. fee_satoshis > MAX_VALUE_MSAT { // this is required to stop potential overflow in build_closing_transaction
43364333 return Err ( ChannelError :: Close ( "Remote tried to send us a closing tx with > 21 million BTC fee" . to_owned ( ) ) ) ;
43374334 }
43384335
@@ -6710,7 +6707,7 @@ mod tests {
67106707 use crate :: ln:: PaymentHash ;
67116708 use crate :: ln:: channelmanager:: { self , HTLCSource , PaymentId } ;
67126709 use crate :: ln:: channel:: { Channel , InboundHTLCOutput , OutboundHTLCOutput , InboundHTLCState , OutboundHTLCState , HTLCCandidate , HTLCInitiator } ;
6713- use crate :: ln:: channel:: { MAX_FUNDING_SATOSHIS_NO_WUMBO , TOTAL_BITCOIN_SUPPLY_SATOSHIS , MIN_THEIR_CHAN_RESERVE_SATOSHIS } ;
6710+ use crate :: ln:: channel:: { MAX_FUNDING_SATOSHIS_NO_WUMBO , MIN_THEIR_CHAN_RESERVE_SATOSHIS } ;
67146711 use crate :: ln:: features:: ChannelTypeFeatures ;
67156712 use crate :: ln:: msgs:: { ChannelUpdate , DataLossProtect , DecodeError , OptionalField , UnsignedChannelUpdate , MAX_VALUE_MSAT } ;
67166713 use crate :: ln:: script:: ShutdownScript ;
@@ -6749,8 +6746,8 @@ mod tests {
67496746
67506747 #[ test]
67516748 fn test_max_funding_satoshis_no_wumbo ( ) {
6752- assert_eq ! ( TOTAL_BITCOIN_SUPPLY_SATOSHIS , 21_000_000 * 100_000_000 ) ;
6753- assert ! ( MAX_FUNDING_SATOSHIS_NO_WUMBO <= TOTAL_BITCOIN_SUPPLY_SATOSHIS ,
6749+ assert_eq ! ( MAX_VALUE_MSAT , 21_000_000 * 100_000_000 ) ;
6750+ assert ! ( MAX_FUNDING_SATOSHIS_NO_WUMBO <= MAX_VALUE_MSAT ,
67546751 "MAX_FUNDING_SATOSHIS_NO_WUMBO is greater than all satoshis in existence" ) ;
67556752 }
67566753
0 commit comments