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

[CAD-3383] Init db-analyser from stored ledger state snapshot #3397

Merged
merged 2 commits into from
Oct 7, 2021

Conversation

EncodePanda
Copy link
Contributor

@EncodePanda EncodePanda commented Sep 28, 2021

TL;DR

You can now start db-analyser starting from a particular ledger state snapshot by providing --analyse-from
Note that this feature is only available when --only-immutable-db is active.

Example usage

Consider ChainDB that holds snapshots 39842331 and 40174168

 λ ls -lath db_mainnet_with_alonzo_40217333/ledger
total 2.9G
drwxr-xr-x 6 encodepanda  192 Sep 28 15:35 .
-rw-r--r-- 1 encodepanda 732M Sep 28 13:36 39842331_db-analyser
-rw-r--r-- 1 encodepanda 747M Sep 22 10:22 40174168_db-analyser
(...)

We can now run the db-analyser starting from one of the snapshots. Here we start from snapshot 39842331, we ask for 10 blocks only and we want to print out their block and slot numbers

λ cabal run ouroboros-consensus-cardano:db-analyser -- \
  --db db_mainnet_with_alonzo_40217333 cardano \
  --configByron dbacfg/mainnet-byron-genesis.json \
  --configShelley dbacfg/mainnet-shelley-genesis.json \
  --nonce 1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81 \
  --configAlonzo dbacfg/mainnet-alonzo-genesis.json \
  --show-slot-block-no \
  --num-blocks-to-process 10 \
  --analyse-from 39842331
  --only-immutable-db

BlockNo 6232309	SlotNo 39842333
BlockNo 6232310	SlotNo 39842339
BlockNo 6232311	SlotNo 39842355
BlockNo 6232312	SlotNo 39842379
BlockNo 6232313	SlotNo 39842411
BlockNo 6232314	SlotNo 39842441
BlockNo 6232315	SlotNo 39842449
BlockNo 6232316	SlotNo 39842460
BlockNo 6232317	SlotNo 39842492
BlockNo 6232318	SlotNo 39842508
ImmutableDB tip: At (Block {blockPointSlot = SlotNo 40174168, blockPointHash = db782958bd783e491d750a84080194d118828b6603130a21a4b9d66e855d6032})

We can now even store a new snapshot at 39842441 by initializing from the existing snapshot at 39842331

λ cabal run ouroboros-consensus-cardano:db-analyser -- \
  --db db_mainnet_with_alonzo_40217333 cardano \
  --configByron dbacfg/mainnet-byron-genesis.json \
  --configShelley dbacfg/mainnet-shelley-genesis.json \
  --nonce 1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81 \
  --configAlonzo dbacfg/mainnet-alonzo-genesis.json \
  --store-ledger 39842441 \
  --num-blocks-to-process 10 
  --only-immutable-db
  --analyse-from 39842331

About to store snapshot of a ledger at SlotNo 39842441 this might take a while...
storing state at BlockNo 6232314	SlotNo 39842441	6d793c1dfc019f152d0df9a7eececdf0de0a5982aaf7cdc80555904b36b24ce8

And now we can check that it actually worked.

  1. new snapshot was created (39842441_db-analyser)
λ ls -lath db_mainnet_with_alonzo_40217333/ledger
total 3.7G
-rw-r--r-- 1 encodepanda 732M Sep 28 15:43 39842441_db-analyser
drwxr-xr-x 7 encodepanda  224 Sep 28 15:43 .
-rw-r--r-- 1 encodepanda 732M Sep 28 13:36 39842331_db-analyser
-rw-r--r-- 1 encodepanda 747M Sep 22 10:22 40174168_db-analyser
(...)
  1. we can start db-analyser from that newly created snapshot
λ cabal run ouroboros-consensus-cardano:db-analyser -- \
  --db db_mainnet_with_alonzo_40217333 cardano \
  --configByron dbacfg/mainnet-byron-genesis.json \
  --configShelley dbacfg/mainnet-shelley-genesis.json \
  --nonce 1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81 \
  --configAlonzo dbacfg/mainnet-alonzo-genesis.json \
  --show-slot-block-no \
  --num-blocks-to-process 15 \
  --only-immutable-db \
  --analyse-from 39842441 

BlockNo 6232315	SlotNo 39842449
BlockNo 6232316	SlotNo 39842460
BlockNo 6232317	SlotNo 39842492
BlockNo 6232318	SlotNo 39842508
BlockNo 6232319	SlotNo 39842527
BlockNo 6232320	SlotNo 39842542
BlockNo 6232321	SlotNo 39842545
BlockNo 6232322	SlotNo 39842580
BlockNo 6232323	SlotNo 39842586
BlockNo 6232324	SlotNo 39842602
BlockNo 6232325	SlotNo 39842616
BlockNo 6232326	SlotNo 39842658
BlockNo 6232327	SlotNo 39842695
BlockNo 6232328	SlotNo 39842708
BlockNo 6232329	SlotNo 39842731
ChainDB tip: At (Block {blockPointSlot = SlotNo 40217333, blockPointHash = fd4487549a0d2c6dcba32255c2a4f7e1419cb1c88a07b8872a32db19e4b02a41})

@EncodePanda EncodePanda changed the title [WIP][CAD-3383] Init db-analyser from stored ledger state snapshot [CAD-3383] Init db-analyser from stored ledger state snapshot Sep 28, 2021
@EncodePanda EncodePanda force-pushed the EncodePanda/CAD-3383/init-from-snapshot branch 2 times, most recently from 2058b15 to 3390718 Compare September 28, 2021 21:14
Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

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

I'm Requesting Changes if only to ensure the --help text becomes more specific. But we may need to have a higher-level conversation (at our Wednesday sync, tomorrow) about what it means for the tool "to start from a snapshot".

@EncodePanda EncodePanda force-pushed the EncodePanda/CAD-3383/init-from-snapshot branch from 3390718 to 214cf82 Compare October 4, 2021 10:08
Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

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

I made some suggestions for simplifying based on the fact that a ChainDB-based analysis always starts from Origin (since we had decided that --analyse-from should require --only-immutable-db).

Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

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

Approved!

  • Please clean-up commits before merging (looks like the last two have the same message?)

  • Similarly, somethings (like --onlyImmutableDb having old capitalization) are out of date in the PR description, which bors puts as the merge commit's message.

@EncodePanda EncodePanda force-pushed the EncodePanda/CAD-3383/init-from-snapshot branch 2 times, most recently from 5427bdf to 254a8c6 Compare October 6, 2021 10:26
Move implementation of streamAll to streamFrom, where `from` becomes
a parameter to that function. Then streamAll can just call streamFrom
with a GenesisPoint as an argument.
@EncodePanda EncodePanda force-pushed the EncodePanda/CAD-3383/init-from-snapshot branch from 254a8c6 to 1241181 Compare October 6, 2021 10:29
@EncodePanda EncodePanda removed the request for review from jasagredo October 6, 2021 10:46
@EncodePanda
Copy link
Contributor Author

bors merge

iohk-bors bot added a commit that referenced this pull request Oct 6, 2021
3397: [CAD-3383] Init db-analyser from stored ledger state snapshot r=EncodePanda a=EncodePanda

## TL;DR
You can now start db-analyser starting from a particular ledger state snapshot by providing `--analyse-from`
Note that this feature is only available when `--only-immutable-db` is active.

## Example usage

Consider ChainDB that holds snapshots `39842331` and `40174168`
```
 λ ls -lath db_mainnet_with_alonzo_40217333/ledger
total 2.9G
drwxr-xr-x 6 encodepanda  192 Sep 28 15:35 .
-rw-r--r-- 1 encodepanda 732M Sep 28 13:36 39842331_db-analyser
-rw-r--r-- 1 encodepanda 747M Sep 22 10:22 40174168_db-analyser
(...)
```

We can now run the `db-analyser` starting from one of the snapshots. Here we start from snapshot `39842331`, we ask for 10 blocks only and we want to print out their block and slot numbers

```
λ cabal run ouroboros-consensus-cardano:db-analyser -- \
  --db db_mainnet_with_alonzo_40217333 cardano \
  --configByron dbacfg/mainnet-byron-genesis.json \
  --configShelley dbacfg/mainnet-shelley-genesis.json \
  --nonce 1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81 \
  --configAlonzo dbacfg/mainnet-alonzo-genesis.json \
  --show-slot-block-no \
  --num-blocks-to-process 10 \
  --analyse-from 39842331
  --only-immutable-db

BlockNo 6232309	SlotNo 39842333
BlockNo 6232310	SlotNo 39842339
BlockNo 6232311	SlotNo 39842355
BlockNo 6232312	SlotNo 39842379
BlockNo 6232313	SlotNo 39842411
BlockNo 6232314	SlotNo 39842441
BlockNo 6232315	SlotNo 39842449
BlockNo 6232316	SlotNo 39842460
BlockNo 6232317	SlotNo 39842492
BlockNo 6232318	SlotNo 39842508
ImmutableDB tip: At (Block {blockPointSlot = SlotNo 40174168, blockPointHash = db782958bd783e491d750a84080194d118828b6603130a21a4b9d66e855d6032})
```

We can now even store a new snapshot at `39842441` by initializing from the existing snapshot at `39842331`

```
λ cabal run ouroboros-consensus-cardano:db-analyser -- \
  --db db_mainnet_with_alonzo_40217333 cardano \
  --configByron dbacfg/mainnet-byron-genesis.json \
  --configShelley dbacfg/mainnet-shelley-genesis.json \
  --nonce 1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81 \
  --configAlonzo dbacfg/mainnet-alonzo-genesis.json \
  --store-ledger 39842441 \
  --num-blocks-to-process 10 
  --only-immutable-db
  --analyse-from 39842331

About to store snapshot of a ledger at SlotNo 39842441 this might take a while...
storing state at BlockNo 6232314	SlotNo 39842441	6d793c1dfc019f152d0df9a7eececdf0de0a5982aaf7cdc80555904b36b24ce8
```

And now we can check that it actually worked.

1. new snapshot was created (`39842441_db-analyser`)

```
λ ls -lath db_mainnet_with_alonzo_40217333/ledger
total 3.7G
-rw-r--r-- 1 encodepanda 732M Sep 28 15:43 39842441_db-analyser
drwxr-xr-x 7 encodepanda  224 Sep 28 15:43 .
-rw-r--r-- 1 encodepanda 732M Sep 28 13:36 39842331_db-analyser
-rw-r--r-- 1 encodepanda 747M Sep 22 10:22 40174168_db-analyser
(...)
```

2. we can start db-analyser from that newly created snapshot

```
λ cabal run ouroboros-consensus-cardano:db-analyser -- \
  --db db_mainnet_with_alonzo_40217333 cardano \
  --configByron dbacfg/mainnet-byron-genesis.json \
  --configShelley dbacfg/mainnet-shelley-genesis.json \
  --nonce 1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81 \
  --configAlonzo dbacfg/mainnet-alonzo-genesis.json \
  --show-slot-block-no \
  --num-blocks-to-process 15 \
  --only-immutable-db \
  --analyse-from 39842441 

BlockNo 6232315	SlotNo 39842449
BlockNo 6232316	SlotNo 39842460
BlockNo 6232317	SlotNo 39842492
BlockNo 6232318	SlotNo 39842508
BlockNo 6232319	SlotNo 39842527
BlockNo 6232320	SlotNo 39842542
BlockNo 6232321	SlotNo 39842545
BlockNo 6232322	SlotNo 39842580
BlockNo 6232323	SlotNo 39842586
BlockNo 6232324	SlotNo 39842602
BlockNo 6232325	SlotNo 39842616
BlockNo 6232326	SlotNo 39842658
BlockNo 6232327	SlotNo 39842695
BlockNo 6232328	SlotNo 39842708
BlockNo 6232329	SlotNo 39842731
ChainDB tip: At (Block {blockPointSlot = SlotNo 40217333, blockPointHash = fd4487549a0d2c6dcba32255c2a4f7e1419cb1c88a07b8872a32db19e4b02a41})
```

Co-authored-by: EncodePanda <paul.szulc@gmail.com>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 6, 2021

Build failed:

Note that this flag is only optional if user is running
--only-immutable-db. We made that choice, because when running from ChainDB, the DB
will reply its ledger state(s) from most recent ledger. This might be
especially problematic when doing profiling - user would see
obfuscated data because additional objects would be loaded into memory
(intermediate ledgers etc). Thus we've decided (at
least for now) to not make it an option when running db-analyser with
whole ChainDB.

With this flag user can select which snapshot will be chosen to
initalize the db-analyser with. User provides the slot number and if
the snapshot with a name 'slotnumber_db-analyser' exists, the db-analyser
tool will start working starting from that snapshot (instead of
starting from genesis). This ledger will be then can be used with
processAll function (see --store-ledger as an example usage).
@EncodePanda EncodePanda force-pushed the EncodePanda/CAD-3383/init-from-snapshot branch from 1241181 to c71eea4 Compare October 6, 2021 20:02
@EncodePanda
Copy link
Contributor Author

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 7, 2021

@iohk-bors iohk-bors bot merged commit 0e7cc86 into master Oct 7, 2021
@iohk-bors iohk-bors bot deleted the EncodePanda/CAD-3383/init-from-snapshot branch October 7, 2021 08:37
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.

2 participants