From 74c58c455c444250b9d0e932ac9852d9ea76c7a6 Mon Sep 17 00:00:00 2001 From: Kristofer Peterson Date: Mon, 11 May 2020 20:34:43 +0100 Subject: [PATCH] rustfmt --- core/src/accounts_hash_verifier.rs | 4 +- core/src/rpc_service.rs | 4 +- core/src/snapshot_packager_service.rs | 8 +- core/tests/bank_forks.rs | 24 +- ledger-tool/src/main.rs | 26 +- ledger/src/bank_forks.rs | 9 +- ledger/src/snapshot_package.rs | 4 +- ledger/src/snapshot_utils.rs | 245 ++++++------ local-cluster/tests/local_cluster.rs | 2 +- runtime/src/accounts.rs | 11 +- runtime/src/accounts_db.rs | 50 +-- runtime/src/bank.rs | 11 +- runtime/src/serde_utils.rs | 555 +++++++++++--------------- validator/src/main.rs | 10 +- 14 files changed, 433 insertions(+), 530 deletions(-) diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index 8c0b58a535a2a7..6f01177aa0816c 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -177,11 +177,11 @@ mod tests { use crate::cluster_info::make_accounts_hashes_message; use crate::contact_info::ContactInfo; use solana_ledger::bank_forks::CompressionType; + use solana_ledger::snapshot_utils::SnapshotVersion; use solana_sdk::{ hash::hash, signature::{Keypair, Signer}, }; - use solana_ledger::snapshot_utils::SnapshotVersion; #[test] fn test_should_halt() { @@ -240,7 +240,7 @@ mod tests { tar_output_file: PathBuf::from("."), storages: vec![], compression: CompressionType::Bzip2, - snapshot_version: SnapshotVersion::default(), + snapshot_version: SnapshotVersion::default(), }; AccountsHashVerifier::process_accounts_package( diff --git a/core/src/rpc_service.rs b/core/src/rpc_service.rs index e0fee7ce807c2c..abc5971215c3a6 100644 --- a/core/src/rpc_service.rs +++ b/core/src/rpc_service.rs @@ -356,7 +356,7 @@ mod tests { bank_forks::CompressionType, genesis_utils::{create_genesis_config, GenesisConfigInfo}, get_tmp_ledger_path, - snapshot_utils::SnapshotVersion, + snapshot_utils::SnapshotVersion, }; use solana_runtime::bank::Bank; use solana_sdk::signature::Signer; @@ -428,7 +428,7 @@ mod tests { snapshot_package_output_path: PathBuf::from("/"), snapshot_path: PathBuf::from("/"), compression: CompressionType::Bzip2, - snapshot_version: SnapshotVersion::default(), + snapshot_version: SnapshotVersion::default(), }), cluster_info, None, diff --git a/core/src/snapshot_packager_service.rs b/core/src/snapshot_packager_service.rs index 85e81d42698b60..4bd6595c390122 100644 --- a/core/src/snapshot_packager_service.rs +++ b/core/src/snapshot_packager_service.rs @@ -81,11 +81,9 @@ mod tests { use solana_ledger::bank_forks::CompressionType; use solana_ledger::{ snapshot_package::AccountsPackage, - snapshot_utils::{self, SNAPSHOT_STATUS_CACHE_FILE_NAME, SnapshotVersion}, - }; - use solana_runtime::{ - accounts_db::AccountStorageEntry, bank::BankSlotDelta, + snapshot_utils::{self, SnapshotVersion, SNAPSHOT_STATUS_CACHE_FILE_NAME}, }; + use solana_runtime::{accounts_db::AccountStorageEntry, bank::BankSlotDelta}; use solana_sdk::hash::Hash; use std::{ fs::{self, remove_dir_all, OpenOptions}, @@ -175,7 +173,7 @@ mod tests { output_tar_path.clone(), Hash::default(), CompressionType::Bzip2, - SnapshotVersion::default(), + SnapshotVersion::default(), ); // Make tarball from packageable snapshot diff --git a/core/tests/bank_forks.rs b/core/tests/bank_forks.rs index 750196457d208a..6f7548bc902a17 100644 --- a/core/tests/bank_forks.rs +++ b/core/tests/bank_forks.rs @@ -57,7 +57,7 @@ mod tests { snapshot_package_output_path: PathBuf::from(snapshot_output_path.path()), snapshot_path: PathBuf::from(snapshot_dir.path()), compression: CompressionType::Bzip2, - snapshot_version: snapshot_utils::SnapshotVersion::default(), + snapshot_version: snapshot_utils::SnapshotVersion::default(), }; bank_forks.set_snapshot_config(Some(snapshot_config.clone())); SnapshotTestConfig { @@ -131,7 +131,11 @@ mod tests { let accounts_dir = &snapshot_test_config.accounts_dir; let snapshot_config = &snapshot_test_config.snapshot_config; let mint_keypair = &snapshot_test_config.genesis_config_info.mint_keypair; - let snapshot_version = bank_forks.snapshot_config.as_ref().unwrap().snapshot_version; + let snapshot_version = bank_forks + .snapshot_config + .as_ref() + .unwrap() + .snapshot_version; let (s, _r) = channel(); let sender = Some(s); @@ -161,7 +165,7 @@ mod tests { &snapshot_config.snapshot_package_output_path, storages, CompressionType::Bzip2, - snapshot_version, + snapshot_version, ) .unwrap(); @@ -222,12 +226,22 @@ mod tests { let snapshot_config = &snapshot_test_config.snapshot_config; let mint_keypair = &snapshot_test_config.genesis_config_info.mint_keypair; let genesis_config = &snapshot_test_config.genesis_config_info.genesis_config; - let snapshot_version = bank_forks.snapshot_config.as_ref().unwrap().snapshot_version; + let snapshot_version = bank_forks + .snapshot_config + .as_ref() + .unwrap() + .snapshot_version; // Take snapshot of zeroth bank let bank0 = bank_forks.get(0).unwrap(); let storages: Vec<_> = bank0.get_snapshot_storages(); - snapshot_utils::add_snapshot(&snapshot_config.snapshot_path, bank0, &storages, snapshot_version).unwrap(); + snapshot_utils::add_snapshot( + &snapshot_config.snapshot_path, + bank0, + &storages, + snapshot_version, + ) + .unwrap(); // Set up snapshotting channels let (sender, receiver) = channel(); diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index bd0334692015b9..8dfc7da206ca00 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -561,7 +561,7 @@ fn load_bank_forks( snapshot_package_output_path: ledger_path.clone(), snapshot_path: ledger_path.clone().join("snapshot"), compression: CompressionType::Bzip2, - snapshot_version: snapshot_utils::SnapshotVersion::default(), + snapshot_version: snapshot_utils::SnapshotVersion::default(), }) }; let account_paths = if let Some(account_paths) = arg_matches.value_of("account_paths") { @@ -632,9 +632,11 @@ fn main() { let snapshot_version_arg = Arg::with_name("snapshot_version") .long("snapshot-version") .value_name("VERSION") - .validator(|arg| arg.parse::() - .map(|_| ()) - .map_err(|e| e.to_string())) + .validator(|arg| { + arg.parse::() + .map(|_| ()) + .map_err(|e| e.to_string()) + }) .multiple(false) .required(false) .takes_value(true) @@ -1026,11 +1028,15 @@ fn main() { ("create-snapshot", Some(arg_matches)) => { let snapshot_slot = value_t_or_exit!(arg_matches, "snapshot_slot", Slot); let output_directory = value_t_or_exit!(arg_matches, "output_directory", String); - let snapshot_version = match arg_matches.value_of("snapshot_version") { - Some(s) => s.parse::() - .unwrap_or_else(|e| { eprintln!("Error: {}", e); exit(1) }), - None => snapshot_utils::SnapshotVersion::default(), - }; + let snapshot_version = match arg_matches.value_of("snapshot_version") { + Some(s) => s + .parse::() + .unwrap_or_else(|e| { + eprintln!("Error: {}", e); + exit(1) + }), + None => snapshot_utils::SnapshotVersion::default(), + }; let process_options = ProcessOptions { dev_halt_at_slot: Some(snapshot_slot), new_hard_forks: hardforks_of(arg_matches, "hard_forks"), @@ -1064,7 +1070,7 @@ fn main() { output_directory, storages, CompressionType::Bzip2, - snapshot_version, + snapshot_version, ) }) .and_then(|package| { diff --git a/ledger/src/bank_forks.rs b/ledger/src/bank_forks.rs index 164c3abd0ce6cd..b5c2acfa1c4bdf 100644 --- a/ledger/src/bank_forks.rs +++ b/ledger/src/bank_forks.rs @@ -324,7 +324,12 @@ impl BankForks { let storages: Vec<_> = bank.get_snapshot_storages(); let mut add_snapshot_time = Measure::start("add-snapshot-ms"); - snapshot_utils::add_snapshot(&config.snapshot_path, &bank, &storages, config.snapshot_version)?; + snapshot_utils::add_snapshot( + &config.snapshot_path, + &bank, + &storages, + config.snapshot_version, + )?; add_snapshot_time.stop(); inc_new_counter_info!("add-snapshot-ms", add_snapshot_time.as_ms() as usize); @@ -343,7 +348,7 @@ impl BankForks { &config.snapshot_package_output_path, storages, config.compression.clone(), - config.snapshot_version, + config.snapshot_version, )?; accounts_package_sender.send(package)?; diff --git a/ledger/src/snapshot_package.rs b/ledger/src/snapshot_package.rs index c4014ec52eb52b..5ee587cfaa1790 100644 --- a/ledger/src/snapshot_package.rs +++ b/ledger/src/snapshot_package.rs @@ -36,7 +36,7 @@ impl AccountsPackage { tar_output_file: PathBuf, hash: Hash, compression: CompressionType, - snapshot_version: SnapshotVersion, + snapshot_version: SnapshotVersion, ) -> Self { Self { root, @@ -47,7 +47,7 @@ impl AccountsPackage { tar_output_file, hash, compression, - snapshot_version, + snapshot_version, } } } diff --git a/ledger/src/snapshot_utils.rs b/ledger/src/snapshot_utils.rs index 07e6a4db00ecd8..4380cac74bed15 100644 --- a/ledger/src/snapshot_utils.rs +++ b/ledger/src/snapshot_utils.rs @@ -9,16 +9,10 @@ use log::*; use regex::Regex; use solana_measure::measure::Measure; use solana_runtime::{ - bank::{ - Bank, BankSlotDelta, - }, + bank::{Bank, BankSlotDelta}, serde_utils::{ - context_bankrc_to_stream, - context_bankrc_from_stream, - SnapshotStorage, - SnapshotStorages, - SerdeContextV1_1_0, - SerdeContextV1_1_1, + context_bankrc_from_stream, context_bankrc_to_stream, SerdeContextV1_1_0, + SerdeContextV1_1_1, SnapshotStorage, SnapshotStorages, }, }; use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash, pubkey::Pubkey}; @@ -51,16 +45,16 @@ pub enum SnapshotVersion { impl Default for SnapshotVersion { fn default() -> Self { - Self::V1_1_0 + Self::V1_1_0 } } impl From for &'static str { fn from(snapshot_version: SnapshotVersion) -> &'static str { - match snapshot_version { - SnapshotVersion::V1_1_0 => VERSION_STRING_V1_1_0, - SnapshotVersion::V1_1_1 => VERSION_STRING_V1_1_1, - } + match snapshot_version { + SnapshotVersion::V1_1_0 => VERSION_STRING_V1_1_0, + SnapshotVersion::V1_1_1 => VERSION_STRING_V1_1_1, + } } } @@ -68,21 +62,21 @@ impl FromStr for SnapshotVersion { type Err = &'static str; fn from_str(version_string: &str) -> std::result::Result { - match version_string { - VERSION_STRING_V1_1_0 => Ok(SnapshotVersion::V1_1_0), - VERSION_STRING_V1_1_1 => Ok(SnapshotVersion::V1_1_1), - _ => Err("unsupported snapshot version") - } + match version_string { + VERSION_STRING_V1_1_0 => Ok(SnapshotVersion::V1_1_0), + VERSION_STRING_V1_1_1 => Ok(SnapshotVersion::V1_1_1), + _ => Err("unsupported snapshot version"), + } } } impl SnapshotVersion { pub fn as_str(self) -> &'static str { - <&str as From>::from(self) + <&str as From>::from(self) } fn maybe_from_string(version_string: &str) -> Option { - version_string.parse::().ok() + version_string.parse::().ok() } } @@ -175,7 +169,7 @@ pub fn package_snapshot, Q: AsRef>( snapshot_package_output_file, bank.get_accounts_hash(), compression, - snapshot_version, + snapshot_version, ); Ok(package) @@ -343,30 +337,25 @@ where } } -pub fn serialize_snapshot_data_file( - data_file_path: &Path, - serializer: F, -) -> Result +pub fn serialize_snapshot_data_file(data_file_path: &Path, serializer: F) -> Result where F: FnOnce(&mut BufWriter) -> Result<()>, { serialize_snapshot_data_file_capped::( - data_file_path, - MAX_SNAPSHOT_DATA_FILE_SIZE, - serializer) + data_file_path, + MAX_SNAPSHOT_DATA_FILE_SIZE, + serializer, + ) } -pub fn deserialize_snapshot_data_file( - data_file_path: &Path, - deserializer: F, -) -> Result +pub fn deserialize_snapshot_data_file(data_file_path: &Path, deserializer: F) -> Result where F: FnOnce(&mut BufReader) -> Result, { deserialize_snapshot_data_file_capped::( - data_file_path, - MAX_SNAPSHOT_DATA_FILE_SIZE, - deserializer, + data_file_path, + MAX_SNAPSHOT_DATA_FILE_SIZE, + deserializer, ) } @@ -436,28 +425,30 @@ fn create_versioned_bank_snapshot_serializer<'a>( snapshot_storages: &'a [SnapshotStorage], ) -> Result) -> Result<()> + 'a>> { match snapshot_version { - SnapshotVersion::V1_1_0 => Ok(Box::new( - move |stream: &mut BufWriter| -> Result<()> { - serialize_into(stream.by_ref(), bank)?; - context_bankrc_to_stream::( - stream.by_ref(), - &bank.rc, - snapshot_storages)?; - Ok(()) - } - )), - SnapshotVersion::V1_1_1 => Ok(Box::new( - move |stream: &mut BufWriter| -> Result<()> { - serialize_into(stream.by_ref(), bank)?; - context_bankrc_to_stream::( - stream.by_ref(), - &bank.rc, - snapshot_storages)?; - Ok(()) - } - )), - //If additional snapshot version were defined but not implemented... - //_ => Err(get_io_error(&format!("unsupported snapshot version: {}", snapshot_version.to_string()))), + SnapshotVersion::V1_1_0 => Ok(Box::new( + move |stream: &mut BufWriter| -> Result<()> { + serialize_into(stream.by_ref(), bank)?; + context_bankrc_to_stream::( + stream.by_ref(), + &bank.rc, + snapshot_storages, + )?; + Ok(()) + }, + )), + SnapshotVersion::V1_1_1 => Ok(Box::new( + move |stream: &mut BufWriter| -> Result<()> { + serialize_into(stream.by_ref(), bank)?; + context_bankrc_to_stream::( + stream.by_ref(), + &bank.rc, + snapshot_storages, + )?; + Ok(()) + }, + )), + //If additional snapshot version were defined but not implemented... + //_ => Err(get_io_error(&format!("unsupported snapshot version: {}", snapshot_version.to_string()))), } } @@ -470,47 +461,46 @@ fn create_versioned_bank_snapshot_deserializer<'a, P: AsRef>( ) -> Result) -> Result + 'a>> { let operating_mode = genesis_config.operating_mode; match SnapshotVersion::maybe_from_string(snapshot_version) { - Some(SnapshotVersion::V1_1_0) => Ok(Box::new( - move |stream: &mut BufReader| { - let mut bank: Bank = bincode::config() - .limit(MAX_SNAPSHOT_DATA_FILE_SIZE) - .deserialize_from(stream.by_ref())?; - bank.operating_mode = Some(operating_mode); - info!("Rebuilding accounts..."); - let rc = context_bankrc_from_stream::( - account_paths, - bank.slot(), - &bank.ancestors, - frozen_account_pubkeys, - stream.by_ref(), - &append_vecs_path, - )?; - bank.rc = rc; - bank.finish_init(); - Ok(bank) - } - )), - Some(SnapshotVersion::V1_1_1) => Ok(Box::new( - move |stream: &mut BufReader| { - let mut bank: Bank = bincode::config() - .limit(MAX_SNAPSHOT_DATA_FILE_SIZE) - .deserialize_from(stream.by_ref())?; - bank.operating_mode = Some(operating_mode); - info!("Rebuilding accounts..."); - let rc = context_bankrc_from_stream::( - account_paths, - bank.slot(), - &bank.ancestors, - frozen_account_pubkeys, - stream.by_ref(), - &append_vecs_path, - )?; - bank.rc = rc; - bank.finish_init(); - Ok(bank) - } - )), - _ => Err(get_io_error(&format!("unsupported snapshot version: {}", snapshot_version))), + Some(SnapshotVersion::V1_1_0) => Ok(Box::new(move |stream: &mut BufReader| { + let mut bank: Bank = bincode::config() + .limit(MAX_SNAPSHOT_DATA_FILE_SIZE) + .deserialize_from(stream.by_ref())?; + bank.operating_mode = Some(operating_mode); + info!("Rebuilding accounts..."); + let rc = context_bankrc_from_stream::( + account_paths, + bank.slot(), + &bank.ancestors, + frozen_account_pubkeys, + stream.by_ref(), + &append_vecs_path, + )?; + bank.rc = rc; + bank.finish_init(); + Ok(bank) + })), + Some(SnapshotVersion::V1_1_1) => Ok(Box::new(move |stream: &mut BufReader| { + let mut bank: Bank = bincode::config() + .limit(MAX_SNAPSHOT_DATA_FILE_SIZE) + .deserialize_from(stream.by_ref())?; + bank.operating_mode = Some(operating_mode); + info!("Rebuilding accounts..."); + let rc = context_bankrc_from_stream::( + account_paths, + bank.slot(), + &bank.ancestors, + frozen_account_pubkeys, + stream.by_ref(), + &append_vecs_path, + )?; + bank.rc = rc; + bank.finish_init(); + Ok(bank) + })), + _ => Err(get_io_error(&format!( + "unsupported snapshot version: {}", + snapshot_version + ))), } } @@ -533,15 +523,10 @@ pub fn add_snapshot>( ); let mut bank_serialize = Measure::start("bank-serialize-ms"); - let bank_snapshot_serializer = create_versioned_bank_snapshot_serializer( - snapshot_version, - bank, - snapshot_storages - )?; - let consumed_size = serialize_snapshot_data_file( - &snapshot_bank_file_path, - bank_snapshot_serializer, - )?; + let bank_snapshot_serializer = + create_versioned_bank_snapshot_serializer(snapshot_version, bank, snapshot_storages)?; + let consumed_size = + serialize_snapshot_data_file(&snapshot_bank_file_path, bank_snapshot_serializer)?; bank_serialize.stop(); // Monitor sizes because they're capped to MAX_SNAPSHOT_DATA_FILE_SIZE @@ -574,13 +559,10 @@ pub fn serialize_status_cache( snapshot_links.path().join(SNAPSHOT_STATUS_CACHE_FILE_NAME); let mut status_cache_serialize = Measure::start("status_cache_serialize-ms"); - let consumed_size = serialize_snapshot_data_file( - &snapshot_status_cache_file_path, - |stream| { - serialize_into(stream, slot_deltas)?; - Ok(()) - }, - )?; + let consumed_size = serialize_snapshot_data_file(&snapshot_status_cache_file_path, |stream| { + serialize_into(stream, slot_deltas)?; + Ok(()) + })?; status_cache_serialize.stop(); // Monitor sizes because they're capped to MAX_SNAPSHOT_DATA_FILE_SIZE @@ -793,28 +775,23 @@ where info!("Loading bank from {:?}", &root_paths.snapshot_file_path); let bank_snapshot_deserializer = create_versioned_bank_snapshot_deserializer( - snapshot_version, - account_paths, - frozen_account_pubkeys, - &append_vecs_path, - genesis_config, - )?; - let bank = deserialize_snapshot_data_file( - &root_paths.snapshot_file_path, - bank_snapshot_deserializer, + snapshot_version, + account_paths, + frozen_account_pubkeys, + &append_vecs_path, + genesis_config, )?; + let bank = + deserialize_snapshot_data_file(&root_paths.snapshot_file_path, bank_snapshot_deserializer)?; let status_cache_path = unpacked_snapshots_dir.join(SNAPSHOT_STATUS_CACHE_FILE_NAME); - let slot_deltas = deserialize_snapshot_data_file( - &status_cache_path, - |stream| { - info!("Rebuilding status cache..."); - let slot_deltas: Vec = bincode::config() - .limit(MAX_SNAPSHOT_DATA_FILE_SIZE) - .deserialize_from(stream)?; - Ok(slot_deltas) - }, - )?; + let slot_deltas = deserialize_snapshot_data_file(&status_cache_path, |stream| { + info!("Rebuilding status cache..."); + let slot_deltas: Vec = bincode::config() + .limit(MAX_SNAPSHOT_DATA_FILE_SIZE) + .deserialize_from(stream)?; + Ok(slot_deltas) + })?; bank.src.append(&slot_deltas); diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 36ef0cb04f8ecd..2246723b38ff5d 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -1229,7 +1229,7 @@ fn setup_snapshot_validator_config( snapshot_package_output_path: PathBuf::from(snapshot_output_path.path()), snapshot_path: PathBuf::from(snapshot_dir.path()), compression: CompressionType::Bzip2, - snapshot_version: snapshot_utils::SnapshotVersion::default(), + snapshot_version: snapshot_utils::SnapshotVersion::default(), }; // Create the account paths diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index df3e1e556aa63a..b2a07ef8330dab 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -66,11 +66,11 @@ pub enum AccountAddressFilter { impl Accounts { pub(crate) fn new_empty() -> Self { - Self { + Self { account_locks: Mutex::new(HashSet::new()), readonly_locks: Arc::new(RwLock::new(Some(HashMap::new()))), - ..Self::default() - } + ..Self::default() + } } pub fn new(paths: Vec) -> Self { @@ -778,10 +778,7 @@ mod tests { // TODO: all the bank tests are bank specific, issue: 2194 use super::*; - use crate::{ - bank::HashAgeKind, - rent_collector::RentCollector, - }; + use crate::{bank::HashAgeKind, rent_collector::RentCollector}; use solana_sdk::{ account::Account, epoch_schedule::EpochSchedule, diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index e5de86d319cdb0..0a5ac933888769 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -27,9 +27,7 @@ use lazy_static::lazy_static; use log::*; use rand::{thread_rng, Rng}; use rayon::{prelude::*, ThreadPool}; -use serde::{ - Deserialize, Serialize, -}; +use serde::{Deserialize, Serialize}; use solana_measure::measure::Measure; use solana_rayon_threadlimit::get_thread_count; use solana_sdk::{ @@ -141,7 +139,9 @@ pub enum AccountStorageStatus { } impl Default for AccountStorageStatus { - fn default() -> Self { Self::Available } + fn default() -> Self { + Self::Available + } } #[derive(Debug)] @@ -172,12 +172,12 @@ pub struct AccountStorageEntry { impl Default for AccountStorageEntry { fn default() -> Self { - Self { - id: 0, - slot: 0, - accounts: AppendVec::new_empty_map(0), + Self { + id: 0, + slot: 0, + accounts: AppendVec::new_empty_map(0), count_and_status: RwLock::new((0, AccountStorageStatus::Available)), - } + } } } @@ -1882,23 +1882,17 @@ pub mod tests { // TODO: all the bank tests are bank specific, issue: 2194 use super::*; use crate::{ - accounts_index::RefCount, - append_vec::AccountMeta, - serde_utils::{ - accountsdb_from_stream, - accountsdb_to_stream, - }, + accounts_index::RefCount, + append_vec::AccountMeta, + serde_utils::{accountsdb_from_stream, accountsdb_to_stream}, }; use assert_matches::assert_matches; use rand::{thread_rng, Rng}; use solana_sdk::{account::Account, hash::HASH_BYTES}; use std::{ - fs, - io::{ - BufReader, - Cursor, - }, - str::FromStr, + fs, + io::{BufReader, Cursor}, + str::FromStr, }; use tempfile::TempDir; @@ -2763,24 +2757,14 @@ pub mod tests { fn reconstruct_accounts_db_via_serialization(accounts: &AccountsDB, slot: Slot) -> AccountsDB { let mut writer = Cursor::new(vec![]); let snapshot_storages = accounts.get_snapshot_storages(slot); - accountsdb_to_stream( - &mut writer, - &accounts, - slot, - &snapshot_storages - ) - .unwrap(); + accountsdb_to_stream(&mut writer, &accounts, slot, &snapshot_storages).unwrap(); let buf = writer.into_inner(); let mut reader = BufReader::new(&buf[..]); let copied_accounts = TempDir::new().unwrap(); // Simulate obtaining a copy of the AppendVecs from a tarball copy_append_vecs(&accounts, copied_accounts.path()).unwrap(); - let daccounts = accountsdb_from_stream( - &mut reader, - &[], - copied_accounts.path() - ).unwrap(); + let daccounts = accountsdb_from_stream(&mut reader, &[], copied_accounts.path()).unwrap(); print_count_and_status("daccounts", &daccounts); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index a1c81937672feb..20c9105dfd7d08 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -60,7 +60,7 @@ use std::{ collections::{HashMap, HashSet}, mem, ops::RangeInclusive, - path::{PathBuf}, + path::PathBuf, rc::Rc, sync::atomic::{AtomicBool, AtomicU64, Ordering}, sync::{Arc, RwLock, RwLockReadGuard}, @@ -5772,10 +5772,11 @@ mod tests { let mut writer = Cursor::new(&mut buf); serialize_into(&mut writer, &bank2).unwrap(); crate::serde_utils::bankrc_to_stream( - &mut std::io::BufWriter::new(&mut writer), - &bank2.rc, - &snapshot_storages - ).unwrap(); + &mut std::io::BufWriter::new(&mut writer), + &bank2.rc, + &snapshot_storages, + ) + .unwrap(); let mut rdr = Cursor::new(&buf[..]); let mut dbank: Bank = bincode::deserialize_from(&mut rdr).unwrap(); diff --git a/runtime/src/serde_utils.rs b/runtime/src/serde_utils.rs index ad793b7e5c22f6..e38f70a00ce3d5 100644 --- a/runtime/src/serde_utils.rs +++ b/runtime/src/serde_utils.rs @@ -1,124 +1,70 @@ use { crate::{ - accounts::{ - Accounts, - }, - accounts_db::{ - AccountsDB, - AccountStorage, - AccountStorageEntry, - AccountStorageStatus, - AppendVecId, - BankHashInfo, - SlotStores, - }, - append_vec::AppendVec, - bank::BankRc, - }, - bincode::{ - deserialize_from, - serialize_into, + accounts::Accounts, + accounts_db::{ + AccountStorage, AccountStorageEntry, AccountStorageStatus, AccountsDB, AppendVecId, + BankHashInfo, SlotStores, + }, + append_vec::AppendVec, + bank::BankRc, }, + bincode::{deserialize_from, serialize_into}, fs_extra::dir::CopyOptions, - log::{ - info, - warn, - }, + log::{info, warn}, + rand::{thread_rng, Rng}, serde::{ - Deserialize, - Deserializer, - Serialize, - Serializer, - de::{ - DeserializeOwned, - Visitor, - }, - }, - rand::{ - thread_rng, - Rng, - }, - solana_sdk::{ - clock::Slot, - pubkey::Pubkey, + de::{DeserializeOwned, Visitor}, + Deserialize, Deserializer, Serialize, Serializer, }, + solana_sdk::{clock::Slot, pubkey::Pubkey}, std::{ - cmp::min, - collections::HashMap, - fmt::{ - Formatter, - Result as FormatResult, - }, - io::{ - BufReader, - BufWriter, - Cursor, - Error as IoError, - ErrorKind as IoErrorKind, - Read, - Write, - }, - path::{ - Path, - PathBuf, - }, - result::Result, - sync::{ - Arc, - atomic::Ordering, - RwLock, - }, + cmp::min, + collections::HashMap, + fmt::{Formatter, Result as FormatResult}, + io::{ + BufReader, BufWriter, Cursor, Error as IoError, ErrorKind as IoErrorKind, Read, Write, + }, + path::{Path, PathBuf}, + result::Result, + sync::{atomic::Ordering, Arc, RwLock}, }, }; - -pub use crate::accounts_db::{ - SnapshotStorage, - SnapshotStorages, -}; - +pub use crate::accounts_db::{SnapshotStorage, SnapshotStorages}; pub trait SerdeContext<'a> { - type SerializableAccountStorageEntry - : Serialize - + DeserializeOwned - + From<&'a AccountStorageEntry> - + Into; + type SerializableAccountStorageEntry: Serialize + + DeserializeOwned + + From<&'a AccountStorageEntry> + + Into; } - pub struct SerdeContextV1_1_0 {} impl<'a> SerdeContext<'a> for SerdeContextV1_1_0 { type SerializableAccountStorageEntry = SerializableAccountStorageEntryV1_1_0; } - pub struct SerdeContextV1_1_1 {} impl<'a> SerdeContext<'a> for SerdeContextV1_1_1 { type SerializableAccountStorageEntry = SerializableAccountStorageEntryV1_1_1; } - type DefaultSerdeContext = SerdeContextV1_1_1; - const MAX_ACCOUNTS_DB_STREAM_SIZE: u64 = 32 * 1024 * 1024 * 1024; - fn bankrc_to_io_error(error: T) -> IoError { let msg = error.to_string(); warn!("BankRc error: {:?}", msg); IoError::new(IoErrorKind::Other, msg) } - fn accountsdb_to_io_error(error: T) -> IoError { let msg = error.to_string(); warn!("AccountsDB error: {:?}", msg); IoError::new(IoErrorKind::Other, msg) } - pub fn bankrc_from_stream( account_paths: &[PathBuf], slot: Slot, @@ -129,19 +75,18 @@ pub fn bankrc_from_stream( ) -> std::result::Result where R: Read, - P: AsRef + P: AsRef, { context_bankrc_from_stream::( - account_paths, - slot, - ancestors, - frozen_account_pubkeys, - stream, - stream_append_vecs_path, + account_paths, + slot, + ancestors, + frozen_account_pubkeys, + stream, + stream_append_vecs_path, ) } - pub fn bankrc_to_stream( stream: &mut BufWriter, bank_rc: &BankRc, @@ -150,14 +95,9 @@ pub fn bankrc_to_stream( where W: Write, { - context_bankrc_to_stream::( - stream, - bank_rc, - snapshot_storages, - ) + context_bankrc_to_stream::(stream, bank_rc, snapshot_storages) } - #[cfg(test)] pub(crate) fn accounts_from_stream( account_paths: &[PathBuf], @@ -171,15 +111,14 @@ where P: AsRef, { context_accounts_from_stream::( - account_paths, - ancestors, - frozen_account_pubkeys, - stream, - stream_append_vecs_path, + account_paths, + ancestors, + frozen_account_pubkeys, + stream, + stream_append_vecs_path, ) } - #[cfg(test)] pub(crate) fn accountsdb_to_stream( stream: &mut W, @@ -191,14 +130,13 @@ where W: Write, { context_accountsdb_to_stream::( - stream, - accounts_db, - slot, - account_storage_entries, + stream, + accounts_db, + slot, + account_storage_entries, ) } - #[cfg(test)] pub(crate) fn accountsdb_from_stream( stream: &mut BufReader, @@ -210,13 +148,12 @@ where P: AsRef, { context_accountsdb_from_stream::( - stream, - account_paths, - stream_append_vecs_path, + stream, + account_paths, + stream_append_vecs_path, ) } - pub fn context_bankrc_from_stream<'a, C, R, P>( account_paths: &[PathBuf], slot: Slot, @@ -228,11 +165,10 @@ pub fn context_bankrc_from_stream<'a, C, R, P>( where C: SerdeContext<'a>, R: Read, - P: AsRef + P: AsRef, { // read and discard the prepended serialized byte vector length - let _len: usize = - deserialize_from(&mut stream).map_err(bankrc_to_io_error)?; + let _len: usize = deserialize_from(&mut stream).map_err(bankrc_to_io_error)?; // read and deserialise the accounts database directly from the stream let accounts = context_accounts_from_stream::( @@ -250,7 +186,6 @@ where }) } - pub fn context_bankrc_to_stream<'a, 'b, C, W>( stream: &'b mut BufWriter, bank_rc: &'a BankRc, @@ -261,43 +196,45 @@ where W: Write, { struct BankRcSerialize<'a, C> { - bank_rc: &'a BankRc, - snapshot_storages: &'a [SnapshotStorage], - phantom: std::marker::PhantomData, + bank_rc: &'a BankRc, + snapshot_storages: &'a [SnapshotStorage], + phantom: std::marker::PhantomData, } impl<'a, C: SerdeContext<'a>> Serialize for BankRcSerialize<'a, C> { - fn serialize(&self, serializer: S) -> std::result::Result - where + fn serialize(&self, serializer: S) -> std::result::Result + where S: serde::ser::Serializer, - { - // first serialize the accounts database to a byte vector - let mut buf = Vec::new(); - context_accountsdb_to_stream::( - &mut Cursor::new(&mut buf), - &*self.bank_rc.accounts.accounts_db, - self.bank_rc.slot, - self.snapshot_storages) - .map_err(serde::ser::Error::custom)?; - - // then serialize the byte vector to the stream - // as compared to serializing directory to the stream, - // this effectively prepends a u64 containing the length - // of the byte vector to the serialized output + { + // first serialize the accounts database to a byte vector + let mut buf = Vec::new(); + context_accountsdb_to_stream::( + &mut Cursor::new(&mut buf), + &*self.bank_rc.accounts.accounts_db, + self.bank_rc.slot, + self.snapshot_storages, + ) + .map_err(serde::ser::Error::custom)?; + + // then serialize the byte vector to the stream + // as compared to serializing directory to the stream, + // this effectively prepends a u64 containing the length + // of the byte vector to the serialized output serializer.serialize_bytes(&buf) - } + } } - serialize_into(stream, - &BankRcSerialize:: { - bank_rc, - snapshot_storages, - phantom: std::marker::PhantomData::default(), - }) - .map_err(bankrc_to_io_error) + serialize_into( + stream, + &BankRcSerialize:: { + bank_rc, + snapshot_storages, + phantom: std::marker::PhantomData::default(), + }, + ) + .map_err(bankrc_to_io_error) } - pub(crate) fn context_accounts_from_stream<'a, C, R, P>( account_paths: &[PathBuf], ancestors: &HashMap, @@ -310,21 +247,17 @@ where R: Read, P: AsRef, { - let mut accounts_db = context_accountsdb_from_stream::( - stream, - account_paths, - stream_append_vecs_path - )?; + let mut accounts_db = + context_accountsdb_from_stream::(stream, account_paths, stream_append_vecs_path)?; accounts_db.freeze_accounts(ancestors, frozen_account_pubkeys); Ok(Accounts { - accounts_db: Arc::new(accounts_db), - ..Accounts::new_empty() + accounts_db: Arc::new(accounts_db), + ..Accounts::new_empty() }) } - pub(crate) fn context_accountsdb_from_stream<'a, C, R, P>( mut stream: &mut BufReader, account_paths: &[PathBuf], @@ -340,28 +273,26 @@ where // read and discard u64 byte vector length // (artifact from accountsdb_to_stream serializing first // into byte vector and then into stream) - let serialized_len: u64 = - deserialize_from(&mut stream).map_err(accountsdb_to_io_error)?; + let serialized_len: u64 = deserialize_from(&mut stream).map_err(accountsdb_to_io_error)?; // read map of slots to account storage entries - let storage: HashMap> = - bincode::config() - .limit(min(serialized_len, MAX_ACCOUNTS_DB_STREAM_SIZE)) - .deserialize_from(&mut stream) - .map_err(accountsdb_to_io_error)?; + let storage: HashMap> = bincode::config() + .limit(min(serialized_len, MAX_ACCOUNTS_DB_STREAM_SIZE)) + .deserialize_from(&mut stream) + .map_err(accountsdb_to_io_error)?; // convert to two level map of slot -> id -> account storage entry let storage = { let mut map = HashMap::new(); - for (slot, entries) in storage.into_iter() { - let sub_map = map.entry(slot).or_insert_with(HashMap::new); - for entry in entries.into_iter() { - let mut entry: AccountStorageEntry = entry.into(); + for (slot, entries) in storage.into_iter() { + let sub_map = map.entry(slot).or_insert_with(HashMap::new); + for entry in entries.into_iter() { + let mut entry: AccountStorageEntry = entry.into(); entry.slot = slot; sub_map.insert(entry.id, Arc::new(entry)); - } - } - map + } + } + map }; // Remap the deserialized AppendVec paths to point to correct local paths @@ -377,8 +308,7 @@ where // Move the corresponding AppendVec from the snapshot into the directory pointed // at by `local_dir` - let append_vec_relative_path = - AppendVec::new_relative_path(slot, storage_entry.id); + let append_vec_relative_path = AppendVec::new_relative_path(slot, storage_entry.id); let append_vec_abs_path = stream_append_vecs_path .as_ref() .join(&append_vec_relative_path); @@ -391,10 +321,13 @@ where &local_dir, ©_options, ) - .map_err(|e| format!( - "unable to move {:?} to {:?}: {}", - append_vec_abs_path, local_dir, e)) - .map_err(accountsdb_to_io_error); + .map_err(|e| { + format!( + "unable to move {:?} to {:?}: {}", + append_vec_abs_path, local_dir, e + ) + }) + .map_err(accountsdb_to_io_error); if e.is_err() { info!("{:?}", e); continue; @@ -428,7 +361,11 @@ where let (slot, bank_hash): (Slot, BankHashInfo) = deserialize_from(&mut stream) .map_err(|e| format!("bank hashes deserialize error: {}", e.to_string())) .map_err(accountsdb_to_io_error)?; - accounts_db.bank_hashes.write().unwrap().insert(slot, bank_hash); + accounts_db + .bank_hashes + .write() + .unwrap() + .insert(slot, bank_hash); // Process deserialized data, set necessary fields in self let max_id: usize = *storage @@ -444,12 +381,13 @@ where } accounts_db.next_id.store(max_id + 1, Ordering::Relaxed); - accounts_db.write_version.fetch_add(version, Ordering::Relaxed); + accounts_db + .write_version + .fetch_add(version, Ordering::Relaxed); accounts_db.generate_index(); Ok(accounts_db) } - pub(crate) fn context_accountsdb_to_stream<'a, 'b, C, W>( stream: &'b mut W, accounts_db: &'a AccountsDB, @@ -461,74 +399,82 @@ where W: Write, { struct AccountsDBSerialize<'a, C> { - accounts_db: &'a AccountsDB, - slot: Slot, - account_storage_entries: &'a [SnapshotStorage], - phantom: std::marker::PhantomData, + accounts_db: &'a AccountsDB, + slot: Slot, + account_storage_entries: &'a [SnapshotStorage], + phantom: std::marker::PhantomData, } impl<'a, C: SerdeContext<'a>> Serialize for AccountsDBSerialize<'a, C> { - fn serialize(&self, serializer: S) -> std::result::Result - where + fn serialize(&self, serializer: S) -> std::result::Result + where S: serde::ser::Serializer, - { + { use serde::ser::Error; - let mut buf = vec![]; - { - let mut wr = Cursor::new(&mut buf); - - // sample write version before serializing storage entries - let version = self.accounts_db.write_version.load(Ordering::Relaxed); - - // write the list of account storage entry lists out as a map - serialize_into(&mut wr, &( - self.account_storage_entries - .iter() - .map(|x| ( - x.first().unwrap().slot, - x.iter() - .map(|x| C::SerializableAccountStorageEntry::from(x.as_ref())) - .collect::>() - )) - .collect::>() - )) - .map_err(Error::custom)?; - - // write the current write version sampled before the account - // storage entries were written out - serialize_into(&mut wr, &version) - .map_err(Error::custom)?; - - // write out bank hashes - serialize_into(&mut wr, &( - self.slot, - &*self - .accounts_db - .bank_hashes - .read() - .unwrap() - .get(&self.slot) - .unwrap_or_else(|| panic!("No bank_hashes entry for slot {}", - self.slot)), - )) - .map_err(Error::custom)?; - } + let mut buf = vec![]; + { + let mut wr = Cursor::new(&mut buf); + + // sample write version before serializing storage entries + let version = self.accounts_db.write_version.load(Ordering::Relaxed); + + // write the list of account storage entry lists out as a map + serialize_into( + &mut wr, + &(self + .account_storage_entries + .iter() + .map(|x| { + ( + x.first().unwrap().slot, + x.iter() + .map(|x| C::SerializableAccountStorageEntry::from(x.as_ref())) + .collect::>(), + ) + }) + .collect::>()), + ) + .map_err(Error::custom)?; + + // write the current write version sampled before the account + // storage entries were written out + serialize_into(&mut wr, &version).map_err(Error::custom)?; + + // write out bank hashes + serialize_into( + &mut wr, + &( + self.slot, + &*self + .accounts_db + .bank_hashes + .read() + .unwrap() + .get(&self.slot) + .unwrap_or_else(|| { + panic!("No bank_hashes entry for slot {}", self.slot) + }), + ), + ) + .map_err(Error::custom)?; + } serializer.serialize_bytes(&buf) - } + } } - serialize_into(stream, - &AccountsDBSerialize::<'a, C> { - accounts_db, - slot, - account_storage_entries, - phantom: std::marker::PhantomData::default(), - }) - .map_err(bankrc_to_io_error) + serialize_into( + stream, + &AccountsDBSerialize::<'a, C> { + accounts_db, + slot, + account_storage_entries, + phantom: std::marker::PhantomData::default(), + }, + ) + .map_err(bankrc_to_io_error) } - // Serializable version of AccountStorageEntry for snapshot format V1_1_0 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct SerializableAccountStorageEntryV1_1_0 { @@ -537,51 +483,45 @@ pub struct SerializableAccountStorageEntryV1_1_0 { count_and_status: (usize, AccountStorageStatus), } - impl From<&AccountStorageEntry> for SerializableAccountStorageEntryV1_1_0 { fn from(rhs: &AccountStorageEntry) -> Self { - Self { - id: rhs.id, - accounts: SerializableAppendVecV1_1_0::from(&rhs.accounts), - ..Self::default() - } + Self { + id: rhs.id, + accounts: SerializableAppendVecV1_1_0::from(&rhs.accounts), + ..Self::default() + } } } - impl Into for SerializableAccountStorageEntryV1_1_0 { fn into(self) -> AccountStorageEntry { - let mut ase = AccountStorageEntry::default(); - ase.id = self.id; - ase.accounts = self.accounts.into(); - ase + let mut ase = AccountStorageEntry::default(); + ase.id = self.id; + ase.accounts = self.accounts.into(); + ase } } - // Serializable version of AppendVec for snapshot format V1_1_0 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] struct SerializableAppendVecV1_1_0 { current_len: usize, } - impl From<&AppendVec> for SerializableAppendVecV1_1_0 { fn from(rhs: &AppendVec) -> SerializableAppendVecV1_1_0 { - SerializableAppendVecV1_1_0 { - current_len: rhs.len(), - } + SerializableAppendVecV1_1_0 { + current_len: rhs.len(), + } } } - impl Into for SerializableAppendVecV1_1_0 { fn into(self) -> AppendVec { - AppendVec::new_empty_map(self.current_len) + AppendVec::new_empty_map(self.current_len) } } - // Serialization of AppendVec V1_1_0 requires serialization of u64 to // eight byte vector which is then itself serialized to the stream impl Serialize for SerializableAppendVecV1_1_0 { @@ -590,15 +530,13 @@ impl Serialize for SerializableAppendVecV1_1_0 { S: Serializer, { const LEN: usize = std::mem::size_of::(); - let mut buf = [0u8; LEN]; - serialize_into(Cursor::new(&mut buf[..]), - &(self.current_len as u64)) + let mut buf = [0u8; LEN]; + serialize_into(Cursor::new(&mut buf[..]), &(self.current_len as u64)) .map_err(serde::ser::Error::custom)?; - serializer.serialize_bytes(&buf) + serializer.serialize_bytes(&buf) } } - // Deserialization of AppendVec V1_1_0 requires deserialization // of eight byte vector from which u64 is then deserialized impl<'de> Deserialize<'de> for SerializableAppendVecV1_1_0 { @@ -606,32 +544,33 @@ impl<'de> Deserialize<'de> for SerializableAppendVecV1_1_0 { where D: Deserializer<'de>, { - use serde::de::Error; - struct SerializableAppendVecV1_1_0Visitor; - impl<'a> Visitor<'a> for SerializableAppendVecV1_1_0Visitor { - type Value = SerializableAppendVecV1_1_0; - fn expecting(&self, formatter: &mut Formatter) -> FormatResult { - formatter.write_str("Expecting SerializableAppendVecV1_1_0") - } - fn visit_bytes(self, data: &[u8]) -> std::result::Result - where - E: Error, - { - const LEN: u64 = std::mem::size_of::() as u64; - let mut rd = Cursor::new(&data[..]); - let current_len: usize = deserialize_from(&mut rd).map_err(Error::custom)?; - if rd.position() != LEN { - Err(Error::custom("SerializableAppendVecV1_1_0: unexpected length")) - } else { - Ok(SerializableAppendVecV1_1_0 { current_len }) - } - } - } + use serde::de::Error; + struct SerializableAppendVecV1_1_0Visitor; + impl<'a> Visitor<'a> for SerializableAppendVecV1_1_0Visitor { + type Value = SerializableAppendVecV1_1_0; + fn expecting(&self, formatter: &mut Formatter) -> FormatResult { + formatter.write_str("Expecting SerializableAppendVecV1_1_0") + } + fn visit_bytes(self, data: &[u8]) -> std::result::Result + where + E: Error, + { + const LEN: u64 = std::mem::size_of::() as u64; + let mut rd = Cursor::new(&data[..]); + let current_len: usize = deserialize_from(&mut rd).map_err(Error::custom)?; + if rd.position() != LEN { + Err(Error::custom( + "SerializableAppendVecV1_1_0: unexpected length", + )) + } else { + Ok(SerializableAppendVecV1_1_0 { current_len }) + } + } + } deserializer.deserialize_bytes(SerializableAppendVecV1_1_0Visitor) } } - // Serializable version of AccountStorageEntry for snapshot format V1_1_1 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct SerializableAccountStorageEntryV1_1_1 { @@ -639,62 +578,43 @@ pub struct SerializableAccountStorageEntryV1_1_1 { accounts_current_len: usize, } - impl From<&AccountStorageEntry> for SerializableAccountStorageEntryV1_1_1 { fn from(rhs: &AccountStorageEntry) -> Self { - Self { - id: rhs.id, - accounts_current_len: rhs.accounts.len(), - ..Self::default() - } + Self { + id: rhs.id, + accounts_current_len: rhs.accounts.len(), + ..Self::default() + } } } - impl Into for SerializableAccountStorageEntryV1_1_1 { fn into(self) -> AccountStorageEntry { - AccountStorageEntry { - id: self.id, - accounts: AppendVec::new_empty_map(self.accounts_current_len), - ..AccountStorageEntry::default() - } + AccountStorageEntry { + id: self.id, + accounts: AppendVec::new_empty_map(self.accounts_current_len), + ..AccountStorageEntry::default() + } } } - #[cfg(test)] mod tests { use { - super::*, - crate::{ - accounts::{ - Accounts, - create_test_accounts, - }, - accounts_db::{ - get_temp_accounts_paths, - tests::copy_append_vecs, - }, - }, - rand::{ - thread_rng, - Rng, - }, - solana_sdk::{ - account::Account, - pubkey::Pubkey, - }, - std::{ - collections::HashMap, - io::{ - BufReader, - Cursor, - }, - }, - tempfile::TempDir, + super::*, + crate::{ + accounts::{create_test_accounts, Accounts}, + accounts_db::{get_temp_accounts_paths, tests::copy_append_vecs}, + }, + rand::{thread_rng, Rng}, + solana_sdk::{account::Account, pubkey::Pubkey}, + std::{ + collections::HashMap, + io::{BufReader, Cursor}, + }, + tempfile::TempDir, }; - fn check_accounts(accounts: &Accounts, pubkeys: &Vec, num: usize) { for _ in 1..num { let idx = thread_rng().gen_range(0, num - 1); @@ -708,7 +628,6 @@ mod tests { } } - #[test] fn test_accounts_serialize() { solana_logger::setup(); diff --git a/validator/src/main.rs b/validator/src/main.rs index ddc9ecf5d5b5d3..eb9644cff75c04 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -967,9 +967,11 @@ pub fn main() { } } let snapshot_version = match matches.value_of("snapshot_version") { - Some(s) => s.parse::() - .unwrap_or_else(|e| { eprintln!("Error: {}", e); exit(1) }), - None => SnapshotVersion::default(), + Some(s) => s.parse::().unwrap_or_else(|e| { + eprintln!("Error: {}", e); + exit(1) + }), + None => SnapshotVersion::default(), }; validator_config.snapshot_config = Some(SnapshotConfig { snapshot_interval_slots: if snapshot_interval_slots > 0 { @@ -980,7 +982,7 @@ pub fn main() { snapshot_path, snapshot_package_output_path: ledger_path.clone(), compression: snapshot_compression, - snapshot_version, + snapshot_version, }); validator_config.accounts_hash_interval_slots =