Skip to content

Commit 00b9a87

Browse files
authored
Merge pull request #1284 from o1-labs/block-producer-makefile-target
Fix BP doc and add a CLI command to generate encrypted key
2 parents 2c8a3f0 + 2341493 commit 00b9a87

File tree

9 files changed

+585
-53
lines changed

9 files changed

+585
-53
lines changed

.github/workflows/doc-commands.yml

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
- name: Setup Rust
3333
uses: ./.github/actions/setup-rust
3434
with:
35-
toolchain: nightly
35+
components: rustfmt
36+
toolchain: 1.84
3637
cache-prefix: test-doc-commands-v0
3738

3839
- name: Download circuits files
@@ -71,7 +72,7 @@ jobs:
7172
echo "Testing that generated key can be used by run-block-producer target..."
7273
# Run with --help to avoid actually starting the producer but verify
7374
# key validation passes
74-
timeout 30s make run-block-producer-devnet COINBASE_RECEIVER="test" || {
75+
timeout 30s make run-block-producer NETWORK=devnet COINBASE_RECEIVER=$(cat ./openmina-workdir/producer-key.pub) || {
7576
EXIT_CODE=$?
7677
if [ $EXIT_CODE -eq 124 ]; then
7778
echo "✅ Command started successfully (timed out as expected)"
@@ -83,6 +84,61 @@ jobs:
8384
fi
8485
}
8586
87+
- name: Test generate-block-producer-key with custom filename
88+
run: |
89+
echo "Testing generate-block-producer-key with custom PRODUCER_KEY_FILENAME..."
90+
make generate-block-producer-key PRODUCER_KEY_FILENAME=./openmina-workdir/custom-producer-key
91+
92+
# Verify custom private key file exists
93+
if [ ! -f "./openmina-workdir/custom-producer-key" ]; then
94+
echo "❌ Custom producer key file was not generated"
95+
exit 1
96+
fi
97+
98+
# Verify custom public key file exists
99+
if [ ! -f "./openmina-workdir/custom-producer-key.pub" ]; then
100+
echo "❌ Custom producer public key file was not generated"
101+
exit 1
102+
fi
103+
104+
# Check file permissions (should be 600 for private key)
105+
PERMS=$(stat -c "%a" "./openmina-workdir/custom-producer-key")
106+
if [ "$PERMS" != "600" ]; then
107+
echo "❌ Custom producer key file has incorrect permissions: $PERMS (expected: 600)"
108+
exit 1
109+
fi
110+
111+
# Check both files are not empty
112+
if [ ! -s "./openmina-workdir/custom-producer-key" ]; then
113+
echo "❌ Custom producer key file is empty"
114+
exit 1
115+
fi
116+
117+
if [ ! -s "./openmina-workdir/custom-producer-key.pub" ]; then
118+
echo "❌ Custom producer public key file is empty"
119+
exit 1
120+
fi
121+
122+
echo "✅ Custom producer key pair generated successfully"
123+
124+
- name: Test generate-block-producer-key failure when keys exist
125+
run: |
126+
echo "Testing that generate-block-producer-key fails when keys already exist..."
127+
128+
# Try to generate keys again with default filename (should fail)
129+
if make generate-block-producer-key 2>/dev/null; then
130+
echo "❌ Command should have failed when keys already exist"
131+
exit 1
132+
fi
133+
134+
# Try to generate keys again with custom filename (should fail)
135+
if make generate-block-producer-key PRODUCER_KEY_FILENAME=./openmina-workdir/custom-producer-key 2>/dev/null; then
136+
echo "❌ Command should have failed when custom keys already exist"
137+
exit 1
138+
fi
139+
140+
echo "✅ Command correctly fails when keys already exist"
141+
86142
- name: Test other documented make targets exist
87143
run: |
88144
echo "Testing that documented make targets exist..."

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4747
([#1221](https://github.com/o1-labs/openmina/pull/1221)).
4848
- **Documentation**: add section regarding peers setup and seeds
4949
([#1295](https://github.com/o1-labs/openmina/pull/1295))
50+
- **Node**: add `openmina misc mina-encrypted-key` to generate a new encrypted
51+
key with password, as the OCaml node provides
52+
([#1284](https://github.com/o1-labs/openmina/pull/1284/)).
5053

5154
### Changed
5255

Makefile

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PG_HOST ?= localhost
1515
PG_PORT ?= 5432
1616

1717
# Block producer configuration
18-
PRODUCER_KEY ?= ./openmina-workdir/producer-key
18+
PRODUCER_KEY_FILENAME ?= ./openmina-workdir/producer-key
1919
COINBASE_RECEIVER ?=
2020
OPENMINA_LIBP2P_EXTERNAL_IP ?=
2121
OPENMINA_LIBP2P_PORT ?= 8302
@@ -313,44 +313,45 @@ run-archive: build-release ## Run an archive node with local storage
313313

314314
.PHONY: run-block-producer
315315
run-block-producer: build-release ## Run a block producer node on $(NETWORK) network
316-
@if [ ! -f "$(PRODUCER_KEY)" ]; then \
317-
echo "Error: Producer key not found at $(PRODUCER_KEY)"; \
318-
echo "Please place your producer private key at $(PRODUCER_KEY)"; \
316+
@if [ ! -f "$(PRODUCER_KEY_FILENAME)" ]; then \
317+
echo "Error: Producer key not found at $(PRODUCER_KEY_FILENAME)"; \
318+
echo "Please place your producer private key at $(PRODUCER_KEY_FILENAME)"; \
319319
exit 1; \
320320
fi
321-
MINA_PRIVKEY_PASS="$(MINA_PRIVKEY_PASS)" \
322-
cargo run --bin openmina \
321+
cargo run \
322+
--bin openmina \
323+
--package=cli \
323324
--release -- \
324325
node \
325-
--producer-key $(PRODUCER_KEY) \
326+
--producer-key $(PRODUCER_KEY_FILENAME) \
326327
$(if $(COINBASE_RECEIVER),--coinbase-receiver $(COINBASE_RECEIVER)) \
327328
$(if $(OPENMINA_LIBP2P_EXTERNAL_IP),--libp2p-external-ip $(OPENMINA_LIBP2P_EXTERNAL_IP)) \
328329
$(if $(OPENMINA_LIBP2P_PORT),--libp2p-port $(OPENMINA_LIBP2P_PORT)) \
329330
--network $(NETWORK)
330331

331-
.PHONY: run-block-producer-devnet
332-
run-block-producer-devnet: ## Run a block producer node on devnet
333-
$(MAKE) run-block-producer NETWORK=devnet
334-
335-
.PHONY: run-block-producer-mainnet
336-
run-block-producer-mainnet: ## Run a block producer node on mainnet
337-
$(MAKE) run-block-producer NETWORK=mainnet
338332

339333
.PHONY: generate-block-producer-key
340-
generate-block-producer-key: build-release ## Generate a new block producer key pair
334+
generate-block-producer-key: build-release ## Generate a new block producer key pair (fails if keys exist, use PRODUCER_KEY_FILENAME to customize, MINA_PRIVKEY_PASS for password)
335+
@if [ -f "$(PRODUCER_KEY_FILENAME)" ] || [ -f "$(PRODUCER_KEY_FILENAME).pub" ]; then \
336+
echo "Error: Producer key already exists at $(PRODUCER_KEY_FILENAME) or public key exists at $(PRODUCER_KEY_FILENAME).pub"; \
337+
echo ""; \
338+
echo "To generate a key with a different filename, set PRODUCER_KEY_FILENAME:"; \
339+
echo " make generate-block-producer-key PRODUCER_KEY_FILENAME=./path/to/new-key"; \
340+
echo ""; \
341+
echo "Or remove the existing key first to regenerate it."; \
342+
exit 1; \
343+
fi
341344
@mkdir -p openmina-workdir
342-
@echo "Generating new block producer key pair..."
343-
@OUTPUT=$$(cargo run --release --package=cli --bin openmina -- misc mina-key-pair); \
344-
SECRET_KEY=$$(echo "$$OUTPUT" | grep "secret key:" | cut -d' ' -f3); \
345+
@echo "Generating new encrypted block producer key..."
346+
@OUTPUT=$$($(if $(MINA_PRIVKEY_PASS),MINA_PRIVKEY_PASS="$(MINA_PRIVKEY_PASS)") cargo run --release --package=cli --bin openmina -- misc mina-encrypted-key --file $(PRODUCER_KEY_FILENAME)); \
345347
PUBLIC_KEY=$$(echo "$$OUTPUT" | grep "public key:" | cut -d' ' -f3); \
346-
echo "$$SECRET_KEY" > $(PRODUCER_KEY); \
347-
chmod 600 $(PRODUCER_KEY); \
348+
chmod 600 $(PRODUCER_KEY_FILENAME); \
348349
echo ""; \
349-
echo "✓ Generated new producer key pair:"; \
350-
echo " Secret key saved to: $(PRODUCER_KEY)"; \
351-
echo " Public key: $$PUBLIC_KEY"; \
350+
echo "✓ Generated new encrypted producer key:"; \
351+
echo " Encrypted key saved to: $(PRODUCER_KEY_FILENAME)"; \
352+
echo " Public key: $$PUBLIC_KEY, saved to $(PRODUCER_KEY_FILENAME).pub"; \
352353
echo ""; \
353-
echo "⚠️ IMPORTANT: Keep your secret key secure and backed up!"
354+
echo "⚠️ IMPORTANT: Keep your encrypted key file and password secure and backed up!"
354355

355356
.PHONY: postgres-clean
356357
postgres-clean:

0 commit comments

Comments
 (0)