Skip to content

Commit 2a14f45

Browse files
committed
Fix and update ledger-state benchmark instructions
1 parent 43f2d0a commit 2a14f45

File tree

2 files changed

+62
-29
lines changed

2 files changed

+62
-29
lines changed

libs/ledger-state/README.md

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,97 @@ the memory overhead.
99
In order to be able to use the tool we need to get ahold of current ledger
1010
state. For this we need to start a cardano node and wait for it to sync.
1111

12-
```haskell
13-
$ export CARDANO_DATA="${HOME}/iohk/chain/mainnet"
14-
$ mkdir -p "${CARDANO_DATA}"/db
12+
```shell
13+
$ export CARDANO_DATA=${HOME}/iohk/chain/mainnet
14+
$ mkdir -p "${CARDANO_DATA}/db"
1515
$ cd "${CARDANO_DATA}"
1616
```
1717

18-
Download all the [mainnet related config files](https://developers.cardano.org/docs/get-started/running-cardano/#mainnet--production):
18+
Download all the [mainnet related config files](https://developers.cardano.org/docs/get-started/cardano-node/running-cardano/#configuration-files):
19+
20+
```shell
21+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/config.json
22+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/db-sync-config.json
23+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/submit-api-config.json
24+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/topology.json
25+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/byron-genesis.json
26+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/shelley-genesis.json
27+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/alonzo-genesis.json
28+
curl -O -J https://book.play.dev.cardano.org/environments/mainnet/conway-genesis.json
1929
```
20-
curl -O -J https://hydra.iohk.io/build/7370192/download/1/mainnet-config.json
21-
curl -O -J https://hydra.iohk.io/build/7370192/download/1/mainnet-byron-genesis.json
22-
curl -O -J https://hydra.iohk.io/build/7370192/download/1/mainnet-shelley-genesis.json
23-
curl -O -J https://hydra.iohk.io/build/7370192/download/1/mainnet-alonzo-genesis.json
24-
curl -O -J https://hydra.iohk.io/build/7370192/download/1/mainnet-topology.json
30+
31+
Download or build copies of `cardano-node` and `cardano-cli`. A convenient way of doing this is to download the assets from one of the `cardano-node` [releases](https://github.com/IntersectMBO/cardano-node/releases) on GitHub. The Linux executables are statically linked, so will run on any system.
32+
2533
```
2634
2735
Start the node and wait for it to fully sync
2836
29-
```
37+
```shell
3038
$ export CARDANO_NODE_SOCKET_PATH="${CARDANO_DATA}/db/node.socket"
31-
$ cardano-node run
32-
--topology "${CARDANO_DATA}/mainnet-topology.json" \
33-
--database-path "${CARDANO_DATA}/db" \
34-
--socket-path "${CARDANO_NODE_SOCKET_PATH}" \
35-
--host-addr 127.0.0.1 \
36-
--port 3001 \
37-
--config "${CARDANO_DATA}/mainnet-config.json" &
39+
$ cardano-node run \
40+
--topology "${CARDANO_DATA}/topology.json" \
41+
--config "${CARDANO_DATA}/config.json" \
42+
--database-path "${CARDANO_DATA}/db" \
43+
--socket-path "${CARDANO_NODE_SOCKET_PATH}" \
44+
--host-addr 0.0.0.0 \
45+
--port 3001 &
3846
```
3947

40-
Dump the ledger state and focus back onto the node:
48+
Dump the ledger state:
49+
50+
```shell
51+
$ cardano-cli query ledger-state --mainnet \
52+
--socket-path "${CARDANO_NODE_SOCKET_PATH}" \
53+
--out-file "${CARDANO_DATA}/new-epoch-state.bin"
54+
```
55+
56+
Bring the node back into the foreground and use Ctrl-C to stop it:
4157

4258
```shell
43-
$ cardano-cli query ledger-state --mainnet --out-file "${CARDANO_DATA}/ledger-state.bin"
4459
$ fg
60+
$ ^C
4561
```
46-
Hit Ctr-C to stop the node
4762

48-
## Populate sqlite db
63+
## Populate sqlite db from `NewEpochState` file
4964

5065
```shell
51-
$ cabal run -- ledger-state:ledger-state --new-epoch-state-cbor="${CARDANO_DATA}/ledger-state.bin" --sqlite-db="${CARDANO_DATA}/ledger-state.sqlite"
66+
$ cabal run -- ledger-state:ledger-state \
67+
--new-epoch-state-cbor="${CARDANO_DATA}/new-epoch-state.bin" \
68+
--sqlite-db="${CARDANO_DATA}/epoch-state.sqlite"
5269
```
5370

54-
## Create NewEpochState from sqlite db
71+
## Create `EpochState` file from sqlite db
5572

5673
```shell
57-
$ cabal run -- ledger-state:ledger-state --epoch-state-cbor="${CARDANO_DATA}/ledger-state.bin" --sqlite-db="${CARDANO_DATA}/ledger-state.sqlite"
74+
$ cabal run -- ledger-state:ledger-state \
75+
--epoch-state-cbor="${CARDANO_DATA}/epoch-state.bin" \
76+
--sqlite-db="${CARDANO_DATA}/epoch-state.sqlite"
5877
```
5978

6079
## Running benchmarks
6180

6281
### Memory
6382

6483
```shell
65-
$ cabal bench ledger-state:memory --benchmark-options="--new-epoch-state-cbor=\"${CARDANO_DATA}/ledger-state.bin\" --new-epoch-state-sqlite=\"${CARDANO_DATA}/ledger-state.sqlite\""
84+
$ cabal build ledger-state:memory
85+
$ cabal bench ledger-state:memory -v0 \
86+
--benchmark-option="--new-epoch-state-cbor=${CARDANO_DATA}/new-epoch-state.bin" \
87+
--benchmark-option="--epoch-state-cbor=${CARDANO_DATA}/epoch-state.bin" \
88+
--benchmark-option="--sqlite-db=${CARDANO_DATA}/epoch-state.sqlite" |
89+
tee ledger-state:memory.txt
6690
```
6791
### Performance
6892

6993
Performance benchmarks need an actual mainnet ledger state and genesis config
7094
file to run properly. It is not possible to add extra arguments to criterion cli
7195
menu, therefore paths to those files must be supplied as environment variables.
7296

97+
```shell
98+
$ export BENCH_GENESIS_PATH=${CARDANO_DATA}/shelley-genesis.json
99+
$ export BENCH_LEDGER_STATE_PATH=${CARDANO_DATA}/new-epoch-state.bin
100+
$ cabal bench ledger-state:performance --benchmark-option=--csv=ledger-state:performance.csv
101+
```
102+
103+
The csv file will be saved in the `libs/ledger-state` directory.
104+
105+
Since the `performance` benchmark uses only `new-epoch-state.bin` you don't need to run the `sqlite.db` steps above if you want to run only the `performance` benchmark.

libs/ledger-state/app/Main.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import System.IO
1414
-- | Insight into options:
1515
--
1616
-- * `optsNewEpochStateBinaryFile` is for reading a previously serialized
17-
-- * `NewEpochState` produced by cadano-cli` and is used to populate sqlite
17+
-- * `NewEpochState` produced by cardano-cli` and is used to populate sqlite
1818
-- * database
1919
--
2020
-- * `optsEpochStateBinaryFile` is used for grabbing data from sqlite,
@@ -26,7 +26,7 @@ data Opts = Opts
2626
-- load into sqlite database
2727
, optsEpochStateBinaryFile :: Maybe FilePath
2828
-- ^ Path to the CBOR encoded EpochState data type, which will have data
29-
-- from sqlite database written into.
29+
-- from sqlite database written into it.
3030
, optsSqliteDbFile :: Maybe FilePath
3131
-- ^ Path to Sqlite database file.
3232
}
@@ -62,7 +62,7 @@ optsParser =
6262
<> value Nothing
6363
<> help
6464
( "Path to Sqlite database file. When supplied then new-epoch-state "
65-
<> "will be loaded into the databse. Requires --new-epoch-state-cbor"
65+
<> "will be loaded into the database. Requires --new-epoch-state-cbor"
6666
)
6767
)
6868

@@ -92,7 +92,7 @@ main = do
9292
epochState <- loadEpochState dbFp
9393
putStrLn "Loaded EpochState from the database"
9494
writeEpochState binFp epochState
95-
putStrLn $ "Written EpochState into: " ++ dbFpStr
95+
putStrLn $ "Written EpochState into: " ++ binFp
9696

9797
-- forM_ (optsSqliteDbFile opts) $ \dbFpStr -> do
9898
-- let dbFp = T.pack dbFpStr

0 commit comments

Comments
 (0)