Skip to content

Commit

Permalink
feat: add database analyse-gas-usage command (#10240)
Browse files Browse the repository at this point in the history
Add a command which allows to analyse gas usage on some part of the
blockchain.
The command goes over the specified blocks and gathers information about
how much
gas was used by each block, shard and account.
Then it displays an analysis of all the data.

The analysis contains:
* Total gas used
* Gas used on each shard
* Top 10 accounts by gas usage
* The optimal account by which a shard could be split into two halves
with similar gas usage

Help page:
```bash
$ ./neard database analyse-gas-usage --help
Analyse gas usage in a chosen sequnce of blocks

Usage: neard database analyse-gas-usage [OPTIONS]

Options:
      --last-blocks <LAST_BLOCKS>
          Analyse the last N blocks in the blockchain
      --from-block-height <FROM_BLOCK_HEIGHT>
          Analyse blocks from the given block height, inclusive
      --to-block-height <TO_BLOCK_HEIGHT>
          Analyse blocks up to the given block height, inclusive
  -h, --help
          Print help
```

Example usage:
```bash
# Analyse gas usage in the last 1000 blocks
cargo run --bin neard -- database analyse-gas-usage --last-blocks 1000

# Analyse gas usage in blocks with heights between 200 and 300 (inclusive)
./neard database analyse-gas-usage --from-block-height 200 --to-block-height 300
```
  • Loading branch information
jancionear committed Nov 30, 2023
1 parent 426b283 commit 935cc98
Show file tree
Hide file tree
Showing 8 changed files with 790 additions and 0 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.

3 changes: 3 additions & 0 deletions tools/database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tempfile.workspace = true

nearcore.workspace = true
near-epoch-manager.workspace = true
near-chain.workspace = true
near-chain-configs.workspace = true
near-store.workspace = true
near-primitives.workspace = true
Expand All @@ -32,13 +33,15 @@ near-primitives.workspace = true
nightly = [
"nightly_protocol",
"near-chain-configs/nightly",
"near-chain/nightly",
"near-epoch-manager/nightly",
"near-primitives/nightly",
"near-store/nightly",
"nearcore/nightly",
]
nightly_protocol = [
"near-chain-configs/nightly_protocol",
"near-chain/nightly_protocol",
"near-epoch-manager/nightly_protocol",
"near-primitives/nightly_protocol",
"near-store/nightly_protocol",
Expand Down
Loading

0 comments on commit 935cc98

Please sign in to comment.