@@ -456,7 +456,6 @@ struct CommitmentTxInfoCached {
456456}
457457
458458pub 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
460459
461460#[ cfg( not( test) ) ]
462461const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -3426,7 +3425,7 @@ impl<Signer: Sign> Channel<Signer> {
34263425 }
34273426
34283427 pub fn get_fee_proportional_millionths ( & self ) -> u32 {
3429- self . config . fee_proportional_millionths
3428+ self . config . forwarding_fee_proportional_millionths
34303429 }
34313430
34323431 pub fn get_cltv_expiry_delta ( & self ) -> u16 {
@@ -3499,24 +3498,8 @@ impl<Signer: Sign> Channel<Signer> {
34993498
35003499 /// Gets the fee we'd want to charge for adding an HTLC output to this Channel
35013500 /// 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
35203503 }
35213504
35223505 /// 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
44604443 return !script. is_p2pkh ( ) && !script. is_p2sh ( ) && !script. is_v0_p2wpkh ( ) && !script. is_v0_p2wsh ( )
44614444}
44624445
4463- const SERIALIZATION_VERSION : u8 = 1 ;
4446+ const SERIALIZATION_VERSION : u8 = 2 ;
44644447const MIN_SERIALIZATION_VERSION : u8 = 1 ;
44654448
44664449impl_writeable_tlv_based_enum ! ( InboundHTLCRemovalReason , ;
@@ -4502,7 +4485,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
45024485 write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
45034486
45044487 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) ?;
45064495
45074496 self . channel_id . write ( writer) ?;
45084497 ( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -4661,10 +4650,15 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
46614650 self . counterparty_dust_limit_satoshis . write ( writer) ?;
46624651 self . holder_dust_limit_satoshis . write ( writer) ?;
46634652 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.
46644655 self . counterparty_selected_channel_reserve_satoshis . unwrap_or ( 0 ) . write ( writer) ?;
4656+
46654657 self . counterparty_htlc_minimum_msat . write ( writer) ?;
46664658 self . holder_htlc_minimum_msat . write ( writer) ?;
46674659 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.
46684662 self . minimum_depth . unwrap_or ( 0 ) . write ( writer) ?;
46694663
46704664 match & self . counterparty_forwarding_info {
@@ -4700,6 +4694,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
47004694 // override that.
47014695 ( 1 , self . minimum_depth, option) ,
47024696 ( 3 , self . counterparty_selected_channel_reserve_satoshis, option) ,
4697+ ( 5 , self . config, required) ,
47034698 } ) ;
47044699
47054700 Ok ( ( ) )
@@ -4710,10 +4705,21 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
47104705impl < ' a , Signer : Sign , K : Deref > ReadableArgs < & ' a K > for Channel < Signer >
47114706 where K :: Target : KeysInterface < Signer = Signer > {
47124707 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 ) ;
47144709
47154710 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+ }
47174723
47184724 let channel_id = Readable :: read ( reader) ?;
47194725 let channel_state = Readable :: read ( reader) ?;
@@ -4843,20 +4849,25 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48434849 let counterparty_dust_limit_satoshis = Readable :: read ( reader) ?;
48444850 let holder_dust_limit_satoshis = Readable :: read ( reader) ?;
48454851 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) ?;
48514859 }
48524860 let counterparty_htlc_minimum_msat = Readable :: read ( reader) ?;
48534861 let holder_htlc_minimum_msat = Readable :: read ( reader) ?;
48544862 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) ?;
48604871 }
48614872
48624873 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>
48874898 ( 0 , announcement_sigs, option) ,
48884899 ( 1 , minimum_depth, option) ,
48894900 ( 3 , counterparty_selected_channel_reserve_satoshis, option) ,
4901+ ( 5 , config, option) , // Note that if none is provided we will *not* overwrite the existing one.
48904902 } ) ;
48914903
48924904 let mut secp_ctx = Secp256k1 :: new ( ) ;
@@ -4895,7 +4907,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48954907 Ok ( Channel {
48964908 user_id,
48974909
4898- config,
4910+ config : config . unwrap ( ) ,
48994911 channel_id,
49004912 channel_state,
49014913 secp_ctx,
0 commit comments