@@ -304,6 +304,85 @@ const MULTI_STATE_FLAGS: u32 = BOTH_SIDES_SHUTDOWN_MASK | ChannelState::PeerDisc
304
304
305
305
pub const INITIAL_COMMITMENT_NUMBER : u64 = ( 1 << 48 ) - 1 ;
306
306
307
+ pub const DEFAULT_MAX_HTLCS : u16 = 50 ;
308
+
309
+ pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
310
+ const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
311
+ const COMMITMENT_TX_BASE_ANCHOR_WEIGHT : u64 = 1124 ;
312
+ if opt_anchors { COMMITMENT_TX_BASE_ANCHOR_WEIGHT } else { COMMITMENT_TX_BASE_WEIGHT }
313
+ }
314
+
315
+ #[ cfg( not( test) ) ]
316
+ const COMMITMENT_TX_WEIGHT_PER_HTLC : u64 = 172 ;
317
+ #[ cfg( test) ]
318
+ pub const COMMITMENT_TX_WEIGHT_PER_HTLC : u64 = 172 ;
319
+
320
+ pub const ANCHOR_OUTPUT_VALUE_SATOSHI : u64 = 330 ;
321
+
322
+ /// The percentage of the channel value `holder_max_htlc_value_in_flight_msat` used to be set to,
323
+ /// before this was made configurable. The percentage was made configurable in LDK 0.0.107,
324
+ /// although LDK 0.0.104+ enabled serialization of channels with a different value set for
325
+ /// `holder_max_htlc_value_in_flight_msat`.
326
+ pub const MAX_IN_FLIGHT_PERCENT_LEGACY : u8 = 10 ;
327
+
328
+ /// Maximum `funding_satoshis` value according to the BOLT #2 specification, if
329
+ /// `option_support_large_channel` (aka wumbo channels) is not supported.
330
+ /// It's 2^24 - 1.
331
+ pub const MAX_FUNDING_SATOSHIS_NO_WUMBO : u64 = ( 1 << 24 ) - 1 ;
332
+
333
+ /// Total bitcoin supply in satoshis.
334
+ pub const TOTAL_BITCOIN_SUPPLY_SATOSHIS : u64 = 21_000_000 * 1_0000_0000 ;
335
+
336
+ /// The maximum network dust limit for standard script formats. This currently represents the
337
+ /// minimum output value for a P2SH output before Bitcoin Core 22 considers the entire
338
+ /// transaction non-standard and thus refuses to relay it.
339
+ /// We also use this as the maximum counterparty `dust_limit_satoshis` allowed, given many
340
+ /// implementations use this value for their dust limit today.
341
+ pub const MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS : u64 = 546 ;
342
+
343
+ /// The maximum channel dust limit we will accept from our counterparty.
344
+ pub const MAX_CHAN_DUST_LIMIT_SATOSHIS : u64 = MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS ;
345
+
346
+ /// The dust limit is used for both the commitment transaction outputs as well as the closing
347
+ /// transactions. For cooperative closing transactions, we require segwit outputs, though accept
348
+ /// *any* segwit scripts, which are allowed to be up to 42 bytes in length.
349
+ /// In order to avoid having to concern ourselves with standardness during the closing process, we
350
+ /// simply require our counterparty to use a dust limit which will leave any segwit output
351
+ /// standard.
352
+ /// See <https://github.com/lightning/bolts/issues/905> for more details.
353
+ pub const MIN_CHAN_DUST_LIMIT_SATOSHIS : u64 = 354 ;
354
+
355
+ // Just a reasonable implementation-specific safe lower bound, higher than the dust limit.
356
+ pub const MIN_THEIR_CHAN_RESERVE_SATOSHIS : u64 = 1000 ;
357
+
358
+ /// Used to return a simple Error back to ChannelManager. Will get converted to a
359
+ /// msgs::ErrorAction::SendErrorMessage or msgs::ErrorAction::IgnoreError as appropriate with our
360
+ /// channel_id in ChannelManager.
361
+ pub ( super ) enum ChannelError {
362
+ Ignore ( String ) ,
363
+ Warn ( String ) ,
364
+ Close ( String ) ,
365
+ }
366
+
367
+ impl fmt:: Debug for ChannelError {
368
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
369
+ match self {
370
+ & ChannelError :: Ignore ( ref e) => write ! ( f, "Ignore : {}" , e) ,
371
+ & ChannelError :: Warn ( ref e) => write ! ( f, "Warn : {}" , e) ,
372
+ & ChannelError :: Close ( ref e) => write ! ( f, "Close : {}" , e) ,
373
+ }
374
+ }
375
+ }
376
+
377
+ macro_rules! secp_check {
378
+ ( $res: expr, $err: expr) => {
379
+ match $res {
380
+ Ok ( thing) => thing,
381
+ Err ( _) => return Err ( ChannelError :: Close ( $err) ) ,
382
+ }
383
+ } ;
384
+ }
385
+
307
386
/// The "channel disabled" bit in channel_update must be set based on whether we are connected to
308
387
/// our counterparty or not. However, we don't want to announce updates right away to avoid
309
388
/// spamming the network with updates if the connection is flapping. Instead, we "stage" updates to
@@ -1874,85 +1953,6 @@ struct CommitmentTxInfoCached {
1874
1953
feerate : u32 ,
1875
1954
}
1876
1955
1877
- pub const DEFAULT_MAX_HTLCS : u16 = 50 ;
1878
-
1879
- pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
1880
- const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
1881
- const COMMITMENT_TX_BASE_ANCHOR_WEIGHT : u64 = 1124 ;
1882
- if opt_anchors { COMMITMENT_TX_BASE_ANCHOR_WEIGHT } else { COMMITMENT_TX_BASE_WEIGHT }
1883
- }
1884
-
1885
- #[ cfg( not( test) ) ]
1886
- const COMMITMENT_TX_WEIGHT_PER_HTLC : u64 = 172 ;
1887
- #[ cfg( test) ]
1888
- pub const COMMITMENT_TX_WEIGHT_PER_HTLC : u64 = 172 ;
1889
-
1890
- pub const ANCHOR_OUTPUT_VALUE_SATOSHI : u64 = 330 ;
1891
-
1892
- /// The percentage of the channel value `holder_max_htlc_value_in_flight_msat` used to be set to,
1893
- /// before this was made configurable. The percentage was made configurable in LDK 0.0.107,
1894
- /// although LDK 0.0.104+ enabled serialization of channels with a different value set for
1895
- /// `holder_max_htlc_value_in_flight_msat`.
1896
- pub const MAX_IN_FLIGHT_PERCENT_LEGACY : u8 = 10 ;
1897
-
1898
- /// Maximum `funding_satoshis` value according to the BOLT #2 specification, if
1899
- /// `option_support_large_channel` (aka wumbo channels) is not supported.
1900
- /// It's 2^24 - 1.
1901
- pub const MAX_FUNDING_SATOSHIS_NO_WUMBO : u64 = ( 1 << 24 ) - 1 ;
1902
-
1903
- /// Total bitcoin supply in satoshis.
1904
- pub const TOTAL_BITCOIN_SUPPLY_SATOSHIS : u64 = 21_000_000 * 1_0000_0000 ;
1905
-
1906
- /// The maximum network dust limit for standard script formats. This currently represents the
1907
- /// minimum output value for a P2SH output before Bitcoin Core 22 considers the entire
1908
- /// transaction non-standard and thus refuses to relay it.
1909
- /// We also use this as the maximum counterparty `dust_limit_satoshis` allowed, given many
1910
- /// implementations use this value for their dust limit today.
1911
- pub const MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS : u64 = 546 ;
1912
-
1913
- /// The maximum channel dust limit we will accept from our counterparty.
1914
- pub const MAX_CHAN_DUST_LIMIT_SATOSHIS : u64 = MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS ;
1915
-
1916
- /// The dust limit is used for both the commitment transaction outputs as well as the closing
1917
- /// transactions. For cooperative closing transactions, we require segwit outputs, though accept
1918
- /// *any* segwit scripts, which are allowed to be up to 42 bytes in length.
1919
- /// In order to avoid having to concern ourselves with standardness during the closing process, we
1920
- /// simply require our counterparty to use a dust limit which will leave any segwit output
1921
- /// standard.
1922
- /// See <https://github.com/lightning/bolts/issues/905> for more details.
1923
- pub const MIN_CHAN_DUST_LIMIT_SATOSHIS : u64 = 354 ;
1924
-
1925
- // Just a reasonable implementation-specific safe lower bound, higher than the dust limit.
1926
- pub const MIN_THEIR_CHAN_RESERVE_SATOSHIS : u64 = 1000 ;
1927
-
1928
- /// Used to return a simple Error back to ChannelManager. Will get converted to a
1929
- /// msgs::ErrorAction::SendErrorMessage or msgs::ErrorAction::IgnoreError as appropriate with our
1930
- /// channel_id in ChannelManager.
1931
- pub ( super ) enum ChannelError {
1932
- Ignore ( String ) ,
1933
- Warn ( String ) ,
1934
- Close ( String ) ,
1935
- }
1936
-
1937
- impl fmt:: Debug for ChannelError {
1938
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1939
- match self {
1940
- & ChannelError :: Ignore ( ref e) => write ! ( f, "Ignore : {}" , e) ,
1941
- & ChannelError :: Warn ( ref e) => write ! ( f, "Warn : {}" , e) ,
1942
- & ChannelError :: Close ( ref e) => write ! ( f, "Close : {}" , e) ,
1943
- }
1944
- }
1945
- }
1946
-
1947
- macro_rules! secp_check {
1948
- ( $res: expr, $err: expr) => {
1949
- match $res {
1950
- Ok ( thing) => thing,
1951
- Err ( _) => return Err ( ChannelError :: Close ( $err) ) ,
1952
- }
1953
- } ;
1954
- }
1955
-
1956
1956
impl < Signer : WriteableEcdsaChannelSigner > Channel < Signer > {
1957
1957
fn get_initial_channel_type ( config : & UserConfig , their_features : & InitFeatures ) -> ChannelTypeFeatures {
1958
1958
// The default channel type (ie the first one we try) depends on whether the channel is
0 commit comments