Skip to content

feat: add miner_ RPC namespace matching geth-bsc MinerAPI#286

Merged
joey0612 merged 10 commits intodevelopfrom
feat/add-miner-rpc-api
Mar 26, 2026
Merged

feat: add miner_ RPC namespace matching geth-bsc MinerAPI#286
joey0612 merged 10 commits intodevelopfrom
feat/add-miner-rpc-api

Conversation

@constwz
Copy link
Copy Markdown
Contributor

@constwz constwz commented Mar 16, 2026

Summary

Add missing RPC methods to match geth-bsc's API surface, covering the miner_ namespace and two eth_ methods.

1. miner_* RPC Namespace (12 methods)

Reference: bsc/eth/api_miner.go

Fully Functional (shared state with mev_ namespace)

Method Params Return Description
miner_mevRunning bool Check if validator is accepting MEV bids
miner_startMev () Enable MEV bid acceptance
miner_stopMev () Disable MEV bid acceptance (in-flight bids still considered)
miner_addBuilder address, url () Add a builder to the whitelist (url accepted for compat, not used yet)
miner_removeBuilder address () Remove a builder from the whitelist

Informational Error (not applicable in reth-bsc architecture)

These methods return descriptive errors explaining the reth-bsc equivalent configuration approach:

Method geth-bsc Behavior reth-bsc Guidance
miner_start Start mining Mining lifecycle managed by node configuration
miner_stop Stop mining Mining lifecycle managed by node configuration
miner_setExtra Set block extra data Extra data managed by Parlia consensus
miner_setGasPrice Set min gas price Use BSC_MIN_GAS_TIP env var
miner_setGasLimit Set gas limit target Use BSC_GAS_LIMIT env var
miner_setEtherbase Set validator address Derived from BSC_PRIVATE_KEY / BSC_KEYSTORE_PATH
miner_setRecommitInterval Set recommit interval Not supported

2. eth_coinbase and eth_health

Method Description
eth_coinbase Returns configured validator address (replaces reth's default "unimplemented" error)
eth_health Returns true if the node is healthy (can provide a best block number)

Note: eth_config (EIP-7910) is already provided by reth's EthConfigHandler — no changes needed.

Implementation Details

  • Builder whitelist moved to global shared state (shared.rs) so both mev_ and miner_ namespaces operate on the same Arc<RwLock<HashSet<Address>>>
  • MEV start/stop exposed via shared::start_mev() / shared::stop_mev() for the miner_ namespace
  • eth_coinbase override: uses remove_method_from_configured("eth_coinbase") to remove reth's default unimplemented handler, then registers the BSC implementation
  • New files: src/rpc/miner.rs, src/rpc/eth_ext.rs
  • Registered in src/main.rs alongside existing parlia, mev, blob RPC modules

Test plan

  • cargo check passes
  • cargo clippy -p reth_bsc --tests --all-features — no warnings
  • Manual test: curl -X POST --data '{"jsonrpc":"2.0","method":"miner_mevRunning","params":[],"id":1}' http://localhost:8545
  • Manual test: miner_addBuilder / miner_removeBuilder verify shared state with mev_hasBuilder
  • Manual test: eth_coinbase returns validator address instead of "unimplemented" error
  • Manual test: eth_health returns true on healthy node

🤖 Generated with Claude Code

@constwz constwz requested a review from joey0612 as a code owner March 16, 2026 08:43
cbh876 and others added 4 commits March 26, 2026 10:19
Add all 12 miner_* RPC methods to match geth-bsc's MinerAPI interface.

Fully functional methods (shared state with mev_ namespace):
- miner_mevRunning: check if MEV is accepting bids
- miner_startMev: enable MEV bid acceptance
- miner_stopMev: disable MEV bid acceptance
- miner_addBuilder: add builder to whitelist
- miner_removeBuilder: remove builder from whitelist

Informational error methods (not applicable in reth-bsc architecture):
- miner_start / miner_stop: mining lifecycle managed by node config
- miner_setExtra: extra data managed by Parlia consensus
- miner_setGasPrice: configured via BSC_MIN_GAS_TIP env var
- miner_setGasLimit: configured via BSC_GAS_LIMIT env var
- miner_setEtherbase: derived from configured private key
- miner_setRecommitInterval: not supported

Builder whitelist is now shared globally via shared.rs so both
mev_ and miner_ namespaces operate on the same state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add BSC-specific implementations for two eth_ namespace methods:

- eth_coinbase: returns the configured validator address (replaces
  reth's default "unimplemented" response). In geth-bsc this is an
  alias for Etherbase() returning the mining reward address.

- eth_health: returns true if the node is healthy (can provide a
  best block number). In geth-bsc this checks RPC serving latency
  percentile.

Note: eth_config (EIP-7910) is already provided by reth's
EthConfigHandler and registered in BscNodeAddOns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two fixes:

1. Remove reth's built-in MinerApi methods (miner_setExtra, miner_setGasPrice,
   miner_setGasLimit) before registering BscMinerApi. These conflict because
   IPC registers all modules by default, including reth's stub MinerApi.

2. Replace .unwrap() with proper error handling in the block import critical
   task. Previously, if launch() failed (e.g., due to RPC registration error),
   the oneshot sender would be dropped, causing the block import task to panic
   with RecvError. Now it logs the error and exits gracefully.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
spawn_critical is designed to shut down the node on task failure.
Replacing unwrap() with graceful error handling would cause the
task to exit silently, leaving the node running in a broken state
without block import capability — which is worse than a clean shutdown.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@constwz constwz force-pushed the feat/add-miner-rpc-api branch from a9f005e to e9aa990 Compare March 26, 2026 02:25
cbh876 and others added 6 commits March 26, 2026 10:41
All 12 miner_* methods now have real implementations backed by
shared dynamic state, matching geth-bsc behavior:

- miner_start/stop: controls mining via shared AtomicBool flag,
  checked by NewWorkWorker before queueing new mining tasks
- miner_setGasLimit: updates gas limit read by MainWorkWorker
  on each block build
- miner_setGasPrice: updates min gas tip for tx selection
- miner_setExtra: stores extra data bytes (max 32 bytes, validated)
- miner_setEtherbase: updates coinbase address, also reflected
  in eth_coinbase responses
- miner_setRecommitInterval: stores recommit interval in shared state

Shared state is initialized from MiningConfig at BscMiner::new().
If no RPC calls are made, behavior is identical to before — the
miner reads the original config values from shared state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Four differences fixed:

1. Validators/recents/recent_fork_hashes now use BTreeMap instead of
   HashMap, producing sorted JSON output matching geth's key ordering.

2. recent_fork_hashes now contains actual fork hash data extracted from
   block headers' extra data (bytes 28..32 of the 32-byte vanity prefix),
   instead of fabricated "00000000" entries. Added recent_fork_hashes
   field to Snapshot struct with #[serde(default)] for backward compat.

3. Fork hash window maintenance matches geth: version_history_check_len()
   = validators_count * turn_length, with cleanup on epoch boundaries
   when validator set changes.

4. Attestation field names changed from camelCase (sourceNumber) to
   PascalCase (SourceNumber) to match geth-bsc format.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…cs (#285)

Add missing metrics to match geth/BSC monitoring dashboards:
- chain.delay.block_recv/vote_first/vote_majority: chain delay histograms
- curVotesPq.local, receivedVotes.local, curVotes.local: vote pool gauges/counters
- monitor.maliciousVote.violateRule1/violateRule2: malicious vote detection
- parlia.doublesign: double sign counter
- New MaliciousVoteMonitor module (ported from geth)
- New block_stats module for chain delay tracking

Co-authored-by: cbh876 <3930922419@qq.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mined blocks also receive votes from other validators but were not
registered in the block_stats cache, so chain_delay_vote_first and
chain_delay_vote_majority were never recorded for self-mined blocks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Also fix proxyed_node_ids → proxied_node_ids rename from upstream.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…aliciousVoteMonitor

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@constwz constwz force-pushed the feat/add-miner-rpc-api branch from e9aa990 to 857e869 Compare March 26, 2026 02:44
@joey0612 joey0612 merged commit ce3c29a into develop Mar 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants