@@ -39,7 +39,7 @@ use util::events::ClosureReason;
39
39
use util:: ser:: { Readable , ReadableArgs , Writeable , Writer , VecWriter } ;
40
40
use util:: logger:: Logger ;
41
41
use util:: errors:: APIError ;
42
- use util:: config:: { UserConfig , ChannelConfig , ChannelHandshakeConfig , ChannelHandshakeLimits } ;
42
+ use util:: config:: { UserConfig , ChannelConfig , ChannelHandshakeConfig , ChannelHandshakeLimits , LegacyChannelConfig } ;
43
43
use util:: scid_utils:: scid_from_parts;
44
44
45
45
use io;
@@ -490,6 +490,10 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
490
490
// Holder designates channel data owned for the benefice of the user client.
491
491
// Counterparty designates channel data owned by the another channel participant entity.
492
492
pub ( super ) struct Channel < Signer : Sign > {
493
+ // This only here for backwards-compatibility in serialization, in the future it can be removed,
494
+ // breaking clients running 0.0.107 and earlier.
495
+ _legacy_config : LegacyChannelConfig ,
496
+
493
497
#[ cfg( any( test, feature = "_test_utils" ) ) ]
494
498
pub ( crate ) config : ChannelConfig ,
495
499
#[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
@@ -929,17 +933,24 @@ impl<Signer: Sign> Channel<Signer> {
929
933
}
930
934
}
931
935
932
- // Also update `ChannelConfig::announced_channel ` to make sure we still allow users to
933
- // downgrade versions after the fact.
936
+ // Also update `LegacyChannelConfig ` to make sure we still allow users to downgrade versions
937
+ // after the fact.
934
938
//
935
- // TODO: This can be removed once we prevent downgrades to v0.0.107.
936
- let mut channel_options = config. channel_options . clone ( ) ;
937
- channel_options. announced_channel = config. own_channel_config . announced_channel ;
939
+ // TODO: This can be removed once we break compatibility with versions 0.0.107 and earlier.
940
+ let legacy_config = LegacyChannelConfig {
941
+ config : config. channel_options . clone ( ) ,
942
+ announced_channel : config. own_channel_config . announced_channel ,
943
+ commit_upfront_shutdown_pubkey : config. own_channel_config . commit_upfront_shutdown_pubkey ,
944
+ } ;
938
945
939
946
Ok ( Channel {
940
947
user_id,
941
- config : channel_options,
948
+
949
+ _legacy_config : legacy_config,
950
+ config : config. channel_options . clone ( ) ,
951
+
942
952
announced : config. own_channel_config . announced_channel ,
953
+
943
954
inbound_handshake_limits_override : Some ( config. peer_channel_config_limits . clone ( ) ) ,
944
955
945
956
channel_id : keys_provider. get_secure_random_bytes ( ) ,
@@ -1195,12 +1206,15 @@ impl<Signer: Sign> Channel<Signer> {
1195
1206
return Err ( ChannelError :: Close ( "Peer tried to open channel but their announcement preference is different from ours" . to_owned ( ) ) ) ;
1196
1207
}
1197
1208
}
1198
- // Also update `ChannelConfig::announced_channel ` to make sure we still allow users to
1199
- // downgrade versions after the fact.
1209
+ // Also update `LegacyChannelConfig ` to make sure we still allow users to downgrade versions
1210
+ // after the fact.
1200
1211
//
1201
- // TODO: This can be removed once we prevent downgrades to v0.0.107.
1202
- let mut channel_options = config. channel_options . clone ( ) ;
1203
- channel_options. announced_channel = announced_channel;
1212
+ // TODO: This can be removed once we break compatibility with versions 0.0.107 and earlier.
1213
+ let legacy_config = LegacyChannelConfig {
1214
+ config : config. channel_options . clone ( ) ,
1215
+ announced_channel,
1216
+ commit_upfront_shutdown_pubkey : config. own_channel_config . commit_upfront_shutdown_pubkey ,
1217
+ } ;
1204
1218
1205
1219
let holder_selected_channel_reserve_satoshis = Channel :: < Signer > :: get_holder_selected_channel_reserve_satoshis ( msg. funding_satoshis ) ;
1206
1220
if holder_selected_channel_reserve_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
@@ -1267,8 +1281,12 @@ impl<Signer: Sign> Channel<Signer> {
1267
1281
1268
1282
let chan = Channel {
1269
1283
user_id,
1270
- config : channel_options,
1284
+
1285
+ _legacy_config : legacy_config,
1286
+ config : config. channel_options . clone ( ) ,
1287
+
1271
1288
announced : announced_channel,
1289
+
1272
1290
inbound_handshake_limits_override : None ,
1273
1291
1274
1292
channel_id : msg. temporary_channel_id ,
@@ -6011,7 +6029,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
6011
6029
( 2 , chan_type, option) ,
6012
6030
( 3 , self . counterparty_selected_channel_reserve_satoshis, option) ,
6013
6031
( 4 , serialized_holder_selected_reserve, option) ,
6014
- ( 5 , self . config , required) ,
6032
+ ( 5 , self . _legacy_config , required) ,
6015
6033
( 6 , serialized_holder_htlc_max_in_flight, option) ,
6016
6034
( 7 , self . shutdown_scriptpubkey, option) ,
6017
6035
( 9 , self . target_closing_feerate_sats_per_kw, option) ,
@@ -6022,6 +6040,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
6022
6040
( 19 , self . latest_inbound_scid_alias, option) ,
6023
6041
( 21 , self . outbound_scid_alias, required) ,
6024
6042
( 23 , self . announced, required) ,
6043
+ ( 25 , self . config, required) ,
6025
6044
} ) ;
6026
6045
6027
6046
Ok ( ( ) )
@@ -6037,13 +6056,13 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6037
6056
6038
6057
let user_id = Readable :: read ( reader) ?;
6039
6058
6040
- let mut config = Some ( ChannelConfig :: default ( ) ) ;
6059
+ let mut legacy_config = Some ( LegacyChannelConfig :: default ( ) ) ;
6041
6060
if ver == 1 {
6042
6061
// Read the old serialization of the ChannelConfig from version 0.0.98.
6043
- config . as_mut ( ) . unwrap ( ) . forwarding_fee_proportional_millionths = Readable :: read ( reader) ?;
6044
- config . as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
6045
- config . as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
6046
- config . as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
6062
+ legacy_config . as_mut ( ) . unwrap ( ) . config . forwarding_fee_proportional_millionths = Readable :: read ( reader) ?;
6063
+ legacy_config . as_mut ( ) . unwrap ( ) . config . cltv_expiry_delta = Readable :: read ( reader) ?;
6064
+ legacy_config . as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
6065
+ legacy_config . as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
6047
6066
} else {
6048
6067
// Read the 8 bytes of backwards-compatibility ChannelConfig data.
6049
6068
let mut _val: u64 = Readable :: read ( reader) ?;
@@ -6280,14 +6299,15 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6280
6299
let mut latest_inbound_scid_alias = None ;
6281
6300
let mut outbound_scid_alias = None ;
6282
6301
let mut announced = None ;
6302
+ let mut config = None ;
6283
6303
6284
6304
read_tlv_fields ! ( reader, {
6285
6305
( 0 , announcement_sigs, option) ,
6286
6306
( 1 , minimum_depth, option) ,
6287
6307
( 2 , channel_type, option) ,
6288
6308
( 3 , counterparty_selected_channel_reserve_satoshis, option) ,
6289
6309
( 4 , holder_selected_channel_reserve_satoshis, option) ,
6290
- ( 5 , config , option) , // Note that if none is provided we will *not* overwrite the existing one.
6310
+ ( 5 , legacy_config , option) , // Note that if none is provided we will *not* overwrite the existing one.
6291
6311
( 6 , holder_max_htlc_value_in_flight_msat, option) ,
6292
6312
( 7 , shutdown_scriptpubkey, option) ,
6293
6313
( 9 , target_closing_feerate_sats_per_kw, option) ,
@@ -6298,6 +6318,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6298
6318
( 19 , latest_inbound_scid_alias, option) ,
6299
6319
( 21 , outbound_scid_alias, option) ,
6300
6320
( 23 , announced, option) ,
6321
+ ( 25 , config, option) ,
6301
6322
} ) ;
6302
6323
6303
6324
if let Some ( preimages) = preimages_opt {
@@ -6337,8 +6358,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6337
6358
Ok ( Channel {
6338
6359
user_id,
6339
6360
6340
- config : config. unwrap ( ) ,
6341
- announced : announced. unwrap_or ( config. unwrap ( ) . announced_channel ) ,
6361
+ _legacy_config : legacy_config. unwrap ( ) ,
6362
+ config : config. unwrap_or ( legacy_config. unwrap ( ) . config ) ,
6363
+
6364
+ announced : announced. unwrap_or ( legacy_config. unwrap ( ) . announced_channel ) ,
6342
6365
6343
6366
// Note that we don't care about serializing handshake limits as we only ever serialize
6344
6367
// channel data after the handshake has completed.
0 commit comments