Reword the Tmux setup to handle all simulation scenarios in more visible way

This commit is contained in:
Zahary Karadjov 2020-06-16 21:38:51 +03:00 committed by zah
parent e9d68e2f7b
commit 1def383ad1
13 changed files with 181 additions and 163 deletions

View File

@ -136,7 +136,7 @@ clean_eth2_network_simulation_files:
rm -rf tests/simulation/{data,validators} rm -rf tests/simulation/{data,validators}
eth2_network_simulation: | build deps clean_eth2_network_simulation_files eth2_network_simulation: | build deps clean_eth2_network_simulation_files
+ GIT_ROOT="$$PWD" NIMFLAGS="$(NIMFLAGS)" LOG_LEVEL="$(LOG_LEVEL)" tests/simulation/start.sh + GIT_ROOT="$$PWD" NIMFLAGS="$(NIMFLAGS)" LOG_LEVEL="$(LOG_LEVEL)" tests/simulation/start-in-tmux.sh
clean-testnet0: clean-testnet0:
rm -rf build/data/testnet0* rm -rf build/data/testnet0*

View File

@ -31,7 +31,7 @@ import
const const
genesisFile* = "genesis.ssz" genesisFile* = "genesis.ssz"
timeToInitNetworkingBeforeGenesis = chronos.seconds(10) timeToInitNetworkingBeforeGenesis = chronos.seconds(30)
hasPrompt = not defined(withoutPrompt) hasPrompt = not defined(withoutPrompt)
type type
@ -95,12 +95,14 @@ proc getStateFromSnapshot(conf: BeaconNodeConf): NilableBeaconStateRef =
genesisPath, dataDir = conf.dataDir.string genesisPath, dataDir = conf.dataDir.string
writeGenesisFile = true writeGenesisFile = true
genesisPath = snapshotPath genesisPath = snapshotPath
else: elif fileExists(genesisPath):
try: try: snapshotContents = readFile(genesisPath)
snapshotContents = readFile(genesisPath)
except CatchableError as err: except CatchableError as err:
error "Failed to read genesis file", err = err.msg error "Failed to read genesis file", err = err.msg
quit 1 quit 1
else:
# No snapshot was provided. We should wait for genesis.
return nil
result = try: result = try:
newClone(SSZ.decode(snapshotContents, BeaconState)) newClone(SSZ.decode(snapshotContents, BeaconState))

View File

@ -243,7 +243,7 @@ type
name: "keyfile" }: seq[ValidatorKeyPath] name: "keyfile" }: seq[ValidatorKeyPath]
of deposits: of deposits:
case depositsCmd*: DepositsCmd case depositsCmd* {.command.}: DepositsCmd
of create: of create:
totalDeposits* {. totalDeposits* {.
defaultValue: 1 defaultValue: 1
@ -253,7 +253,7 @@ type
outValidatorsDir* {. outValidatorsDir* {.
defaultValue: "validators" defaultValue: "validators"
desc: "Output folder for validator keystores and deposits." desc: "Output folder for validator keystores and deposits."
name: "out-validators-dir" }: string name: "out-deposits-dir" }: string
outSecretsDir* {. outSecretsDir* {.
defaultValue: "secrets" defaultValue: "secrets"
@ -277,7 +277,7 @@ type
depositsDir* {. depositsDir* {.
defaultValue: "validators" defaultValue: "validators"
desc: "A folder with validator metadata created by the `deposits create` command." desc: "A folder with validator metadata created by the `deposits create` command."
name: "out-validators-dir" }: string name: "deposits-dir" }: string
minDelay* {. minDelay* {.
defaultValue: 0.0 defaultValue: 0.0

View File

@ -176,12 +176,14 @@ proc sendDeposits*(deposits: seq[Deposit],
let depositContract = web3.contractSender(DepositContract, contractAddress) let depositContract = web3.contractSender(DepositContract, contractAddress)
for i, dp in deposits: for i, dp in deposits:
discard await depositContract.deposit( let status = await depositContract.deposit(
Bytes48(dp.data.pubKey.toRaw()), Bytes48(dp.data.pubKey.toRaw()),
Bytes32(dp.data.withdrawal_credentials.data), Bytes32(dp.data.withdrawal_credentials.data),
Bytes96(dp.data.signature.toRaw()), Bytes96(dp.data.signature.toRaw()),
FixedBytes[32](hash_tree_root(dp.data).data)).send(value = 32.u256.ethToWei, gasPrice = 1) FixedBytes[32](hash_tree_root(dp.data).data)).send(value = 32.u256.ethToWei, gasPrice = 1)
info "Deposit sent", status = $status
if delayGenerator != nil: if delayGenerator != nil:
await sleepAsync(delayGenerator()) await sleepAsync(delayGenerator())

View File

@ -538,41 +538,42 @@ proc run(m: MainchainMonitor, delayBeforeStart: Duration) {.async.} =
defer: await close(dataProvider) defer: await close(dataProvider)
let processFut = m.processDeposits(dataProvider) let processFut = m.processDeposits(dataProvider)
defer: await processFut try:
dataProvider.onDisconnect do:
error "Eth1 data provider disconnected",
provider = m.dataProviderFactory.desc
processFut.cancel()
dataProvider.onDisconnect do: let startBlkNum = await dataProvider.getBlockNumber(m.startBlock)
error "Eth1 data provider disconnected", notice "Monitoring eth1 deposits",
provider = m.dataProviderFactory.desc fromBlock = startBlkNum.uint64,
processFut.cancel() contract = $m.depositContractAddress,
url = m.dataProviderFactory.desc
let startBlkNum = await dataProvider.getBlockNumber(m.startBlock) await dataProvider.onDepositEvent(Eth1BlockNumber(startBlkNum)) do (
notice "Monitoring eth1 deposits", pubkey: Bytes48,
fromBlock = startBlkNum.uint64, withdrawalCredentials: Bytes32,
contract = $m.depositContractAddress, amount: Bytes8,
url = m.dataProviderFactory.desc signature: Bytes96, merkleTreeIndex: Bytes8, j: JsonNode)
{.raises: [Defect], gcsafe.}:
try:
let
blockHash = BlockHash.fromHex(j["blockHash"].getStr())
eventType = if j.hasKey("removed"): RemovedEvent
else: NewEvent
await dataProvider.onDepositEvent(Eth1BlockNumber(startBlkNum)) do ( m.depositQueue.addLastNoWait((blockHash, eventType))
pubkey: Bytes48,
withdrawalCredentials: Bytes32,
amount: Bytes8,
signature: Bytes96, merkleTreeIndex: Bytes8, j: JsonNode)
{.raises: [Defect], gcsafe.}:
try:
let
blockHash = BlockHash.fromHex(j["blockHash"].getStr())
eventType = if j.hasKey("removed"): RemovedEvent
else: NewEvent
m.depositQueue.addLastNoWait((blockHash, eventType)) except CatchableError as exc:
warn "Received invalid deposit", err = exc.msg, j
except CatchableError as exc: except Exception as err:
warn "Received invalid deposit", err = exc.msg, j # chronos still raises exceptions which inherit directly from Exception
except Exception as err: if err[] of Defect:
# chronos still raises exceptions which inherit directly from Exception raise (ref Defect)(err)
if err[] of Defect: else:
raise (ref Defect)(err) warn "Received invalid deposit", err = err.msg, j
else: finally:
warn "Received invalid deposit", err = err.msg, j await processFut
proc start(m: MainchainMonitor, delayBeforeStart: Duration) = proc start(m: MainchainMonitor, delayBeforeStart: Duration) =
if m.runFut.isNil: if m.runFut.isNil:

View File

@ -147,7 +147,7 @@ cli do (skipGoerliKey {.
mode = Verbose mode = Verbose
exec replace(&"""{beaconNodeBinary} deposits create exec replace(&"""{beaconNodeBinary} deposits create
--count=1 --count=1
--out-validators-dir="{validatorsDir}" --out-deposits-dir="{validatorsDir}"
--out-secrets-dir="{secretsDir}" --out-secrets-dir="{secretsDir}"
--deposit-private-key={privKey} --deposit-private-key={privKey}
--web3-url={web3Url} --web3-url={web3Url}

View File

@ -140,7 +140,7 @@ $MAKE LOG_LEVEL="${LOG_LEVEL}" NIMFLAGS="-d:insecure -d:testnet_servers_image ${
./build/beacon_node deposits create \ ./build/beacon_node deposits create \
--count=${TOTAL_VALIDATORS} \ --count=${TOTAL_VALIDATORS} \
--out-validators-dir="${DEPOSITS_DIR}" \ --out-deposits-dir="${DEPOSITS_DIR}" \
--out-secrets-dir="${SECRETS_DIR}" \ --out-secrets-dir="${SECRETS_DIR}" \
--dont-send --dont-send

View File

@ -85,7 +85,7 @@ make build
../build/beacon_node deposits create \ ../build/beacon_node deposits create \
--count=$TOTAL_VALIDATORS \ --count=$TOTAL_VALIDATORS \
--out-validators-dir="$DEPOSITS_DIR_ABS" \ --out-deposits-dir="$DEPOSITS_DIR_ABS" \
--out-secrets-dir="$SECRETS_DIR_ABS" \ --out-secrets-dir="$SECRETS_DIR_ABS" \
--dont-send --dont-send

View File

@ -16,6 +16,8 @@ else
ADDITIONAL_BEACON_NODE_ARGS="" ADDITIONAL_BEACON_NODE_ARGS=""
fi fi
BOOTSTRAP_ARG=""
if [[ ! -z "$1" ]]; then if [[ ! -z "$1" ]]; then
BOOTSTRAP_NODE_ID=$1 BOOTSTRAP_NODE_ID=$1
BOOTSTRAP_ADDRESS_FILE="${SIMULATION_DIR}/node-${BOOTSTRAP_NODE_ID}/beacon_node.address" BOOTSTRAP_ADDRESS_FILE="${SIMULATION_DIR}/node-${BOOTSTRAP_NODE_ID}/beacon_node.address"
@ -25,6 +27,10 @@ else
BOOTSTRAP_ADDRESS_FILE=$NETWORK_BOOTSTRAP_FILE BOOTSTRAP_ADDRESS_FILE=$NETWORK_BOOTSTRAP_FILE
fi fi
if [[ "$NODE_ID" != "$MASTER_NODE" ]]; then
BOOTSTRAP_ARG="--bootstrap-file=$BOOTSTRAP_ADDRESS_FILE"
fi
# set up the environment # set up the environment
# shellcheck source=/dev/null # shellcheck source=/dev/null
source "${SIM_ROOT}/../../env.sh" source "${SIM_ROOT}/../../env.sh"
@ -75,12 +81,17 @@ if [ -f "${SNAPSHOT_FILE}" ]; then
SNAPSHOT_ARG="--state-snapshot=${SNAPSHOT_FILE}" SNAPSHOT_ARG="--state-snapshot=${SNAPSHOT_FILE}"
fi fi
DEPOSIT_CONTRACT_ARGS=""
if [ -f "${DEPOSIT_CONTRACT_FILE}" ]; then
DEPOSIT_CONTRACT_ARGS="--deposit-contract=$(cat $DEPOSIT_CONTRACT_FILE) $WEB3_ARG"
fi
cd "$NODE_DATA_DIR" cd "$NODE_DATA_DIR"
# if you want tracing messages, add "--log-level=TRACE" below # if you want tracing messages, add "--log-level=TRACE" below
$BEACON_NODE_BIN \ $BEACON_NODE_BIN \
--log-level=${LOG_LEVEL:-DEBUG} \ --log-level=${LOG_LEVEL:-DEBUG} \
--bootstrap-file=$BOOTSTRAP_ADDRESS_FILE \ $BOOTSTRAP_ARG \
--data-dir=$NODE_DATA_DIR \ --data-dir=$NODE_DATA_DIR \
--secrets-dir=$NODE_SECRETS_DIR \ --secrets-dir=$NODE_SECRETS_DIR \
--node-name=$NODE_ID \ --node-name=$NODE_ID \
@ -88,8 +99,7 @@ $BEACON_NODE_BIN \
--udp-port=$PORT \ --udp-port=$PORT \
$SNAPSHOT_ARG \ $SNAPSHOT_ARG \
$NAT_ARG \ $NAT_ARG \
$WEB3_ARG \ $DEPOSIT_CONTRACT_ARGS \
--deposit-contract=$DEPOSIT_CONTRACT_ADDRESS \
--rpc \ --rpc \
--rpc-address="127.0.0.1" \ --rpc-address="127.0.0.1" \
--rpc-port="$(( $BASE_RPC_PORT + $NODE_ID ))" \ --rpc-port="$(( $BASE_RPC_PORT + $NODE_ID ))" \

View File

@ -0,0 +1,42 @@
#!/bin/bash
set -eo pipefail
cd "$(dirname "$0")"
TMUX_CMD="${TMUX_CMD:-tmux}"
USE_TMUX="${USE_TMUX:-no}"
type "$TMUX_CMD" &>/dev/null || { echo "${TMUX_CMD}" is missing; USE_TMUX="no"; }
if [[ "$USE_TMUX" != "no" ]]; then
TMUX_SESSION_NAME="${TMUX_SESSION_NAME:-nbc-sim}"
export USE_TMUX=yes
export TMUX_CMD
export TMUX_SESSION_NAME
$TMUX_CMD new-session -s "${TMUX_SESSION_NAME}" -d
# maybe these should be moved to a user config file
$TMUX_CMD set-option -t "${TMUX_SESSION_NAME}" history-limit 999999
$TMUX_CMD set-option -t "${TMUX_SESSION_NAME}" remain-on-exit on
$TMUX_CMD set -t "${TMUX_SESSION_NAME}" mouse on
# We create a new window, so the above settings can take place
$TMUX_CMD new-window -d -t "${TMUX_SESSION_NAME}" -n "sim"
$TMUX_CMD kill-pane -t "${TMUX_SESSION_NAME}:0"
trap 'tmux kill-session -t "${TMUX_SESSION_NAME}"' SIGINT EXIT
$TMUX_CMD new-window -t "${TMUX_SESSION_NAME}" -n "start-script" "$PWD/start.sh"
$TMUX_CMD select-window -t "${TMUX_SESSION_NAME}:start-script"
#$TMUX_CMD send-keys -t "${TMUX_SESSION_NAME}:0" "$PWD/start.sh" Enter
#$TMUX_CMD select-window -t "${TMUX_SESSION_NAME}:0"
# $TMUX_CMD attach-session -t "${TMUX_SESSION_NAME}"
$TMUX_CMD attach-session -t "${TMUX_SESSION_NAME}"
else
./start.sh
fi

View File

@ -3,29 +3,39 @@
set -eo pipefail set -eo pipefail
# To allow overriding the program names # To allow overriding the program names
MULTITAIL="${MULTITAIL:-multitail}" MULTITAIL_CMD="${MULTITAIL_CMD:-multitail}"
TMUX="${TMUX:-tmux}" GANACHE_CMD="${GANACHE_CMD:-ganache-cli}"
GANACHE="${GANACHE:-ganache-cli}" PROMETHEUS_CMD="${PROMETHEUS_CMD:-prometheus}"
PROMETHEUS="${PROMETHEUS:-prometheus}" CTAIL_CMD="${CTAIL_CMD:-ctail}"
CTAIL="${CTAIL:-ctail}"
# Using tmux or multitail is an opt-in TMUX_SESSION_NAME="${TMUX_SESSION_NAME:-nbc-sim}"
USE_MULTITAIL="${USE_MULTITAIL:-no}"
type "$MULTITAIL" &>/dev/null || { echo "${MULTITAIL}" is missing; USE_MULTITAIL="no"; }
USE_TMUX="${USE_TMUX:-no}"
type "$TMUX" &>/dev/null || { echo "${TMUX}" is missing; USE_TMUX="no"; }
WAIT_GENESIS="${WAIT_GENESIS:-no}" WAIT_GENESIS="${WAIT_GENESIS:-no}"
USE_MULTITAIL="${USE_MULTITAIL:-no}"
if [[ "$USE_MULTITAIL" != "no" ]]; then
type "$MULTITAIL" &>/dev/null || { echo "${MULTITAIL}" is missing; USE_MULTITAIL="no"; }
fi
USE_TMUX="${USE_TMUX:-yes}"
if [[ "$USE_TMUX" == "yes" ]]; then
type "$TMUX" &>/dev/null || { echo "${TMUX}" is missing; USE_TMUX="no"; }
fi
USE_GANACHE="${USE_GANACHE:-yes}" USE_GANACHE="${USE_GANACHE:-yes}"
type "$GANACHE" &>/dev/null || { echo $GANACHE is missing; USE_GANACHE="no"; WAIT_GENESIS="no"; } if [[ "$USE_GANACHE" == "yes" ]]; then
type "$GANACHE" &>/dev/null || { echo $GANACHE is missing; USE_GANACHE="no"; }
fi
USE_PROMETHEUS="${USE_PROMETHEUS:-yes}" USE_PROMETHEUS="${USE_PROMETHEUS:-yes}"
type "$PROMETHEUS" &>/dev/null || { echo $PROMETHEUS is missing; USE_PROMETHEUS="no"; } if [[ "$USE_PROMETHEUS" == "yes" ]]; then
type "$PROMETHEUS" &>/dev/null || { echo $PROMETHEUS is missing; USE_PROMETHEUS="no"; }
fi
USE_CTAIL="${USE_CTAIL:-yes}" USE_CTAIL="${USE_CTAIL:-yes}"
type "$CTAIL" &>/dev/null || { echo $CTAIL is missing; USE_CTAIL="no"; } if [[ "$USE_CTAIL" == "yes" ]]; then
type "$CTAIL_CMD" &>/dev/null || { echo $CTAIL_CMD is missing; USE_CTAIL="no"; }
fi
# Read in variables # Read in variables
# shellcheck source=/dev/null # shellcheck source=/dev/null
@ -53,31 +63,6 @@ else
MAKE="make" MAKE="make"
fi fi
TMUX_SESSION_NAME="${TMUX_SESSION_NAME:-nbc-sim}"
WAIT_GENESIS="${WAIT_GENESIS:-no}"
# Using tmux or multitail is an opt-in
USE_MULTITAIL="${USE_MULTITAIL:-no}"
if [[ "$USE_MULTITAIL" != "no" ]]; then
type "$MULTITAIL" &>/dev/null || { echo "${MULTITAIL}" is missing; USE_MULTITAIL="no"; }
fi
USE_TMUX="${USE_TMUX:-yes}"
if [[ "$USE_TMUX" == "yes" ]]; then
type "$TMUX" &>/dev/null || { echo "${TMUX}" is missing; USE_TMUX="no"; }
fi
USE_GANACHE="${USE_GANACHE:-yes}"
if [[ "$USE_GANACHE" == "yes" ]]; then
type "$GANACHE" &>/dev/null || { echo $GANACHE is missing; USE_GANACHE="no"; }
fi
USE_PROMETHEUS="${USE_PROMETHEUS:-yes}"
if [[ "$USE_PROMETHEUS" == "yes" ]]; then
type "$PROMETHEUS" &>/dev/null || { echo $PROMETHEUS is missing; USE_PROMETHEUS="no"; }
fi
mkdir -p "${METRICS_DIR}" mkdir -p "${METRICS_DIR}"
./scripts/make_prometheus_config.sh \ ./scripts/make_prometheus_config.sh \
--nodes ${TOTAL_NODES} \ --nodes ${TOTAL_NODES} \
@ -86,43 +71,29 @@ mkdir -p "${METRICS_DIR}"
COMMANDS=() COMMANDS=()
if [[ "$USE_TMUX" != "no" ]]; then if [[ "$USE_GANACHE" == "yes" ]]; then
$TMUX new-session -s "${TMUX_SESSION_NAME}" -d if [[ "$USE_TMUX" == "yes" ]]; then
$TMUX_CMD new-window -d -t $TMUX_SESSION_NAME -n "$GANACHE_CMD" "$GANACHE_CMD -e 100000"
# maybe these should be moved to a user config file
$TMUX set-option -t "${TMUX_SESSION_NAME}" history-limit 999999
$TMUX set-option -t "${TMUX_SESSION_NAME}" remain-on-exit on
$TMUX set -t "${TMUX_SESSION_NAME}" mouse on
# We create a new window, so the above settings can take place
$TMUX new-window -d -t "${TMUX_SESSION_NAME}" -n "sim"
trap 'tmux kill-session -t "${TMUX_SESSION_NAME}"' SIGINT EXIT
fi
if [[ "$USE_GANACHE" != "no" ]]; then
if [[ "$USE_TMUX" != "no" ]]; then
$TMUX new-window -d -t $TMUX_SESSION_NAME -n "$GANACHE" "$GANACHE"
else else
echo NOTICE: $GANACHE will be started automatically only with USE_TMUX=1 echo NOTICE: $GANACHE_CMD will be started automatically only with USE_TMUX=1
USE_GANACHE="no" USE_GANACHE="no"
fi fi
fi fi
if [[ "$USE_PROMETHEUS" != "no" ]]; then if [[ "$USE_PROMETHEUS" == "yes" ]]; then
if [[ "$USE_TMUX" != "no" ]]; then if [[ "$USE_TMUX" == "yes" ]]; then
rm -rf "${METRICS_DIR}/data"
mkdir -p "${METRICS_DIR}/data"
# TODO: Prometheus is not shut down properly on tmux kill-session
killall prometheus
PROMETHEUS_FLAGS="--config.file=./prometheus.yml --storage.tsdb.path=./data" PROMETHEUS_FLAGS="--config.file=./prometheus.yml --storage.tsdb.path=./data"
$TMUX new-window -d -t $TMUX_SESSION_NAME -n "$PROMETHEUS" "cd '$METRICS_DIR' && $PROMETHEUS $PROMETHEUS_FLAGS" $TMUX_CMD new-window -d -t $TMUX_SESSION_NAME -n "$PROMETHEUS_CMD" "cd '$METRICS_DIR' && $PROMETHEUS_CMD $PROMETHEUS_FLAGS"
else else
echo NOTICE: $PROMETHEUS will be started automatically only with USE_TMUX=1 echo NOTICE: $PROMETHEUS_CMD will be started automatically only with USE_TMUX=1
USE_PROMETHEUS="no" USE_PROMETHEUS="no"
fi fi
fi fi
if [[ "$USE_TMUX" != "no" ]]; then
$TMUX select-window -t "${TMUX_SESSION_NAME}:sim"
fi
$MAKE -j3 --no-print-directory NIMFLAGS="$CUSTOM_NIMFLAGS $DEFS" LOG_LEVEL="${LOG_LEVEL:-DEBUG}" beacon_node validator_client $MAKE -j3 --no-print-directory NIMFLAGS="$CUSTOM_NIMFLAGS $DEFS" LOG_LEVEL="${LOG_LEVEL:-DEBUG}" beacon_node validator_client
count_files () { count_files () {
@ -138,22 +109,41 @@ if [[ $EXISTING_VALIDATORS -lt $NUM_VALIDATORS ]]; then
$BEACON_NODE_BIN deposits create \ $BEACON_NODE_BIN deposits create \
--count="${NUM_VALIDATORS}" \ --count="${NUM_VALIDATORS}" \
--non-interactive \ --non-interactive \
--out-validators-dir="$VALIDATORS_DIR" \ --out-deposits-dir="$VALIDATORS_DIR" \
--out-secrets-dir="$SECRETS_DIR" \ --out-secrets-dir="$SECRETS_DIR" \
--dont-send --dont-send
echo "All deposits prepared" echo "All deposits prepared"
fi fi
if [ ! -f "${SNAPSHOT_FILE}" ]; then
if [[ "${WAIT_GENESIS}" != "yes" ]]; then
echo Creating testnet genesis...
$BEACON_NODE_BIN \
--data-dir="${SIMULATION_DIR}/node-$MASTER_NODE" \
createTestnet \
--validators-dir="${VALIDATORS_DIR}" \
--total-validators="${NUM_VALIDATORS}" \
--output-genesis="${SNAPSHOT_FILE}" \
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
--bootstrap-address=127.0.0.1 \
--bootstrap-port=$(( BASE_P2P_PORT + MASTER_NODE )) \
--genesis-offset=45 # Delay in seconds
fi
fi
if [[ "$USE_TMUX" == "yes" ]]; then
$TMUX_CMD select-window -t "${TMUX_SESSION_NAME}:sim"
fi
function run_cmd { function run_cmd {
i=$1 i=$1
CMD=$2 CMD=$2
bin_name=$3 bin_name=$3
if [[ "$USE_TMUX" != "no" ]]; then if [[ "$USE_TMUX" == "yes" ]]; then
echo "Starting node $i..." echo "Starting node $i..."
echo $TMUX split-window -t "${TMUX_SESSION_NAME}" "$CMD" $TMUX_CMD split-window -t "${TMUX_SESSION_NAME}" "$CMD"
$TMUX split-window -t "${TMUX_SESSION_NAME}" "$CMD" $TMUX_CMD select-layout -t "${TMUX_SESSION_NAME}:sim" tiled
$TMUX select-layout -t "${TMUX_SESSION_NAME}" tiled
elif [[ "$USE_MULTITAIL" != "no" ]]; then elif [[ "$USE_MULTITAIL" != "no" ]]; then
if [[ "$i" == "$MASTER_NODE" ]]; then if [[ "$i" == "$MASTER_NODE" ]]; then
SLEEP="0" SLEEP="0"
@ -167,47 +157,24 @@ function run_cmd {
fi fi
} }
if [ "$WEB3_ARG" != "" ]; then if [ "$USE_GANACHE" != "no" ]; then
make deposit_contract make deposit_contract
echo Deploying the validator deposit contract... echo Deploying the validator deposit contract...
echo $DEPLOY_DEPOSIT_CONTRACT_BIN deploy $WEB3_ARG echo $DEPLOY_DEPOSIT_CONTRACT_BIN deploy $WEB3_ARG
DEPOSIT_CONTRACT_ADDRESS=$($DEPLOY_DEPOSIT_CONTRACT_BIN deploy $WEB3_ARG) DEPOSIT_CONTRACT_ADDRESS=$($DEPLOY_DEPOSIT_CONTRACT_BIN deploy $WEB3_ARG)
echo Contract deployed at $DEPOSIT_CONTRACT_ADDRESS echo Contract deployed at $DEPOSIT_CONTRACT_ADDRESS
export DEPOSIT_CONTRACT_ADDRESS echo $DEPOSIT_CONTRACT_ADDRESS > $DEPOSIT_CONTRACT_FILE
if [[ "$WAIT_GENESIS" != "no" ]]; then
echo "(deposit maker)" "$BEACON_NODE_BIN deposits send \
--non-interactive \
--validators-dir='$VALIDATORS_DIR' \
--min-delay=1 --max-delay=5 \
$WEB3_ARG \
--deposit-contract=${DEPOSIT_CONTRACT_ADDRESS}"
if [[ "$WAIT_GENESIS" == "yes" ]]; then
run_cmd "(deposit maker)" "$BEACON_NODE_BIN deposits send \ run_cmd "(deposit maker)" "$BEACON_NODE_BIN deposits send \
--non-interactive \ --non-interactive \
--validators-dir='$VALIDATORS_DIR' \ --deposits-dir='$VALIDATORS_DIR' \
--min-delay=1 --max-delay=5 \ --min-delay=1 --max-delay=5 \
$WEB3_ARG \ $WEB3_ARG \
--deposit-contract=${DEPOSIT_CONTRACT_ADDRESS}" --deposit-contract=${DEPOSIT_CONTRACT_ADDRESS}"
fi fi
fi fi
if [ ! -f "${SNAPSHOT_FILE}" ]; then
if [[ "${WAIT_GENESIS}" == "no" ]]; then
echo Creating testnet genesis...
$BEACON_NODE_BIN \
--data-dir="${SIMULATION_DIR}/node-$MASTER_NODE" \
createTestnet \
--validators-dir="${VALIDATORS_DIR}" \
--total-validators="${NUM_VALIDATORS}" \
--output-genesis="${SNAPSHOT_FILE}" \
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
--bootstrap-address=127.0.0.1 \
--bootstrap-port=$(( BASE_P2P_PORT + MASTER_NODE )) \
--genesis-offset=15 # Delay in seconds
fi
fi
# Delete any leftover address files from a previous session # Delete any leftover address files from a previous session
if [ -f "${MASTER_NODE_ADDRESS_FILE}" ]; then if [ -f "${MASTER_NODE_ADDRESS_FILE}" ]; then
rm "${MASTER_NODE_ADDRESS_FILE}" rm "${MASTER_NODE_ADDRESS_FILE}"
@ -216,7 +183,7 @@ fi
# Kill child processes on Ctrl-C/SIGTERM/exit, passing the PID of this shell # Kill child processes on Ctrl-C/SIGTERM/exit, passing the PID of this shell
# instance as the parent and the target process name as a pattern to the # instance as the parent and the target process name as a pattern to the
# "pkill" command. # "pkill" command.
if [[ "$USE_MULTITAIL" == "no" && "$USE_TMUX" == "no" ]]; then if [[ "$USE_MULTITAIL" == "no" && "$USE_TMUX" != "yes" ]]; then
trap 'pkill -P $$ beacon_node' SIGINT EXIT trap 'pkill -P $$ beacon_node' SIGINT EXIT
fi fi
@ -243,24 +210,21 @@ for i in $(seq $MASTER_NODE -1 $TOTAL_USER_NODES); do
done done
if [[ "$USE_CTAIL" != "no" ]]; then if [[ "$USE_CTAIL" != "no" ]]; then
if [[ "$USE_TMUX" != "no" ]]; then if [[ "$USE_TMUX" == "yes" ]]; then
$TMUX new-window -d -t $TMUX_SESSION_NAME -n "$CTAIL" "$CTAIL tail -q -n +1 -f ${SIMULATION_DIR}/node-*/beacon_node.log" $TMUX_CMD new-window -d -t $TMUX_SESSION_NAME -n "$CTAIL_CMD" "$CTAIL_CMD tail -q -n +1 -f ${SIMULATION_DIR}/node-*/beacon_node.log"
else else
echo NOTICE: $CTAIL will be started automatically only with USE_TMUX=1 echo NOTICE: $CTAIL_CMD will be started automatically only with USE_TMUX=1
USE_CTAIL="no" USE_CTAIL="no"
fi fi
fi fi
if [[ "$USE_TMUX" != "no" ]]; then if [[ "$USE_TMUX" == "yes" ]]; then
# kill the console window in the pane where the simulation is running # kill the console window in the pane where the simulation is running
$TMUX kill-pane -t $TMUX_SESSION_NAME:sim.0 $TMUX_CMD kill-pane -t $TMUX_SESSION_NAME:sim.0
# kill the original console window $TMUX_CMD select-window -t "${TMUX_SESSION_NAME}:sim"
# (this one doesn't have the right history-limit) $TMUX_CMD select-layout tiled
$TMUX kill-pane -t $TMUX_SESSION_NAME:0.0
$TMUX select-layout -t "${TMUX_SESSION_NAME}" tiled
$TMUX attach-session -t "${TMUX_SESSION_NAME}" -d
elif [[ "$USE_MULTITAIL" != "no" ]]; then elif [[ "$USE_MULTITAIL" != "no" ]]; then
eval $MULTITAIL -s 3 -M 0 -x \"Nimbus beacon chain\" "${COMMANDS[@]}" eval $MULTITAIL_CMD -s 3 -M 0 -x \"Nimbus beacon chain\" "${COMMANDS[@]}"
else else
wait # Stop when all nodes have gone down wait # Stop when all nodes have gone down
fi fi

View File

@ -31,18 +31,15 @@ VALIDATORS_DIR="${SIM_ROOT}/validators"
SECRETS_DIR="${SIM_ROOT}/secrets" SECRETS_DIR="${SIM_ROOT}/secrets"
SNAPSHOT_FILE="${SIMULATION_DIR}/state_snapshot.ssz" SNAPSHOT_FILE="${SIMULATION_DIR}/state_snapshot.ssz"
NETWORK_BOOTSTRAP_FILE="${SIMULATION_DIR}/bootstrap_nodes.txt" NETWORK_BOOTSTRAP_FILE="${SIMULATION_DIR}/bootstrap_nodes.txt"
DEPOSIT_CONTRACT_FILE="${SIMULATION_DIR}/deposit_contract.txt"
BEACON_NODE_BIN="${GIT_ROOT}/build/beacon_node" BEACON_NODE_BIN="${GIT_ROOT}/build/beacon_node"
VALIDATOR_CLIENT_BIN="${GIT_ROOT}/build/validator_client" VALIDATOR_CLIENT_BIN="${GIT_ROOT}/build/validator_client"
DEPLOY_DEPOSIT_CONTRACT_BIN="${GIT_ROOT}/build/deposit_contract" DEPLOY_DEPOSIT_CONTRACT_BIN="${GIT_ROOT}/build/deposit_contract"
MASTER_NODE_ADDRESS_FILE="${SIMULATION_DIR}/node-${MASTER_NODE}/beacon_node.address" MASTER_NODE_ADDRESS_FILE="${SIMULATION_DIR}/node-${MASTER_NODE}/beacon_node.address"
WEB3_ARG="--web3-url=ws://localhost:8545"
BASE_P2P_PORT=30000 BASE_P2P_PORT=30000
BASE_RPC_PORT=7000 BASE_RPC_PORT=7000
BASE_METRICS_PORT=8008 BASE_METRICS_PORT=8008
if [[ "$USE_GANACHE" == "yes" ]]; then
WEB3_ARG=--web3-url=ws://localhost:8545
else
WEB3_ARG=""
DEPOSIT_CONTRACT_ADDRESS="0x"
fi

@ -1 +1 @@
Subproject commit 26667818be48d428892b26be9535c1f0a98d1510 Subproject commit aac25d1610a8fc15ae90fdd2a0b38ed60ea412fb