Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/doc-commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Documentation Commands Test

on:
push:
branches: [ main, develop ]
pull_request:
paths:
- 'Makefile'
- 'docs/**'
- 'CLAUDE.md'
- '.github/workflows/doc-commands.yml'
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test-doc-commands:
runs-on: ubuntu-22.04
steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Setup build dependencies
uses: ./.github/actions/setup-build-deps

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
toolchain: nightly
cache-prefix: test-doc-commands-v0

- name: Download circuits files
uses: ./.github/actions/setup-circuits

- name: Test generate-block-producer-key command
run: |
echo "Testing generate-block-producer-key command..."
make generate-block-producer-key

- name: Verify generated key file
run: |
echo "Verifying generated key file exists and has correct permissions..."
if [ ! -f "./openmina-workdir/producer-key" ]; then
echo "❌ Producer key file was not generated"
exit 1
fi

# Check file permissions (should be 600)
PERMS=$(stat -c "%a" "./openmina-workdir/producer-key")
if [ "$PERMS" != "600" ]; then
echo "❌ Producer key file has incorrect permissions: $PERMS (expected: 600)"
exit 1
fi

# Check file is not empty
if [ ! -s "./openmina-workdir/producer-key" ]; then
echo "❌ Producer key file is empty"
exit 1
fi

echo "✅ Producer key file generated successfully with correct permissions"

- name: Test key file can be read by run-block-producer
run: |
echo "Testing that generated key can be used by run-block-producer target..."
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't set MINA_PRIVKEY_PASS which is required for the block producer to decrypt the private key. This could lead to misleading test results or expose error handling issues.

Suggested change
echo "Testing that generated key can be used by run-block-producer target..."
echo "Testing that generated key can be used by run-block-producer target..."
# Set MINA_PRIVKEY_PASS environment variable
export MINA_PRIVKEY_PASS="testpass"

Copilot uses AI. Check for mistakes.

# Run with --help to avoid actually starting the producer but verify
# key validation passes
timeout 30s make run-block-producer-devnet COINBASE_RECEIVER="test" || {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this make call not trigger compilation process? If it does then 30 seconds will not be enough. Or do I misunderstand what this job is doing?

On my machine the time to do the following is about 3 minutes:

її> make run-block-producer-devnet COINBASE_RECEIVER="test"
make run-block-producer NETWORK=devnet
make[1]: Entering directory '/home/volhovm/code/openmina'
cargo build --release --package=cli --bin openmina
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /home/volhovm/code/openmina/ledger/Cargo.toml
workspace: /home/volhovm/code/openmina/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /home/volhovm/code/openmina/tools/fuzzing/Cargo.toml
workspace: /home/volhovm/code/openmina/Cargo.toml
   Compiling mina-tree v0.16.0 (/home/volhovm/code/openmina/ledger)
   Compiling snark v0.16.0 (/home/volhovm/code/openmina/snark)
   Compiling vrf v0.16.0 (/home/volhovm/code/openmina/vrf)
   Compiling node v0.16.0 (/home/volhovm/code/openmina/node)
   Compiling openmina-node-common v0.16.0 (/home/volhovm/code/openmina/node/common)
   Compiling openmina-node-native v0.16.0 (/home/volhovm/code/openmina/node/native)
   Compiling cli v0.16.0 (/home/volhovm/code/openmina/cli)
    Finished `release` profile [optimized] target(s) in 2m 52s
MINA_PRIVKEY_PASS="" \
        cargo run --bin openmina \
        --release -- \
        node \
        --producer-key ./openmina-workdir/producer-key \
        --coinbase-receiver test \
         \
        --libp2p-port 8302 \
        --network devnet

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the code is recompiled because of action_kind.rs being changed. Gotta fix that first. Good point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be better now.
See https://github.com/o1-labs/openmina/actions/runs/16652525657/job/47128853688?pr=1221.

I changed the target definition by relying on build-release, instead of calling `$(MAKE) build-release in the definition.
Also, thanks to #1276, it should not always recompile the binary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: you can always execute a CI job locally by using act. For instance, you can test locally the doc job using act -j test-doc-commands.

EXIT_CODE=$?
if [ $EXIT_CODE -eq 124 ]; then
echo "✅ Command started successfully (timed out as expected)"
elif [ $EXIT_CODE -eq 1 ]; then
echo "❌ Key validation failed"
exit 1
else
echo "✅ Command validation passed (exit code: $EXIT_CODE)"
fi
}

- name: Test other documented make targets exist
run: |
echo "Testing that documented make targets exist..."
make help | grep -E "(run-block-producer|generate-block-producer-key|run-archive)" || {
echo "❌ Some documented make targets are missing from help output"
exit 1
}
echo "✅ All documented make targets are available"
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1247](https://github.com/o1-labs/openmina/pull/1234)).
- **Development tools**: Add shellcheck to the CI
([#1255](https://github.com/o1-labs/openmina/pull/1255))


- **Makefile**: Add `run-block-producer` target with devnet/mainnet support and
`generate-block-producer-key` target for key generation
([#1221](https://github.com/o1-labs/openmina/pull/1221)).

### Changed

Expand Down
49 changes: 48 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ PG_DB ?= openmina_archive
PG_HOST ?= localhost
PG_PORT ?= 5432

# Block producer configuration
PRODUCER_KEY ?= ./openmina-workdir/producer-key
COINBASE_RECEIVER ?=
OPENMINA_LIBP2P_EXTERNAL_IP ?=
OPENMINA_LIBP2P_PORT ?= 8302

# Utilities
NETWORK ?= devnet
GIT_COMMIT := $(shell git rev-parse --short=8 HEAD)
Expand Down Expand Up @@ -296,9 +302,50 @@ run-archive: build-release ## Run an archive node with local storage
--release -- \
node \
--archive-archiver-process \
--archive-local-storage
--archive-local-storage \
--network $(NETWORK)

.PHONY: run-block-producer
run-block-producer: build-release ## Run a block producer node on $(NETWORK) network
@if [ ! -f "$(PRODUCER_KEY)" ]; then \
echo "Error: Producer key not found at $(PRODUCER_KEY)"; \
echo "Please place your producer private key at $(PRODUCER_KEY)"; \
exit 1; \
fi
MINA_PRIVKEY_PASS="$(MINA_PRIVKEY_PASS)" \
cargo run --bin openmina \
--release -- \
node \
--producer-key $(PRODUCER_KEY) \
$(if $(COINBASE_RECEIVER),--coinbase-receiver $(COINBASE_RECEIVER)) \
$(if $(OPENMINA_LIBP2P_EXTERNAL_IP),--libp2p-external-ip $(OPENMINA_LIBP2P_EXTERNAL_IP)) \
$(if $(OPENMINA_LIBP2P_PORT),--libp2p-port $(OPENMINA_LIBP2P_PORT)) \
--network $(NETWORK)

.PHONY: run-block-producer-devnet
run-block-producer-devnet: ## Run a block producer node on devnet
$(MAKE) run-block-producer NETWORK=devnet

.PHONY: run-block-producer-mainnet
run-block-producer-mainnet: ## Run a block producer node on mainnet
$(MAKE) run-block-producer NETWORK=mainnet

.PHONY: generate-block-producer-key
generate-block-producer-key: build-release ## Generate a new block producer key pair
@mkdir -p openmina-workdir
@echo "Generating new block producer key pair..."
@OUTPUT=$$(cargo run --release --package=cli --bin openmina -- misc mina-key-pair); \
SECRET_KEY=$$(echo "$$OUTPUT" | grep "secret key:" | cut -d' ' -f3); \
PUBLIC_KEY=$$(echo "$$OUTPUT" | grep "public key:" | cut -d' ' -f3); \
echo "$$SECRET_KEY" > $(PRODUCER_KEY); \
chmod 600 $(PRODUCER_KEY); \
echo ""; \
echo "✓ Generated new producer key pair:"; \
echo " Secret key saved to: $(PRODUCER_KEY)"; \
echo " Public key: $$PUBLIC_KEY"; \
echo ""; \
echo "⚠️ IMPORTANT: Keep your secret key secure and backed up!"

.PHONY: postgres-clean
postgres-clean:
@echo "Dropping DB: ${PG_DB} and user: ${PG_USER}"
Expand Down
76 changes: 76 additions & 0 deletions website/docs/node-runners/block-producer.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,82 @@ Ensure Docker and Docker Compose are installed on your system -
[monitor sync](http://localhost:8070/dashboard) and
[block production](http://localhost:8070/block-production).

## Alternative: Using Make Command

As an alternative to Docker Compose, you can run the block producer directly
using the Makefile target. This method requires building from source.

### Prerequisites

- Rust toolchain installed
- Git repository cloned and accessible

### Setup and Run

1. **Prepare Your Keys**

You have two options for setting up your producer key:

**Option A: Generate a new key pair**

```bash
make generate-block-producer-key
```

This will create a new key pair and save the private key to
`openmina-workdir/producer-key`.

**Option B: Use an existing key**

```bash
mkdir -p openmina-workdir
cp /path/to/your/private_key openmina-workdir/producer-key
```

2. **Run Block Producer**

For devnet (default):

```bash
make run-block-producer-devnet COINBASE_RECEIVER="YourWalletAddress" \
MINA_PRIVKEY_PASS="YourPassword"
```

Or explicitly specify devnet:

```bash
make run-block-producer NETWORK=devnet COINBASE_RECEIVER="YourWalletAddress" \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this kind of command, I will add later a script and add in the CI with a timeout 30 ./scripts/foo_bar.sh.

MINA_PRIVKEY_PASS="YourPassword"
```

For mainnet (when supported):

```bash
make run-block-producer-mainnet COINBASE_RECEIVER="YourWalletAddress" \
MINA_PRIVKEY_PASS="YourPassword"
```

Optional parameters:
- `OPENMINA_LIBP2P_EXTERNAL_IP` - Sets external IP address
- `OPENMINA_LIBP2P_PORT` - Sets libp2p communication port
- `PRODUCER_KEY` - Path to producer key (default:
`./openmina-workdir/producer-key`)

Example with all options:

```bash
make run-block-producer-devnet \
COINBASE_RECEIVER="YourWalletAddress" \
MINA_PRIVKEY_PASS="YourPassword" \
OPENMINA_LIBP2P_EXTERNAL_IP="1.2.3.4" \
OPENMINA_LIBP2P_PORT="8302"
```

3. **Monitor the Node**

The node will start and listen on port 3000. You can monitor its status by
checking the console output or connecting a frontend dashboard.

### Access Logs

Logs are stored in `openmina-workdir` with filenames like
Expand Down
Loading