Skip to content

Commit c909941

Browse files
authored
Bump duplicate cache time (sigp#5493)
* Bump seen_ttl for gossipsub duplicate cache
1 parent 9d24844 commit c909941

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

beacon_node/lighthouse_network/src/config.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ pub const DEFAULT_TCP_PORT: u16 = 9000u16;
2020
pub const DEFAULT_DISC_PORT: u16 = 9000u16;
2121
pub const DEFAULT_QUIC_PORT: u16 = 9001u16;
2222

23-
/// The cache time is set to accommodate the circulation time of an attestation.
24-
///
25-
/// The p2p spec declares that we accept attestations within the following range:
26-
///
27-
/// ```ignore
28-
/// ATTESTATION_PROPAGATION_SLOT_RANGE = 32
29-
/// attestation.data.slot + ATTESTATION_PROPAGATION_SLOT_RANGE >= current_slot >= attestation.data.slot
30-
/// ```
31-
///
32-
/// Therefore, we must accept attestations across a span of 33 slots (where each slot is 12
33-
/// seconds). We add an additional second to account for the 500ms gossip clock disparity, and
34-
/// another 500ms for "fudge factor".
35-
pub const DUPLICATE_CACHE_TIME: Duration = Duration::from_secs(33 * 12 + 1);
36-
3723
/// The maximum size of gossip messages.
3824
pub fn gossip_max_size(is_merge_enabled: bool, gossip_max_size: usize) -> usize {
3925
if is_merge_enabled {
@@ -452,6 +438,8 @@ pub fn gossipsub_config(
452438
network_load: u8,
453439
fork_context: Arc<ForkContext>,
454440
gossipsub_config_params: GossipsubConfigParams,
441+
seconds_per_slot: u64,
442+
slots_per_epoch: u64,
455443
) -> gossipsub::Config {
456444
fn prefix(
457445
prefix: [u8; 4],
@@ -491,6 +479,13 @@ pub fn gossipsub_config(
491479

492480
let load = NetworkLoad::from(network_load);
493481

482+
// Since EIP 7045 (activated at the deneb fork), we allow attestations that are
483+
// 2 epochs old to be circulated around the p2p network.
484+
// To accommodate the increase, we should increase the duplicate cache time to filter older seen messages.
485+
// 2 epochs is quite sane for pre-deneb network parameters as well.
486+
// Hence we keep the same parameters for pre-deneb networks as well to avoid switching at the fork.
487+
let duplicate_cache_time = Duration::from_secs(slots_per_epoch * seconds_per_slot * 2);
488+
494489
gossipsub::ConfigBuilder::default()
495490
.max_transmit_size(gossip_max_size(
496491
is_merge_enabled,
@@ -509,7 +504,7 @@ pub fn gossipsub_config(
509504
.history_gossip(load.history_gossip)
510505
.validate_messages() // require validation before propagation
511506
.validation_mode(gossipsub::ValidationMode::Anonymous)
512-
.duplicate_cache_time(DUPLICATE_CACHE_TIME)
507+
.duplicate_cache_time(duplicate_cache_time)
513508
.message_id_fn(gossip_message_id)
514509
.allow_self_origin(true)
515510
.build()

beacon_node/lighthouse_network/src/service/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
256256
config.network_load,
257257
ctx.fork_context.clone(),
258258
gossipsub_config_params,
259+
ctx.chain_spec.seconds_per_slot,
260+
TSpec::slots_per_epoch(),
259261
);
260262

261263
// If metrics are enabled for libp2p build the configuration

0 commit comments

Comments
 (0)