Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Arbitrum One and Arbitrum Nova Support #1112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BIN_IMAGE = blockbook-build
DEB_IMAGE = blockbook-build-deb
PACKAGER = $(shell id -u):$(shell id -g)
DOCKER_VERSION = $(shell docker version --format '{{.Client.Version}}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same docker version installed on host machine for deb image for safety

BASE_IMAGE = $$(awk -F= '$$1=="ID" { print $$2 ;}' /etc/os-release):$$(awk -F= '$$1=="VERSION_ID" { print $$2 ;}' /etc/os-release | tr -d '"')
NO_CACHE = false
TCMALLOC =
Expand All @@ -27,7 +28,7 @@ test-all: .bin-image
docker run -t --rm -e PACKAGER=$(PACKAGER) -v "$(CURDIR):/src" --network="host" $(BIN_IMAGE) make test-all ARGS="$(ARGS)"

deb-backend-%: .deb-image
docker run -t --rm -e PACKAGER=$(PACKAGER) -v "$(CURDIR):/src" -v "$(CURDIR)/build:/out" $(DEB_IMAGE) /build/build-deb.sh backend $* $(ARGS)
docker run -t --rm -e PACKAGER=$(PACKAGER) -v /var/run/docker.sock:/var/run/docker.sock -v "$(CURDIR):/src" -v "$(CURDIR)/build:/out" $(DEB_IMAGE) /build/build-deb.sh backend $* $(ARGS)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mount docker socket to enable the ability to pull docker images from inside a docker container


deb-blockbook-%: .deb-image
docker run -t --rm -e PACKAGER=$(PACKAGER) -v "$(CURDIR):/src" -v "$(CURDIR)/build:/out" $(DEB_IMAGE) /build/build-deb.sh blockbook $* $(ARGS)
Expand Down Expand Up @@ -55,7 +56,7 @@ build-images: clean-images
.deb-image: .bin-image
@if [ $$(build/tools/image_status.sh $(DEB_IMAGE):latest build/docker) != "ok" ]; then \
echo "Building image $(DEB_IMAGE)..."; \
docker build --no-cache=$(NO_CACHE) -t $(DEB_IMAGE) build/docker/deb; \
docker build --no-cache=$(NO_CACHE) --build-arg DOCKER_VERSION=$(DOCKER_VERSION) -t $(DEB_IMAGE) build/docker/deb; \
else \
echo "Image $(DEB_IMAGE) is up to date"; \
fi
Expand Down
77 changes: 77 additions & 0 deletions bchain/coins/arbitrum/arbitrumrpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package arbitrum

import (
"context"
"encoding/json"

"github.com/golang/glog"
"github.com/juju/errors"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/eth"
)

const (
ArbitrumOneMainNet eth.Network = 42161
ArbitrumNovaMainNet eth.Network = 42170
)

// ArbitrumRPC is an interface to JSON-RPC arbitrum service.
type ArbitrumRPC struct {
*eth.EthereumRPC
}

// NewArbitrumRPC returns new ArbitrumRPC instance.
func NewArbitrumRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
c, err := eth.NewEthereumRPC(config, pushHandler)
if err != nil {
return nil, err
}

s := &ArbitrumRPC{
EthereumRPC: c.(*eth.EthereumRPC),
}

return s, nil
}

// Initialize arbitrum rpc interface
func (b *ArbitrumRPC) Initialize() error {
b.OpenRPC = eth.OpenRPC

rc, ec, err := b.OpenRPC(b.ChainConfig.RPCURL)
if err != nil {
return err
}

// set chain specific
b.Client = ec
b.RPC = rc
b.NewBlock = eth.NewEthereumNewBlock()
b.NewTx = eth.NewEthereumNewTx()

ctx, cancel := context.WithTimeout(context.Background(), b.Timeout)
defer cancel()

id, err := b.Client.NetworkID(ctx)
if err != nil {
return err
}

// parameters for getInfo request
switch eth.Network(id.Uint64()) {
case ArbitrumOneMainNet:
b.MainNetChainID = ArbitrumOneMainNet
b.Testnet = false
b.Network = "livenet"
case ArbitrumNovaMainNet:
b.MainNetChainID = ArbitrumNovaMainNet
b.Testnet = false
b.Network = "livenet"
default:
return errors.Errorf("Unknown network id %v", id)
}

glog.Info("rpc: block chain ", b.Network)

return nil
}
5 changes: 5 additions & 0 deletions bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/juju/errors"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/arbitrum"
"github.com/trezor/blockbook/bchain/coins/avalanche"
"github.com/trezor/blockbook/bchain/coins/bch"
"github.com/trezor/blockbook/bchain/coins/bellcoin"
Expand Down Expand Up @@ -141,6 +142,10 @@ func init() {
BlockChainFactories["Polygon Archive"] = polygon.NewPolygonRPC
BlockChainFactories["Optimism"] = optimism.NewOptimismRPC
BlockChainFactories["Optimism Archive"] = optimism.NewOptimismRPC
BlockChainFactories["Arbitrum"] = arbitrum.NewArbitrumRPC
BlockChainFactories["Arbitrum Archive"] = arbitrum.NewArbitrumRPC
BlockChainFactories["Arbitrum Nova"] = arbitrum.NewArbitrumRPC
BlockChainFactories["Arbitrum Nova Archive"] = arbitrum.NewArbitrumRPC
}

// NewBlockChain creates bchain.BlockChain and bchain.Mempool for the coin passed by the parameter coin
Expand Down
10 changes: 10 additions & 0 deletions build/docker/deb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ RUN apt-get update && \
apt-get install -y devscripts debhelper make dh-exec zstd && \
apt-get clean

# install docker cli
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Install docker cli to enable binary via docker image

ARG DOCKER_VERSION

RUN if [ -z "$DOCKER_VERSION" ]; then echo "DOCKER_VERSION is a required build arg" && exit 1; fi

RUN wget -O docker.tgz "https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz" && \
tar -xzf docker.tgz --strip 1 -C /usr/local/bin/ && \
rm docker.tgz && \
docker --version

ADD gpg-keys /tmp/gpg-keys
RUN gpg --batch --import /tmp/gpg-keys/*

Expand Down
12 changes: 11 additions & 1 deletion build/templates/backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
ARCHIVE := $(shell basename {{.Backend.BinaryURL}})

all:
mkdir backend
{{- if ne .Backend.DockerImage "" }}
docker container inspect extract > /dev/null 2>&1 && docker rm extract || true
docker create --name extract {{.Backend.DockerImage}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create docker extraction image to allow copying of pre-built contents directly from the official docker image

{{- if eq .Backend.VerificationType "docker"}}
[ "$$(docker inspect --format='{{`{{index .RepoDigests 0}}`}}' {{.Backend.DockerImage}} | sed 's/.*@sha256://')" = "{{.Backend.VerificationSource}}" ]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker verification type will validate the hash of the specified docker image

{{- end}}
{{.Backend.ExtractCommand}}
docker rm extract
{{- else }}
wget {{.Backend.BinaryURL}}
{{- if eq .Backend.VerificationType "gpg"}}
wget {{.Backend.VerificationSource}} -O checksum
Expand All @@ -13,8 +23,8 @@ all:
{{- else if eq .Backend.VerificationType "sha256"}}
[ "$$(sha256sum ${ARCHIVE} | cut -d ' ' -f 1)" = "{{.Backend.VerificationSource}}" ]
{{- end}}
mkdir backend
{{.Backend.ExtractCommand}} ${ARCHIVE}
{{- end}}
{{- if .Backend.ExcludeFiles}}
# generated from exclude_files
{{- range $index, $name := .Backend.ExcludeFiles}}
Expand Down
34 changes: 34 additions & 0 deletions build/templates/backend/scripts/arbitrum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

{{define "main" -}}

set -e

INSTALL_DIR={{.Env.BackendInstallPath}}/{{.Coin.Alias}}
DATA_DIR={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend

NITRO_BIN=$INSTALL_DIR/nitro

$NITRO_BIN \
--chain.name arb1 \
--init.url https://snapshot.arbitrum.foundation/arb1/nitro-pruned.tar \
--init.download-path $DATA_DIR/tmp \
--auth.jwtsecret $DATA_DIR/jwtsecret \
--persistent.chain $DATA_DIR \
--parent-chain.connection.url http://127.0.0.1:8136 \
--parent-chain.blob-client.beacon-url http://127.0.0.1:7536 \
--http.addr 127.0.0.1 \
--http.port {{.Ports.BackendHttp}} \
--http.api eth,net,web3,debug,txpool,arb \
--http.vhosts '*' \
--http.corsdomain '*' \
--ws.addr 127.0.0.1 \
--ws.api eth,net,web3,debug,txpool,arb \
--ws.port {{.Ports.BackendRPC}} \
--ws.origins '*' \
--file-logging.enable='false' \
--node.staker.enable='false' \
--execution.tx-lookup-limit 0 \
--validation.wasm.allowed-wasm-module-roots "$INSTALL_DIR/nitro-legacy/machines,$INSTALL_DIR/target/machines"

{{end}}
35 changes: 35 additions & 0 deletions build/templates/backend/scripts/arbitrum_archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

{{define "main" -}}

set -e

INSTALL_DIR={{.Env.BackendInstallPath}}/{{.Coin.Alias}}
DATA_DIR={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend

NITRO_BIN=$INSTALL_DIR/nitro

$NITRO_BIN \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have found that running this script demands write access to /home/arbitrum (seems like some data directory for the app?). It is not acceptable for us, is it possible to somehow override this with some option? We would like e.g. the DATA_DIR location

--chain.name arb1 \
--init.url https://snapshot.arbitrum.foundation/arb1/nitro-archive.tar \
--init.download-path $DATA_DIR/tmp \
--auth.jwtsecret $DATA_DIR/jwtsecret \
--persistent.chain $DATA_DIR \
--parent-chain.connection.url http://127.0.0.1:8136 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the archive version, port 8116 should be needed instead of 8136

--parent-chain.blob-client.beacon-url http://127.0.0.1:7536 \
--http.addr 127.0.0.1 \
--http.port {{.Ports.BackendHttp}} \
--http.api eth,net,web3,debug,txpool,arb \
--http.vhosts '*' \
--http.corsdomain '*' \
--ws.addr 127.0.0.1 \
--ws.api eth,net,web3,debug,txpool,arb \
--ws.port {{.Ports.BackendRPC}} \
--ws.origins '*' \
--file-logging.enable='false' \
--node.staker.enable='false' \
--execution.caching.archive \
--execution.tx-lookup-limit 0 \
--validation.wasm.allowed-wasm-module-roots "$INSTALL_DIR/nitro-legacy/machines,$INSTALL_DIR/target/machines"

{{end}}
34 changes: 34 additions & 0 deletions build/templates/backend/scripts/arbitrum_nova.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

{{define "main" -}}

set -e

INSTALL_DIR={{.Env.BackendInstallPath}}/{{.Coin.Alias}}
DATA_DIR={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend

NITRO_BIN=$INSTALL_DIR/nitro

$NITRO_BIN \
--chain.name nova \
--init.url https://snapshot.arbitrum.foundation/nova/nitro-pruned.tar \
--init.download-path $DATA_DIR/tmp \
--auth.jwtsecret $DATA_DIR/jwtsecret \
--persistent.chain $DATA_DIR \
--parent-chain.connection.url http://127.0.0.1:8136 \
--parent-chain.blob-client.beacon-url http://127.0.0.1:7536 \
--http.addr 127.0.0.1 \
--http.port {{.Ports.BackendHttp}} \
--http.api eth,net,web3,debug,txpool,arb \
--http.vhosts '*' \
--http.corsdomain '*' \
--ws.addr 127.0.0.1 \
--ws.api eth,net,web3,debug,txpool,arb \
--ws.port {{.Ports.BackendRPC}} \
--ws.origins '*' \
--file-logging.enable='false' \
--node.staker.enable='false' \
--execution.tx-lookup-limit 0 \
--validation.wasm.allowed-wasm-module-roots "$INSTALL_DIR/nitro-legacy/machines,$INSTALL_DIR/target/machines"

{{end}}
35 changes: 35 additions & 0 deletions build/templates/backend/scripts/arbitrum_nova_archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

{{define "main" -}}

set -e

INSTALL_DIR={{.Env.BackendInstallPath}}/{{.Coin.Alias}}
DATA_DIR={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend

NITRO_BIN=$INSTALL_DIR/nitro

$NITRO_BIN \
--chain.name nova \
--init.url https://snapshot.arbitrum.foundation/nova/nitro-archive.tar \
--init.download-path $DATA_DIR/tmp \
--auth.jwtsecret $DATA_DIR/jwtsecret \
--persistent.chain $DATA_DIR \
--parent-chain.connection.url http://127.0.0.1:8136 \
--parent-chain.blob-client.beacon-url http://127.0.0.1:7536 \
--http.addr 127.0.0.1 \
--http.port {{.Ports.BackendHttp}} \
--http.api eth,net,web3,debug,txpool,arb \
--http.vhosts '*' \
--http.corsdomain '*' \
--ws.addr 127.0.0.1 \
--ws.api eth,net,web3,debug,txpool,arb \
--ws.port {{.Ports.BackendRPC}} \
--ws.origins '*' \
--file-logging.enable='false' \
--node.staker.enable='false' \
--execution.caching.archive \
--execution.tx-lookup-limit 0 \
--validation.wasm.allowed-wasm-module-roots "$INSTALL_DIR/nitro-legacy/machines,$INSTALL_DIR/target/machines"

{{end}}
2 changes: 2 additions & 0 deletions build/tools/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Backend struct {
SystemUser string `json:"system_user"`
Version string `json:"version"`
BinaryURL string `json:"binary_url"`
DockerImage string `json:"docker_image"`
VerificationType string `json:"verification_type"`
VerificationSource string `json:"verification_source"`
ExtractCommand string `json:"extract_command"`
Expand Down Expand Up @@ -203,6 +204,7 @@ func LoadConfig(configsDir, coin string) (*Config, error) {
case "gpg":
case "sha256":
case "gpg-sha256":
case "docker":
default:
return nil, fmt.Errorf("Invalid verification type: %s", config.Backend.VerificationType)
}
Expand Down
65 changes: 65 additions & 0 deletions configs/coins/arbitrum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"coin": {
"name": "Arbitrum",
"shortcut": "ETH",
"label": "Arbitrum",
"alias": "arbitrum"
},
"ports": {
"backend_rpc": 8205,
"backend_p2p": 38405,
"backend_http": 8305,
"blockbook_internal": 9205,
"blockbook_public": 9305
},
"ipc": {
"rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}",
"rpc_timeout": 25
},
"backend": {
"package_name": "backend-arbitrum",
"package_revision": "satoshilabs-1",
"system_user": "arbitrum",
"version": "3.0.3",
"docker_image": "offchainlabs/nitro-node:v3.0.3-3ecd01e",
"verification_type": "docker",
"verification_source": "6bfb702e99d66db88658e712ed0d8691abe03797afe436eaab60a6f31e627e0d",
"extract_command": "docker cp extract:/home/user/target backend/target; docker cp extract:/home/user/nitro-legacy backend/nitro-legacy; docker cp extract:/usr/local/bin/nitro backend/nitro",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example of docker extract command. copy the nitro binary and associated wasm modules

"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/arbitrum_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
"exec_script": "arbitrum.sh",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log",
"postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret",
"service_type": "simple",
"service_additional_params_template": "",
"protect_memory": true,
"mainnet": true,
"server_config_file": "",
"client_config_file": ""
},
"blockbook": {
"package_name": "blockbook-arbitrum",
"system_user": "blockbook-arbitrum",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
"explorer_url": "",
"additional_params": "",
"block_chain": {
"parse": true,
"mempool_workers": 8,
"mempool_sub_workers": 2,
"block_addresses_to_keep": 300,
"additional_params": {
"mempoolTxTimeoutHours": 48,
"queryBackendOnMempoolResync": false,
"fiat_rates": "coingecko",
"fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}"
}
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "[email protected]"
}
}
Loading