-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrun-dev-node.sh
More file actions
executable file
·135 lines (111 loc) · 4.8 KB
/
run-dev-node.sh
File metadata and controls
executable file
·135 lines (111 loc) · 4.8 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
set -euo pipefail
# Allow overrides from the environment or CLI
NITRO_NODE_VERSION="${NITRO_NODE_VERSION:-v3.7.1-926f1ab}"
TARGET_IMAGE="${TARGET_IMAGE:-offchainlabs/nitro-node:${NITRO_NODE_VERSION}}"
CONTAINER_NAME=nitro-dev
RPC=http://127.0.0.1:8547
PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659
CREATE2_FACTORY=0x4e59b44847b379578588920ca78fbf26c0b4956c
SALT=0x0000000000000000000000000000000000000000000000000000000000000000
EXTRA_ARGS=""
# Clean up docker container on shutdown signals
cleanup() {
echo "Shutting down Docker container '${CONTAINER_NAME}'..."
docker stop -t 30 "${CONTAINER_NAME}" >/dev/null 2>&1 || true
# Force remove the container if shutdown didn't work within the timeout period
docker rm -f "${CONTAINER_NAME}" >/dev/null 2>&1 || true
}
trap cleanup INT TERM EXIT
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--contract-size)
shift
EXTRA_ARGS="${EXTRA_ARGS} --init.dev-max-code-size $1"
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Ensure no stale container is hanging around
docker rm -f "${CONTAINER_NAME}" >/dev/null 2>&1 || true
# Start Nitro dev node in the background
echo "Starting Nitro dev node..."
docker run --rm --name "${CONTAINER_NAME}" -p 8547:8547 "${TARGET_IMAGE}" --dev --http.addr 0.0.0.0 --http.api=net,web3,eth,debug $EXTRA_ARGS &
# Wait for the node to initialize
echo "Waiting for the Nitro node to initialize..."
until [[ "$(curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}' \
$RPC)" == *"result"* ]]; do
sleep 0.1
done
# Check if node is running
curl_output=$(curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}' \
$RPC)
if [[ "$curl_output" == *"result"* ]]; then
echo "Nitro node is running!"
else
echo "Failed to start Nitro node."
exit 1
fi
# Make the caller a chain owner
echo "Setting chain owner to pre-funded dev account..."
cast send 0x00000000000000000000000000000000000000FF "becomeChainOwner()" \
--private-key $PRIVATE_KEY \
--rpc-url $RPC
# Set the L1 data fee to 0 so it doesn't impact the L2 Gas limit.
# This makes the gas estimates closer to Ethereum and allows the deployment of the CREATE2 factory
cast send -r $RPC --private-key $PRIVATE_KEY 0x0000000000000000000000000000000000000070 'setL1PricePerUnit(uint256)' 0x0
# Deploy CREATE2 factory
echo "Deploying the CREATE2 factory"
cast send --rpc-url $RPC --private-key $PRIVATE_KEY --value "1 ether" 0x3fab184622dc19b6109349b94811493bf2a45362
cast publish --rpc-url $RPC 0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222
if [ "$(cast code -r $RPC $CREATE2_FACTORY)" == "0x" ]; then
echo "Failed to deploy CREATE2 factory"
exit 1
fi
# Deploy Cache Manager Contract
echo "Deploying Cache Manager contract..."
deploy_output=$(cast send --private-key $PRIVATE_KEY \
--rpc-url $RPC \
--create 0x60a06040523060805234801561001457600080fd5b50608051611d1c61003060003960006105260152611d1c6000f3fe)
# Extract contract address using awk from plain text output
contract_address=$(echo "$deploy_output" | awk '/contractAddress/ {print $2}')
# Check if contract deployment was successful
if [[ -z "$contract_address" ]]; then
echo "Error: Failed to extract contract address. Full output:"
echo "$deploy_output"
exit 1
fi
echo "Cache Manager contract deployed at address: $contract_address"
# Register the deployed Cache Manager contract
echo "Registering Cache Manager contract as a WASM cache manager..."
registration_output=$(cast send --private-key $PRIVATE_KEY \
--rpc-url $RPC \
0x0000000000000000000000000000000000000070 \
"addWasmCacheManager(address)" "$contract_address")
# Check if registration was successful
if [[ "$registration_output" == *"error"* ]]; then
echo "Failed to register Cache Manager contract. Registration output:"
echo "$registration_output"
exit 1
fi
echo "Cache Manager deployed and registered successfully"
# Deploy StylusDeployer
deployer_code=$(cat ./stylus-deployer-bytecode.txt)
deployer_address=$(cast create2 --salt $SALT --init-code $deployer_code)
cast send --private-key $PRIVATE_KEY --rpc-url $RPC \
$CREATE2_FACTORY "$SALT$deployer_code"
if [ "$(cast code -r $RPC $deployer_address)" == "0x" ]; then
echo "Failed to deploy StylusDeployer"
exit 1
fi
echo "StylusDeployer deployed at address: $deployer_address"
echo "Nitro node is running... (press Ctrl-C to stop)"
# Keep the script alive so cleanup runs on exit
wait