Skip to content

Import state from reth ​

This page tells you how to build the first Cinder database from the database of a synced reth node. Cinder cannot sync from genesis. At the end you have a Cinder database with the state of one block.

Before you start ​

  • A Cinder build. See Install Cinder.
  • A synced reth 2.x node with the default "storage v2" database layout. Reth can continue to run during the import.
  • The HTTP JSON-RPC API of that reth node, with the eth and debug namespaces. The default URL is http://127.0.0.1:8545.
  • Free disk space for the Cinder database: an NVMe SSD of 2 TB is recommended. Read Disk for the size and the growth. The import stops if less than 64 GB of disk space stays free.

Steps ​

  1. Check the import options.

    bash
    build/release/bin/cinder-import --help

    Output

    text
    usage: cinder-import --reth-db DIR --db OUT [--rpc URL] [--check-only] [--force] [--page-size BYTES]

    --reth-db is the db directory in the reth data directory. --db is a new, empty directory for Cinder. --rpc is the HTTP JSON-RPC URL of the same reth node. For all options, see the command line reference.

  2. Do only the checks first. With --check-only, the tool compares sample accounts with the answers of the reth RPC at the last block that reth finished, and then stops.

    bash
    build/release/bin/cinder-import --reth-db /path/to/reth/datadir/db --db ./cinder-data --rpc http://127.0.0.1:8545 --check-only

    Output

    If the tool cannot open the reth database, it prints this and stops:

    text
    cannot open reth database at /path/to/reth/datadir/db

    This is a description, not captured output. If the path is right, the tool prints the snapshot block, its state root and the size of the reth tables. Then it prints one line for each sample account and this last line:

    text
    pre-flight: N accounts, M slots checked against RPC at block B, 0 problems

    If the number of problems is not 0, do not import. Find the cause first.

  3. Run the import.

    bash
    build/release/bin/cinder-import --reth-db /path/to/reth/datadir/db --db ./cinder-data --rpc http://127.0.0.1:8545

    Output

    Example. The format comes from the code. The values come from the v0.2 import record (block 26063014).

    The tool prints a progress line at least every 30 seconds. At the end it prints one line for the imported block and one line for the check of the state root:

    text
    reth snapshot: block 26063014 0x...
      state root 0x...
      420909751 accounts, 1659034272 storage slots, 2798063 bytecodes
      ...
    state: 420909751 accounts, 1659034272 slots in ... s
    imported block 26063014: 420909751 accounts, 1659034272 slots, 2798063 bytecodes, 256 headers in ... s
    state root 0x... matches the header

    The import does these steps:

    1. It opens the reth database read-only, so reth can continue to run. It reads all of the state in one snapshot, at the last block that reth finished.
    2. It runs the checks of step 2. If a check fails, it stops.
    3. It compares the free disk space with an estimate of the database size. If the space is too small, it stops.
    4. It copies the accounts, storage slots and bytecodes, and builds the tries again.
    5. It computes the state root and compares it with the root in the block header. It writes the database head only if the two roots are equal.

    On mainnet, the import took about 3 hours. While the import runs, the reth database file grows, because the import keeps its read snapshot open. To import again, delete the Cinder database directory first.

Check the database (optional) ​

Shadow mode follows the reth node over JSON-RPC. It executes each new block against the Cinder database and compares the result with the block header. With --receipts, it also compares each receipt with the receipts of reth. This check is optional. Do it to find a wrong import before you connect a consensus client.

  1. Run shadow mode for three blocks.

    bash
    build/release/bin/cinder --shadow --db ./cinder-data --rpc http://127.0.0.1:8545 --threads 8 --receipts --blocks 3

    Output

    Example. The format comes from the code. The values are not from a captured run, so they show as ....

    The node prints one line for each block, then one summary line:

    text
    block B  txs ...  gas ...M  exec ... ms  root ... ms  commit ... ms  (N behind)
    block B+1  txs ...  gas ...M  exec ... ms  root ... ms  commit ... ms  (N behind)
    block B+2  txs ...  gas ...M  exec ... ms  root ... ms  commit ... ms  (N behind)
    3 blocks, ... Mgas: exec ... ms/block, root ... ms/block, commit ... ms/block; ... s total

    Shadow mode stays two blocks behind reth. It writes each block to the Cinder database. It stops on the first difference and prints the block number and the cause. Without --blocks, it runs until you press Ctrl-C. Press Ctrl-C between two blocks.

For more on shadow mode, see Engine mode and shadow mode.

Next: Run with a consensus client