Skip to content

Commit

Permalink
Feat(evm-archive): Add possibility to save current state into archive…
Browse files Browse the repository at this point in the history
… at startup.
  • Loading branch information
vldm committed Dec 13, 2021
1 parent e21f0da commit 894ef34
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ fn new_banks_from_ledger(
blockstore.clone(),
exit,
config.rpc_config.enable_cpi_and_log_storage,
evm_archive,
evm_archive.clone(),
)
} else {
TransactionHistoryServices::default()
Expand All @@ -1188,6 +1188,7 @@ fn new_banks_from_ledger(
.cache_block_meta_sender
.as_ref(),
config.verify_evm_state,
evm_archive,
)
.unwrap_or_else(|err| {
error!("Failed to load ledger: {:?}", err);
Expand Down
1 change: 1 addition & 0 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ mod tests {
AccountSecondaryIndexes::default(),
false,
false,
None,
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ fn load_bank_forks(
None,
None,
verify_evm_state,
None,
)
}

Expand Down
2 changes: 2 additions & 0 deletions ledger/src/bank_forks_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub fn load(
transaction_status_sender: Option<&TransactionStatusSender>,
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
verify_evm_state: bool,
evm_archive: Option<evm_state::Storage>,
) -> LoadResult {
if let Some(snapshot_config) = snapshot_config.as_ref() {
info!(
Expand Down Expand Up @@ -77,6 +78,7 @@ pub fn load(
process_options.account_indexes.clone(),
process_options.accounts_db_caching_enabled,
verify_evm_state,
evm_archive,
)
.expect("Load from snapshot failed");
if let Some(shrink_paths) = shrink_paths {
Expand Down
29 changes: 28 additions & 1 deletion runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub(crate) fn bank_from_stream<R>(
caching_enabled: bool,
evm_state_backup_path: &Path,
skip_purge_verify: bool,
evm_archive: Option<evm_state::Storage>,
) -> std::result::Result<Bank, Error>
where
R: Read,
Expand All @@ -167,6 +168,7 @@ where
evm_state_version.support_gc(),
skip_purge_verify,
true, // enable gc
evm_archive,
)
.map_err(|err| {
warn!("bankrc_from_stream error: {:?}", err);
Expand Down Expand Up @@ -257,6 +259,7 @@ fn reconstruct_bank_from_fields<E>(
skip_purge_verify: bool,
// true if gc should be enabled
enable_gc: bool,
evm_archive: Option<evm_state::Storage>,
) -> Result<Bank, Error>
where
E: SerializableStorage,
Expand Down Expand Up @@ -309,9 +312,20 @@ where
.map_err(|e| Error::custom(format!("Unable to open destination evm-state {}", e)))?;

let mut measure = Measure::start("EVM snapshot purging");

// vars to save temp arrays for copy_and_purge
let (archive_dest, regular_dest);
let destination: &[_] = if let Some(evm_archive) = evm_archive {
info!("Copying current evm state to archive during evm purging.");
archive_dest = [destination, evm_archive];
&archive_dest
} else {
regular_dest = [destination];
&regular_dest
};
evm_state::storage::copy_and_purge(
src,
&[destination], // TODO: Add archive storage
&destination,
bank_fields.evm_persist_feilds.last_root(),
)
.map_err(|e| Error::custom(format!("Unable to copy_and_purge storage {}", e)))?;
Expand All @@ -323,6 +337,19 @@ where
.map_err(|e| Error::custom(format!("Unable to restore evm backup storage {}", e)))?;
measure.stop();
info!("{}", measure);
if let Some(evm_archive) = evm_archive {
info!("Copying current evm state to archive.");
let src =
evm_state::Storage::open_persistent(evm_state_path, enable_gc).map_err(|e| {
Error::custom(format!("Unable to restore tmp evm backup storage {}", e))
})?;
evm_state::storage::copy_and_purge(
src,
&[evm_archive],
bank_fields.evm_persist_feilds.last_root(),
)
.map_err(|e| Error::custom(format!("Unable to copy_and_purge storage {}", e)))?;
};
}

let evm_state = evm_state::EvmState::load_from(
Expand Down
1 change: 1 addition & 0 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ fn test_bank_serialize_style(evm_version: EvmStateVersion) {
false,
evm_backup_state_path.path(),
true,
None,
)
.unwrap();
dbank.src = ref_sc;
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ pub fn bank_from_archive<P: AsRef<Path>>(
account_indexes: AccountSecondaryIndexes,
accounts_db_caching_enabled: bool,
verify_evm_state: bool,
evm_archive: Option<evm_state::Storage>,
) -> Result<Bank> {
// Untar the snapshot into a temporary directory
let unpack_dir = tempfile::Builder::new()
Expand Down Expand Up @@ -672,6 +673,7 @@ pub fn bank_from_archive<P: AsRef<Path>>(
account_indexes,
accounts_db_caching_enabled,
verify_evm_state,
evm_archive,
)?;

if !bank.verify_snapshot_bank() {
Expand Down Expand Up @@ -823,6 +825,7 @@ fn rebuild_bank_from_snapshots(
account_indexes: AccountSecondaryIndexes,
accounts_db_caching_enabled: bool,
verify_evm_state: bool,
evm_archive: Option<evm_state::Storage>,
) -> Result<Bank> {
info!("snapshot version: {}", snapshot_version);

Expand Down Expand Up @@ -864,6 +867,7 @@ fn rebuild_bank_from_snapshots(
accounts_db_caching_enabled,
&root_paths.evm_state_backup_path,
!verify_evm_state,
evm_archive,
)?)
})?;

Expand Down

0 comments on commit 894ef34

Please sign in to comment.