@@ -456,7 +456,6 @@ struct CommitmentTxInfoCached {
456
456
}
457
457
458
458
pub const OUR_MAX_HTLCS : u16 = 50 ; //TODO
459
- const SPENDING_INPUT_FOR_A_OUTPUT_WEIGHT : u64 = 79 ; // prevout: 36, nSequence: 4, script len: 1, witness lengths: (3+1)/4, sig: 73/4, if-selector: 1, redeemScript: (6 ops + 2*33 pubkeys + 1*2 delay)/4
460
459
461
460
#[ cfg( not( test) ) ]
462
461
const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -3426,7 +3425,7 @@ impl<Signer: Sign> Channel<Signer> {
3426
3425
}
3427
3426
3428
3427
pub fn get_fee_proportional_millionths ( & self ) -> u32 {
3429
- self . config . fee_proportional_millionths
3428
+ self . config . forwarding_fee_proportional_millionths
3430
3429
}
3431
3430
3432
3431
pub fn get_cltv_expiry_delta ( & self ) -> u16 {
@@ -3499,24 +3498,8 @@ impl<Signer: Sign> Channel<Signer> {
3499
3498
3500
3499
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
3501
3500
/// Allowed in any state (including after shutdown)
3502
- pub fn get_holder_fee_base_msat < F : Deref > ( & self , fee_estimator : & F ) -> u32
3503
- where F :: Target : FeeEstimator
3504
- {
3505
- // For lack of a better metric, we calculate what it would cost to consolidate the new HTLC
3506
- // output value back into a transaction with the regular channel output:
3507
-
3508
- // the fee cost of the HTLC-Success/HTLC-Timeout transaction:
3509
- let mut res = self . feerate_per_kw as u64 * cmp:: max ( HTLC_TIMEOUT_TX_WEIGHT , HTLC_SUCCESS_TX_WEIGHT ) / 1000 ;
3510
-
3511
- if self . is_outbound ( ) {
3512
- // + the marginal fee increase cost to us in the commitment transaction:
3513
- res += self . feerate_per_kw as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC / 1000 ;
3514
- }
3515
-
3516
- // + the marginal cost of an input which spends the HTLC-Success/HTLC-Timeout output:
3517
- res += fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Normal ) as u64 * SPENDING_INPUT_FOR_A_OUTPUT_WEIGHT / 1000 ;
3518
-
3519
- res as u32
3501
+ pub fn get_outbound_forwarding_fee_base_msat ( & self ) -> u32 {
3502
+ self . config . forwarding_fee_base_msat
3520
3503
}
3521
3504
3522
3505
/// Returns true if we've ever received a message from the remote end for this Channel
@@ -4460,7 +4443,7 @@ fn is_unsupported_shutdown_script(their_features: &InitFeatures, script: &Script
4460
4443
return !script. is_p2pkh ( ) && !script. is_p2sh ( ) && !script. is_v0_p2wpkh ( ) && !script. is_v0_p2wsh ( )
4461
4444
}
4462
4445
4463
- const SERIALIZATION_VERSION : u8 = 1 ;
4446
+ const SERIALIZATION_VERSION : u8 = 2 ;
4464
4447
const MIN_SERIALIZATION_VERSION : u8 = 1 ;
4465
4448
4466
4449
impl_writeable_tlv_based_enum ! ( InboundHTLCRemovalReason , ;
@@ -4502,7 +4485,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4502
4485
write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
4503
4486
4504
4487
self . user_id . write ( writer) ?;
4505
- self . config . write ( writer) ?;
4488
+
4489
+ // Write out the old serialization for the config object. This is read by version-1
4490
+ // deserializers, but we will read the version in the TLV at the end instead.
4491
+ self . config . forwarding_fee_proportional_millionths . write ( writer) ?;
4492
+ self . config . cltv_expiry_delta . write ( writer) ?;
4493
+ self . config . announced_channel . write ( writer) ?;
4494
+ self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
4506
4495
4507
4496
self . channel_id . write ( writer) ?;
4508
4497
( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -4661,10 +4650,15 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4661
4650
self . counterparty_dust_limit_satoshis . write ( writer) ?;
4662
4651
self . holder_dust_limit_satoshis . write ( writer) ?;
4663
4652
self . counterparty_max_htlc_value_in_flight_msat . write ( writer) ?;
4653
+
4654
+ // Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
4664
4655
self . counterparty_selected_channel_reserve_satoshis . unwrap_or ( 0 ) . write ( writer) ?;
4656
+
4665
4657
self . counterparty_htlc_minimum_msat . write ( writer) ?;
4666
4658
self . holder_htlc_minimum_msat . write ( writer) ?;
4667
4659
self . counterparty_max_accepted_htlcs . write ( writer) ?;
4660
+
4661
+ // Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
4668
4662
self . minimum_depth . unwrap_or ( 0 ) . write ( writer) ?;
4669
4663
4670
4664
match & self . counterparty_forwarding_info {
@@ -4700,6 +4694,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4700
4694
// override that.
4701
4695
( 1 , self . minimum_depth, option) ,
4702
4696
( 3 , self . counterparty_selected_channel_reserve_satoshis, option) ,
4697
+ ( 5 , self . config, required) ,
4703
4698
} ) ;
4704
4699
4705
4700
Ok ( ( ) )
@@ -4710,10 +4705,21 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
4710
4705
impl < ' a , Signer : Sign , K : Deref > ReadableArgs < & ' a K > for Channel < Signer >
4711
4706
where K :: Target : KeysInterface < Signer = Signer > {
4712
4707
fn read < R : :: std:: io:: Read > ( reader : & mut R , keys_source : & ' a K ) -> Result < Self , DecodeError > {
4713
- let _ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
4708
+ let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
4714
4709
4715
4710
let user_id = Readable :: read ( reader) ?;
4716
- let config: ChannelConfig = Readable :: read ( reader) ?;
4711
+
4712
+ let mut config = Some ( ChannelConfig :: default ( ) ) ;
4713
+ if ver == 1 {
4714
+ // Read the old serialization of the ChannelConfig from version 0.0.98.
4715
+ config. as_mut ( ) . unwrap ( ) . forwarding_fee_proportional_millionths = Readable :: read ( reader) ?;
4716
+ config. as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
4717
+ config. as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
4718
+ config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
4719
+ } else {
4720
+ // Read the 8 bytes of backwards-compatibility ChannelConfig data.
4721
+ let mut _val: u64 = Readable :: read ( reader) ?;
4722
+ }
4717
4723
4718
4724
let channel_id = Readable :: read ( reader) ?;
4719
4725
let channel_state = Readable :: read ( reader) ?;
@@ -4843,20 +4849,25 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4843
4849
let counterparty_dust_limit_satoshis = Readable :: read ( reader) ?;
4844
4850
let holder_dust_limit_satoshis = Readable :: read ( reader) ?;
4845
4851
let counterparty_max_htlc_value_in_flight_msat = Readable :: read ( reader) ?;
4846
- let mut counterparty_selected_channel_reserve_satoshis = Some ( Readable :: read ( reader) ?) ;
4847
- if counterparty_selected_channel_reserve_satoshis == Some ( 0 ) {
4848
- // Versions up to 0.0.98 had counterparty_selected_channel_reserve_satoshis as a
4849
- // non-option, writing 0 for what we now consider None.
4850
- counterparty_selected_channel_reserve_satoshis = None ;
4852
+ let mut counterparty_selected_channel_reserve_satoshis = None ;
4853
+ if ver == 1 {
4854
+ // Read the old serialization from version 0.0.98.
4855
+ counterparty_selected_channel_reserve_satoshis = Some ( Readable :: read ( reader) ?) ;
4856
+ } else {
4857
+ // Read the 8 bytes of backwards-compatibility data.
4858
+ let _dummy: u64 = Readable :: read ( reader) ?;
4851
4859
}
4852
4860
let counterparty_htlc_minimum_msat = Readable :: read ( reader) ?;
4853
4861
let holder_htlc_minimum_msat = Readable :: read ( reader) ?;
4854
4862
let counterparty_max_accepted_htlcs = Readable :: read ( reader) ?;
4855
- let mut minimum_depth = Some ( Readable :: read ( reader) ?) ;
4856
- if minimum_depth == Some ( 0 ) {
4857
- // Versions up to 0.0.98 had minimum_depth as a non-option, writing 0 for what we now
4858
- // consider None.
4859
- minimum_depth = None ;
4863
+
4864
+ let mut minimum_depth = None ;
4865
+ if ver == 1 {
4866
+ // Read the old serialization from version 0.0.98.
4867
+ minimum_depth = Some ( Readable :: read ( reader) ?) ;
4868
+ } else {
4869
+ // Read the 4 bytes of backwards-compatibility data.
4870
+ let _dummy: u32 = Readable :: read ( reader) ?;
4860
4871
}
4861
4872
4862
4873
let counterparty_forwarding_info = match <u8 as Readable >:: read ( reader) ? {
@@ -4887,6 +4898,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4887
4898
( 0 , announcement_sigs, option) ,
4888
4899
( 1 , minimum_depth, option) ,
4889
4900
( 3 , counterparty_selected_channel_reserve_satoshis, option) ,
4901
+ ( 5 , config, option) , // Note that if none is provided we will *not* overwrite the existing one.
4890
4902
} ) ;
4891
4903
4892
4904
let mut secp_ctx = Secp256k1 :: new ( ) ;
@@ -4895,7 +4907,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4895
4907
Ok ( Channel {
4896
4908
user_id,
4897
4909
4898
- config,
4910
+ config : config . unwrap ( ) ,
4899
4911
channel_id,
4900
4912
channel_state,
4901
4913
secp_ctx,
0 commit comments