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

AA-226 Support 2-bundler (p2p tests) #36

Merged
merged 11 commits into from
Nov 13, 2023
3 changes: 3 additions & 0 deletions bundlers/skandha/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#This is be the ENR exposed by they "boot" node, manually copied here to be fed into the peer node.
#TODO: sanity-check that the boot node indeed exposes this one..
BOOT_ENR="enr:-KS4QKKtZ64yNl2JqCmOAe6owCLe6CFuPZYVR2Na5-ymtoBHc3ce3Np6RU5ObROx73t-O4MiK01Lt6T9zlbFeHstA-AFgmlkgnY0gmlwhMCoZGWPbWVtcG9vbF9zdWJuZXRziAAAAAAAAAAAiXNlY3AyNTZrMaEDXy5_rNLasQOQHoH6ONKx7dt9MX7IV9RlUqiZ7o-vG-yDdGNwghDxg3VkcIIQ8Q"
5 changes: 5 additions & 0 deletions bundlers/skandha/bootDataDir/peer-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "16Uiu2HAmK4YCszGhF5eLPfPBBAbULdvWxgiFtqo6cmujLffLjWZR",
"pubKey": "CAISIQNfLn+s0tqxA5Aegfo40rHt230xfshX1GVSqJnuj68b7A==",
"privKey": "CAISINU2K8Ay8Vhz2MQeAvG2KQexFVktCwgrqRewm0VMdeWw"
}
34 changes: 34 additions & 0 deletions bundlers/skandha/p2p-boot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# start a standlone bundler for testing.
# bring up a the bundler with its own geth instance

#TODO: we assume that the boot bundler exposes BOOT_ENR
# need to EITHER receive ENR as parameter, or validate we generate exactly the same one.
services:

bundler:
ports: [ '3000:3000' ]
image: etherspot/skandha
command: node --testingMode --api.port 3000
--p2p.enrHost $BUNDLER_IP
--redirectRpc --executor.bundlingMode manual
networks:
default:
p2p:
ipv4_address: $BUNDLER_IP
volumes:
- ./bootDataDir/peer-id.json:/root/.skandha/db/peer-id.json
environment:
- SKANDHA_DEV_RPC=$ETH_RPC_URL
- SKANDHA_DEV_ENTRYPOINTS=${ENTRYPOINT}
- SKANDHA_DEV_RELAYER=test test test test test test test test test test test junk
- SKANDHA_DEV_BENEFICIARY=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266


bundler-verify:
image: docker
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock
depends_on:
bundler:
condition: service_started
command: echo docker exec runbundler-bundler-1 cat /root/.skandha/db/enr
22 changes: 22 additions & 0 deletions bundlers/skandha/p2p-peer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# start a standlone bundler for testing.
# bring up a the bundler with its own geth instance

services:

bundler:
ports: [ "3001:3000" ]
image: etherspot/skandha
command: node --testingMode --api.port 3000
--redirectRpc --executor.bundlingMode manual
--p2p.enrHost $BUNDLER2_IP
--p2p.bootEnrs $BOOT_ENR
networks:
default:
p2p:
ipv4_address: $BUNDLER2_IP
environment:
- SKANDHA_DEV_RPC=$ETH_RPC_URL
- SKANDHA_DEV_ENTRYPOINTS=${ENTRYPOINT}
- SKANDHA_DEV_RELAYER=junk junk junk junk junk junk junk junk junk junk junk test
- SKANDHA_DEV_BENEFICIARY=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

4 changes: 4 additions & 0 deletions empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#first "docker-compose" file referenced by "runbundler"
#Used to make sure all paths are relative to project root,
#regardless from where the "real" docker-compose is loaded.
version: '3'
25 changes: 22 additions & 3 deletions runall.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash
#!/bin/bash -x
root=`realpath \`dirname $0\``

BUILD=$root/build
OUT=$BUILD/out
test -d bundler-spec-tests || git clone https://github.com/eth-infinitism/bundler-spec-tests.git

BUNDLERS="`pwd`/bundlers/*/*yml"
#by default, run all single-bundler configs
BUNDLERS=`ls $root/bundlers/*/*yml|grep -v p2p`

#if parameter is given, use it as single-bundler yml, or as testenv file
if [ -n "$1" -a -r "$1" ]; then
BUNDLERS=`realpath $1`
shift
Expand All @@ -31,12 +34,21 @@ echo ====================================================================
echo ====== $bundlerTitle
echo ====================================================================

basename=`basename -s .yml $bundler`
basename=`basename -s .env \`basename -s .yml $bundler\``
outxml=$OUT/$basename.xml
outjson=$OUT/$basename.json
outraw=$OUT/$basename.txt
outlogs=$OUT/$basename.log

function getEnv {
envFile=$1
name=$2
def=$3

val=`sh -c "source $envFile; echo \\\$$name"`
echo ${val:-$def}
}

#todo: better name to extract the name from the yml file?
#from actual image, can do docker inspect {imageid} | jq .Config.Env
name=`sed -ne 's/ *NAME=[ "]*\([^"]*\)"*/\1/p' $bundler`
Expand All @@ -45,9 +57,16 @@ test -z $name && name=$basename

echo "Running bundler $bundler, name=$name" > $outraw
if $root/runbundler/runbundler.sh $bundler start; then

case "$bunder" in
*yml) PYTEST_FOLDER=`getEnv $root/runbundler/runbundler.env PYTEST_FOLDER tests/single` ;;
*env) PYTEST_FOLDER=`getEnv $bundler PYTEST_FOLDER tests/p2p` ;;
esac

OPTIONS="
--junit-xml $outxml
-o junit_logging=all -o junit_log_passing_tests=false
$PYTEST_FOLDER
"
# --log-rpc
pdm run test -o junit_suite_name="$name" $OPTIONS "$@" | tee -a $outraw
Expand Down
2 changes: 1 addition & 1 deletion runbundler/geth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
container_name: geth-1.10
ports: [ '8545:8545' ]
image: ethereum/client-go:release-1.10
command: --verbosity 2
command: --verbosity 1
--http.vhosts '*,localhost,host.docker.internal'
--http
--http.api personal,eth,net,web3,debug
Expand Down
32 changes: 32 additions & 0 deletions runbundler/run2bundlers.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#note: this is the global env, read by the docker-compose.yml file.
# each service in the docker-compose must forward
# needed environment vars to its own environment

#urls are based on service names (defined in the docker-compose)
ETH_RPC_URL=http://eth-node:8545
ETH_NODE_YML=runbundler/geth.yml

#bootnode bundler must expose itself as this url
BUNDLER_URL=http://bundler:3000/rpc

#2nd bundler (peer) must expose itself as:
BUNDLER2_URL=http://bundler2:3000/rpc

# subnet to contain the static IPs of bundlers:
P2P_SUBNET=192.168.100.0/24

#bootnode bundler must use this IP.
BUNDLER_IP=192.168.100.101
#peer bundler must use this IP
BUNDLER2_IP=192.168.100.102

ENTRYPOINT=0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789

#extra addresses (or private keys) to fund
FUND="0xc6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb
0x43378ff8C70109Ee4Dbe85aF34428ab0615EBd23
0x49Aa4e8210822CCd50b966944D415e5b4667AE3E
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"

#enable "bash -x" on scripts
VERBOSE=
32 changes: 32 additions & 0 deletions runbundler/run2bundlers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -e
dir=`dirname $0`

if [ -z "$2" ] ; then
echo usage: "$0 {bootyml} {start|stop|..}"
exit 1
fi

DC="docker-compose --env-file $dir/run2bundlers.env -f $dir/run2bundlers.yml"

export BUNDLER_YML=`realpath $1`
export BUNDLER2_YML=`realpath $2`
ENVFILE=`dirname $BUNDLER_YML`/.env
if [ -r $ENVFILE ] ; then
export `grep -v '#' $ENVFILE`
fi
#env for bundler2 ?

cmd=$3
shift
shift
shift
case "$cmd" in

start) $DC run --rm wait-all ;;
down) $DC down -t 1 ;;
stop) $DC stop -t 1 ;;
#execute misc docker-compose command
*) $DC $cmd $* ;;

esac

102 changes: 102 additions & 0 deletions runbundler/run2bundlers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# docker-compose to bring up a single bundler, with all needed services
version: '3'

services:

funder:
build: ./runbundler/funder
environment:
- FUND=$FUND 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
- ETH_RPC_URL=$ETH_RPC_URL
- ENTRYPOINT=$ENTRYPOINT
- VERBOSE=$VERBOSE
restart: on-failure:3
depends_on:
eth-node:
condition: service_started

deployer:
image: accountabstraction/deployer:0.6
# build: ./deployer
environment:
- ETH_RPC_URL=$ETH_RPC_URL
- ENTRYPOINT=$ENTRYPOINT
- VERBOSE=$VERBOSE
depends_on:
funder:
condition: service_completed_successfully

#launch shared node.
eth-node:
extends:
file: $ETH_NODE_YML
service: eth-node

bundler:
extends:
file: $BUNDLER_YML
service: bundler
depends_on:
deployer:
condition: service_completed_successfully

bundler-verify:
extends:
file: $BUNDLER_YML
service: bundler-verify

bundler2:
extends:
file: $BUNDLER2_YML
service: bundler
depends_on:
bundler-waiter:
condition: service_completed_successfully

bundler-waiter:
image: ghcr.io/foundry-rs/foundry:latest
command:
- "sleep 1; cast rpc eth_chainId -r $BUNDLER_URL"
depends_on:
bundler:
condition: service_started
restart: on-failure:5

bundler-waiter2:
image: ghcr.io/foundry-rs/foundry:latest
command:
- "sleep 1; cast rpc eth_chainId -r $BUNDLER2_URL"
depends_on:
bundler2:
condition: service_started
restart: on-failure:5

wait-all:
image: ghcr.io/foundry-rs/foundry:latest
command: echo started
depends_on:
bundler-waiter:
condition: service_completed_successfully
bundler-waiter2:
condition: service_completed_successfully

networks:
#the network where BUNDLER_IP and BUNDLER2_IP reside
p2p:
ipam:
config:
- subnet: "$P2P_SUBNET"

#todo: incomplete..
# runtest:
# build: ./runtest
# # command: $RUNTEST
# environment:
# - TEST=pdm run pytest --tb=short -rA -W ignore::DeprecationWarning --url $BUNDLER_URL --entry-point $ENTRYPOINT --ethereum-node $ETH_RPC_URL
# - ETH_RPC_URL=$ETH_RPC_URL
# - ENTRYPOINT=$ENTRYPOINT
# - BUNDLER_URL=$BUNDLER_URL
# depends_on:
# wait-all:
# condition: service_completed_successfully

5 changes: 3 additions & 2 deletions runbundler/.env → runbundler/runbundler.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#urls are based on service names (defined in the docker-compose)
ETH_RPC_URL=http://eth-node:8545
#BUNDLER_URL=http://bundler:3000/rpc
ETH_NODE_YML=runbundler/geth.yml

#bundler must expose itself as this url:
BUNDLER_URL=http://bundler:3000/rpc
ETH_NODE_YML=geth.yml

ENTRYPOINT=0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789

Expand Down
60 changes: 47 additions & 13 deletions runbundler/runbundler.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
#!/bin/bash
#!/bin/bash
dir=`dirname $0`
root=`cd $dir/.. ; pwd`

if [ -z "$2" ] ; then
echo usage: "$0 {ymlfile} {start|stop|..}"
exit 1
fi
function usage() {
cat <<EOF
usage: $0 {ymlfile|testfile} {start|stop|..}
ymlfile - a single bundler yml file. uses DCFILE="runbundler.yml"
testfile - env file to define all launch env. params.
cmd:
start (wait for wait-all task to complete)
any docker-compose command (e.g: up,start,down,logs)
testfile expected env.vars:
DCFILE - the docker-compose.yml file to use. defaults to run2bundlers.yml
BUNDLER_YML - bundler-specific file for bootnode bundler
BUNDLER2_YML - bundler-specific file for peer bundler
ENVFILE, ENVFILE2 - extra env.vars used by above bundlers
EOF
exit 1

DC="docker-compose -f $dir/runbundler.yml"
export BUNDLER_YML=`realpath $1`
ENVFILE=`dirname $BUNDLER_YML`/.env
if [ -r $ENVFILE ] ; then
export `grep -v '#' $ENVFILE`
fi
}

file=`realpath $1`
cmd=$2
shift
shift

test -z "$cmd" && usage

case "$file" in
*.yml)
export DCFILE="$dir/runbundler.yml"
export DCPARAMS="--env-file $dir/runbundler.env"
envfile1=`dirname $file`/.env
ENVFILE=`cd $root; realpath $envfile1 2> /dev/null`
test -r "$ENVFILE" && DCPARAMS="$DCPARAMS --env-file $ENVFILE"
export BUNDLER_YML=$file
;;

*.env)
export DCFILE="$dir/run2bundlers.yml"
export DCPARAMS="--env-file $dir/run2bundlers.env"
source $file
test -n "$ENVFILE" && test -r "$root/$ENVFILE" && DCPARAMS="$DCPARAMS --env-file $root/$ENVFILE"
test -n "$ENVFILE2" && test -r "$root/$ENVFILE2" && DCPARAMS="$DCPARAMS --env-file $root/$ENVFILE2"
;;
*) usage ;;

esac

DC="docker-compose $DCPARAMS -f $root/empty.yml -f $DCFILE"
cmd=$cmd
case "$cmd" in

start) $DC run --rm wait-for-bundler ;;
down) $DC down -t 1 ;;
start) $DC run --rm wait-all ;;
down) $DC down -t 1 ;;
stop) $DC stop -t 1 ;;
#execute misc docker-compose command
*) $DC $cmd $* ;;
Expand Down
Loading
Loading