Skip to content

Instantly share code, notes, and snippets.

@hkalina
Last active April 4, 2024 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkalina/9fa5bf30a64edf326023ca650f5c4613 to your computer and use it in GitHub Desktop.
Save hkalina/9fa5bf30a64edf326023ca650f5c4613 to your computer and use it in GitHub Desktop.

Replacing go-ethereum/lachesis-base with custom branch for development:

go mod edit -replace github.com/ethereum/go-ethereum=github.com/hkalina/go-ethereum@86abe1a01dc15bb3282628cc39eb7b451e6c1113
go mod edit -replace github.com/Fantom-foundation/lachesis-base=github.com/hkalina/lachesis-base@01569740d42de172b09866c8bb45e9aabd8b0235
GOPRIVATE=github.com/Fantom-foundation go mod tidy

Running Opera with websocket:

build/opera --genesis /media/sda2/opera/testnet.g --ipcpath /home/jkalina/.opera/opera.ipc \
    --http --http.addr 127.0.0.1 --http.port 18545 --http.corsdomain '*' --http.api eth,ftm,debug \
    --ws --ws.addr 127.0.0.1 --ws.port 18546 --ws.origins '*' --ws.api eth,ftm,debug \
    --datadir /media/sda2/opera/datadir-testnet-pebble/ --metrics --pprof --metrics.expensive

Capturing and browsing profiling data:

sudo -u opera opera attach /var/opera/mainnet/opera.ipc
> debug.cpuProfile('/tmp/testCpuProfile', 60)
> debug.writeMemProfile("/tmp/memprofile")
> debug.goTrace('/tmp/operaTrace', 60)
go tool pprof -http=localhost:8080 /usr/local/bin/opera /tmp/testCpuProfile
go tool trace -http=localhost:8080 /usr/local/bin/opera /tmp/operaTrace

Database stats and compact:

sudo -u opera opera attach /var/opera/mainnet/opera.ipc
debug.chaindbCompact()
debug.chaindbProperty("metrics")

Upgrading Opera on server:

sudo -u opera -i
cd go/src/go-opera/
git pull
make
exit
sudo cp -f /home/opera/go/src/go-opera/build/opera /usr/local/bin/opera
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/opera
sudo systemctl restart opera
sudo systemctl status opera

Importing/Exporting Events:

opera --datadir /var/opera/mainnet/ --pprof --metrics export events ./exported-events-file
opera --datadir /var/opera/mainnet/ --pprof --metrics --metrics.expensive import events ./exported-events-file

Prometheus

opera ... --pprof --metrics --metrics.expensive
curl http://localhost:6060/debug/metrics/prometheus

/etc/prometheus/prometheus.yml:

  - job_name: opera
    scrape_interval: 30s
    scrape_timeout: 30s
    metrics_path: '/debug/metrics/prometheus'
    static_configs:
      - targets: ['localhost:6060']

Obtaining running/blocked threads:

curl http://localhost:6060/debug/pprof/goroutine > gorutine
curl http://localhost:6060/debug/pprof/block > block
curl http://localhost:6060/debug/pprof/profile > cpuprofile
go tool pprof -http=:8080 ./gorutine

Testing RPC queries

Testing time and memory intensive RPC requests for all ERC-20 transfers:

{"id":58, "method":"eth_getLogs", "params": [{ "fromBlock": "0x10", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"] }]}

Get block (and transactions in it):

curl 'http://localhost:18545/' -X POST -H 'Content-Type: application/json' \
--data '{"id":1, "method":"eth_getBlockByNumber", "params": ["0x1", true]}'

Get all logs in a block range:

curl http://localhost:18545/ -X POST -H "Content-Type: application/json" \
--data '{"method":"eth_getLogs","params":[{"fromBlock": "0x0", "toBlock": "0x50"}],"id":1,"jsonrpc":"2.0"}'

Get ERC-20 transfers only:

curl http://localhost:37797/ -X POST -H "Content-Type: application/json" \
--data '{"method":"eth_getLogs","params":[{"fromBlock": "0x0", "toBlock": "0x60", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],"id":1,"jsonrpc":"2.0"}' | jq

debug_trace (testnet samples):

curl 'http://localhost:18545/' -X POST -H 'Content-Type: application/json' \
--data '{"id":1, "method":"debug_traceBlockByHash", "params": ["0x00000cab00006e30244b07ae80e50726dd910fb5c30ed25db49380f6c384e28d"]}'
curl 'http://localhost:18545/' -X POST -H 'Content-Type: application/json' \
--data '{"id":1, "method":"debug_traceTransaction", "params": ["0x408f985a7390e429247230d08eb4e4f1f6987db9b1436ccba9e616a77ad3b813"]}'

Testing debug_trace query:

curl 'http://rpcapi-tracing.fantom.network/' -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","id":3,"method":"debug_traceTransaction","params":["0x0182bfea01b334ac94eaa933a144f2936c1bec1f9f1e383ae7ff247d6ef32128",{"tracer":"callTracer"}]}'

Nonce:

curl 'http://localhost:18545/' -X POST -H 'content-type: application/json' --data-raw '{"method":"eth_getTransactionCount","params":["0x9066874c8F0308c25D832Ad5d6Da797bc44edF10","latest"],"id":7379,"jsonrpc":"2.0"}'

Get NetworkRules:

curl 'http://localhost:18545/' -X POST -H 'Content-Type: application/json' \
--data '{"id":1, "method":"ftm_getRules", "params": ["0x356B2"]}'

FTM specific methods:

curl 'http://rpcapi.fantom.network/' -X POST -H 'Content-Type: application/json' --data '{"id":1, "method":"ftm_getRules", "params": ["0x356B2"]}'
curl 'http://rpcapi.fantom.network/' -X POST -H 'Content-Type: application/json' --data '{"id":1, "method":"ftm_getEpochBlock", "params": ["0x356B2"]}'
curl 'http://rpcapi.fantom.network/' -X POST -H 'Content-Type: application/json' --data '{"id":1, "method":"ftm_currentEpoch"}'

Contract call:

curl 'http://norma-a.fantom.network:18545/' -X POST -H 'Content-Type: application/json' --data '{"id":1, "method":"eth_call", "params": [{ "from":"0x8488d47027300bef2aeed2d1badfc69081b31694", "to":"0x8a3bbcab308bf58b2fa338d57991c34e2b37606d", "data":"0xa9059cbb00000000000000000000000001624296820165acc432befef82addc9e6bd465a000000000000000000000000000000000000000000000000069789fbbc4f8000" }, "0x61B2B"]}'

Estimate gas:

curl 'http://norma-a.fantom.network:18545/' -X POST -H 'Content-Type: application/json' --data '{"id":1, "method":"eth_estimateGas", "params": [{ "from":"0x8488d47027300bef2aeed2d1badfc69081b31694", "to":"0x8a3bbcab308bf58b2fa338d57991c34e2b37606d", "data":"0xa9059cbb00000000000000000000000001624296820165acc432befef82addc9e6bd465a000000000000000000000000000000000000000000000000069789fbbc4f8000" }, "0x61B2B"]}'

Get code:

curl 'http://norma-a.fantom.network:18545/' -X POST -H 'Content-Type: application/json' --data '{"id":1, "method":"eth_getCode", "params": ["0x3bb7144beddd99172aaf65b105e6135b54525ba3", "latest"]}'

Get pending txs:

curl http://localhost:18545/ -X POST -H "Content-Type: application/json" \
--data '{"method":"txpool_content","params":[],"id":1,"jsonrpc":"2.0"}' | jq | less

Proof:

curl http://localhost:18545/ -X POST -H "Content-Type: application/json" \
--data '{"method":"eth_getProof","params":[ \
"0x948e7B62804b676Fe0196bCA4fEE7da7d5b8aBBa", \
["0xada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d"], \
"latest"],"id":1,"jsonrpc":"2.0"}' | jq

Opera using systemd

sudo nano /usr/lib/systemd/system/opera.service
[Unit]
Description=Fantom Opera Node
After=network.target auditd.service

[Service]
Type=simple
User=opera
Group=opera
WorkingDirectory=/var/opera
ExecStart=/usr/local/bin/opera \
    --datadir=/var/opera/mainnet \
    --genesis=/var/opera/mainnet/genesis.g \
    --config=/etc/opera/config.toml \
    --port=5050 \
    --cache=8192 \
    --maxpeers=201 \
    --verbosity=3 \
    --ws \
    --ws.addr=0.0.0.0 \
    --ws.port=18546 \
    --ws.origins="*" \
    --ws.api=eth,web3,net,ftm,sfc \
    --http \
    --http.addr=0.0.0.0 \
    --http.port=80 \
    --http.corsdomain="*" \
    --http.vhosts="*" \
    --http.api=eth,web3,net,ftm,sfc \
    --metrics --pprof
ExecStopPost=/bin/sleep 30
LimitNOFILE=262144
OOMScoreAdjust=-900
;Restart=on-failure
;RestartSec=30s
TimeoutSec=300

[Install]
WantedBy=multi-user.target
Alias=lachesis.service

Allow non-root process to open privileged port (0-1024):

sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/opera

Set higher limit on opened files (for Pebble database):

ulimit -n 262144

Opera ufw firewall configuration

sudo nano /etc/ufw/applications.d/opera-server
[Opera]
title=Fantom Foundation Opera server
description=Opera Net Server for Fantom with Lachesis consensus.
ports=5050/tcp|5050/udp
sudo nano /etc/ufw/applications.d/opera-api
[OperaAPI]
title=Fantom Foundation Opera RPC-API
description=Fantom Opera RPC-API Interface.
ports=80/tcp|18546/tcp
sudo ufw allow Opera
sudo ufw allow OperaAPI
sudo ufw allow from 1.2.3.4 to any app OperaAPI

Generating custom fakenet-based genesis:

build/opera --fakenet 1/1 --datadir /tmp/fakenet11 --statedb.impl=geth --http --http.api=eth,web3,net,ftm,txpool,abft,dag --http.corsdomain=*
...fill the chain with data...
build/opera export genesis --datadir /tmp/fakenet11 --export.evm.mode ext-mpt ./fakegenesis.g 0 4000

Private repository Go dependency

git config --global url."git@github.com:Fantom-foundation".insteadOf "https://github.com/Fantom-foundation"

Tgz genesis

cd /var/opera/mainnet
sudo tar -c --use-compress-program=pigz -f ../mainnet-archive.tar.gz carmen chaindata
cd ..
md5sum mainnet-archive.tar.gz | sudo tee mainnet-archive.tar.gz.md5

tar --use-compress-program=pigz -xvf ../mainnet-archive.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment