|
| 1 | +## Prerequisites |
| 2 | + |
| 3 | +### Hardware requirements |
| 4 | + |
| 5 | +* A Linux-based OS (e.g. Ubuntu 22.04 LTS). |
| 6 | +* At least 32GB RAM with a 4-core CPU. |
| 7 | +* Both Apple Silicon and AMD64 are supported. |
| 8 | + |
| 9 | +!!! tip |
| 10 | + - On x86, the following packages are required to use the optimal, vectorized-Poseidon-hashing for the sparse Merkle tree: |
| 11 | + |
| 12 | + - Linux: `libgtest-dev libomp-dev libgmp-dev` |
| 13 | + - MacOS: `brew install libomp` `brew install gmp` |
| 14 | + |
| 15 | + - For Apple silicon, the `iden3` library is used instead. |
| 16 | + |
| 17 | +### Software |
| 18 | + |
| 19 | +The installation requires [Go 1.19](https://go.dev/doc/manage-install). |
| 20 | + |
| 21 | +### Set up |
| 22 | + |
| 23 | +1. Clone the repo and `cd` to the root: |
| 24 | + |
| 25 | + ```sh |
| 26 | + git clone https://github.com/0xPolygonHermez/cdk-erigon |
| 27 | + cd cdk-erigon/ |
| 28 | + ``` |
| 29 | + |
| 30 | +2. Install the relevant libraries for your architecture by running: |
| 31 | + |
| 32 | + ```sh |
| 33 | + make build-libs |
| 34 | + ``` |
| 35 | + |
| 36 | +## L1 interaction |
| 37 | + |
| 38 | +In order to retrieve data from L1, the L1 syncer needs to know how to request the highest block. |
| 39 | + |
| 40 | +This can be configured by the flag: `zkevm.l1-highest-block-type`. |
| 41 | + |
| 42 | +The flag defaults to retrieving the `finalized` block. However, there are cases where you may wish to pass `safe` or `latest`. |
| 43 | + |
| 44 | +## Set up sequencer |
| 45 | + |
| 46 | +!!! warning "Work in progress" |
| 47 | + - Sequencer is production ready from `v2.x.x` onwards. |
| 48 | + - Please check the [roadmap](releases.md#roadmap) for more information. |
| 49 | + |
| 50 | +Enable the sequencer by setting the following environment variable: |
| 51 | + |
| 52 | +```sh |
| 53 | +CDK_ERIGON_SEQUENCER=1 ./build/bin/cdk-erigon <flags> |
| 54 | +``` |
| 55 | + |
| 56 | +### Special mode - L1 recovery |
| 57 | + |
| 58 | +The sequencer supports a special recovery mode which allows it to continue the chain using data from the L1. |
| 59 | + |
| 60 | +To enable this add the following flag: |
| 61 | + |
| 62 | +```sh |
| 63 | +`zkevm.l1-sync-start-block: [first l1 block with sequencer data]`. |
| 64 | +``` |
| 65 | + |
| 66 | +!!! important |
| 67 | + Find the first block on the L1 from the sequencer contract that contains the `sequenceBatches` event. |
| 68 | + |
| 69 | +When the node starts up it pulls the L1 data into the `cdk-erigon` database and uses this during execution rather than waiting for transactions from the transaction pool, effectively rebuilding the chain from the L1 data. |
| 70 | + |
| 71 | +You can use this in tandem with unwinding the chain, or using the `zkevm.sync-limit` flag to limit the chain to a certain block height before starting the L1 recovery. This is useful if you have an RPC node available to speed up the process. |
| 72 | + |
| 73 | +!!! warning |
| 74 | + If using the `zkevm.sync-limit` flag, you need to go to the boundary of a `batch+1` block; so if batch `41` ends at block `99` then set the flag to `100`. |
| 75 | + |
| 76 | +## Enable zkEVM APIs |
| 77 | + |
| 78 | +In order to enable the `zkevm_ namespace`, add `zkevm` to the [`http.api`](#configurations) flag. |
| 79 | + |
| 80 | +### Supported functions |
| 81 | + |
| 82 | +- `zkevm_batchNumber` |
| 83 | +- `zkevm_batchNumberByBlockNumber` |
| 84 | +- `zkevm_consolidatedBlockNumber` |
| 85 | +- `zkevm_isBlockConsolidated` |
| 86 | +- `zkevm_verifiedBatchNumber` |
| 87 | +- `zkevm_isBlockVirtualized` |
| 88 | +- `zkevm_virtualBatchNumber` |
| 89 | +- `zkevm_getFullBlockByHash` |
| 90 | +- `zkevm_getFullBlockByNumber` |
| 91 | +- `zkevm_virtualCounters` |
| 92 | +- `zkevm_traceTransactionCounters` |
| 93 | + |
| 94 | +### Supported functions (remote) |
| 95 | + |
| 96 | +- `zkevm_getBatchByNumber` |
| 97 | + |
| 98 | +### Not yet supported |
| 99 | + |
| 100 | +- `zkevm_getNativeBlockHashesInRange` |
| 101 | + |
| 102 | +### Deprecated |
| 103 | + |
| 104 | +- `zkevm_getBroadcastURI` - removed by zkEVM. |
| 105 | + |
| 106 | +## Limitations/warnings |
| 107 | + |
| 108 | +- The golden poseidon hashing is much faster on x86, so developers using MacOS M1/M2 chips may experience slower processing. |
| 109 | +- Falling behind the network significantly causes an SMT rebuild which takes some time to complete on longer chains. |
| 110 | + |
| 111 | +## Configuration files |
| 112 | + |
| 113 | +- Config files are the easiest way to configure `cdk-erigon`. |
| 114 | +- There are examples files in the repository for each network; e.g. [`hermezconfig-mainnet.yaml.example`](https://github.com/0xPolygonHermez/cdk-erigon/blob/1d56fb0a5a64160fd8c05e11ffc8b668bd70b9e8/hermezconfig-mainnet.yaml.example#L4). |
| 115 | +- Depending on your RPC provider, you may wish to alter `zkevm.rpc-ratelimit` in the yaml file. |
| 116 | + |
| 117 | +## Running CDK Erigon |
| 118 | + |
| 119 | +1. Build the node with the following command: |
| 120 | + |
| 121 | + ```sh |
| 122 | + make cdk-erigon |
| 123 | + ``` |
| 124 | + |
| 125 | +2. Set up your config file by copying one of the examples found in the repository root directory, and edit as required and add your network name to the following command. |
| 126 | + |
| 127 | + ```sh |
| 128 | + run ./build/bin/cdk-erigon --config="./hermezconfig-{network}.yaml" |
| 129 | + ``` |
| 130 | + |
| 131 | +!!! warn |
| 132 | + Be aware that the `--externalcl` flag is removed upstream in `cdk-erigon` so take care when reusing commands/configurations. |
| 133 | + |
| 134 | +### Run modes |
| 135 | + |
| 136 | +`cdk-erigon` can run as an RPC node which uses the data stream to fetch new block/batch information and track a remote sequencer. This is the default behavior. |
| 137 | + |
| 138 | +It can also run as a sequencer. To enable the sequencer, set the `CDK_ERIGON_SEQUENCER` environment variable to `1` and start the node. |
| 139 | + |
| 140 | +!!! warning "Work in progress" |
| 141 | + - Sequencer is production ready from `v2.x.x` onwards. |
| 142 | + - Please check the [roadmap](releases.md#roadmap) for more information. |
| 143 | + |
| 144 | +`cdk-erigon` supports migrating a node from being an RPC node to a sequencer and vice versa. To do this, stop the node, set the `CDK_ERIGON_SEQUENCER` environment variable to the desired value and restart the node. Please ensure that you do include the sequencer specific flags found below when running as a sequencer. You can include these flags when running as an RPC to keep a consistent configuration between the two run modes. |
| 145 | + |
| 146 | +### Docker (DockerHub) |
| 147 | + |
| 148 | +The image comes with three preinstalled default configurations which you can edit according to the configuration section below; otherwise you can mount your own config to the container as necessary. |
| 149 | + |
| 150 | +A datadir must be mounted to the container to persist the chain data between runs. |
| 151 | + |
| 152 | +#### Example `docker` commands |
| 153 | + |
| 154 | +##### Mainnet |
| 155 | + |
| 156 | +```sh |
| 157 | +docker run -d -p 8545:8545 -v ./cdk-erigon-data/:/home/erigon/.local/share/erigon hermeznetwork/cdk-erigon --config="./mainnet.yaml" --zkevm.l1-rpc-url=https://rpc.eth.gateway.fm |
| 158 | +``` |
| 159 | + |
| 160 | +##### Cardona |
| 161 | + |
| 162 | +```sh |
| 163 | +docker run -d -p 8545:8545 -v ./cdk-erigon-data/:/home/erigon/.local/share/erigon hermeznetwork/cdk-erigon --config="./cardona.yaml" --zkevm.l1-rpc-url=https://rpc.sepolia.org |
| 164 | +``` |
| 165 | + |
| 166 | +#### Example `docker-compose` commands |
| 167 | + |
| 168 | +##### Mainnet |
| 169 | + |
| 170 | +```sh |
| 171 | +NETWORK=mainnet L1_RPC_URL=https://rpc.eth.gateway.fm docker-compose -f docker-compose-example.yml up -d |
| 172 | +``` |
| 173 | + |
| 174 | +##### Cardona: |
| 175 | + |
| 176 | +```sh |
| 177 | +NETWORK=cardona L1_RPC_URL=https://rpc.sepolia.org docker-compose -f docker-compose-example.yml up -d |
| 178 | +``` |
| 179 | + |
| 180 | +## Configurations |
| 181 | + |
| 182 | +The following examples are comprehensive. There are key fields which must be set, such as `datadir`, and some you may wish to change to increase performance, such as `zkevm.l1-rpc-url` as the provided RPCs may have restrictive rate limits. |
| 183 | + |
| 184 | +- `datadir`: Path to your node's data directory. |
| 185 | +- `chain`: Specifies the L2 network to connect with; e.g. `hermez-mainnet`. For dynamic configs this should always be in the format `dynamic-{network}`. |
| 186 | +- `http`: Enables HTTP RPC server (set to `true`). |
| 187 | +- `private.api.addr`: Address for the private API, typically `localhost:9091`. Change this to run multiple instances on the same machine. |
| 188 | +- `zkevm.l2-chain-id`: Chain ID for the L2 network; e.g. 1101. |
| 189 | +- `zkevm.l2-sequencer-rpc-url`: URL for the L2 sequencer RPC. |
| 190 | +- `zkevm.l2-datastreamer-url`: URL for the L2 data streamer. |
| 191 | +- `zkevm.l1-chain-id`: Chain ID for the L1 network. |
| 192 | +- `zkevm.l1-rpc-url`: L1 Ethereum RPC URL. |
| 193 | +- `zkevm.address-sequencer`: The contract address for the sequencer. |
| 194 | +- `zkevm.address-zkevm`: The address for the zkevm contract. |
| 195 | +- `zkevm.address-admin`: The address for the admin contract. |
| 196 | +- `zkevm.address-rollup`: The address for the rollup contract. |
| 197 | +- `zkevm.address-ger-manager`: The address for the GER manager contract. |
| 198 | +- `zkevm.rpc-ratelimit`: Rate limit for RPC calls. |
| 199 | +- `zkevm.data-stream-port`: Port for the data stream. This needs to be set to enable the datastream server. |
| 200 | +- `zkevm.data-stream-host`: The host for the data stream i.e. `localhost`. This must be set to enable the datastream server. |
| 201 | +- `zkevm.datastream-version`: Version of the data stream protocol. |
| 202 | +- `externalcl`: External consensus layer flag. |
| 203 | +- `http.api`: List of enabled HTTP API modules. |
| 204 | +
|
| 205 | +### Sequencer specific config |
| 206 | +
|
| 207 | +- `zkevm.executor-urls`: A csv list of the executor URLs. These are used in a round robbin fashion by the sequencer. |
| 208 | +- `zkevm.executor-strict`: Default is true but can be set to false when running the sequencer without verifications (_use with extreme caution_). |
| 209 | +- `zkevm.witness-full`: Default is true. Controls whether the full or partial witness is used with the executor. |
| 210 | +- `zkevm.sequencer-initial-fork-id`: The fork id to start the network with. |
| 211 | +
|
| 212 | +### Useful config entries |
| 213 | +
|
| 214 | +- `zkevm.sync-limit`: This ensures the network only syncs to a given block height. |
0 commit comments