-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoxen-multi-sn-upgrade
More file actions
executable file
·147 lines (119 loc) · 4.66 KB
/
oxen-multi-sn-upgrade
File metadata and controls
executable file
·147 lines (119 loc) · 4.66 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
#!/bin/bash
set -e
print_help() {
cat <<HELP
Usage: oxen-multi-sn-upgrade 'https://l2.provider/url' [backups...]
Usage: oxen-multi-sn-upgrade l2-oxend IP:PORT/PUBKEY [backups...]
Specify one or more l2-providers to add to oxend configs.
To set up all multi-nodes on this machine to communicate directly with an
Arbitrum One RPC provider, simply run this command with the primary RPC URL
optionally followed by any backup providers you want to configure that will be
used if the backup is inaccessible or starts significantly lagging. For
example:
oxen-multi-sn-upgrade 'https://example.com/arb1rpc' 'https://backup.example.com/arb1'
You can also configure oxend in L2 proxy mode to significantly reduce the L2
provider RPC usage. This script can configure nodes to use a preconfigured
oxend proxy, but does not automatically configure the proxy oxend node itself.
For more details on setting up a proxy, see online Session node documentation.
The listed providers will be tested to make sure they are reachable and are
providing services for the correct Arbitrum One network; to skip this check add
the word "nocheck" before the URLs:
oxen-multi-sn-upgrade nocheck 'http://example.com/xyzrpc' 'https://backup.example.org'
To configure the nodes on this server to use such a proxy run this command with
one or more address/pubkeys that have been configured to allow this node to use
the proxy, such as the following (ignore the \\, the command should be entered
as one single command):
oxen-multi-sn-upgrade l2-oxend \\
10.11.12.13:5678/1ed91b8657b897dcca052343d19df402bf58a90134132266b1634e0bacdf89d2 \\
10.20.30.40:9876/d511bcbbf01f739187df45a59501aafaa02cedda678d05cb9aee27f9b91f0caf
(Note that if the proxy is a very old node (installed before Oxen v8), it may
have different primary pubkey and Ed25519 pubkeys: in such a case you must use
Ed25519 pubkey rather than the primary SN pubkey here).
HELP
}
if [ "$#" -eq 0 ] || [[ "$1" =~ ^- ]]; then
print_help
exit 1
fi
if [ "$UID" -ne 0 ]; then
echo "This script must be run as root (e.g. via sudo)."
exit 1
fi
l2_setting=
bad=
if [ "$1" = "l2-oxend" ]; then
shift
for proxy in "$@"; do
if [[ "$proxy" =~ ^([1-9][0-9]*\.){3}[1-9][0-9]*:[1-9][0-9]{0,4}/[a-fA-F0-9]{64}$ ]] || [[ "$proxy" =~ ^ipc://. ]]; then
l2_setting="$l2_setting\nl2-oxend=$proxy"
else
bad=1
echo "Invalid l2-oxend proxy address: '$proxy'; expected IP:PORT/PUBKEY"
fi
done
else
if [ "$1" = "nocheck" ]; then
shift
else
for url in "$@"; do
outi=$(mktemp)
erri=$(mktemp)
echo -en "\nChecking '$url'..."
if curl -sSX POST "$url" --connect-timeout 10 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' -o "$outi" 2>"$erri"; then
if grep '"0xa4b1"' "$outi" >/dev/null; then
echo -e " Success!"
else
bad=1
echo -e " Did not find expected Arbitrum One network id \"0xa4b1\" in the L2 provider 'eth_chainId' response:\n-----"
cat "$outi"
echo -e "-----\nThis RPC provider may be on the wrong network\n"
fi
else
bad=1
echo -e " Request failed:\n-----"
cat "$erri"
echo -e "-----\n"
fi
done
fi
for proxy in "$@"; do
l2_setting="$l2_setting\nl2-provider=$proxy"
done
fi
if [ "$#" -eq 0 ]; then
echo "No L2 providers given, unable to proceed!"
bad=1
fi
if [ -n "$bad" ]; then
echo -e "\n\n\e[31;1mCorrect the errors above and then re-run this script\e[0m\n"
exit 1
fi
oxend_upgrade=()
shopt -s nullglob
echo "Finding oxend configs that need L2 configuration:"
for x in /etc/oxen/node-[0-9][0-9].conf; do
if ! grep -q '^\(l2-oxend\|l2-provider\)' $x; then
oxend_upgrade+=("$x")
echo " - $x"
fi
done
if [ "${#oxend_upgrade[@]}" = "0" ]; then
echo "Nothing to upgrade"
exit 0
fi
restarts=()
if [ "${#oxend_upgrade[@]}" -gt 0 ]; then
echo -e "\n"
echo "About to add the following L2 configuration to the oxend configs listed above:"
echo -e "$l2_setting" | sed -e 's/^/ /'
echo ""
read -p "Press enter to continue, Ctrl-C to abort."
for ox in "${oxend_upgrade[@]}"; do
echo -e "$l2_setting" >>"$ox"
done
restarts+=(oxen-nodes.target)
fi
echo -e "\nAll done."
if [ "${#restarts[*]}" -gt 0 ]; then
echo -e "\nYou probably want to run this now to restart services with the update configs:\n\n systemctl restart ${restarts[*]}\n"
fi