-
Notifications
You must be signed in to change notification settings - Fork 26
/
setup.py
168 lines (132 loc) · 5.32 KB
/
setup.py
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
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
Exposes function to set up the project, in particular clone the Optimism monorepo and build it.
"""
import os
import shutil
import deps
import libroll as lib
from config import Config
####################################################################################################
def setup(config: Config):
deps.check_or_install_go()
deps.go_path_setup()
deps.check_or_install_jq()
deps.check_or_install_node()
deps.check_or_install_pnpm()
deps.check_or_install_foundry()
setup_optimism_repo(config)
setup_op_geth_repo(config)
####################################################################################################
def setup_optimism_repo(config: Config):
github_url = "https://github.com/ethereum-optimism/optimism.git"
git_tag = "op-node/v1.3.1"
git_fix1_tag = "2e57472890f9fea39cde72537935393b068d3e0f"
git_fix2_tag = "5252c82f607af81f6cb741a370425eaf26280892"
git_custom_tag = "roll-op/v1.3.1"
if os.path.isfile("optimism"):
raise Exception("Error: 'optimism' exists as a file and not a directory.")
elif not os.path.exists("optimism"):
print("Cloning the optimism repository. This may take a while...")
lib.clone_repo(github_url, "clone the optimism repository")
head_tag = lib.run(
"get head tag",
"git tag --contains HEAD",
cwd="optimism").strip()
if head_tag != git_custom_tag:
lib.run("[optimism] fetch",
"git fetch",
cwd="optimism")
lib.run("[optimism] checkout stable version",
f"git checkout --detach {git_tag}",
cwd="optimism")
lib.run("[optimism] install devnet fix",
f"git cherry-pick {git_fix1_tag}",
cwd="optimism")
lib.run("[optimism] install submodules fix",
f"git cherry-pick {git_fix2_tag}",
cwd="optimism")
lib.run("[optimism] tag custom version",
f"git tag {git_custom_tag}",
cwd="optimism")
log_file = f"{config.logs_dir}/build_optimism.log"
print(
f"Starting to build the optimism repository. Logging to {log_file}\n"
"This may take a while...")
lib.run_roll_log(
descr="build optimism",
command=deps.cmd_with_node("make build"),
cwd="optimism",
log_file=log_file)
shutil.copyfile("optimism/op-proposer/bin/op-proposer", "bin/op-proposer")
lib.chmodx("bin/op-proposer")
shutil.copyfile("optimism/op-batcher/bin/op-batcher", "bin/op-batcher")
lib.chmodx("bin/op-batcher")
shutil.copyfile("optimism/op-node/bin/op-node", "bin/op-node")
lib.chmodx("bin/op-node")
if not os.path.isfile("optimism/op-program/bin/prestate-proof.json"):
print("Building the Cannon pre-state")
lib.run(
"building the Cannon pre-state",
"make cannon-prestate",
cwd="optimism")
print("Successfully built the optimism repository.")
####################################################################################################
def setup_op_geth_repo(config: Config):
"""
Clone the op-geth repository and build it.
"""
github_url = "https://github.com/ethereum-optimism/op-geth.git"
git_tag = "v1.101304.1"
if os.path.isfile("op-geth"):
raise Exception("Error: 'op-geth' exists as a file and not a directory.")
elif not os.path.exists("op-geth"):
print("Cloning the op-geth repository. This may take a while...")
lib.clone_repo(github_url, "clone the op-geth repository")
head_tag = lib.run(
"get head tag",
"git tag --contains HEAD",
cwd="optimism").strip()
if head_tag != git_tag:
lib.run(
"[op-geth] fetch",
"git fetch",
cwd="op-geth")
lib.run(
"[op-geth] checkout stable version",
f"git checkout --detach {git_tag}",
cwd="op-geth")
log_file = f"{config.logs_dir}/build_op_geth.log"
print(f"Starting to build the op-geth repository. Logging to {log_file}\n"
"This may take a while...")
lib.run_roll_log(
descr="build op-geth",
command=deps.cmd_with_node("make geth"),
cwd="op-geth",
log_file=log_file)
shutil.copyfile("op-geth/build/bin/geth", "bin/op-geth")
lib.chmodx("bin/op-geth")
print("Successfully built the op-geth repository.")
####################################################################################################
def clean_build():
"""
Clean the build outputs (from the Optimism monorepo and the op-geth repo).
Running this will require re-running the setup!
"""
lib.run(
descr="clean optimism repo",
# This encompases `make clean` and `make clean-node-modules` and avoids erroring on `make
# nuke` because Docker is not running.
command="git clean -Xdf",
cwd="optimism",
forward="self")
lib.run(
descr="clean op-geth repo",
command="make clean",
cwd="op-geth",
forward="self")
lib.run(
descr="clean account-abstraction repo",
command="npm run clean && rm -rf node_modules",
cwd="account-abstraction",
forward="self")
####################################################################################################