Recommended configuration for mainnet, can appropriately downgrade for testnet.
For mainnet: Ensure Docker's home directory is set to the maximum available disk space and configure disk usage alerts.
For mainnet: Choose the Singapore region as the deployment location for your synchronization nodes.
Please ensure that time synchronization is enabled and set to UTC+0 on all deployment-related servers.
Server
Components
Recommended hardware
Comments
Database
Sync Server
state-db, prover-db
sync, prover
CPU: 64VCORE, >= 3050MHZ
RAM: 128G
DISK: 2000GB, NVMe SSD
Synchronize the L2 state from master node and L1, only one can run at a time.
RPC Server(s)
json-rpc, prover
CPU: 64VCORE, >= 3050MHZ
RAM: 128G
DISK: 2000GB, NVMe SSD
Provide access entry for external requests, can run multiple instances.
Deployment Steps
Prepare configuration files
docker-compose.yml
If you have modified the default configuration of the database container [merlin-state-db], please synchronize this configuration with [StateDB] in node.config.toml and databaseURL in prover.config.json.
CREATE DATABASE prover_db;
\connect prover_db;
CREATE SCHEMA state;
CREATE TABLE state.nodes (hash BYTEA PRIMARY KEY, data BYTEA NOT NULL);
CREATE TABLE state.program (hash BYTEA PRIMARY KEY, data BYTEA NOT NULL);
CREATE USER prover_user with password 'prover_password';
ALTER DATABASE prover_db OWNER TO prover_user;
ALTER SCHEMA state OWNER TO prover_user;
ALTER SCHEMA public OWNER TO prover_user;
ALTER TABLE state.nodes OWNER TO prover_user;
ALTER TABLE state.program OWNER TO prover_user;
ALTER USER prover_user SET SEARCH_PATH=state;
node.config.toml
Update [StateDB] if you use a customized database configuration.
# Confirm the creation date of below downloaded files; they must be on the same day.
# Testnet
wget https://rpc-snapshot.merlinchain.io/testnet_state_db.sql.tar.gz
wget https://rpc-snapshot.merlinchain.io/testnet_prover_db.sql.tar.gz
# Mainnet
wget https://rpc-snapshot.merlinchain.io/state_db.sql.tar.gz
wget https://rpc-snapshot.merlinchain.io/prover_db.sql.tar.gz
Prepare recovery script
git clone https://github.com/0xPolygon/cdk-validium-node.git
cd cdk-validium-node
# Recommend using Go 1.21 or a later version
go build -o ./build ./cmd
Prepare recovery configuration
# touch a config file named "snapshot_restore.toml"
vim snapshot_restore.toml
# update the database connection info based on your "docker-compose.yml"
[Log]
Environment = "production" # "production" or "development"
Level = "debug" # "info"
Outputs = ["stderr"]
[State]
[State.DB]
User = "state_user"
Password = "state_password"
Name = "state_db"
Host = "127.0.0.1"
Port = "5432"
EnableLog = false
MaxConns = 200
[HashDB]
User = "prover_user"
Password = "prover_password"
Name = "prover_db"
Host = "127.0.0.1"
Port = "5432"
EnableLog = false
MaxConns = 200
Execute recovery
# Assuming you are currently under previous Git directory, and the snapshot recovery file you downloaded is also in the current directory (or you can manually specify the location), execute the following command for recovery:
./build restore --cfg ./snapshot_restore.toml -is ./state_db.sql.tar.gz -ih ./prover_db.sql.tar.gz
Add extra index for state db
CREATE INDEX IF NOT EXISTS l2block_block_hash_idx ON state.l2block (block_hash);
CREATE INDEX IF NOT EXISTS l2block_created_at_idx ON state.l2block (created_at);
CREATE INDEX IF NOT EXISTS log_log_index_idx ON state.log (log_index);
CREATE INDEX IF NOT EXISTS log_topic0_idx ON state.log (topic0);
CREATE INDEX IF NOT EXISTS log_topic1_idx ON state.log (topic1);
CREATE INDEX IF NOT EXISTS log_topic2_idx ON state.log (topic2);
CREATE INDEX IF NOT EXISTS log_topic3_idx ON state.log (topic3);
CREATE INDEX IF NOT EXISTS idx_receipt_tx_index ON state.receipt (block_num, tx_index);
CREATE INDEX IF NOT EXISTS receipt_block_num_idx ON state.receipt USING btree (block_num);
Launch other containers
Sync Server
docker compose up -d cdk-validium-prover
docker compose up -d cdk-validium-pool-db
sleep 5
docker compose up -d cdk-validium-sync
RPC Server
docker compose up -d cdk-validium-prover
docker compose up -d cdk-validium-pool-db
sleep 5
docker compose up -d cdk-validium-json-rpc
The expected result should be a valid block number:
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2855"
}
Troubleshooting
Please note that there should be no indication of port occupation when checking the port mappings for Docker.
Ensure that in all your configuration files, the databases have the correct host / user / password value. You can test connectivity using the command line before proceeding with the installation.
Commercial RPC nodes
For reference, you can also subscribe to the following third-party RPC vendors.