Skip to content

Commit 3b6921b

Browse files
caposselezeroecco
andauthored
BM-193: Add make devnet-up and devnet-down (github#31)
We have considered creating a local devnet using Docker. After some considerations, if the objective of the devnet is to just run in dev-mode and be available as fast as possible, Docker does not sound as a good fit; it takes too much to bootstrap a network, mainly to build the broker. As an alternative, this PR proposes to use a simple Makefile to spin up anvil and the broker natively. Add a `Makefile` to: - start a local devnet in dev-mode: `make devnet-up` - stop the local devnet: `make devnet-down` --------- Co-authored-by: zeroecco <[email protected]>
1 parent da8c2a4 commit 3b6921b

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ out/
88
/broadcast/*/11155111/
99
/broadcast/**/dry-run/
1010

11+
# Devnet logs
12+
/logs
13+
1114
# Dotenv file
1215
# .env
1316

Makefile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.POSIX:
2+
.SILENT:
3+
4+
.PHONY: devnet-up devnet-down check-deps clean all
5+
6+
# Variables
7+
ANVIL_PORT = 8545
8+
ANVIL_BLOCK_TIME = 2
9+
RISC0_DEV_MODE = 1
10+
RUST_LOG = info,broker=debug,boundless_market=debug
11+
PRIV_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
12+
DEPOSIT_AMOUNT = 10
13+
14+
LOGS_DIR = logs
15+
PID_FILE = $(LOGS_DIR)/devnet.pid
16+
17+
all: devnet-up
18+
19+
# Check that required dependencies are installed
20+
check-deps:
21+
for cmd in forge cargo anvil jq; do \
22+
command -v $$cmd >/dev/null 2>&1 || { echo "Error: $$cmd is not installed."; exit 1; }; \
23+
done
24+
25+
devnet-up: check-deps
26+
mkdir -p $(LOGS_DIR)
27+
echo "Building contracts..."
28+
forge build || { echo "Failed to build contracts"; $(MAKE) devnet-down; exit 1; }
29+
echo "Building Rust project..."
30+
cargo build --bin broker || { echo "Failed to build broker binary"; $(MAKE) devnet-down; exit 1; }
31+
echo "Starting Anvil..."
32+
anvil -b $(ANVIL_BLOCK_TIME) > $(LOGS_DIR)/anvil.txt 2>&1 & echo $$! >> $(PID_FILE)
33+
sleep 5
34+
echo "Deploying contracts..."
35+
RISC0_DEV_MODE=$(RISC0_DEV_MODE) forge script contracts/scripts/Deploy.s.sol --rpc-url http://localhost:$(ANVIL_PORT) --broadcast -vv || { echo "Failed to deploy contracts"; $(MAKE) devnet-down; exit 1; }
36+
echo "Fetching contract addresses..."
37+
{ \
38+
SET_VERIFIER_ADDRESS=$$(jq -re '.transactions[] | select(.contractName == "RiscZeroSetVerifier") | .contractAddress' ./broadcast/Deploy.s.sol/31337/run-latest.json); \
39+
PROOF_MARKET_ADDRESS=$$(jq -re '.transactions[] | select(.contractName == "ProofMarket") | .contractAddress' ./broadcast/Deploy.s.sol/31337/run-latest.json); \
40+
echo "Contract deployed at addresses:"; \
41+
echo "SET_VERIFIER_ADDRESS=$$SET_VERIFIER_ADDRESS"; \
42+
echo "PROOF_MARKET_ADDRESS=$$PROOF_MARKET_ADDRESS"; \
43+
echo "Updating .env file..."; \
44+
sed -i.bak "s/^SET_VERIFIER_ADDRESS=.*/SET_VERIFIER_ADDRESS=$$SET_VERIFIER_ADDRESS/" .env && \
45+
sed -i.bak "s/^PROOF_MARKET_ADDRESS=.*/PROOF_MARKET_ADDRESS=$$PROOF_MARKET_ADDRESS/" .env && \
46+
rm .env.bak; \
47+
echo ".env file updated successfully."; \
48+
echo "Starting Broker service..."; \
49+
RISC0_DEV_MODE=$(RISC0_DEV_MODE) RUST_LOG=$(RUST_LOG) ./target/debug/broker \
50+
--priv-key $(PRIV_KEY) \
51+
--proof-market-addr $$PROOF_MARKET_ADDRESS \
52+
--set-verifier-addr $$SET_VERIFIER_ADDRESS \
53+
--deposit-amount $(DEPOSIT_AMOUNT) > $(LOGS_DIR)/broker.txt 2>&1 & echo $$! >> $(PID_FILE); \
54+
} || { echo "Failed to fetch addresses or start broker"; $(MAKE) devnet-down; exit 1; }
55+
echo "Devnet is up and running!"
56+
echo "Make sure to run 'source .env' to load the environment variables."
57+
58+
devnet-down:
59+
echo "Bringing down all services..."
60+
if [ -f $(PID_FILE) ]; then \
61+
while read pid; do \
62+
kill $$pid 2>/dev/null || true; \
63+
done < $(PID_FILE); \
64+
rm $(PID_FILE); \
65+
fi
66+
echo "Devnet stopped."
67+
68+
clean: devnet-down
69+
echo "Cleaning up..."
70+
rm -rf $(LOGS_DIR) ./broadcast
71+
cargo clean
72+
forge clean
73+
echo "Cleanup complete."

docs/src/market/local-development.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@ Before starting, ensure you have cloned with recursive submodules, or pull them
1111
git submodule update --init
1212
```
1313

14+
1. Start a local devnet
15+
```console
16+
make devnet-up
17+
source .env
18+
```
19+
20+
2. Test your deployment with the client CLI.
21+
You can read more about the client on the [proving request][page-requestor-request] page.
22+
23+
```console
24+
RISC0_DEV_MODE=1 RUST_LOG=info,boundless_market=debug cargo run --bin cli -- submit-request request.yaml --wait
25+
```
26+
27+
> If you see "Error: Market error: Failed to check fulfillment status",
28+
> check the deployment logs from running `forge script` and ensure it matches the addresses listed in `.env`
29+
> If they don't match, adjust the `.env` file or try restarting anvil and deploying again.
30+
31+
Congratulations! You now have a local devnet running and a prover that will respond to proving requests.
32+
33+
3. To tear down the local devnet run:
34+
35+
```console
36+
make devnet-down
37+
```
38+
39+
Check out the is-even example in the [Boundless Foundry template][boundless-foundry-template] for an example of how to run and application using the prover market.
40+
41+
You can also try editing `request.yaml` to send a request with different values.
42+
Check `cargo run --bin cli -- --help` for a full list of commands available through the CLI.
43+
44+
If instead you prefer setting up a local devnet step by step, you can run the following commands as an alternative to the Makefile:
45+
1446
1. Build the contracts
1547

1648
```console
@@ -74,10 +106,11 @@ git submodule update --init
74106
75107
Congratulations! You now have a local devnet running and a prover that will respond to proving requests.
76108

77-
Check out the is-even example in the [Boundless Foundry template](https://github.com/boundless-xyz/boundless-foundry-template/)for an example of how to run and application using the prover market.
109+
Check out the is-even example in the [Boundless Foundry template][boundless-foundry-template] for an example of how to run and application using the prover market.
78110

79111
You can also try editing `request.yaml` to send a request with different values.
80112
Check `cargo run --bin cli -- --help` for a full list of commands available through the CLI.
81113

82114
[page-bento-running]: ../prover-manual/bento/running_bento.md
83115
[page-requestor-request]: ../requestor-manual/broadcasting.md
116+
[boundless-foundry-template]: https://github.com/boundless-xyz/boundless-foundry-template/

0 commit comments

Comments
 (0)