Skip to content

Commit

Permalink
chore: Pass correct GenesisValidationMode to neard commands. # (#12052)
Browse files Browse the repository at this point in the history
Address the issue #9080.
The cmd parameter 'unsafe_fast_startup' has not always been passed. 
The PR adds the ability to use the 'unsafe_fast_startup' for some cmd
tools.
The changes have been made only there the 'unsafe_fast_startup' has
already been introduced.
For other places, it's better to create separate PRs.
  • Loading branch information
volodymyrd authored Sep 9, 2024
1 parent 1bb7fc5 commit 0eba28a
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 55 deletions.
16 changes: 10 additions & 6 deletions neard/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl NeardCmd {
cmd.run()?;
}
NeardSubCommand::ColdStore(cmd) => {
cmd.run(&home_dir)?;
cmd.run(&home_dir, genesis_validation)?;
}
NeardSubCommand::StateParts(cmd) => {
cmd.run()?;
Expand All @@ -123,13 +123,13 @@ impl NeardCmd {
cmd.run(&home_dir, genesis_validation)?;
}
NeardSubCommand::ValidateConfig(cmd) => {
cmd.run(&home_dir)?;
cmd.run(&home_dir, genesis_validation)?;
}
NeardSubCommand::UndoBlock(cmd) => {
cmd.run(&home_dir, genesis_validation)?;
}
NeardSubCommand::Database(cmd) => {
cmd.run(&home_dir)?;
cmd.run(&home_dir, genesis_validation)?;
}
NeardSubCommand::ForkNetwork(cmd) => {
cmd.run(
Expand All @@ -143,7 +143,7 @@ impl NeardCmd {
cmd.run()?;
}
NeardSubCommand::ReplayArchive(cmd) => {
cmd.run(&home_dir)?;
cmd.run(&home_dir, genesis_validation)?;
}
};
Ok(())
Expand Down Expand Up @@ -768,8 +768,12 @@ fn make_env_filter(verbose: Option<&str>) -> Result<EnvFilter, BuildEnvFilterErr
pub(super) struct ValidateConfigCommand {}

impl ValidateConfigCommand {
pub(super) fn run(&self, home_dir: &Path) -> anyhow::Result<()> {
nearcore::config::load_config(home_dir, GenesisValidationMode::Full)?;
pub(super) fn run(
&self,
home_dir: &Path,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
nearcore::config::load_config(home_dir, genesis_validation)?;
Ok(())
}
}
Expand Down
14 changes: 8 additions & 6 deletions tools/cold-store/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anyhow;
use anyhow::Context;
use borsh::BorshDeserialize;
use clap;
use near_chain_configs::GenesisValidationMode;
use near_epoch_manager::{EpochManager, EpochManagerAdapter, EpochManagerHandle};
use near_primitives::block::Tip;
use near_primitives::epoch_block_info::BlockInfo;
Expand Down Expand Up @@ -59,14 +60,15 @@ enum SubCommand {
}

impl ColdStoreCommand {
pub fn run(self, home_dir: &Path) -> anyhow::Result<()> {
pub fn run(
self,
home_dir: &Path,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
let mode =
if self.readwrite { near_store::Mode::ReadWrite } else { near_store::Mode::ReadOnly };
let mut near_config = nearcore::config::load_config(
&home_dir,
near_chain_configs::GenesisValidationMode::Full,
)
.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));
let mut near_config = nearcore::config::load_config(&home_dir, genesis_validation)
.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));

let opener = self.get_opener(home_dir, &mut near_config);

Expand Down
12 changes: 7 additions & 5 deletions tools/database/src/adjust_database.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use near_chain_configs::GenesisValidationMode;
use near_store::metadata::DbKind;
use near_store::NodeStorage;
use std::path::Path;
Expand All @@ -24,11 +25,12 @@ pub(crate) struct ChangeDbKindCommand {
}

impl ChangeDbKindCommand {
pub(crate) fn run(&self, home_dir: &Path) -> anyhow::Result<()> {
let near_config = nearcore::config::load_config(
&home_dir,
near_chain_configs::GenesisValidationMode::UnsafeFast,
)?;
pub(crate) fn run(
&self,
home_dir: &Path,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
let near_config = nearcore::config::load_config(&home_dir, genesis_validation)?;
let opener = NodeStorage::opener(
home_dir,
near_config.config.archive,
Expand Down
8 changes: 6 additions & 2 deletions tools/database/src/analyse_gas_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ pub(crate) struct AnalyseGasUsageCommand {
}

impl AnalyseGasUsageCommand {
pub(crate) fn run(&self, home: &PathBuf) -> anyhow::Result<()> {
pub(crate) fn run(
&self,
home: &PathBuf,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
// Create a ChainStore and EpochManager that will be used to read blockchain data.
let mut near_config = load_config(home, GenesisValidationMode::Full).unwrap();
let mut near_config = load_config(home, genesis_validation).unwrap();
let node_storage = open_storage(&home, &mut near_config).unwrap();
let store = node_storage.get_split_store().unwrap_or_else(|| node_storage.get_hot_store());
let chain_store = Rc::new(ChainStore::new(
Expand Down
8 changes: 6 additions & 2 deletions tools/database/src/analyze_contract_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ impl ContractSizeStats {
}

impl AnalyzeContractSizesCommand {
pub(crate) fn run(&self, home: &PathBuf) -> anyhow::Result<()> {
let mut near_config = load_config(home, GenesisValidationMode::Full).unwrap();
pub(crate) fn run(
&self,
home: &PathBuf,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
let mut near_config = load_config(home, genesis_validation).unwrap();
let node_storage = open_storage(&home, &mut near_config).unwrap();
let store = node_storage.get_split_store().unwrap_or_else(|| node_storage.get_hot_store());
let chain_store = Rc::new(ChainStore::new(
Expand Down
8 changes: 6 additions & 2 deletions tools/database/src/analyze_delayed_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ pub(crate) struct AnalyzeDelayedReceiptCommand {
}

impl AnalyzeDelayedReceiptCommand {
pub(crate) fn run(&self, home: &PathBuf) -> anyhow::Result<()> {
let mut near_config = load_config(home, GenesisValidationMode::Full).unwrap();
pub(crate) fn run(
&self,
home: &PathBuf,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
let mut near_config = load_config(home, genesis_validation).unwrap();
let node_storage = open_storage(&home, &mut near_config).unwrap();
let store = node_storage.get_split_store().unwrap_or_else(|| node_storage.get_hot_store());
let chain_store = Rc::new(ChainStore::new(
Expand Down
28 changes: 16 additions & 12 deletions tools/database/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::run_migrations::RunMigrationsCommand;
use crate::state_perf::StatePerfCommand;
use crate::write_to_db::WriteCryptoHashCommand;
use clap::Parser;
use near_chain_configs::GenesisValidationMode;
use std::path::PathBuf;

#[derive(Parser)]
Expand Down Expand Up @@ -66,34 +67,37 @@ enum SubCommand {
}

impl DatabaseCommand {
pub fn run(&self, home: &PathBuf) -> anyhow::Result<()> {
pub fn run(
&self,
home: &PathBuf,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
match &self.subcmd {
SubCommand::AnalyseDataSizeDistribution(cmd) => cmd.run(home),
SubCommand::AnalyseGasUsage(cmd) => cmd.run(home),
SubCommand::ChangeDbKind(cmd) => cmd.run(home),
SubCommand::AnalyseGasUsage(cmd) => cmd.run(home, genesis_validation),
SubCommand::ChangeDbKind(cmd) => cmd.run(home, genesis_validation),
SubCommand::CompactDatabase(cmd) => cmd.run(home),
SubCommand::CorruptStateSnapshot(cmd) => cmd.run(home),
SubCommand::MakeSnapshot(cmd) => {
let near_config = load_config(home);
let near_config = load_config(home, genesis_validation);
cmd.run(home, near_config.config.archive, &near_config.config.store)
}
SubCommand::RunMigrations(cmd) => cmd.run(home),
SubCommand::RunMigrations(cmd) => cmd.run(home, genesis_validation),
SubCommand::StatePerf(cmd) => cmd.run(home),
SubCommand::LoadMemTrie(cmd) => cmd.run(home),
SubCommand::WriteCryptoHash(cmd) => cmd.run(home),
SubCommand::LoadMemTrie(cmd) => cmd.run(home, genesis_validation),
SubCommand::WriteCryptoHash(cmd) => cmd.run(home, genesis_validation),
SubCommand::HighLoadStats(cmd) => cmd.run(home),
SubCommand::AnalyzeDelayedReceipt(cmd) => cmd.run(home),
SubCommand::AnalyzeContractSizes(cmd) => cmd.run(home),
SubCommand::AnalyzeDelayedReceipt(cmd) => cmd.run(home, genesis_validation),
SubCommand::AnalyzeContractSizes(cmd) => cmd.run(home, genesis_validation),
SubCommand::Resharding(cmd) => {
let near_config = load_config(home);
let near_config = load_config(home, genesis_validation);
cmd.run(near_config, home)
}
}
}
}

fn load_config(home: &PathBuf) -> nearcore::NearConfig {
let genesis_validation = near_chain_configs::GenesisValidationMode::UnsafeFast;
fn load_config(home: &PathBuf, genesis_validation: GenesisValidationMode) -> nearcore::NearConfig {
let near_config = nearcore::config::load_config(&home, genesis_validation);
let near_config = near_config.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));
near_config
Expand Down
14 changes: 8 additions & 6 deletions tools/database/src/memtrie.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::open_rocksdb;
use anyhow::Context;
use near_chain::types::RuntimeAdapter;
use near_chain_configs::GenesisValidationMode;
use near_epoch_manager::{EpochManager, EpochManagerAdapter};
use near_o11y::default_subscriber;
use near_o11y::env_filter::EnvFilterBuilder;
Expand All @@ -24,14 +25,15 @@ pub struct LoadMemTrieCommand {
}

impl LoadMemTrieCommand {
pub fn run(&self, home: &Path) -> anyhow::Result<()> {
pub fn run(
&self,
home: &Path,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
let env_filter = EnvFilterBuilder::from_env().verbose(Some("memtrie")).finish()?;
let _subscriber = default_subscriber(env_filter, &Default::default()).global();
let mut near_config = nearcore::config::load_config(
&home,
near_chain_configs::GenesisValidationMode::UnsafeFast,
)
.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));
let mut near_config = nearcore::config::load_config(&home, genesis_validation)
.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));
near_config.config.store.load_mem_tries_for_tracked_shards = true;

let rocksdb = Arc::new(open_rocksdb(home, near_store::Mode::ReadOnly)?);
Expand Down
14 changes: 8 additions & 6 deletions tools/database/src/run_migrations.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use near_chain_configs::GenesisValidationMode;
use std::path::Path;

#[derive(clap::Args)]
pub(crate) struct RunMigrationsCommand {}

impl RunMigrationsCommand {
pub(crate) fn run(&self, home_dir: &Path) -> anyhow::Result<()> {
let mut near_config = nearcore::config::load_config(
&home_dir,
near_chain_configs::GenesisValidationMode::UnsafeFast,
)
.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));
pub(crate) fn run(
&self,
home_dir: &Path,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
let mut near_config = nearcore::config::load_config(&home_dir, genesis_validation)
.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));
nearcore::open_storage(home_dir, &mut near_config)?;
Ok(())
}
Expand Down
12 changes: 7 additions & 5 deletions tools/database/src/write_to_db.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use near_chain_configs::GenesisValidationMode;
use near_store::{DBCol, NodeStorage};
use std::path::Path;

Expand All @@ -23,11 +24,12 @@ pub(crate) struct WriteCryptoHashCommand {
}

impl WriteCryptoHashCommand {
pub(crate) fn run(&self, home_dir: &Path) -> anyhow::Result<()> {
let near_config = nearcore::config::load_config(
&home_dir,
near_chain_configs::GenesisValidationMode::UnsafeFast,
)?;
pub(crate) fn run(
&self,
home_dir: &Path,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<()> {
let near_config = nearcore::config::load_config(&home_dir, genesis_validation)?;
let opener = NodeStorage::opener(
home_dir,
near_config.config.archive,
Expand Down
6 changes: 3 additions & 3 deletions tools/replay-archive/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub struct ReplayArchiveCommand {
}

impl ReplayArchiveCommand {
pub fn run(self, home_dir: &Path) -> Result<()> {
let near_config = load_config(home_dir, GenesisValidationMode::Full)
pub fn run(self, home_dir: &Path, genesis_validation: GenesisValidationMode) -> Result<()> {
let near_config = load_config(home_dir, genesis_validation)
.unwrap_or_else(|e| panic!("Error loading config: {:#}", e));

if !near_config.config.archive {
Expand Down Expand Up @@ -500,7 +500,7 @@ impl ReplayController {

/// Saves the ChunkExtras for the shards in the genesis block.
/// Note that there is no chunks in the genesis block, so we directly generate the ChunkExtras
/// from the information in the genesis block without applying any transactions or receipts.
/// from the information in the genesis block without applying any transactions or receipts.
fn save_genesis_chunk_extras(&mut self, genesis_block: &Block) -> Result<()> {
let chain_genesis = ChainGenesis::new(&self.near_config.genesis.config);
let state_roots = get_genesis_state_roots(self.chain_store.store())?
Expand Down

0 comments on commit 0eba28a

Please sign in to comment.