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

Added reth support #48

Open
wants to merge 5 commits into
base: reflow
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
28 changes: 28 additions & 0 deletions clients/reth-gnosis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARG baseimage=ghcr.io/gnosischain/reth_gnosis
ARG tag=master

FROM $baseimage:$tag as builder

# Install script tools.
RUN apt-get update -y
RUN apt-get install -y bash curl jq

# Add genesis mapper script.
ADD genesis.json /genesis.json
ADD mapper.jq /mapper.jq

# Add the startup script.
ADD reth.sh /reth.sh
RUN chmod +x /reth.sh

# Add the enode URL retriever script.
ADD enode.sh /hive-bin/enode.sh
RUN chmod +x /hive-bin/enode.sh

# Create version.txt
RUN /usr/local/bin/reth --version | sed -e 's/reth \(.*\)/\1/' > /version.txt

# Export the usual networking ports to allow outside access to the node.
EXPOSE 8545 8546 30303 30303/udp

ENTRYPOINT ["/reth.sh"]
40 changes: 40 additions & 0 deletions clients/reth-gnosis/Dockerfile.git
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

### Build Reth From Git:
## Pulls reth from a git repository and builds it from source.

## Builder stage: Compiles reth from a git repository
FROM rust:latest as builder

ARG github=paradigmxyz/reth
ARG tag=main

RUN apt-get update && apt-get install -y libclang-dev pkg-config build-essential \
&& echo "Cloning: $github - $tag" \
&& git clone --depth 1 --branch $tag https://github.com/$github reth \
&& cd reth && cargo build --release \
&& cp target/release/reth /usr/local/bin/reth

## Final stage: Sets up the environment for running reth
FROM debian:latest
RUN apt-get update && apt-get install -y bash curl jq \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Copy compiled binary from builder
COPY --from=builder /usr/local/bin/reth /usr/local/bin/reth

# Add genesis mapper script, startup script, and enode URL retriever script
COPY genesis.json /genesis.json
COPY mapper.jq /mapper.jq
COPY reth.sh /reth.sh
COPY enode.sh /hive-bin/enode.sh

# Set execute permissions for scripts
RUN chmod +x /reth.sh /hive-bin/enode.sh

# Create version.txt
RUN /usr/local/bin/reth --version | head -1 > /version.txt

# Export the usual networking ports
EXPOSE 8545 8546 30303 30303/udp

ENTRYPOINT ["/reth.sh"]
38 changes: 38 additions & 0 deletions clients/reth-gnosis/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Build Reth Locally:
## Requires a copy of <reth>/ -> hive/clients/reth/<reth>

## Builder stage: Compiles reth from a git repository
FROM rust:latest as builder

# Default local client path: clients/reth/<reth>
ARG local_path=reth
COPY $local_path reth

RUN apt-get update && apt-get install -y libclang-dev pkg-config build-essential \
&& cd reth && cargo build --release \
&& cp target/release/reth /usr/local/bin/reth

## Final stage: Sets up the environment for running reth
FROM debian:latest
RUN apt-get update && apt-get install -y bash curl jq \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Copy compiled binary from builder
COPY --from=builder /usr/local/bin/reth /usr/local/bin/reth

# Add genesis mapper script, startup script, and enode URL retriever script
COPY genesis.json /genesis.json
COPY mapper.jq /mapper.jq
COPY reth.sh /reth.sh
COPY enode.sh /hive-bin/enode.sh

# Set execute permissions for scripts
RUN chmod +x /reth.sh /hive-bin/enode.sh

# Create version.txt
RUN /usr/local/bin/reth --version | head -1 > /version.txt

# Export the usual networking ports
EXPOSE 8545 8546 30303 30303/udp

ENTRYPOINT ["/reth.sh"]
8 changes: 8 additions & 0 deletions clients/reth-gnosis/enode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

TARGET_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}' "127.0.0.1:8545" )
TARGET_ENODE=$(echo ${TARGET_RESPONSE}| jq -r '.result.enode')

echo "$TARGET_ENODE"
256 changes: 256 additions & 0 deletions clients/reth-gnosis/genesis.json

Large diffs are not rendered by default.

286 changes: 286 additions & 0 deletions clients/reth-gnosis/mapper.jq

Large diffs are not rendered by default.

164 changes: 164 additions & 0 deletions clients/reth-gnosis/reth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/bin/bash

# Startup script to initialize and boot a reth instance.
#
# This script assumes the following files:
# - `reth` binary is located in the filesystem root
# - `genesis.json` file is located in the filesystem root (mandatory)
# - `chain.rlp` file is located in the filesystem root (optional)
# - `blocks` folder is located in the filesystem root (optional)
#
# This script can be configured using the following environment variables:
#
# - HIVE_BOOTNODE enode URL of the remote bootstrap node
# - HIVE_NETWORK_ID network ID number to use for the eth protocol
# - HIVE_FORK_HOMESTEAD block number of the homestead transition
# - HIVE_FORK_DAO_BLOCK block number of the DAO hard-fork transition
# - HIVE_FORK_TANGERINE block number of TangerineWhistle
# - HIVE_FORK_SPURIOUS block number of SpuriousDragon
# - HIVE_FORK_BYZANTIUM block number for Byzantium transition
# - HIVE_FORK_CONSTANTINOPLE block number for Constantinople transition
# - HIVE_FORK_PETERSBURG block number for ConstantinopleFix/Petersburg transition
# - HIVE_FORK_ISTANBUL block number for Istanbul transition
# - HIVE_FORK_MUIR_GLACIER block number for MuirGlacier transition
# - HIVE_SHANGHAI_TIMESTAMP timestamp for Shanghai transition
# - HIVE_CANCUN_TIMESTAMP timestamp for Cancun transition
# - HIVE_LOGLEVEL client log level
#
# These flags are NOT supported by reth
#
# - HIVE_GRAPHQL_ENABLED turns on GraphQL server
# - HIVE_CLIQUE_PRIVATEKEY private key for clique mining
# - HIVE_NODETYPE sync and pruning selector (archive, full, light)
# - HIVE_MINER address to credit with mining rewards
# - HIVE_MINER_EXTRA extra-data field to set for newly minted blocks

# Immediately abort the script on any error encountered
set -ex

# no ansi colors
export RUST_LOG_STYLE=never

reth=/usr/local/bin/reth

case "$HIVE_LOGLEVEL" in
0|1) FLAGS="$FLAGS -v" ;;
2) FLAGS="$FLAGS -vv" ;;
3) FLAGS="$FLAGS -vvv" ;;
4) FLAGS="$FLAGS -vvvv" ;;
5) FLAGS="$FLAGS -vvvvv" ;;
esac

# Create the data directory.
DATADIR="/reth-hive-datadir"
mkdir $DATADIR
FLAGS="$FLAGS --datadir $DATADIR"

# TODO If a specific network ID is requested, use that
#if [ "$HIVE_NETWORK_ID" != "" ]; then
# FLAGS="$FLAGS --networkid $HIVE_NETWORK_ID"
#else
# FLAGS="$FLAGS --networkid 1337"
#fi

# Configure the chain.
mv /genesis.json /genesis-input.json
jq -f /mapper.jq /genesis-input.json > /genesis.json

# Dump genesis.
if [ "$HIVE_LOGLEVEL" -lt 4 ]; then
echo "Supplied genesis state (trimmed, use --sim.loglevel 4 or 5 for full output):"
jq 'del(.alloc[] | select(.balance == "0x123450000000000000000"))' /genesis.json
else
echo "Supplied genesis state:"
cat /genesis.json
fi

echo "Command flags till now:"
echo $FLAGS

# Initialize the local testchain with the genesis state
echo "Initializing database with genesis state..."
$reth init $FLAGS --chain /genesis.json

# Make sure pruner doesn't start
echo -e "[prune]\\nblock_interval = 500_000" >> $DATADIR/reth.toml

# make sure we use the same genesis each time
FLAGS="$FLAGS --chain /genesis.json"

# Don't immediately abort, some imports are meant to fail
set +ex

# Load the test chain if present
echo "Loading initial blockchain..."
if [ -f /chain.rlp ]; then
RUST_LOG=info $reth import $FLAGS /chain.rlp
else
echo "Warning: chain.rlp not found."
fi

# Load the remainder of the test chain
echo "Loading remaining individual blocks..."
if [ -d /blocks ]; then
echo "Loading remaining individual blocks..."
for file in $(ls /blocks | sort -n); do
echo "Importing " $file
$reth import $FLAGS /blocks/$file
done
else
echo "Warning: blocks folder not found."
fi

# Only set boot nodes in online steps
# It doesn't make sense to dial out, use only a pre-set bootnode.
if [ "$HIVE_BOOTNODE" != "" ]; then
FLAGS="$FLAGS --bootnodes=$HIVE_BOOTNODE"
fi

# Configure any mining operation
# TODO
#if [ "$HIVE_MINER" != "" ]; then
# FLAGS="$FLAGS --mine --miner.etherbase $HIVE_MINER"
#fi
#if [ "$HIVE_MINER_EXTRA" != "" ]; then
# FLAGS="$FLAGS --miner.extradata $HIVE_MINER_EXTRA"
#fi

# Import clique signing key.
# TODO
#if [ "$HIVE_CLIQUE_PRIVATEKEY" != "" ]; then
# # Create password file.
# echo "Importing clique key..."
# echo "$HIVE_CLIQUE_PRIVATEKEY" > ./private_key.txt
#
# # Ensure password file is used when running geth in mining mode.
# if [ "$HIVE_MINER" != "" ]; then
# FLAGS="$FLAGS --miner.sigfile private_key.txt"
# fi
#fi

# If clique is expected enable auto-mine
if [ -n "${HIVE_CLIQUE_PRIVATEKEY}" ] || [ -n "${HIVE_CLIQUE_PERIOD}" ]; then
FLAGS="$FLAGS --auto-mine"
if [ -n "${HIVE_CLIQUE_PERIOD}" ]; then
FLAGS="$FLAGS --dev.block-time ${HIVE_CLIQUE_PERIOD}s"
fi
fi

# Configure RPC.
FLAGS="$FLAGS --http --http.addr=0.0.0.0 --http.api=admin,debug,eth,net,web3"
FLAGS="$FLAGS --ws --ws.addr=0.0.0.0 --ws.api=admin,debug,eth,net,web3"

if [ "$HIVE_TERMINAL_TOTAL_DIFFICULTY" != "" ]; then
JWT_SECRET="7365637265747365637265747365637265747365637265747365637265747365"
echo -n $JWT_SECRET > /jwt.secret
FLAGS="$FLAGS --authrpc.addr=0.0.0.0 --authrpc.jwtsecret=/jwt.secret"
fi

# Configure NAT
FLAGS="$FLAGS --nat none"
jq '(.alloc | with_entries(.key |= if (length == 40) then "0x" + . else . end)) as $new_alloc | .alloc = $new_alloc' /genesis.json > /genesis-temp.json && mv /genesis-temp.json /genesis.json
# Launch the main client.
echo "Running reth with flags: $FLAGS"
RUST_LOG=info $reth node $FLAGS
4 changes: 4 additions & 0 deletions configs/generic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- client: custom_client
build_args:
baseimage: custom_image
tag: custom_tag