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