From 7933596c891db74e344292e650b05f49673ab830 Mon Sep 17 00:00:00 2001 From: Pawan Dhananjay Date: Fri, 4 Dec 2020 05:03:28 +0000 Subject: [PATCH] Add a purge-eth1-cache cli option (#2039) ## Issue Some eth1 clients are missing deposit logs on mainnet for multiple reasons (not fully synced, eth1 client issues) because of which we are getting `FailedToInsertDeposit` errors. Ideally, LH should pick up where it left off after pointing it to a nice eth1 client endpoint (which has all deposits). However, I have seen instances where LH keeps getting `FailedToInsertDeposit` even after switching to a good endpoint. Only deleting the beacon directory (which also wipes the eth1 cache) and resyncing the eth1 caches seems to be the solution. This wouldn't be great for mainnet if you have to sync your beacon node again as well. ## Proposed Changes Add a `--purge-eth1-db` option which just wipes the eth1 cache and doesn't touch the rest of the beacon db. Still need to investigate if and why LH isn't picking up where it left off for the deposit logs sync, but I think it would be good to have an option to just delete eth1 caches regardless. --- beacon_node/client/src/builder.rs | 2 ++ beacon_node/eth1/src/service.rs | 3 +++ beacon_node/src/cli.rs | 7 +++++++ beacon_node/src/config.rs | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/beacon_node/client/src/builder.rs b/beacon_node/client/src/builder.rs index cbffed970..737cd072e 100644 --- a/beacon_node/client/src/builder.rs +++ b/beacon_node/client/src/builder.rs @@ -594,6 +594,8 @@ where eth1_service_from_genesis.drop_block_cache(); CachingEth1Backend::from_service(eth1_service_from_genesis) + } else if config.purge_cache { + CachingEth1Backend::new(config, context.log().clone(), spec) } else { beacon_chain_builder .get_persisted_eth1_backend()? diff --git a/beacon_node/eth1/src/service.rs b/beacon_node/eth1/src/service.rs index 6b23a43a4..faef1cf3e 100644 --- a/beacon_node/eth1/src/service.rs +++ b/beacon_node/eth1/src/service.rs @@ -343,6 +343,8 @@ pub struct Config { pub max_log_requests_per_update: Option, /// The maximum number of log requests per update. pub max_blocks_per_update: Option, + /// If set to true, the eth1 caches are wiped clean when the eth1 service starts. + pub purge_cache: bool, } impl Config { @@ -386,6 +388,7 @@ impl Default for Config { blocks_per_log_query: 1_000, max_log_requests_per_update: Some(100), max_blocks_per_update: Some(8_192), + purge_cache: false, } } } diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index c5d2cf4c6..f89579cf8 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -281,6 +281,13 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { Defaults to http://127.0.0.1:8545.") .takes_value(true) ) + .arg( + Arg::with_name("eth1-purge-cache") + .long("eth1-purge-cache") + .value_name("PURGE-CACHE") + .help("Purges the eth1 block and deposit caches") + .takes_value(false) + ) .arg( Arg::with_name("eth1-blocks-per-log-query") .long("eth1-blocks-per-log-query") diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 926ff54cc..d70ab8e46 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -183,6 +183,10 @@ pub fn get_config( .map_err(|_| "eth1-blocks-per-log-query is not a valid integer".to_string())?; } + if cli_args.is_present("eth1-purge-cache") { + client_config.eth1.purge_cache = true; + } + if let Some(freezer_dir) = cli_args.value_of("freezer-dir") { client_config.freezer_db_path = Some(PathBuf::from(freezer_dir)); }