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

[DRAFT] simulators: Beacon API Simulator #784

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
52 changes: 34 additions & 18 deletions clients/prysm-bn/prysm_bn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Immediately abort the script on any error encountered
set -e

if [ ! -f "/hive/input/genesis.ssz" ]; then
if [ ! -f "/hive/input/genesis.ssz" ] && [ ! -f "/hive/input/checkpoint_state.ssz" ]; then
if [ -z "$HIVE_ETH2_ETH1_RPC_ADDRS" ]; then
echo "genesis.ssz file is missing, and no Eth1 RPC addr was provided for building genesis from scratch."
# TODO: alternative to start from weak-subjectivity-state
Expand All @@ -26,22 +26,40 @@ esac

echo "bootnodes: ${HIVE_ETH2_BOOTNODE_ENRS}"

# znrt encodes the values of these items between double quotes (""), which is against the spec:
# https://github.com/ethereum/consensus-specs/blob/v1.1.10/configs/mainnet.yaml
sed -i 's/"\([[:digit:]]\+\)"/\1/' /hive/input/config.yaml
sed -i 's/"\(0x[[:xdigit:]]\+\)"/\1/' /hive/input/config.yaml
if [ -f "/hive/input/config.yaml" ]; then
# znrt encodes the values of these items between double quotes (""), which is against the spec:
# https://github.com/ethereum/consensus-specs/blob/v1.1.10/configs/mainnet.yaml
sed -i 's/"\([[:digit:]]\+\)"/\1/' /hive/input/config.yaml
sed -i 's/"\(0x[[:xdigit:]]\+\)"/\1/' /hive/input/config.yaml

if [ "$HIVE_TERMINAL_TOTAL_DIFFICULTY" != "" ]; then
sed -i '/TERMINAL_TOTAL_DIFFICULTY/d' /hive/input/config.yaml
echo "TERMINAL_TOTAL_DIFFICULTY: $HIVE_TERMINAL_TOTAL_DIFFICULTY" >> /hive/input/config.yaml
if [ "$HIVE_TERMINAL_TOTAL_DIFFICULTY" != "" ]; then
sed -i '/TERMINAL_TOTAL_DIFFICULTY/d' /hive/input/config.yaml
echo "TERMINAL_TOTAL_DIFFICULTY: $HIVE_TERMINAL_TOTAL_DIFFICULTY" >> /hive/input/config.yaml
fi

if [[ "$HIVE_ETH2_SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY" != "" ]]; then
echo "SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY: $HIVE_ETH2_SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY" >> /hive/input/config.yaml
fi

echo config.yaml:
cat /hive/input/config.yaml
config_option="--chain-config-file=/hive/input/config.yaml"
fi

if [[ "$HIVE_ETH2_SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY" != "" ]]; then
echo "SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY: $HIVE_ETH2_SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY" >> /hive/input/config.yaml
if [ -f "/hive/input/genesis.ssz" ]; then
genesis_option="--genesis-state=/hive/input/genesis.ssz"
fi

echo config.yaml:
cat /hive/input/config.yaml
if [ -f "/hive/input/checkpoint_state.ssz" ]; then
if [ ! -f "/hive/input/checkpoint_block.ssz" ]; then
echo "checkpoint_block.ssz file is missing"
exit 1
fi
checkpoint_option="--checkpoint-state=/hive/input/checkpoint_state.ssz --checkpoint-block=/hive/input/checkpoint_block.ssz"
fi
if [[ "$HIVE_ETH2_ETH1_RPC_ADDRS" != "" ]]; then
execution_option="--execution-endpoint=$HIVE_ETH2_ETH1_RPC_ADDRS --jwt-secret=/jwtsecret --deposit-contract=${HIVE_ETH2_CONFIG_DEPOSIT_CONTRACT_ADDRESS:-0x1111111111111111111111111111111111111111} --contract-deployment-block=${HIVE_ETH2_DEPOSIT_DEPLOY_BLOCK_NUMBER:-0}"
fi

CONTAINER_IP=`hostname -i | awk '{print $1;}'`
metrics_option=$([[ "$HIVE_ETH2_METRICS_PORT" == "" ]] && echo "--disable-monitoring=true" || echo "--disable-monitoring=false --monitoring-host=0.0.0.0 --monitoring-port=$HIVE_ETH2_METRICS_PORT")
Expand All @@ -65,22 +83,20 @@ echo Starting Prysm Beacon Node
--verbosity="$LOG" \
--accept-terms-of-use=true \
--datadir=/data/beacon \
--chain-config-file=/hive/input/config.yaml \
--genesis-state=/hive/input/genesis.ssz \
$config_option \
$genesis_option \
$bootnode_option \
$checkpoint_option \
--p2p-tcp-port="${HIVE_ETH2_P2P_TCP_PORT:-9000}" \
--p2p-udp-port="${HIVE_ETH2_P2P_UDP_PORT:-9000}" \
--p2p-host-ip="${CONTAINER_IP}" \
--p2p-local-ip="${CONTAINER_IP}" \
--execution-endpoint="$HIVE_ETH2_ETH1_RPC_ADDRS" \
--jwt-secret=/jwtsecret \
$execution_option \
--min-sync-peers=1 \
--subscribe-all-subnets=true \
--enable-debug-rpc-endpoints=true \
$metrics_option \
$builder_option \
--deposit-contract="${HIVE_ETH2_CONFIG_DEPOSIT_CONTRACT_ADDRESS:-0x1111111111111111111111111111111111111111}" \
--contract-deployment-block="${HIVE_ETH2_DEPOSIT_DEPLOY_BLOCK_NUMBER:-0}" \
--rpc-host=0.0.0.0 --rpc-port="${HIVE_ETH2_BN_GRPC_PORT:-3500}" \
--grpc-gateway-host=0.0.0.0 --grpc-gateway-port="${HIVE_ETH2_BN_API_PORT:-4000}" --grpc-gateway-corsdomain="*" \
--suggested-fee-recipient="0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B"
Expand Down
19 changes: 19 additions & 0 deletions simulators/beacon/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Build the simulator binary
FROM golang:1-alpine AS builder
RUN apk --no-cache add gcc musl-dev linux-headers cmake make clang build-base clang-static clang-dev

# Prepare workspace.
# Note: the build context of this simulator image is the parent directory!
ADD . /source

# Build within simulator folder
WORKDIR /source/api
RUN go build -o ./sim .

# Build the runner container.
FROM alpine:latest
ADD . /
COPY --from=builder /source/api/sim /
ADD ./api/tests /tests

ENTRYPOINT ["./sim"]
146 changes: 146 additions & 0 deletions simulators/beacon/api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
module github.com/ethereum/hive/simulators/beacon/api

go 1.20

require (
github.com/ethereum/go-ethereum v1.11.6
github.com/ethereum/hive v0.0.0-20230516150403-448156fa839e
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
github.com/holiman/uint256 v1.2.2
github.com/libp2p/go-libp2p v0.27.3
github.com/libp2p/go-libp2p-pubsub v0.9.3
github.com/marioevz/eth-clients v0.0.0-20230503173323-98293c926363
github.com/pkg/errors v0.9.1
github.com/protolambda/eth2api v0.0.0-20230316214135-5f8afbd6d05d
github.com/protolambda/zrnt v0.30.1-0.20230514200506-8154369c6d3e
github.com/protolambda/ztyp v0.2.2
github.com/prysmaticlabs/fastssz v0.0.0-20221107182844-78142813af44
github.com/prysmaticlabs/prysm/v4 v4.0.5
github.com/sirupsen/logrus v1.9.2
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/VictoriaMetrics/fastcache v1.12.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.0.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect
github.com/huin/goupnp v1.1.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/klauspost/compress v1.16.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
github.com/libp2p/go-mplex v0.7.0 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.1.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
github.com/libp2p/go-reuseport v0.2.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.0 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.53 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.9.0 // indirect
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.8.1 // indirect
github.com/multiformats/go-multihash v0.2.1 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo/v2 v2.9.2 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7 // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 // indirect
github.com/prysmaticlabs/gohashtree v0.0.3-alpha // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/quic-go/webtransport-go v0.5.2 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.16.1 // indirect
go.uber.org/fx v1.19.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84 // indirect
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
nhooyr.io/websocket v1.8.7 // indirect
)
Loading