diff --git a/Cargo.lock b/Cargo.lock index fb107ca71d31fc..be5081023827df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6289,6 +6289,7 @@ dependencies = [ "log", "solana-logger 1.12.0", "solana-runtime", + "solana-sdk 1.12.0", "solana-version", ] diff --git a/runtime/store-tool/Cargo.toml b/runtime/store-tool/Cargo.toml index 513ee7755b1911..1dfd5512073c8b 100644 --- a/runtime/store-tool/Cargo.toml +++ b/runtime/store-tool/Cargo.toml @@ -14,6 +14,7 @@ clap = "2.33.1" log = { version = "0.4.17" } solana-logger = { path = "../../logger", version = "=1.12.0" } solana-runtime = { path = "..", version = "=1.12.0" } +solana-sdk = { path = "../../sdk", version = "=1.12.0" } solana-version = { path = "../../version", version = "=1.12.0" } [package.metadata.docs.rs] diff --git a/runtime/store-tool/src/main.rs b/runtime/store-tool/src/main.rs index 5ed478b5134e07..edfc00d8ee1323 100644 --- a/runtime/store-tool/src/main.rs +++ b/runtime/store-tool/src/main.rs @@ -1,7 +1,8 @@ use { - clap::{crate_description, crate_name, value_t_or_exit, App, Arg}, + clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg}, log::*, - solana_runtime::append_vec::AppendVec, + solana_runtime::append_vec::{AppendVec, StoredAccountMeta}, + solana_sdk::{account::AccountSharedData, hash::Hash, pubkey::Pubkey}, }; fn main() { @@ -26,21 +27,37 @@ fn main() { .get_matches(); let file = value_t_or_exit!(matches, "file", String); - let len = value_t_or_exit!(matches, "len", usize); - let (mut store, num_accounts) = AppendVec::new_from_file(file, len).expect("should succeed"); + let len = value_t!(matches, "len", usize) + .unwrap_or_else(|_| std::fs::metadata(&file).unwrap().len() as usize); + + let mut store = AppendVec::new_from_file_unchecked(file, len).expect("should succeed"); store.set_no_remove_on_drop(); - info!( - "store: len: {} capacity: {} accounts: {}", - store.len(), - store.capacity(), - num_accounts, - ); + info!("store: len: {} capacity: {}", store.len(), store.capacity()); + let mut num_accounts: usize = 0; + let mut stored_accounts_len: usize = 0; for account in store.account_iter() { + if is_account_zeroed(&account) { + break; + } info!( " account: {:?} version: {} data: {} hash: {:?}", account.meta.pubkey, account.meta.write_version, account.meta.data_len, account.hash ); + num_accounts = num_accounts.saturating_add(1); + stored_accounts_len = stored_accounts_len.saturating_add(account.stored_size); } + info!( + "num_accounts: {} stored_accounts_len: {}", + num_accounts, stored_accounts_len + ); +} + +fn is_account_zeroed(account: &StoredAccountMeta) -> bool { + account.hash == &Hash::default() + && account.meta.data_len == 0 + && account.meta.write_version == 0 + && account.meta.pubkey == Pubkey::default() + && account.clone_account() == AccountSharedData::default() } #[cfg(test)]