Skip to content

Commit

Permalink
fix: Provide path to evm-state db, rather then use /tmp/evm-state.
Browse files Browse the repository at this point in the history
  • Loading branch information
vldm committed Jan 10, 2021
1 parent e410707 commit 2c12185
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 14 deletions.
4 changes: 4 additions & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,13 @@ fn new_banks_from_ledger(
TransactionHistoryServices::default()
};

// TODO: Add evm-state to config.
let evm_state_path = ledger_path.join("evm-state");

let (mut bank_forks, mut leader_schedule_cache, snapshot_hash) = bank_forks_utils::load(
&genesis_config,
&blockstore,
evm_state_path,
config.account_paths.clone(),
config.snapshot_config.as_ref(),
process_options,
Expand Down
14 changes: 13 additions & 1 deletion core/tests/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod tests {
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, MainnetBeta, V1_2_0_MainnetBeta);

struct SnapshotTestConfig {
evm_state_dir: TempDir,
accounts_dir: TempDir,
snapshot_dir: TempDir,
_snapshot_output_path: TempDir,
Expand All @@ -79,6 +80,7 @@ mod tests {
cluster_type: ClusterType,
snapshot_interval_slots: u64,
) -> SnapshotTestConfig {
let evm_state_dir = TempDir::new().unwrap();
let accounts_dir = TempDir::new().unwrap();
let snapshot_dir = TempDir::new().unwrap();
let snapshot_output_path = TempDir::new().unwrap();
Expand All @@ -102,6 +104,7 @@ mod tests {
};
bank_forks.set_snapshot_config(Some(snapshot_config.clone()));
SnapshotTestConfig {
evm_state_dir,
accounts_dir,
snapshot_dir,
_snapshot_output_path: snapshot_output_path,
Expand All @@ -116,6 +119,7 @@ mod tests {
old_bank_forks: &BankForks,
old_last_slot: Slot,
old_genesis_config: &GenesisConfig,
evm_state_path: &Path,
account_paths: &[PathBuf],
) {
let (snapshot_path, snapshot_package_output_path) = old_bank_forks
Expand All @@ -127,6 +131,7 @@ mod tests {
let old_last_bank = old_bank_forks.get(old_last_slot).unwrap();

let deserialized_bank = snapshot_utils::bank_from_archive(
evm_state_path,
&account_paths,
&[],
&old_bank_forks
Expand Down Expand Up @@ -213,9 +218,16 @@ mod tests {
snapshot_utils::archive_snapshot_package(&snapshot_package).unwrap();

// Restore bank from snapshot
let evm_state_path = snapshot_test_config.evm_state_dir.path();
let account_paths = &[snapshot_test_config.accounts_dir.path().to_path_buf()];
let genesis_config = &snapshot_test_config.genesis_config_info.genesis_config;
restore_from_snapshot(bank_forks, last_slot, genesis_config, account_paths);
restore_from_snapshot(
evm_state_path,
bank_forks,
last_slot,
genesis_config,
account_paths,
);
}

fn run_test_bank_forks_snapshot_n(
Expand Down
7 changes: 6 additions & 1 deletion evm-utils/evm-state/src/layered_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub struct EvmState {
impl Default for EvmState {
fn default() -> Self {
let path = std::env::temp_dir().join("evm-state");
Self::load_from(path, Slot::default()).expect("Unable to instantiate default EVM state")
Self::new(path).expect("Unable to instantiate default EVM state")
}
}

Expand Down Expand Up @@ -260,6 +260,11 @@ impl EvmState {
}

impl EvmState {
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, anyhow::Error> {
//TODO: add flags, to asserts for empty storage.
Self::load_from(path, 0)
}

pub fn load_from<P: AsRef<Path>>(path: P, slot: Slot) -> Result<Self, anyhow::Error> {
info!(
"open evm state storage {} for slot {}",
Expand Down
3 changes: 3 additions & 0 deletions evm-utils/evm-state/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ where
self.db.put(key, value)?;
}
Some(data) => {
warn!("Found confict previous: previous = {:?}, version = {:?}, previous_in_db = {:?}", previous,
version,
CODER.deserialize::<Previous<V>>(&data).typed_ctx() );
// TODO: assert or do some check
// assert_eq!(
// previous,
Expand Down
3 changes: 3 additions & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,12 @@ fn load_bank_forks(
vec![non_primary_accounts_path]
};

let evm_state_path = ledger_path.join("evm-state");

bank_forks_utils::load(
&genesis_config,
&blockstore,
evm_state_path,
account_paths,
snapshot_config.as_ref(),
process_options,
Expand Down
3 changes: 3 additions & 0 deletions ledger/src/bank_forks_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn to_loadresult(
pub fn load(
genesis_config: &GenesisConfig,
blockstore: &Blockstore,
evm_state_path: PathBuf,
account_paths: Vec<PathBuf>,
snapshot_config: Option<&SnapshotConfig>,
process_options: ProcessOptions,
Expand Down Expand Up @@ -59,6 +60,7 @@ pub fn load(
}

let deserialized_bank = snapshot_utils::bank_from_archive(
&evm_state_path,
&account_paths,
&process_options.frozen_accounts,
&snapshot_config.snapshot_path,
Expand Down Expand Up @@ -104,6 +106,7 @@ pub fn load(
blockstore_processor::process_blockstore(
&genesis_config,
&blockstore,
&evm_state_path,
account_paths,
process_options,
),
Expand Down
4 changes: 3 additions & 1 deletion ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use solana_vote_program::vote_state::VoteState;
use std::{
cell::RefCell,
collections::{BTreeMap, HashMap},
path::PathBuf,
path::{Path, PathBuf},
result,
sync::Arc,
time::{Duration, Instant},
Expand Down Expand Up @@ -320,6 +320,7 @@ fn initiate_callback(mut bank: &mut Arc<Bank>, genesis_config: &GenesisConfig) {
pub fn process_blockstore(
genesis_config: &GenesisConfig,
blockstore: &Blockstore,
evm_state_path: &Path,
account_paths: Vec<PathBuf>,
opts: ProcessOptions,
) -> BlockstoreProcessorResult {
Expand All @@ -335,6 +336,7 @@ pub fn process_blockstore(
// Setup bank for slot 0
let mut bank0 = Arc::new(Bank::new_with_paths(
&genesis_config,
Some(evm_state_path),
account_paths,
&opts.frozen_accounts,
));
Expand Down
15 changes: 7 additions & 8 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use std::{
convert::TryFrom,
mem,
ops::RangeInclusive,
path::PathBuf,
path::{Path, PathBuf},
ptr,
rc::Rc,
sync::atomic::{AtomicBool, AtomicU64, Ordering},
Expand Down Expand Up @@ -96,9 +96,6 @@ pub mod inline_spl_token_v2_0 {
}
}

// TODO: get real path from extern configuration
pub const EVM_STATE_STORAGE: &str = "/tmp/solana/evm-state";

pub const SECONDS_PER_YEAR: f64 = 365.25 * 24.0 * 60.0 * 60.0;

pub const MAX_LEADER_SCHEDULE_STAKES: Epoch = 5;
Expand Down Expand Up @@ -473,11 +470,12 @@ impl Default for BlockhashQueue {

impl Bank {
pub fn new(genesis_config: &GenesisConfig) -> Self {
Self::new_with_paths(&genesis_config, Vec::new(), &[])
Self::new_with_paths(&genesis_config, None, Vec::new(), &[])
}

pub fn new_with_paths(
genesis_config: &GenesisConfig,
evm_state_path: Option<&Path>, // TODO: Remove option, currently need for Bank::new, that is used for tests
paths: Vec<PathBuf>,
frozen_account_pubkeys: &[Pubkey],
) -> Self {
Expand All @@ -486,6 +484,9 @@ impl Bank {
bank.ancestors.insert(bank.slot(), 0);

bank.rc.accounts = Arc::new(Accounts::new(paths, &genesis_config.cluster_type));
if let Some(evm_state_path) = evm_state_path {
bank.evm_state = RwLock::new(evm_state::EvmState::new(evm_state_path).unwrap());
}
bank.process_genesis_config(genesis_config);
bank.finish_init(genesis_config);

Expand Down Expand Up @@ -640,6 +641,7 @@ impl Bank {
/// Create a bank from explicit arguments and deserialized fields from snapshot
#[allow(clippy::float_cmp)]
pub(crate) fn new_from_fields(
evm_state: evm_state::EvmState,
bank_rc: BankRc,
genesis_config: &GenesisConfig,
fields: BankFieldsToDeserialize,
Expand All @@ -648,9 +650,6 @@ impl Bank {
T::default()
}

let evm_state = evm_state::EvmState::load_from(EVM_STATE_STORAGE, fields.slot)
.expect("Unable to open EVM state storage");

let mut bank = Self {
rc: bank_rc,
src: new(),
Expand Down
7 changes: 6 additions & 1 deletion runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub(crate) fn bank_from_stream<R, P>(
serde_style: SerdeStyle,
stream: &mut BufReader<R>,
append_vecs_path: P,
evm_state_path: &Path,
account_paths: &[PathBuf],
genesis_config: &GenesisConfig,
frozen_account_pubkeys: &[Pubkey],
Expand All @@ -138,6 +139,7 @@ where
accounts_db_fields,
genesis_config,
frozen_account_pubkeys,
evm_state_path,
account_paths,
append_vecs_path,
)?;
Expand Down Expand Up @@ -222,6 +224,7 @@ fn reconstruct_bank_from_fields<E, P>(
accounts_db_fields: AccountsDbFields<E>,
genesis_config: &GenesisConfig,
frozen_account_pubkeys: &[Pubkey],
evm_state_path: &Path,
account_paths: &[PathBuf],
append_vecs_path: P,
) -> Result<Bank, Error>
Expand All @@ -238,7 +241,9 @@ where
accounts_db.freeze_accounts(&bank_fields.ancestors, frozen_account_pubkeys);

let bank_rc = BankRc::new(Accounts::new_empty(accounts_db), bank_fields.slot);
let bank = Bank::new_from_fields(bank_rc, genesis_config, bank_fields);
let evm_state = evm_state::EvmState::load_from(evm_state_path, bank_fields.slot)
.expect("Unable to open EVM state storage");
let bank = Bank::new_from_fields(evm_state, bank_rc, genesis_config, bank_fields);

Ok(bank)
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
let rdr = Cursor::new(&buf[..]);
let mut reader = std::io::BufReader::new(&buf[rdr.position() as usize..]);

let evm_state_dir = TempDir::new().unwrap();
// Create a new set of directories for this bank's accounts
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
let ref_sc = StatusCacheRc::default();
Expand All @@ -208,6 +209,7 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
serde_style,
&mut reader,
copied_accounts.path(),
&evm_state_dir.path(),
&dbank_paths,
&genesis_config,
&[],
Expand Down
8 changes: 6 additions & 2 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
bank::{Bank, BankSlotDelta, EVM_STATE_STORAGE},
bank::{Bank, BankSlotDelta},
bank_forks::CompressionType,
hardened_unpack::{unpack_snapshot, UnpackError},
serde_snapshot::{
Expand Down Expand Up @@ -599,6 +599,7 @@ pub fn remove_snapshot<P: AsRef<Path>>(slot: Slot, snapshot_path: P) -> Result<(
}

pub fn bank_from_archive<P: AsRef<Path>>(
evm_state_path: &Path,
account_paths: &[PathBuf],
frozen_account_pubkeys: &[Pubkey],
snapshot_path: &PathBuf,
Expand All @@ -620,6 +621,7 @@ pub fn bank_from_archive<P: AsRef<Path>>(

let bank = rebuild_bank_from_snapshots(
snapshot_version.trim(),
evm_state_path,
account_paths,
frozen_account_pubkeys,
&unpacked_snapshots_dir,
Expand Down Expand Up @@ -777,6 +779,7 @@ pub fn untar_snapshot_in<P: AsRef<Path>, Q: AsRef<Path>>(

fn rebuild_bank_from_snapshots<P>(
snapshot_version: &str,
evm_state_path: &Path,
account_paths: &[PathBuf],
frozen_account_pubkeys: &[Pubkey],
unpacked_snapshots_dir: &PathBuf,
Expand Down Expand Up @@ -808,7 +811,7 @@ where
root_paths.evm_state_backup_path
);
let mut measure = Measure::start("evm state database restore");
evm_state::Storage::restore_from(root_paths.evm_state_backup_path, EVM_STATE_STORAGE)
evm_state::Storage::restore_from(root_paths.evm_state_backup_path, evm_state_path)
.expect("Unable to restore EVM state underlying database from storage backup");
measure.stop();
info!("{}", measure);
Expand All @@ -820,6 +823,7 @@ where
SerdeStyle::NEWER,
&mut stream,
&append_vecs_path,
evm_state_path,
account_paths,
genesis_config,
frozen_account_pubkeys,
Expand Down

0 comments on commit 2c12185

Please sign in to comment.