@@ -482,6 +482,16 @@ pub(crate) const CONCURRENT_INBOUND_HTLC_FEE_BUFFER: u32 = 2;
482
482
/// transaction (not counting the value of the HTLCs themselves).
483
483
pub ( crate ) const MIN_AFFORDABLE_HTLC_COUNT : usize = 4 ;
484
484
485
+ /// When a [`Channel`] has its [`ChannelConfig`] updated, its existing one is stashed for up to this
486
+ /// number of ticks to allow forwarding HTLCs by nodes that have yet to receive the new
487
+ /// ChannelUpdate prompted by the config update. This value was determined as follows:
488
+ ///
489
+ /// * The expected interval between ticks (1 minute).
490
+ /// * The average convergence delay of updates across the network, i.e., ~300 seconds on average
491
+ /// for a node to see an update as seen on `<https://arxiv.org/pdf/2205.12737.pdf>`.
492
+ /// * `EXPIRE_PREV_CONFIG_TICKS` = convergence_delay / tick_interval
493
+ pub ( crate ) const EXPIRE_PREV_CONFIG_TICKS : usize = 5 ;
494
+
485
495
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
486
496
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
487
497
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -495,6 +505,11 @@ pub(super) struct Channel<Signer: Sign> {
495
505
#[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
496
506
config : LegacyChannelConfig ,
497
507
508
+ // Track the previous `ChannelConfig` so that we can continue forwarding HTLCs that were
509
+ // constructed using it. The second element in the tuple corresponds to the number of ticks that
510
+ // have elapsed since the update occurred.
511
+ prev_config : Option < ( ChannelConfig , usize ) > ,
512
+
498
513
inbound_handshake_limits_override : Option < ChannelHandshakeLimits > ,
499
514
500
515
user_id : u64 ,
@@ -937,6 +952,8 @@ impl<Signer: Sign> Channel<Signer> {
937
952
commit_upfront_shutdown_pubkey : config. channel_handshake_config . commit_upfront_shutdown_pubkey ,
938
953
} ,
939
954
955
+ prev_config : None ,
956
+
940
957
inbound_handshake_limits_override : Some ( config. channel_handshake_limits . clone ( ) ) ,
941
958
942
959
channel_id : keys_provider. get_secure_random_bytes ( ) ,
@@ -1264,6 +1281,8 @@ impl<Signer: Sign> Channel<Signer> {
1264
1281
commit_upfront_shutdown_pubkey : config. channel_handshake_config . commit_upfront_shutdown_pubkey ,
1265
1282
} ,
1266
1283
1284
+ prev_config : None ,
1285
+
1267
1286
inbound_handshake_limits_override : None ,
1268
1287
1269
1288
channel_id : msg. temporary_channel_id ,
@@ -4491,6 +4510,25 @@ impl<Signer: Sign> Channel<Signer> {
4491
4510
self . config . options . max_dust_htlc_exposure_msat
4492
4511
}
4493
4512
4513
+ /// Returns the previous [`ChannelConfig`] applied to this channel, if any.
4514
+ pub fn prev_config ( & self ) -> Option < ChannelConfig > {
4515
+ self . prev_config . map ( |prev_config| prev_config. 0 )
4516
+ }
4517
+
4518
+ /// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
4519
+ /// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
4520
+ /// no longer be considered when forwarding HTLCs.
4521
+ pub fn maybe_expire_prev_config ( & mut self ) {
4522
+ if self . prev_config . is_none ( ) {
4523
+ return ;
4524
+ }
4525
+ let prev_config = self . prev_config . as_mut ( ) . unwrap ( ) ;
4526
+ prev_config. 1 += 1 ;
4527
+ if prev_config. 1 == EXPIRE_PREV_CONFIG_TICKS {
4528
+ self . prev_config = None ;
4529
+ }
4530
+ }
4531
+
4494
4532
/// Returns the current [`ChannelConfig`] applied to the channel.
4495
4533
pub fn config ( & self ) -> ChannelConfig {
4496
4534
self . config . options
@@ -4504,6 +4542,7 @@ impl<Signer: Sign> Channel<Signer> {
4504
4542
self . config . options . forwarding_fee_base_msat != config. forwarding_fee_base_msat ||
4505
4543
self . config . options . cltv_expiry_delta != config. cltv_expiry_delta ;
4506
4544
if did_channel_update {
4545
+ self . prev_config = Some ( ( self . config . options , 0 ) ) ;
4507
4546
// Update the counter, which backs the ChannelUpdate timestamp, to allow the relay
4508
4547
// policy change to propagate throughout the network.
4509
4548
self . update_time_counter += 1 ;
@@ -6360,6 +6399,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6360
6399
6361
6400
config : config. unwrap ( ) ,
6362
6401
6402
+ prev_config : None ,
6403
+
6363
6404
// Note that we don't care about serializing handshake limits as we only ever serialize
6364
6405
// channel data after the handshake has completed.
6365
6406
inbound_handshake_limits_override : None ,
0 commit comments