Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(state-viewer): list accounts with contracts #8371

Merged
merged 6 commits into from
Jan 17, 2023

Conversation

jakmeier
Copy link
Contributor

A state viewer command to list all accounts with contracts deployed.

So far it only shows the account names and the wasm size.
The intention is to extend it for more sophisticated filtering.

So far, the command finishes all four shards in 2 minutes on a
mainnet archival RocksDB.

@jakmeier jakmeier requested a review from a team as a code owner January 16, 2023 20:42
let (_runtime, state_roots, _header) = load_trie(store.clone(), home_dir, &near_config);

for (shard_id, &state_root) in state_roots.iter().enumerate() {
eprintln!("Starting shard {shard_id}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a single instance of eprintln! used in this file, so maybe let's keep it consistent and use println! here as well? Then it would be easier to redirect script output to file, since you only have to handle stdout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the consistency argument but I believe eprintln is the right choice here anyway.

The reason this goes to stderr is precisely because I don't want it in redirected output. This is just a general progress update to reassure whoever sits in front of the terminal that things are moving along. But scripts working with the output will not want that line.

Case in point, in this comment I have outlined a number of in-terminal data transformations. The script below that adds up all sizes would actually break if there was a line like the above, where the second field is not a number.

awk '{total+=$2} END{printf "%d\n", total}' < contract_accounts.log 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh but if you still think it's better for consistency to not write to eprintln!, then I can also just remove this line, I don't care about it that much. As long as it doesn't go to stdout. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point and it definitely makes sense to print progress messages to stderr.

Let's keep eprintln! here, I think the right solution would be to fix all other instances of printing progress messages to stdout (but definitely not a part of this PR).

tools/state-viewer/src/cli.rs Outdated Show resolved Hide resolved
Comment on lines +65 to +75
let key = TrieKey::ContractCode { account_id: "xx".parse()? }.to_vec();
let (prefix, suffix) = key.split_at(key.len() - 2);
assert_eq!(suffix, "xx".as_bytes());

// `visit_nodes_interval` wants nibbles stored in `Vec<u8>` as input
let nibbles_before: Vec<u8> = NibbleSlice::new(prefix).iter().collect();
let nibbles_after = {
let mut tmp = nibbles_before.clone();
*tmp.last_mut().unwrap() += 1;
tmp
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fyi: I'm working on exposing API around trie key ranges as part of #8332, I will try to keep this use case in mind when designing it, so we can replace this with something nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know, thanks

tools/state-viewer/src/contract_accounts.rs Outdated Show resolved Hide resolved
- update command alias
- better pattern matching
Copy link
Contributor

@pugachAG pugachAG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jakmeier
Copy link
Contributor Author

Thanks for the review.

@Longarithm I will also need a code owner approval on this one, pretty please :)

@near-bulldozer near-bulldozer bot merged commit dce92b8 into near:master Jan 17, 2023
@jakmeier jakmeier deleted the view-contracts branch January 17, 2023 17:31
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 30, 2023
A state viewer command to list all accounts with contracts deployed.

So far it only shows the account names and the wasm size.
The intention is to extend it for more sophisticated filtering.

So far, the command finishes all four shards in 2 minutes on a
mainnet archival RocksDB.
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 30, 2023
A state viewer command to list all accounts with contracts deployed.

So far it only shows the account names and the wasm size.
The intention is to extend it for more sophisticated filtering.

So far, the command finishes all four shards in 2 minutes on a
mainnet archival RocksDB.
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 30, 2023
A state viewer command to list all accounts with contracts deployed.

So far it only shows the account names and the wasm size.
The intention is to extend it for more sophisticated filtering.

So far, the command finishes all four shards in 2 minutes on a
mainnet archival RocksDB.
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 30, 2023
A state viewer command to list all accounts with contracts deployed.

So far it only shows the account names and the wasm size.
The intention is to extend it for more sophisticated filtering.

So far, the command finishes all four shards in 2 minutes on a
mainnet archival RocksDB.
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 30, 2023
A state viewer command to list all accounts with contracts deployed.

So far it only shows the account names and the wasm size.
The intention is to extend it for more sophisticated filtering.

So far, the command finishes all four shards in 2 minutes on a
mainnet archival RocksDB.
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 30, 2023
A state viewer command to list all accounts with contracts deployed.

So far it only shows the account names and the wasm size.
The intention is to extend it for more sophisticated filtering.

So far, the command finishes all four shards in 2 minutes on a
mainnet archival RocksDB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants