Sign inSign up

0labs/prysm

By 0labs

•Updated about 4 years ago

Configure and operate Prysm: an Ethereum 2.0 client written in Go

Image
0

4.7K

0labs/prysm repository overview

OCI logo

Prysm logo

⁠Container File šŸŒ šŸ”— Prysm

GitHub release (latest by date) 0x0I Docker Pulls License: MIT

Configure and operate Prysm: A full-featured client for the Ethereum 2.0 protocol, written in Go

Overview

⁠Setup

Guidelines on running service containers are available and organized according to the following software & machine provisioning stages:

  • build
  • config
  • operations
⁠Build
⁠args
Namedescription
build_versionbase image to utilize for building application binaries/artifacts
bazelisk_versionversion of the bazelisk tool to use for application builds
prysm_versionprysm application version to build within image
goss_versiongoss testing tool version to install within image test target
versioncontainer/image infra application version
docker build --build-arg <arg>=<value> -t <tag> .
⁠targets
Namedescription
builderimage state following build of prysm binary/artifacts
testimage containing test tools, functional test cases for validation and release target contents
releaseminimal resultant image containing service binaries, entrypoints and helper scripts
toolsetup consisting of all prysm utilities, helper tooling and release target contents
docker build --target <target> -t <tag> .
⁠Config

:page_with_curl: Configuration of the prysm client can be expressed in a config file written in YAML⁠, a minimal markup format, used as an alternative to passing command-line flags at runtime. Guidance on and a list of configurable settings can be found here⁠.

The following variables can be customized to manage the location and content of this YAML configuration:

$PRYSM_CONFIG_DIR=</path/to/configuration/dir> (default: /etc/prysm)

  • container path where the prysm YAML configuration should be maintained

    PRYSM_CONFIG_DIR=/mnt/etc/prysm
    

$CONFIG_<setting> = <value (string)> default: None

  • Any configuration setting/value key-pair supported by prysm should be expressible and properly rendered within the associated YAML config.

    <setting> -- represents a YAML config setting:

    # [YAML Setting 'prater']
    CONFIG_prater=<value>
    

    <value> -- represents setting value to configure:

    # [YAML Setting 'prater']
    # Setting: prater
    # Value: true
    CONFIG_prater=true
    

Additionally, the content of the YAML configuration file can either be pregenerated and mounted into a container instance:

$ cat custom-config.yml
mainnet: true
datadir: "/mnt/data"
http-web3provider: "https://mainnet.infura.io/v3/YOUR-PROJECT-ID"

# mount custom config into container
$ docker run -e PRYSM_CONFIG_DIR=/tmp/prysm --mount type=bind,source="$(pwd)"/custom-config.yml,target=/tmp/prysm/config.yml 0labs/prysm:latest beacon-chain

...or developed from both a mounted config and injected environment variables (with envvars taking precedence and overriding mounted config settings):

$ cat custom-config.yml
mainnet: true
datadir: "/mnt/data"
http-web3provider: "https://mainnet.infura.io/v3/YOUR-PROJECT-ID"

# mount custom config into container
$ docker run -it --env PRYSM_CONFIG_DIR=/tmp/prysm --env CONFIG_datadir=/new/data/dir --env CONFIG_accept-terms-of-use=true \
  --mount type=bind,source="$(pwd)"/custom-config.yml,target=/tmp/prysm/config.yml \
  0labs/prysm:latest beacon-chain

Moreover, see here⁠ for a list of supported flags to set as runtime command-line flags.

# connect to Prater Eth2 testnet and automatically accept the terms of use agreement 
docker run 0labs/prysm:latest beacon-chain --prater --accept-terms-of-use

Also, note: as indicated in the linked documentation, CLI flags generally translate into configuration settings by removing the preceding -- flag marker.

$EXTRA_ARGS=<string> (default: '')

  • space separated list of command-line flags to pass at run-time

    docker run --env EXTRA_ARGS="--prater --enable-peer-scorer --force-clear-db" 0labs/prysm:latest
    

...and reference below for network/chain identification and communication configs:

⁠port mappings
Portmapping descriptiontypeconfig settingcommand-line flag
13000The port used by libp2pTCPp2p-tcp-port--p2p-tcp-port
12000The port used by discv5UDPp2p-udp-port--p2p-udp-port
4000RPC port exposed by a beacon nodeTCPrpc-port--rpc-port
3500The port on which the gateway server runs onTCPgrpc-gateway-port--grpc-gateway-port
8080Port used to listen and respond to beacon node metrics request for PrometheusTCPmonitoring-port--monitoring-port
7500Enable gRPC gateway for validator JSON requestsTCPgrpc-gateway-port--grpc-gateway-port
7000RPC port exposed by a validator clientTCPrpc-port--rpc-port
8081Port used to listen and respond to validator metrics request for PrometheusTCPmonitoring-port--monitoring-port
⁠chain id mappings
nameconfig setting (http-web3-provider)command-line flag
Mainnetmainnet--http-web3-provider=mainnet
Goerligoerli--http-web3-provider=goerli

note: only Eth1 web3 providers connected to either Mainnet or the Goerli testnet are supported currently.

see chainlist.org⁠ for a complete list

⁠Operations

:flashlight: To assist with managing a prysm client and interfacing with the Ethereum 2.0 network, the following utility functions have been included within the image. Note: all tool command-line flags can alternatively be expressed as container runtime environment variables, as described below.

⁠Setup deposit accounts and tooling

Download Eth2 deposit CLI tool and setup validator deposit accounts.

$SETUP_DEPOSIT_CLI=<boolean> (default: false)

$DEPOSIT_CLI_VERSION=<string> (default: v1.2.0)

  • version of the Eth 2.0 deposit CLI to download

$ETH2_CHAIN=<string> (default: mainnet)

  • Ethereum 2.0 chain to register deposit validator accounts and keystores for

$SETUP_DEPOSIT_ACCOUNTS=<boolean> (default: false)

  • whether to automatically setup Eth 2.0 validator depositor accounts (see⁠ for more details)

$DEPOSIT_DIR=<path> (default: /var/tmp/deposit)

  • container directory to generate Eth 2.0 validator deposit keystores
⁠Backup beacon-chain node or validator databases

Backup node chain and validator databases using the /db/backup API.

$ prysm-helper status backup-db --help
Usage: prysm-helper status backup-db [OPTIONS]

  Backup Prysm beacon-chain node or validator databases (see for details:
  https://docs.prylabs.network/docs/prysm-usage/database-backups/)

Options:
  --host-addr TEXT  Prysm Eth2 metrics host address in format
                    <protocol(http/https)>://<IP>:<port>  [default:
                    (http://localhost:8080)]
  --help            Show this message and exit.

$BACKUP_HOST_ADDR=<url> (default: http://localhost:8080)

  • Prysm Eth2 metrics host address in format <protocol(http/https)>://:

$AUTO_BACKUP_DB=<boolean> (default: false)

  • whether to automatically execute database backups based on $BACKUP_INTERVAL

$BACKUP_INTERVAL=<cron-schedule> (default: 0 */6 * * * (every 6 hours))

  • database backup frequency based on a cron schedule
⁠Import beacon-chain or validator node database backup

Import backed-up database to designated container/host data location.

$ prysm-helper status import-db-backup --help
Usage: prysm-helper status import-db-backup [OPTIONS]

  Import Prysm beacon-chain or validator Backup Prysm beacon-chain node or
  validator databases (see for details:
  https://docs.prylabs.network/docs/prysm-usage/database-backups/)

Options:
  --backup-path TEXT         path of backup prysm service database  [default:
                             (/root/.eth2/backups/)]
  --restore-target-dir TEXT  Directory to restore imported database backup to
                             [default: (/root/.eth2)]
  --service TEXT             prysm service database to backup  [default:
                             (beacon-chain)]
  --help                     Show this message and exit.

$IMPORT_BACKUP_DB=<string> (default: false)

  • whether to automatically import a beacon-chain or validator node database on launch

$BACKUP_SERVICE=<string> (default: beacon-chain)

  • service (beacon-chain or validator) database to backup

$BACKUP_PATH=<string> (default: /tmp/backups)

  • path of backup Prysm service database to import

$RESTORE_DIR=<string> (default: /root/.ethereum/keystore)

  • directory to restore imported database backup to

$DEPOSIT_MNEMONIC_LANG=<string> (default: english)

  • language to generate deposit mnemonic in

$DEPOSIT_NUM_VALIDATORS=<int> (default: 1)

  • count of Eth 2.0 validator deposit keystores to generate

$DEPOSIT_KEY_PASSWORD=<string> (default: passw0rd)

  • validator deposit keystore password associated with generated mnemonic

A validator_keys directory containing deposit data and the generated validator deposit keystore(s) will be created at the DEPOSIT_DIR path.

ls /var/tmp/deposit/validator_keys
  deposit_data-1632777614.json  keystore-m_12381_3600_0_0_0-1632777613.json
⁠Query Ethereum standard Beacon API

Execute a RESTful Ethereum Beacon HTTP API request.

$ prysm-helper status api-request --help
Usage: prysm-helper status api-request [OPTIONS]

  Execute RESTful API HTTP request

Options:
  --host-addr TEXT   Prysm Eth2 API host address in format
                     <protocol(http/https)>://<IP>:<port>  [default:
                     (http://localhost:3501)]
  --api-method TEXT  HTTP method to execute a part of request  [default:
                     (GET)]
  --api-path TEXT    Restful API path to target resource  [default:
                     (eth/v1/node/health)]
  --api-data TEXT    Restful API request body data included within POST
                     requests  [default: ({})]
  --help             Show this message and exit.

$API_HOST_ADDR=<url> (default: localhost:3501)

  • Prysm Eth2 API host address in format <protocol(http/https)>://:

$API_METHOD=<http-method> (default: GET)

  • HTTP method to execute

$API_PATH=<url-path> (default: /eth/v1/node/health)

  • RESTful API path to target resource

$API_DATA=<json-string> (default: '{}')

  • RESTful API request body data included within POST requests

The output consists of a JSON blob corresponding to the expected return object for a given API query. Reference Prysm's Ethereum Beacon API docs⁠ for more details.

⁠example
docker exec [--env API_PATH=eth/v1/node/syncing] prysm-beacon prysm-helper status api-request [--api-path eth/v1/node/syncing]
{
  "data": {
        "head_slot": "2315233",
        "is_syncing": false,
        "sync_distance": "1"
  }
}
⁠Import validator keystores

Automatically import designated validator keystores and associated wallets on startup.

$SETUP_VALIDATOR=<boolean> (default: false)

  • whether to attempt to import validator keystores and associated wallets

$VALIDATOR_WALLET_PASSWORD=<string> (required)

  • password to secure validator wallet associated with imported keystore

$VALIDATOR_ACCOUNT_PASSWORD=<string> (required)

  • password to secure validator account

$VALIDATOR_KEYS_DIR=<directory> (default: /keys)

  • Path to a directory where keystores to be imported are stored

$VALIDATOR_WALLET_DIR=<directory> (default: /wallets)

  • Path to a wallet directory within container for Prysm validator accounts

$ETH2_CHAIN=<string> (default: prater)

  • Ethereum 2.0 chain imported keystore and wallets are associated with

All account wallets keystore/wallet details will be created at the $VALIDATOR_WALLET_DIR.

ls /wallets/direct/accounts/
  all-accounts.keystore.json

⁠Examples

  • Enable automatic acceptance of the terms of use when launching either a beacon-chain or validator node:
docker run --env CONFIG_accept-terms-of-use=true 0labs/prysm:latest
  • Launch a Prysm beacon-chain node connected to the Prater Ethereum 2.0 testnet using a Goerli web3 Ethereum provider:
# cat .env
CONFIG_http-web3provider=http://ethereum-rpc.goerli.01labs.net:8545
CONFIG_prater=true

docker run --env-file .env 0labs/prysm:latest
  • Import Prater validator keystore and associated wallets on startup:
# cat .env
ETH2_CHAIN=prater
SETUP_VALIDATOR=true
VALIDATOR_WALLET_PASSWORD=N7p3D1?!m+bA
VALIDATOR_ACCOUNT_PASSWORD=passw0rd
VALIDATOR_KEYS_DIR=/validator/keys
VALIDATOR_WALLET_DIR=/validator/wallets

docker run --env-file .env --volume /host/validator/keys:/validator/keys 0labs/prysm:latest validator
  • Install Eth2 deposit CLI tool and automatically setup multiple validator accounts/keys to register on the Prater testnet:
# cat .env
SETUP_DEPOSIT_CLI=true
DEPOSIT_CLI_VERSION=v1.2.0
SETUP_DEPOSIT_ACCOUNTS=true
DEPOSIT_NUM_VALIDATORS=3
ETH2_CHAIN=prater
DEPOSIT_KEY_PASSWORD=ABCabc123!@#$
NOLOAD_CONFIG=1

docker run -it --env-file .env 0labs/prysm:latest ls /var/tmp/deposit
  • Setup automatic cron backups of a localhost beacon-chain node DB every 12 hours (or twice a day):
# cat .env
AUTO_BACKUP_DB=true
BACKUP_HOST_ADDR=http://localhost:8080
BACKUP_INTERVAL=0 */12 * * *

docker run --env-file .env 0labs/prysm:latest

⁠License

MIT

⁠Author Information

This Containerfile was created in 2021 by O1.IO.

šŸ† always happy to help & donations are always welcome šŸ’ø

  • ETH (Ethereum): 0x652eD9d222eeA1Ad843efec01E60C29bF2CF6E4c

  • BTC (Bitcoin): 3E8gMxwEnfAAWbvjoPVqSz6DvPfwQ1q8Jn

  • ATOM (Cosmos): cosmos19vmcf5t68w6ug45mrwjyauh4ey99u9htrgqv09

Tag summary

Content type

Image

Digest

sha256:77673b8ef…

Size

184.4 MB

Last updated

about 4 years ago

docker pull 0labs/prysm