Skip to content

Commit

Permalink
A more convenient store-tool (solana-labs#26796)
Browse files Browse the repository at this point in the history
* Use new_from_file_unchecked - don't sanitize input length for appendvec file

* Exit-early on completely zeroed accounts
  • Loading branch information
apfitzge authored Aug 8, 2022
1 parent ad0acaa commit 6e57a8f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/store-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
37 changes: 27 additions & 10 deletions runtime/store-tool/src/main.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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)]
Expand Down

0 comments on commit 6e57a8f

Please sign in to comment.