Skip to content

Commit b31459d

Browse files
authored
Merge pull request #1221 from o1-labs/block-producer-makefile-target
Add Makefile targets for block producer operations
2 parents 0242e27 + 30ab752 commit b31459d

File tree

4 files changed

+220
-3
lines changed

4 files changed

+220
-3
lines changed

.github/workflows/doc-commands.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Documentation Commands Test
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
paths:
8+
- 'Makefile'
9+
- 'docs/**'
10+
- 'CLAUDE.md'
11+
- '.github/workflows/doc-commands.yml'
12+
workflow_dispatch:
13+
14+
env:
15+
CARGO_TERM_COLOR: always
16+
RUST_BACKTRACE: full
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
test-doc-commands:
24+
runs-on: ubuntu-22.04
25+
steps:
26+
- name: Git checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup build dependencies
30+
uses: ./.github/actions/setup-build-deps
31+
32+
- name: Setup Rust
33+
uses: ./.github/actions/setup-rust
34+
with:
35+
toolchain: nightly
36+
cache-prefix: test-doc-commands-v0
37+
38+
- name: Download circuits files
39+
uses: ./.github/actions/setup-circuits
40+
41+
- name: Test generate-block-producer-key command
42+
run: |
43+
echo "Testing generate-block-producer-key command..."
44+
make generate-block-producer-key
45+
46+
- name: Verify generated key file
47+
run: |
48+
echo "Verifying generated key file exists and has correct permissions..."
49+
if [ ! -f "./openmina-workdir/producer-key" ]; then
50+
echo "❌ Producer key file was not generated"
51+
exit 1
52+
fi
53+
54+
# Check file permissions (should be 600)
55+
PERMS=$(stat -c "%a" "./openmina-workdir/producer-key")
56+
if [ "$PERMS" != "600" ]; then
57+
echo "❌ Producer key file has incorrect permissions: $PERMS (expected: 600)"
58+
exit 1
59+
fi
60+
61+
# Check file is not empty
62+
if [ ! -s "./openmina-workdir/producer-key" ]; then
63+
echo "❌ Producer key file is empty"
64+
exit 1
65+
fi
66+
67+
echo "✅ Producer key file generated successfully with correct permissions"
68+
69+
- name: Test key file can be read by run-block-producer
70+
run: |
71+
echo "Testing that generated key can be used by run-block-producer target..."
72+
# Run with --help to avoid actually starting the producer but verify
73+
# key validation passes
74+
timeout 30s make run-block-producer-devnet COINBASE_RECEIVER="test" || {
75+
EXIT_CODE=$?
76+
if [ $EXIT_CODE -eq 124 ]; then
77+
echo "✅ Command started successfully (timed out as expected)"
78+
elif [ $EXIT_CODE -eq 1 ]; then
79+
echo "❌ Key validation failed"
80+
exit 1
81+
else
82+
echo "✅ Command validation passed (exit code: $EXIT_CODE)"
83+
fi
84+
}
85+
86+
- name: Test other documented make targets exist
87+
run: |
88+
echo "Testing that documented make targets exist..."
89+
make help | grep -E "(run-block-producer|generate-block-producer-key|run-archive)" || {
90+
echo "❌ Some documented make targets are missing from help output"
91+
exit 1
92+
}
93+
echo "✅ All documented make targets are available"

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4040
([#1247](https://github.com/o1-labs/openmina/pull/1234)).
4141
- **Development tools**: Add shellcheck to the CI
4242
([#1255](https://github.com/o1-labs/openmina/pull/1255))
43-
44-
43+
- **Makefile**: Add `run-block-producer` target with devnet/mainnet support and
44+
`generate-block-producer-key` target for key generation
45+
([#1221](https://github.com/o1-labs/openmina/pull/1221)).
4546

4647
### Changed
4748

Makefile

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ PG_DB ?= openmina_archive
1414
PG_HOST ?= localhost
1515
PG_PORT ?= 5432
1616

17+
# Block producer configuration
18+
PRODUCER_KEY ?= ./openmina-workdir/producer-key
19+
COINBASE_RECEIVER ?=
20+
OPENMINA_LIBP2P_EXTERNAL_IP ?=
21+
OPENMINA_LIBP2P_PORT ?= 8302
22+
1723
# Utilities
1824
NETWORK ?= devnet
1925
GIT_COMMIT := $(shell git rev-parse --short=8 HEAD)
@@ -296,9 +302,50 @@ run-archive: build-release ## Run an archive node with local storage
296302
--release -- \
297303
node \
298304
--archive-archiver-process \
299-
--archive-local-storage
305+
--archive-local-storage \
300306
--network $(NETWORK)
301307

308+
.PHONY: run-block-producer
309+
run-block-producer: build-release ## Run a block producer node on $(NETWORK) network
310+
@if [ ! -f "$(PRODUCER_KEY)" ]; then \
311+
echo "Error: Producer key not found at $(PRODUCER_KEY)"; \
312+
echo "Please place your producer private key at $(PRODUCER_KEY)"; \
313+
exit 1; \
314+
fi
315+
MINA_PRIVKEY_PASS="$(MINA_PRIVKEY_PASS)" \
316+
cargo run --bin openmina \
317+
--release -- \
318+
node \
319+
--producer-key $(PRODUCER_KEY) \
320+
$(if $(COINBASE_RECEIVER),--coinbase-receiver $(COINBASE_RECEIVER)) \
321+
$(if $(OPENMINA_LIBP2P_EXTERNAL_IP),--libp2p-external-ip $(OPENMINA_LIBP2P_EXTERNAL_IP)) \
322+
$(if $(OPENMINA_LIBP2P_PORT),--libp2p-port $(OPENMINA_LIBP2P_PORT)) \
323+
--network $(NETWORK)
324+
325+
.PHONY: run-block-producer-devnet
326+
run-block-producer-devnet: ## Run a block producer node on devnet
327+
$(MAKE) run-block-producer NETWORK=devnet
328+
329+
.PHONY: run-block-producer-mainnet
330+
run-block-producer-mainnet: ## Run a block producer node on mainnet
331+
$(MAKE) run-block-producer NETWORK=mainnet
332+
333+
.PHONY: generate-block-producer-key
334+
generate-block-producer-key: build-release ## Generate a new block producer key pair
335+
@mkdir -p openmina-workdir
336+
@echo "Generating new block producer key pair..."
337+
@OUTPUT=$$(cargo run --release --package=cli --bin openmina -- misc mina-key-pair); \
338+
SECRET_KEY=$$(echo "$$OUTPUT" | grep "secret key:" | cut -d' ' -f3); \
339+
PUBLIC_KEY=$$(echo "$$OUTPUT" | grep "public key:" | cut -d' ' -f3); \
340+
echo "$$SECRET_KEY" > $(PRODUCER_KEY); \
341+
chmod 600 $(PRODUCER_KEY); \
342+
echo ""; \
343+
echo "✓ Generated new producer key pair:"; \
344+
echo " Secret key saved to: $(PRODUCER_KEY)"; \
345+
echo " Public key: $$PUBLIC_KEY"; \
346+
echo ""; \
347+
echo "⚠️ IMPORTANT: Keep your secret key secure and backed up!"
348+
302349
.PHONY: postgres-clean
303350
postgres-clean:
304351
@echo "Dropping DB: ${PG_DB} and user: ${PG_USER}"

website/docs/node-runners/block-producer.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,82 @@ Ensure Docker and Docker Compose are installed on your system -
6262
[monitor sync](http://localhost:8070/dashboard) and
6363
[block production](http://localhost:8070/block-production).
6464

65+
## Alternative: Using Make Command
66+
67+
As an alternative to Docker Compose, you can run the block producer directly
68+
using the Makefile target. This method requires building from source.
69+
70+
### Prerequisites
71+
72+
- Rust toolchain installed
73+
- Git repository cloned and accessible
74+
75+
### Setup and Run
76+
77+
1. **Prepare Your Keys**
78+
79+
You have two options for setting up your producer key:
80+
81+
**Option A: Generate a new key pair**
82+
83+
```bash
84+
make generate-block-producer-key
85+
```
86+
87+
This will create a new key pair and save the private key to
88+
`openmina-workdir/producer-key`.
89+
90+
**Option B: Use an existing key**
91+
92+
```bash
93+
mkdir -p openmina-workdir
94+
cp /path/to/your/private_key openmina-workdir/producer-key
95+
```
96+
97+
2. **Run Block Producer**
98+
99+
For devnet (default):
100+
101+
```bash
102+
make run-block-producer-devnet COINBASE_RECEIVER="YourWalletAddress" \
103+
MINA_PRIVKEY_PASS="YourPassword"
104+
```
105+
106+
Or explicitly specify devnet:
107+
108+
```bash
109+
make run-block-producer NETWORK=devnet COINBASE_RECEIVER="YourWalletAddress" \
110+
MINA_PRIVKEY_PASS="YourPassword"
111+
```
112+
113+
For mainnet (when supported):
114+
115+
```bash
116+
make run-block-producer-mainnet COINBASE_RECEIVER="YourWalletAddress" \
117+
MINA_PRIVKEY_PASS="YourPassword"
118+
```
119+
120+
Optional parameters:
121+
- `OPENMINA_LIBP2P_EXTERNAL_IP` - Sets external IP address
122+
- `OPENMINA_LIBP2P_PORT` - Sets libp2p communication port
123+
- `PRODUCER_KEY` - Path to producer key (default:
124+
`./openmina-workdir/producer-key`)
125+
126+
Example with all options:
127+
128+
```bash
129+
make run-block-producer-devnet \
130+
COINBASE_RECEIVER="YourWalletAddress" \
131+
MINA_PRIVKEY_PASS="YourPassword" \
132+
OPENMINA_LIBP2P_EXTERNAL_IP="1.2.3.4" \
133+
OPENMINA_LIBP2P_PORT="8302"
134+
```
135+
136+
3. **Monitor the Node**
137+
138+
The node will start and listen on port 3000. You can monitor its status by
139+
checking the console output or connecting a frontend dashboard.
140+
65141
### Access Logs
66142

67143
Logs are stored in `openmina-workdir` with filenames like

0 commit comments

Comments
 (0)