mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 13:24:44 +00:00
Fix issues with testnet dir, update docs (#992)
* Fix issues with testnet dir, update docs * Remove "simple testnet" docs * Tear out old "bn testnet" stuff * Add back ClientGenesis::Interop * Tidy * Remove lighthouse-bootstrap module * Fix bug with spec constant mismatch * Ensure beacon-node.toml is written to correct dir * Add -t alias for --testnet-dir * Update book/src/local-testnets.md Co-Authored-By: Age Manning <Age@AgeManning.com> * Add --purge CLI flag * Update purge docs * Perform manual delete of files in purge * Rename --purge to --purge-db * Address Michael's comments Co-authored-by: Age Manning <Age@AgeManning.com>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use beacon_chain::builder::PUBKEY_CACHE_FILENAME;
|
||||
use network::NetworkConfig;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
@@ -12,32 +11,24 @@ const TESTNET_SPEC_CONSTANTS: &str = "minimal";
|
||||
/// Default directory name for the freezer database under the top-level data dir.
|
||||
const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db";
|
||||
|
||||
/// Trap file indicating if chain_db was purged
|
||||
const CHAIN_DB_PURGED_TRAP_FILE: &str = ".db_purged";
|
||||
|
||||
/// Defines how the client should initialize the `BeaconChain` and other components.
|
||||
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ClientGenesis {
|
||||
/// Reads the genesis state and other persisted data from the `Store`.
|
||||
Resume,
|
||||
/// Creates a genesis state as per the 2019 Canada interop specifications.
|
||||
Interop {
|
||||
validator_count: usize,
|
||||
genesis_time: u64,
|
||||
},
|
||||
/// Reads the genesis state and other persisted data from the `Store`.
|
||||
FromStore,
|
||||
/// Connects to an eth1 node and waits until it can create the genesis state from the deposit
|
||||
/// contract.
|
||||
DepositContract,
|
||||
/// Loads the genesis state from a SSZ-encoded `BeaconState` file.
|
||||
SszFile { path: PathBuf },
|
||||
/// Loads the genesis state from SSZ-encoded `BeaconState` bytes.
|
||||
///
|
||||
/// We include the bytes instead of the `BeaconState<E>` because the `EthSpec` type
|
||||
/// parameter would be very annoying.
|
||||
SszBytes { genesis_state_bytes: Vec<u8> },
|
||||
/// Connects to another Lighthouse instance and reads the genesis state and other data via the
|
||||
/// HTTP API.
|
||||
RemoteNode { server: String, port: Option<u16> },
|
||||
}
|
||||
|
||||
impl Default for ClientGenesis {
|
||||
@@ -101,68 +92,6 @@ impl Config {
|
||||
.map(|data_dir| data_dir.join(&self.db_name))
|
||||
}
|
||||
|
||||
/// Get the path of the chain db purged trap file
|
||||
pub fn get_db_purged_trap_file_path(&self) -> Option<PathBuf> {
|
||||
self.get_data_dir()
|
||||
.map(|data_dir| data_dir.join(CHAIN_DB_PURGED_TRAP_FILE))
|
||||
}
|
||||
|
||||
/// returns whether chain_db was recently purged
|
||||
pub fn chain_db_was_purged(&self) -> bool {
|
||||
self.get_db_purged_trap_file_path()
|
||||
.map_or(false, |trap_file| trap_file.exists())
|
||||
}
|
||||
|
||||
/// purges the chain_db and creates trap file
|
||||
pub fn purge_chain_db(&self) -> Result<(), String> {
|
||||
// create the trap file
|
||||
let trap_file = self
|
||||
.get_db_purged_trap_file_path()
|
||||
.ok_or("Failed to get trap file path".to_string())?;
|
||||
fs::File::create(trap_file)
|
||||
.map_err(|err| format!("Failed to create trap file: {}", err))?;
|
||||
|
||||
// remove the chain_db
|
||||
fs::remove_dir_all(
|
||||
self.get_db_path()
|
||||
.ok_or("Failed to get db_path".to_string())?,
|
||||
)
|
||||
.map_err(|err| format!("Failed to remove chain_db: {}", err))?;
|
||||
|
||||
// remove the freezer db
|
||||
fs::remove_dir_all(
|
||||
self.get_freezer_db_path()
|
||||
.ok_or("Failed to get freezer db path".to_string())?,
|
||||
)
|
||||
.map_err(|err| format!("Failed to remove chain_db: {}", err))?;
|
||||
|
||||
// also need to remove pubkey cache file if it exists
|
||||
let pubkey_cache_file = self
|
||||
.get_data_dir()
|
||||
.map(|data_dir| data_dir.join(PUBKEY_CACHE_FILENAME))
|
||||
.ok_or("Failed to get pubkey cache file path".to_string())?;
|
||||
if !pubkey_cache_file.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
fs::remove_file(pubkey_cache_file)
|
||||
.map_err(|err| format!("Failed to remove pubkey cache: {}", err))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// cleans up purge_db trap file
|
||||
pub fn cleanup_after_purge_db(&self) -> Result<(), String> {
|
||||
let trap_file = self
|
||||
.get_db_purged_trap_file_path()
|
||||
.ok_or("Failed to get trap file path".to_string())?;
|
||||
if !trap_file.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
fs::remove_file(trap_file).map_err(|err| format!("Failed to remove trap file: {}", err))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the database path, creating it if necessary.
|
||||
pub fn create_db_path(&self) -> Result<PathBuf, String> {
|
||||
let db_path = self
|
||||
|
||||
Reference in New Issue
Block a user