forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-geth.sh
executable file
·86 lines (76 loc) · 2.53 KB
/
init-geth.sh
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
#!/bin/sh
set -e
# Check if the jwtsecret file exists
if [ -f "/tmp/jwtsecret" ]; then
echo "Using jwtsecret from file"
elif [ ! -z "$JWT_SECRET" ]; then
echo "Using jwtsecret from environment variable"
echo "$JWT_SECRET" > /tmp/jwtsecret
else
echo "JWT_SECRET environment variable is not set and jwtsecret file is not found"
exit 1
fi
# Check if the genesis file is specified
if [ -z "$GENESIS_FILE" ]; then
echo "GENESIS_FILE environment variable is not set"
exit 1
fi
# Check if the genesis file exists
if [ ! -f "/$GENESIS_FILE" ]; then
echo "Specified genesis file /$GENESIS_FILE does not exist"
exit 1
fi
# Update the genesis file with the specified timestamp and mixHash if they are set
if [ ! -z "$GENESIS_TIMESTAMP" ]; then
# Check if the timestamp is in hexadecimal format (starts with "0x")
if [[ "$GENESIS_TIMESTAMP" =~ ^0x ]]; then
echo "Using hexadecimal timestamp: $GENESIS_TIMESTAMP"
timestamp_hex="$GENESIS_TIMESTAMP"
else
# Convert base 10 timestamp to hexadecimal
echo "Converting base 10 timestamp to hexadecimal"
timestamp_hex=$(printf "0x%x" "$GENESIS_TIMESTAMP")
fi
echo "Updating timestamp in genesis file"
sed -i "s/\"timestamp\": \".*\"/\"timestamp\": \"$timestamp_hex\"/" "/$GENESIS_FILE"
else
echo "GENESIS_TIMESTAMP environment variable is not set, using existing value in genesis file"
fi
if [ ! -z "$GENESIS_MIX_HASH" ]; then
echo "Updating mixHash in genesis file"
sed -i "s/\"mixHash\": \".*\"/\"mixHash\": \"$GENESIS_MIX_HASH\"/" "/$GENESIS_FILE"
else
echo "GENESIS_MIX_HASH environment variable is not set, using existing value in genesis file"
fi
# Check if the data directory is empty
if [ ! "$(ls -A /root/ethereum)" ]; then
echo "Initializing new blockchain..."
geth init --cache.preimages --state.scheme=hash --datadir /root/ethereum "/$GENESIS_FILE"
else
echo "Blockchain already initialized."
fi
# Set default RPC gas cap if not provided
RPC_GAS_CAP=${RPC_GAS_CAP:-500000000}
# Start geth in server mode without interactive console
exec geth \
--datadir /root/ethereum \
--http \
--http.addr "0.0.0.0" \
--http.api "eth,net,web3,debug" \
--http.vhosts="*" \
--http.corsdomain="*" \
--authrpc.addr "0.0.0.0" \
--authrpc.vhosts="*" \
--authrpc.port 8551 \
--authrpc.jwtsecret /tmp/jwtsecret \
--nodiscover \
--cache 25000 \
--cache.preimages \
--maxpeers 0 \
--rpc.gascap $RPC_GAS_CAP \
--syncmode full \
--gcmode archive \
--rollup.disabletxpoolgossip \
--rollup.enabletxpooladmission=false \
--history.state 0 \
--history.transactions 0