-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbuild-l1-image
executable file
·111 lines (96 loc) · 3.83 KB
/
build-l1-image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
# This script builds a docker image with a geth node and deploys the contracts to it.
#
# Usage
#
# ./build-l1-image [rpc-port]
#
# The default rpc port is 8545.
#
# Part of the process of creating the Docker image is to deploy the L1 contracts required by the
# demo. The deployment is not completely deterministic; timing-related thingsl like block numbers
# may change. Therefore, this script will generate an env file in .env.geth, which can be used to
# override certain environment variables from .env in order to make the demo work with the new L1
# image.
#
# The script may print some errors during deployment but will retry on expected
# errors a few times. If it exits with a zero exit code it was successful.
#
# This script only works correctly if run from the root of the git repo.
set -euo pipefail
trap "exit" INT TERM
trap cleanup EXIT
cleanup(){
docker stop $NAME > /dev/null 2>&1 || true
docker rm $NAME > /dev/null 2>&1 || true
}
RPC_PORT=${1:-8545}
RPC_URL=http://localhost:$RPC_PORT
TAG="geth-with-contracts:dev"
NAME=espresso-polygon-zkevm-demo-l1
DATA_DIR="$PWD/.espresso-geth-dev-data-dir"
BLOCK_PERIOD="${ESPRESSO_ZKEVM_L1_BLOCK_PERIOD:-1}"
if [ -d "$DATA_DIR" ]; then
echo "Data directory $DATA_DIR already exists. Please remove it first."
exit 1
fi
mkdir -p $DATA_DIR
echo "Removing existing docker container if it exists."
docker stop $NAME > /dev/null 2>&1 || true
docker rm $NAME > /dev/null 2>&1 || true
echo "Starting geth node."
# The `--syncmode full` argument is required to avoid "missing trie node" errors.
docker run -d -v $DATA_DIR:/geth --name $NAME -p $RPC_PORT:8545 \
ethereum/client-go --dev --http --http.addr 0.0.0.0 --dev.period "$BLOCK_PERIOD" --datadir /geth --syncmode full --gcmode archive --ipcdisable
while ! cast block-number > /dev/null 2>&1; do
echo "Waiting for port $RPC_PORT ..."
sleep 1
done
echo "Funding accounts."
# Loop over accounts and fund them.
while read address; do
# Retry a few times because sending transactions may still fail for a while
# after the RPC is up.
for try in $(seq 1 5); do
echo "Transfer from coinbase to $address"
geth --exec \
"eth.sendTransaction({from: eth.coinbase, to: \"$address\", value: \"10000000000000000000000000000000000000000\"})" \
attach http://localhost:$RPC_PORT && break || sleep "$BLOCK_PERIOD";
done
done <<EOF
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
0x70997970C51812dc3A010C7d01b50e0d17dc79C8
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
0x90F79bf6EB2c4f870365E785982E1f101E93b906
0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65
0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
0x976EA74026E726554dB657fA54763abd0C3a0aa9
0x14dC79964da2C08b23698B3D3cc7Ca32193d9955
0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f
0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
0xBcd4042DE499D14e55001CcbB24a551F3b954096
0x71bE63f3384f5fb98995898A86B02Fb2426c5788
0xFABB0ac9d68B0B445fB7357272Ff202C5651694a
0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec
0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097
0xcd3B766CCDd6AE721141F452C550Ca635964ce71
0x2546BcD3c84621e976D8185a91A922aE77ECEc30
0xbDA5747bFD65F08deb54cb465eB87D40e51B197E
0xdD2FD4581271e230360230F9337D5c0430Bf44C0
0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199
EOF
# Deploy the contracts. Retry a few times because sending transactions may fail
# for a while after having funded the account.
for try in $(seq 1 5); do
echo "Attempting contract deployment."
cargo run --bin deploy -- --provider-url $RPC_URL -o .env.geth && break || sleep 1;
done
echo "Contract deployment completed."
echo "ESPRESSO_ZKEVM_L1_BLOCK_PERIOD=$BLOCK_PERIOD" >> .env.geth
cat .env.geth
docker stop $NAME
HASH=$(docker commit $NAME)
echo "Tagging image $HASH as $TAG"
docker tag $HASH $TAG
echo "Asking for root permissions to make $USER the owner of files $DATA_DIR"
sudo chown -R $USER $DATA_DIR