> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monad.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Genesis Replay

> Re-execute historical blocks to reconstruct state

Genesis replay re-executes historical blocks so that additional copies of state are available at
any given point in time. Historically, blocks have been stored in a static archive format. This
process downloads those blocks and replays them through the EVM to reconstruct full state.

## Prerequisites

* monad version `0.12.3` or later
* Credentials and configuration to read from your chosen archive source (AWS, R2, MongoDB, MinIO,
  etc.). These are the same credentials used by `monad-archiver`; see
  [Running an Archive Server](/node-ops/archive-data/running-an-archive-server) for details.

## Setup

### 1. Prepare the block database directory

Choose a directory to store EVM-format historical blocks. This guide refers to it as `block-db`.

### 2. Initialize triedb

Create an empty `triedb`:

```bash theme={null}
monad-mpt \
    --storage /dev/triedb \
    --root-offsets-chunk-count 16 \
    --create-empty
```

### 3. Start the block writer

Run inside `tmux` or create a systemd service to download blocks continuously:

```bash theme={null}
monad-block-writer stream \
    --block-data-source <your source string> \
    --dest-path <your block-db path>
```

The source string follows the same format used by `monad-archiver`, for example
`"aws mainnet-deu-009-0"` or `"mongodb ..."`.

The block writer will:

1. Download all blocks from the source
2. Transform them into EVM format
3. Brotli-compress the data
4. Write blocks into subdirectories of the form `block-db/XM/<block_number>`, where
   `X = block_number / 1_000_000` (one million blocks per directory)

**Resumption behavior:** The writer saves a `latest` file in the `block-db` directory. If the
process stops, on the next startup it reads `latest` and compares it against the latest block
available from the `--block-data-source`, then continues from that point.

<Tip>
  If you only need a specific range of blocks, run `monad-block-writer stream --help` for range
  options.
</Tip>

### 4. Configure the replay service

While `monad-block-writer` is running, add the following systemd override for `monad-execution`
in a separate terminal:

```bash theme={null}
sudo systemctl edit monad-execution
```

```ini theme={null}
[Service]
ExecStart=
ExecStart=/usr/local/bin/monad \
    --chain "$CHAIN" \
    --as_eth_blocks \
    --block_db <your block-db path> \
    --nblocks 0 \
    --db /dev/triedb \
    --no-compaction \
    --trace_calls \
    --block-db-timeout 60

AllowedCPUs=
CPUAffinity=
Restart=
Restart=always
```

<Note>
  Ensure `$CHAIN` is defined in your environment. Valid options:

  * `ethereum_mainnet`
  * `monad_devnet`
  * `monad_testnet`
  * `monad_mainnet`
</Note>

**`--block-db-timeout`** sets the number of seconds the replay service will wait for new blocks
to appear in the block database. If the timeout is reached without new blocks, the replay service
will crash and be restarted by systemd. If this happens, verify that the block writer from step 3
is still running and writing blocks to disk. Set to `0` to disable retries.

### 5. Reload and start

```bash theme={null}
sudo systemctl daemon-reload
sudo systemctl restart monad-execution
```

## Running RPC on a replay host

If you want to run `monad-rpc` on this host, you must remove the `--ipc-path` flag from the
`monad-rpc` systemd configuration.
