forked from 0xFacet/facet-geth
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit-geth.sh
More file actions
executable file
·155 lines (129 loc) · 4.29 KB
/
init-geth.sh
File metadata and controls
executable file
·155 lines (129 loc) · 4.29 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/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
ENABLE_PREIMAGES=${ENABLE_PREIMAGES:-true}
# Build preimages flag for init if enabled
INIT_PREIMAGES_FLAG=""
if [ "$ENABLE_PREIMAGES" = "true" ]; then
INIT_PREIMAGES_FLAG="--cache.preimages"
fi
# Check if the data directory is empty
if [ ! "$(ls -A /root/ethereum)" ]; then
echo "Initializing new blockchain..."
geth init $INIT_PREIMAGES_FLAG --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}
# Set default cache size if not provided
CACHE_SIZE=${CACHE_SIZE:-25000}
# Set default auth RPC port if not provided
AUTH_RPC_PORT=${AUTH_RPC_PORT:-8551}
GC_MODE=${GC_MODE:-archive}
STATE_HISTORY=${STATE_HISTORY:-0}
TX_HISTORY=${TX_HISTORY:-0}
CACHE_GC=${CACHE_GC:-25}
CACHE_TRIE=${CACHE_TRIE:-15}
# Build override flags
OVERRIDE_FLAGS=""
if [ ! -z "$BLUEBIRD_TIMESTAMP" ]; then
echo "Setting Bluebird fork timestamp to: $BLUEBIRD_TIMESTAMP"
OVERRIDE_FLAGS="$OVERRIDE_FLAGS --override.bluebird=$BLUEBIRD_TIMESTAMP"
fi
# Build preimages flag if enabled
PREIMAGES_FLAG=""
if [ "$ENABLE_PREIMAGES" = "true" ]; then
PREIMAGES_FLAG="--cache.preimages"
fi
# Log the configuration
echo "Starting geth with:"
echo " GC Mode: $GC_MODE"
echo " State History: $STATE_HISTORY blocks"
echo " Transaction History: $TX_HISTORY blocks"
echo " Cache Size: $CACHE_SIZE MB"
echo " Preimages: $ENABLE_PREIMAGES"
# Remove any stale IPC socket from a previous run
if [ -S /root/ethereum/geth.ipc ]; then
echo "Removing stale IPC socket from previous run"
rm -f /root/ethereum/geth.ipc || true
fi
# Start geth in background to fix IPC permissions
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 $AUTH_RPC_PORT \
--authrpc.jwtsecret /tmp/jwtsecret \
--nodiscover \
--cache $CACHE_SIZE \
--cache.gc $CACHE_GC \
--cache.trie $CACHE_TRIE \
$PREIMAGES_FLAG \
--maxpeers 0 \
--rpc.gascap $RPC_GAS_CAP \
--syncmode full \
--gcmode $GC_MODE \
--rollup.disabletxpoolgossip \
--rollup.enabletxpooladmission=false \
--history.state $STATE_HISTORY \
--history.transactions $TX_HISTORY $OVERRIDE_FLAGS &
# Capture the PID
GETH_PID=$!
# Wait for IPC socket to be created
echo "Waiting for IPC socket to be created..."
while [ ! -S /root/ethereum/geth.ipc ]; do
sleep 0.5
done
# Make it world readable/writable
chmod 666 /root/ethereum/geth.ipc
echo "IPC socket permissions fixed to 666"
ls -la /root/ethereum/geth.ipc
# Bring geth back to foreground so Docker can track it properly
wait $GETH_PID