Setup Optimism archive node for TheGraph MIPs programm

Maxim
4 min readJun 4, 2023

--

📸 If you do not download snapshot, synchronization lasts more than 2 weeks, download snapshot from ftp MIPs, you can in different ways, with aria2c to do it easier and faster, but to do this you need to get a list of files from the server, such as this way example:

get a list of files:

curl ftp://mips:thegraph@dropbox.pinax.network/optimism-attempt2/l2geth/datadir/geth/chaindata-part1/ | grep -o '[0-9]*.ldb' | awk '{print "ftp://dropbox.pinax.network/optimism-attempt2/l2geth/datadir/geth/chaindata-part1/" $1}' > part1.txt && curl ftp://mips:thegraph@dropbox.pinax.network/optimism-attempt2/l2geth/datadir/geth/chaindata-part2/ | grep -o '[0-9]*.ldb' | awk '{print "ftp://dropbox.pinax.network/optimism-attempt2/l2geth/datadir/geth/chaindata-part2/" $1}' >> part2.txt

and now give the received files to aria2c:

aria2c --file-allocation=none -c -d /root/.local/share/optimism/l2geth/datadir/ -x 16 -s 16 -j 44 --ftp-user=mips --ftp-passwd=thegraph --input-file=part1.txt

aria2c --file-allocation=none -c -d /root/.local/share/optimism/l2geth/datadir/ -x 16 -s 16 -j 44 --ftp-user=mips --ftp-passwd=thegraph --input-file=part2.txt

Optimism Baremetal Archive Node

# Pre-requisites
sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y

sudo apt install -y git make wget gcc pkg-config libusb-1.0-0-dev \
libudev-dev jq gcc g++ curl libssl-dev apache2-utils build-essential \
pkg-config

# Add to PATH
echo "export PATH="$PATH:/root/.foundry/bin:/usr/local/go/bin:/root/.local/bin"" >> /root/.bashrc

source /root/.bashrc

# Install go
wget https://go.dev/dl/go1.19.4.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz

# Install nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

# Download foundry
curl -L https://foundry.paradigm.xyz | bash

# Install foundry
foundryup

source /root/.bashrc

# Install node and yarn
nvm install 16 && npm install --global yarn && nvm use 16

source /root/.bashrc

# Check if go and npm are installed:
go version
nvm -v
npm -v
yarn -v

# Set symlinks for node and npm
sudo ln -s "$(which node)" /usr/bin/node
sudo ln -s "$(which npm)" /usr/bin/npm

Building Optimism DTL

cd /root/

git clone -b master https://github.com/ethereum-optimism/optimism.git

cd optimism

yarn

yarn build

mkdir -p /root/.local/share/optimism/dtl/datadir

Setting up the config file

# READ THIS CAREFULLY:

# You can either sync the DTL from ETH L1 or OP L2
# You need an Ethereum Mainnet RPC endpoint (can be full node or archive) if you want to sync from ETH L1
# You need an Alchemy Optimism endpoint if you want to sync from OP L2
# If you want to sync from L1, set DATA_TRANSPORT_LAYER__SYNC_FROM_L1=true and DATA_TRANSPORT_LAYER__SYNC_FROM_L2=false
# If you want to do it the other way, set them the other way around
# Same for ROLLUP_BACKEND=l1, if you're syncing from L2, change it to l2

# Syncing from L1 will always be 2000 blocks behind chainhead due to how rollups work.
# Recommended to sync from L2 via a free Alchemy account

echo "###### DTL ENV ######

DATA_TRANSPORT_LAYER__ADDRESS_MANAGER=0xdE1FCfB0851916CA5101820A69b13a4E276bd81F
DATA_TRANSPORT_LAYER__L1_START_HEIGHT=13596466
DATA_TRANSPORT_LAYER__CONFIRMATIONS=12
DATA_TRANSPORT_LAYER__DANGEROUSLY_CATCH_ALL_ERRORS=true
DATA_TRANSPORT_LAYER__DB_PATH=/root/.local/share/optimism/dtl/datadir
DATA_TRANSPORT_LAYER__ENABLE_METRICS=true
DATA_TRANSPORT_LAYER__ETH_NETWORK_NAME=mainnet
DATA_TRANSPORT_LAYER__L2_CHAIN_ID=10
DATA_TRANSPORT_LAYER__LOGS_PER_POLLING_INTERVAL=2000
DATA_TRANSPORT_LAYER__NODE_ENV=production
DATA_TRANSPORT_LAYER__POLLING_INTERVAL=500
DATA_TRANSPORT_LAYER__SENTRY_TRACE_RATE=0.05
DATA_TRANSPORT_LAYER__SERVER_HOSTNAME=0.0.0.0
DATA_TRANSPORT_LAYER__SERVER_PORT=7878
DATA_TRANSPORT_LAYER__TRANSACTIONS_PER_POLLING_INTERVAL=1000
DATA_TRANSPORT_LAYER__SYNC_FROM_L1=false
DATA_TRANSPORT_LAYER__L1_RPC_ENDPOINT=http://ip:port
DATA_TRANSPORT_LAYER__SYNC_FROM_L2=true
DATA_TRANSPORT_LAYER__L2_RPC_ENDPOINT=https://opt-mainnet.g.alchemy.com/v2/PROJECTID

###### L2 GETH OP ENV ######

NETWORK_NAME=mainnet
NODE_TYPE=archive
USING_OVM=true
SEQUENCER_CLIENT_HTTP=https://mainnet.optimism.io
BLOCK_SIGNER_ADDRESS=0x00000398232E2064F896018496b4b44b3D62751F
BLOCK_SIGNER_PRIVATE_KEY=6587ae678cf4fc9a33000cdbf9f35226b71dcc6a4684a31203241f9bcfd55d27
ETH1_CTC_DEPLOYMENT_HEIGHT=13596466
ETH1_SYNC_SERVICE_ENABLE=true
ROLLUP_CLIENT_HTTP=http://0.0.0.0:7878
ROLLUP_MAX_CALLDATA_SIZE=40000
ROLLUP_POLL_INTERVAL_FLAG=1s
ROLLUP_VERIFIER_ENABLE=true
ROLLUP_DISABLE_TRANSFERS=false
ROLLUP_ENABLE_L2_GAS_POLLING=false
ROLLUP_GAS_PRICE_ORACLE_OWNER_ADDRESS=0x648E3e8101BFaB7bf5997Bd007Fb473786019159
ROLLUP_BACKEND=l2


###### L2 GETH ENV ######

GCMODE=archive
CACHE=32768
DATADIR=/root/.local/share/optimism/l2geth/datadir
CHAIN_ID=10
NETWORK_ID=10
NO_DISCOVER=true
NO_USB=true
GASPRICE=0
TARGET_GAS_LIMIT=15000000
RPC_ADDR=0.0.0.0
RPC_API=eth,rollup,net,web3,debug
RPC_CORS_DOMAIN=*
RPC_ENABLE=true
RPC_PORT=9656
RPC_VHOSTS=*
WS_ADDR=0.0.0.0
WS_API=eth,rollup,net,web3,debug
WS_ORIGINS=*
WS=true" >> /root/optimism/packages/data-transport-layer/.env
# Run DTL
systemctl daemon-reload
systemctl restart dtl
# Viewing Logs
journalctl -fu dtl

# To verify that DTL is running correctly you can run a command If synchronizing from L1:

curl -s http://localhost:7878/eth/syncing?backend=l2 | jq .currentTransactionIndex

Building and preparing L2 GETH

cd /root/optimism/l2geth

make geth

mkdir -p /root/.local/share/optimism/l2geth/genesis/

mkdir -p /root/.local/share/optimism/l2geth/datadir/

# Download the genesis file

wget -O /root/.local/share/optimism/l2geth/genesis/genesis.json https://storage.googleapis.com/optimism/mainnet/genesis-berlin.json

# Init L2 GETH - this takes a while depending on your machine's specs

set -o allexport; source /root/optimism/packages/data-transport-layer/.env; set +o allexport; /root/optimism/l2geth/build/bin/geth init --datadir=/root/.local/share/optimism/l2geth/datadir /root/.local/share/optimism/l2geth/genesis/genesis.json --no-usb

# Import the block signer account

touch $DATADIR/password
echo $BLOCK_SIGNER_PRIVATE_KEY > $DATADIR/block-signer-key

/root/optimism/l2geth/build/bin/geth account import --datadir=$DATADIR --password $DATADIR/password $DATADIR/block-signer-key

# Run L2 GETH

systemctl daemon-reload
systemctl restart l2geth
# journalctl -fu l2geth

# To check if l2geth is running correctly, open another command line window and run these commands:

/root/optimism/l2geth/build/bin/geth attach --datadir=/root/.local/share/optimism/l2geth/datadir

eth.blockNumber

# Wait a few seconds and then look at the blocknumber again and exit:
# If L2 GETH is synchronizing, the second block number is higher than the first.
# DTL Systemd
[Unit]
Description=Optimism DTL Service
After=network.target
StartLimitIntervalSec=60
StartLimitBurst=3

[Service]
Type=simple
Restart=on-failure
RestartSec=5
TimeoutSec=900
User=root
Nice=0
LimitNOFILE=200000
WorkingDirectory=/root/optimism/packages/data-transport-layer/
ExecStart=/root/.nvm/versions/node/v16.20.0/bin/yarn start
EnvironmentFile=/root/optimism/packages/data-transport-layer/.env

KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target

# Systemd file for Optimism L2 GETH

[Unit]
Description=Optimism L2 GETH Service
After=network.target
StartLimitIntervalSec=60
StartLimitBurst=3

[Service]
Type=simple
Restart=on-failure
RestartSec=5
TimeoutSec=900
User=root
Nice=0
LimitNOFILE=200000
WorkingDirectory=/root/optimism
EnvironmentFile=/root/optimism/packages/data-transport-layer/.env
ExecStart=/root/optimism/l2geth/build/bin/geth \
--datadir=/root/.local/share/optimism/l2geth/datadir \
--password=/root/.local/share/optimism/l2geth/datadir/password \
--allow-insecure-unlock \
--unlock=0x00000398232E2064F896018496b4b44b3D62751F \
--mine \
--miner.etherbase=0x00000398232E2064F896018496b4b44b3D62751F \
--vmodule=eth/*=5,miner=4,rpc=5,rollup=4,consensus/clique=1 \
--cache=32768

KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target

--

--