-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack
executable file
·362 lines (311 loc) · 10 KB
/
stack
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OS_ARCH=$(uname -m | awk '{if ($0 ~ /arm64|aarch64/) print "arm64"; else if ($0 ~ /x86_64|amd64/) print "amd64"; else print "unsupported_arch"}')
############################################################################
# docker compose
############################################################################
function compose-env() {
export ADMIN_ADDRESS=${@:-"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}
export DISABLE_TELEMETRY=false
}
function compose-init() {
compose-env
chain-clean
if docker volume ls -q | grep -q "^lilypad_chain-data$"; then
docker volume rm lilypad_chain-data
fi
docker compose -f ./docker/docker-compose.dev.yml up chain -d
chain-boot
}
function compose-build() {
load-local-env
compose-env
docker compose -f ./docker/docker-compose.dev.yml build "$@"
}
function compose-up() {
load-local-env
compose-env
docker compose -f ./docker/docker-compose.dev.yml up "$@"
}
function compose-down() {
compose-env
docker compose -f ./docker/docker-compose.dev.yml down
}
############################################################################
# Load env variables from .local.dev
############################################################################
function load-local-env() {
while IFS= read -r line || [ -n "$line" ]; do
# Skip lines that are empty, start with a #, or are just whitespace
if [[ -n "$line" && ! "$line" =~ ^[[:space:]]*# ]]; then
export $line
fi
done < .local.dev
}
############################################################################
# chain
############################################################################
function chain() {
ADMIN_ADDRESS=${@:-"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}
docker run \
--rm \
--name chain \
-p 0.0.0.0:8547:8547 \
-p 0.0.0.0:8548:8548 \
offchainlabs/nitro-node:v3.1.1-beta.2-6073359 \
--init.dev-init \
--init.dev-init-address $ADMIN_ADDRESS \
--node.dangerous.no-l1-listener \
--node.parent-chain-reader.enable=false \
--parent-chain.id=1337 \
--chain.id=412346 \
--persistent.chain /tmp/dev-test \
--node.sequencer \
--execution.sequencer.enable \
--node.dangerous.no-sequencer-coordinator \
--node.staker.enable=false \
--init.empty=false \
--http.port 8547 \
--http.addr 0.0.0.0 \
--ws.port 8548 \
--ws.addr 0.0.0.0
}
function chain-boot() {
echo "- Install local dependencies"
cd hardhat && npm install -y
echo "- Fund services with ether"
npx hardhat run scripts/fund-services-ether.ts --network dev
echo "- Compile contracts"
npx hardhat compile --network dev
cd ..
go-bindings
echo "- Deploy contracts"
cd hardhat
npx hardhat deploy --network dev
echo "- Fund services with tokens"
npx hardhat run scripts/fund-services-tokens.ts --network dev
cd ..
echo "- Done"
}
function go-bindings() {
# check if the lilypad-solc image exists
# and only build it if it doesn't
if [[ -z $(docker images -q lilypad-solc) ]]; then
docker build -t lilypad-solc hardhat/solc
fi
rm -rf pkg/web3/bindings
mkdir -p pkg/web3/bindings
go-binding LilypadToken token
go-binding LilypadPayments payments
go-binding LilypadStorage storage
go-binding LilypadUsers users
go-binding LilypadMediationRandom mediation
go-binding LilypadOnChainJobCreator jobcreator
go-binding LilypadController controller
go-binding LilypadPow pow
echo "- Generated all go bindings pkg/contract/bindings/"
}
function go-binding() {
local name="$1"
local pkg="$2"
# compile the sol files into bytecode and ABI
docker run --rm \
-v $(pwd)/hardhat:/src \
-w /src \
--user $(id -u):$(id -g) \
--entrypoint solc \
lilypad-solc \
--base-path . \
--include-path node_modules \
--overwrite \
--abi --bin \
"contracts/$name.sol" \
-o artifacts
mkdir -p hardhat/artifacts/bindings/$pkg
# generate the go bindings
docker run --rm \
-v $(pwd)/hardhat:/src \
-w /src \
--user $(id -u):$(id -g) \
--entrypoint abigen \
lilypad-solc \
"--bin=artifacts/$name.bin" \
"--abi=artifacts/$name.abi" \
"--pkg=$pkg" "--out=artifacts/bindings/$pkg/$pkg.go"
cp -r hardhat/artifacts/bindings/$pkg pkg/web3/bindings/$pkg
echo "- Generated go binding hardhat/artifacts/bindings/$pkg/$pkg.go"
}
function chain-clean(){
rm -Rf $(pwd)/data/chain
rm -rf $(pwd)/hardhat/artifacts
rm -rf $(pwd)/hardhat/cache
rm -rf $(pwd)/hardhat/deployments/geth
rm -rf $(pwd)/hardhat/deployments/dev
rm -rf $(pwd)/hardhat/.openzeppelin
}
############################################################################
# helpers
############################################################################
function hardhat-script() {
(
set -euo pipefail
cd hardhat
npx hardhat run "$@"
)
}
function print-env() {
hardhat-script scripts/print-env.ts | grep export
}
function print-contract-env() {
hardhat-script scripts/print-contract-env.ts | grep export
}
function print-local-dev-env() {
print-contract-env
}
function run-cowsay-onchain() {
load-local-env
cd hardhat
npx hardhat run scripts/run-cowsay-onchain.ts
}
############################################################################
# solver
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function solver() {
load-local-env
export WEB3_PRIVATE_KEY=${SOLVER_PRIVATE_KEY}
export LOG_LEVEL=debug
go run . solver --network dev
}
function solver-docker-build() {
docker build \
-t solver \
-f ./docker/solver/Dockerfile \
--build-arg arch=${OS_ARCH} \
--build-arg network=dev \
.
}
function solver-docker-run() {
docker run \
--rm \
--name solver \
--add-host localhost:host-gateway \
-p 8080:8080 \
-e DOPPLER_TOKEN="$(doppler configs tokens create -p solver -c dev docker --max-age 1m --plain)" \
solver
}
############################################################################
# job creator
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function job-creator() {
load-local-env
export WEB3_PRIVATE_KEY=${JOB_CREATOR_PRIVATE_KEY}
export LOG_LEVEL=debug
go run . jobcreator --network dev
}
function job-creator-docker-build() {
docker build \
-t job-creator \
-f ./docker/job-creator/Dockerfile \
--build-arg network=dev \
.
}
function job-creator-docker-run() {
docker run \
--rm \
--name job-creator \
--add-host localhost:host-gateway \
-e DOPPLER_TOKEN="$(doppler configs tokens create -p job-creator -c dev docker --max-age 1m --plain)" \
job-creator
}
############################################################################
# resource provider
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function resource-provider() {
load-local-env
export WEB3_PRIVATE_KEY=${RESOURCE_PROVIDER_PRIVATE_KEY}
export LOG_LEVEL=debug
go run . resource-provider "$@" --network dev --disable-pow true
}
function resource-provider-docker-build() {
docker build \
-t resource-provider \
-f ./docker/resource-provider/Dockerfile \
--build-arg NETWORK=dev \
--build-arg DISABLE_POW=true \
.
}
function resource-provider-docker-run() {
docker run \
--rm \
--name resource-provider \
--add-host localhost:host-gateway \
--env-file <(doppler -p resource-provider -c dev secrets download --no-file --format docker) \
-v /var/run/docker.sock:/var/run/docker.sock \
-e OFFER_GPU=0 \
-e BACALHAU_API_HOST="DO_NOT_SET" \
resource-provider
}
############################################################################
# bacalhau node
############################################################################
function bacalhau-node(){
export BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs
export LOG_LEVEL=debug
bacalhau serve --node-type compute,requester --peer none --private-internal-ipfs=false --job-selection-accept-networked
}
function bacalhau-docker-build() {
docker build \
-t bacalhau \
-f ./docker/bacalhau/Dockerfile \
.
}
function bacalhau-docker-run() {
docker run \
--privileged \
--rm \
--name bacalhau \
--add-host localhost:host-gateway \
-v /tmp/lilypad/data:/tmp/lilypad/data \
-p 1234:1234 \
bacalhau
}
############################################################################
# mediator
############################################################################
function mediator() {
go run . mediator "$@"
}
############################################################################
# tests
############################################################################
function unit-tests() {
cd hardhat
npx hardhat test --network hardhat
}
# this assumes stack is running
# see LOCAL_DEVELOPMENT.md
function integration-tests() {
load-local-env
cd test
go test -v -count 1 .
}
############################################################################
# run
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function run() {
load-local-env
export WEB3_PRIVATE_KEY=${RUN_PRIVATE_KEY}
export LOG_LEVEL=info
go run . run --network dev "$@"
}
eval "$@"