From aebf7d38e040e64a33f42187ebc31ecefbb09c44 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 25 Nov 2019 18:19:55 +1100 Subject: [PATCH] Drop the block cache after genesis --- beacon_node/client/src/builder.rs | 11 +++++++++++ beacon_node/eth1/src/service.rs | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/beacon_node/client/src/builder.rs b/beacon_node/client/src/builder.rs index 3718ddad4e..de28ca4657 100644 --- a/beacon_node/client/src/builder.rs +++ b/beacon_node/client/src/builder.rs @@ -591,6 +591,17 @@ where let backend = if let Some(eth1_service_from_genesis) = self.eth1_service { eth1_service_from_genesis.update_config(config.clone())?; + + // This cache is not useful because it's first (earliest) block likely the block that + // triggered genesis. + // + // In order to vote we need to be able to go back at least 2 * `ETH1_FOLLOW_DISTANCE` + // from the genesis-triggering block. Presently the block cache does not support + // importing blocks with decreasing block numbers, it only accepts them in increasing + // order. If this turns out to be a bottleneck we can update the block cache to allow + // adding earlier blocks too. + eth1_service_from_genesis.drop_block_cache(); + CachingEth1Backend::from_service(eth1_service_from_genesis, store) } else { CachingEth1Backend::new(config, context.log, store) diff --git a/beacon_node/eth1/src/service.rs b/beacon_node/eth1/src/service.rs index bf88491103..51f6877cdd 100644 --- a/beacon_node/eth1/src/service.rs +++ b/beacon_node/eth1/src/service.rs @@ -163,6 +163,11 @@ impl Service { &self.inner.deposit_cache } + /// Drop the block cache, replacing it with an empty one. + pub fn drop_block_cache(&self) { + *(self.inner.block_cache.write()) = BlockCache::default(); + } + /// Returns the number of currently cached blocks. pub fn block_cache_len(&self) -> usize { self.blocks().read().len()