diff --git a/demo/challenge_simple.sh b/demo/challenge_simple.sh index fce9acd2a689b27f03449c6ca0fa265de50cdca1..b3cafa2578005dd5fc80e4da2d4aafda7408f4a4 100755 --- a/demo/challenge_simple.sh +++ b/demo/challenge_simple.sh @@ -1,5 +1,13 @@ #!/usr/bin/env bash +# The following variables can be overridden as environment variables: +# * BLOCK (block whose transition will be challenged) +# * WRONG_BLOCK (block number used by challenger) +# * SKIP_NODE (skip forking a node, useful if you've already forked a node) +# +# Example usage: +# SKIP_NODE=1 BLOCK=13284469 WRONG_BLOCK=13284491 ./demo/challenge_simple.sh + # --- DOC ---------------------------------------------------------------------- # In this example, the challenger will challenge the transition from a block @@ -52,18 +60,20 @@ trap "exit_trap" SIGINT SIGTERM EXIT # --- BOOT MAINNET FORK -------------------------------------------------------- -NODE_LOG="challenge_simple_node.log" +if [[ ! "$SKIP_NODE" ]]; then + NODE_LOG="challenge_simple_node.log" -shout "BOOTING MAINNET FORK NODE IN BACKGROUND (LOG: $NODE_LOG)" + shout "BOOTING MAINNET FORK NODE IN BACKGROUND (LOG: $NODE_LOG)" -# get directory containing this file -SCRIPT_DIR=$(dirname "$(readlink -f "$0")") + # get directory containing this file + SCRIPT_DIR=$(dirname "$(readlink -f "$0")") -# run a hardhat mainnet fork node -"$SCRIPT_DIR/forked_node.sh" > "$NODE_LOG" 2>&1 & + # run a hardhat mainnet fork node + "$SCRIPT_DIR/forked_node.sh" > "$NODE_LOG" 2>&1 & -# give the node some time to boot up -sleep 10 + # give the node some time to boot up + sleep 10 +fi # --- CHALLENGE SETUP ---------------------------------------------------------- @@ -72,10 +82,11 @@ export ID=0 # block whose transition will be challenged # this variable is read by challenge.js, respond.js and assert.js -export BLOCK=13284469 +BLOCK=${BLOCK:-13284469} +export BLOCK # block whose pre-state is used by the challenger instead of the challenged block's pre-state -WRONG_BLOCK=13284491 +WRONG_BLOCK=${WRONG_BLOCK:-13284491} # clear data from previous runs mkdir -p /tmp/cannon /tmp/cannon_fault && rm -rf /tmp/cannon/* /tmp/cannon_fault/* diff --git a/demo/forked_node.sh b/demo/forked_node.sh index 8ec43db65669c6c6282852602cdbf7fb96fe206f..2d4330d9b4756978df3be5e7f0e3d06db9e70e81 100755 --- a/demo/forked_node.sh +++ b/demo/forked_node.sh @@ -3,15 +3,18 @@ # This runs a hardhat node forked from mainnet at the specified block. # You need to run this in a separate terminal (or in the background) # before running challenge_simple.sh or challenge_fault.sh. +# +# RPC_URL and FORK_BLOCK can be overwritten as environment variables. If not +# provided, defaults are used. # Uncomment this line if you receive the error: # Error HH604: Error running JSON-RPC server: error:0308010C:digital envelope routines::unsupported # export NODE_OPTIONS=--openssl-legacy-provider -RPC_URL=https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161 +RPC_URL=${RPC_URL:-"https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"} # block at which to fork mainnet -FORK_BLOCK=13284495 +FORK_BLOCK=${FORK_BLOCK:-13284495} # testing on hardhat (forked mainnet, a few blocks ahead of challenges in # challenge_simple.sh and challenge_fault.sh)