0xPolygonHermez / cdk-erigon

Ethereum implementation on the efficiency frontier
GNU Lesser General Public License v3.0
35 stars 39 forks source link

cdk-erigon

cdk-erigon is a fork of Erigon, currently in Alpha, optimized for syncing with the Polygon Hermez zkEVM network.


Release Roadmap


Hardware requirements

Chain/Fork Support

Current status of cdk-erigon's support for running various chains and fork ids:

Dynamic Chain Configuration

To use chains other than the defaults above, a set of configuration files can be supplied to run any chain.

  1. Ensure your chain name starts with the word dynamic e.g. dynamic-mynetwork
  2. Create 3 files for dynamic configs (examples for Cardona in zk/examples/dynamic-configs, edit as required)
    • dynamic-{network}-allocs.json - the allocs file
    • dynamic-{network}-chainspec.json - the chainspec file
    • dynamic-{network}-conf.json - an additional configuration file
    • dynamic-{network}.yaml - the run config file for erigon. You can use any of the example yaml files at the root of the repo as a base and edit as required, but ensure the chain field is in the format dynamic-{network} and matches the names of the config files above.
  3. Place the erigon config file along with the other files in the directory of your choice, for example dynamic-mynetwork.

Tip: if you have allocs in the format from Polygon when originally launching the network you can save this file to the root of the cdk-erigon code base and run go run cmd/hack/allocs/main.go [your-file-name] to convert it to the format needed by erigon, this will form the dynamic-{network}-allocs.json file.

Tip: the contract addresses in the dynamic-{network}.yaml can be found in the files output when launching the network:

Mount the directory containing the config files on docker container: /dynamic-mynetwork for example

To use the new config when starting erigon use the --cfg flag with the path to the config file e.g. --cfg="/dynamic-mynetwork/dynamic-mynetwork.yaml"

Prereqs

In order to use the optimal vectorized poseidon hashing for the Sparse Merkle Tree, on x86 the following packages are required (for Apple silicon it will fall back to the iden3 library and as such these dependencies are not required in that case.

Please install:

Using the Makefile command: make build-libs will install these for the relevant architecture.

Due to dependency requirements Go 1.21 is required to build.

L1 Interaction

In order to retrieve data from the L1, the L1 syncer must be configured to know how to request the highest block, this can be configured by flag:

L1 Cache

The node can cache the L1 requests/responses to speed up the sync and enable quicker responses to RPC requests requiring for example OldAccInputHash from the L1. This is enabled by default, but can be controlled via the following flags:

To transplant the cache between datadirs, the l1cache dir can be copied. To use an upstream cdk-erigon node's L1 cache, the zkevm.l1-cache-enabled can be set to false, and the node provided the endpoint of the cache, instead of a regular L1 URL. e.g. zkevm.l1-rpc-url=http://myerigonnode:6969?endpoint=http%3A%2F%2Fsepolia-rpc.com&chainid=2440. NB: this node must be syncing the same network for any benefit!

Sequencer (WIP)

Enable Sequencer: CDK_ERIGON_SEQUENCER=1 ./build/bin/cdk-erigon <flags> Golang version >= 1.21; GCC 10+ or Clang; On Linux: kernel > v4

Special mode - L1 recovery

The sequencer supports a special recovery mode which allows it to continue the chain using data from the L1. To enable this add the flag zkevm.l1-sync-start-block: [first l1 block with sequencer data]. It is important to find the first block on the L1 from the sequencer contract that contains the sequenceBatches event. When the node starts up it will pull of the L1 data into the cdk-erigon database and use this during execution rather than waiting for transactions from the txpool, effectively rebuilding the chain from the L1 data. This can be used 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 (useful if you have an RPC node available to speed up the process).

Important Note: 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 sync limit flag to 100.

zkEVM-specific API Support

In order to enable the zkevm_ namespace, please add 'zkevm' to the http.api flag (see the example config below).

Supported

Supported (remote)

Configurable

Not yet supported

Deprecated

Limitations/Warnings/Performance

Initial SMT build performance can be increased if machine has enough RAM:


Configuration Files

Config files are the easiest way to configure cdk-erigon, there are examples in the repository for each network e.g. hermezconfig-mainnet.yaml.example.


Running CDK-Erigon

Run modes

cdk-erigon can be run as an RPC node which will use the data stream to fetch new block/batch information and track a remote sequencer (the default behaviour). It can also run as a sequencer. To enable the sequencer, set the CDK_ERIGON_SEQUENCER environment variable to 1 and start the node. 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.

Docker (DockerHub)

The image comes with 3 preinstalled default configs which you may wish to edit according to the config section below, otherwise you can mount your own config to the container as necessary.

A datadir must be mounted to the container to persist the chain data between runs.

Example commands:

Config

The examples are comprehensive but there are some key fields which will need setting e.g. datadir, and others you may wish to change to increase performance, e.g. zkevm.l1-rpc-url as the provided RPCs may have restrictive rate limits.

For a full explanation of the config options, see below:

Sequencer specific config:

Resource Utilisation config:

Useful config entries:

Metrics and pprof configuration flags:


Networks

Network Name Chain ID ForkID Genesis File RPC URL Rootchain Rollup Address
zkEVM Mainnet 1101 9 Link Mainnet RPC Ethereum Mainnet 0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2
zkEVM Cardona 2442 9 Link Cardona RPC Sepolia 0x32d33D5137a7cFFb54c5Bf8371172bcEc5f310ff

Health Checks

Additional Resources


Supported by Gateway.fm and Limechain.