diff --git a/.github/workflows/doc-commands.yml b/.github/workflows/doc-commands.yml new file mode 100644 index 0000000000..0a874c5472 --- /dev/null +++ b/.github/workflows/doc-commands.yml @@ -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..." + # Run with --help to avoid actually starting the producer but verify + # key validation passes + timeout 30s make run-block-producer-devnet COINBASE_RECEIVER="test" || { + 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" diff --git a/CHANGELOG.md b/CHANGELOG.md index b5dd25577c..811afbcf83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Makefile b/Makefile index 685a7c92a2..6f8cb6d1d6 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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}" diff --git a/website/docs/node-runners/block-producer.md b/website/docs/node-runners/block-producer.md index d5a1140fe6..0807392fbb 100644 --- a/website/docs/node-runners/block-producer.md +++ b/website/docs/node-runners/block-producer.md @@ -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" \ + 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