feat: add miner_ RPC namespace matching geth-bsc MinerAPI#286
Merged
feat: add miner_ RPC namespace matching geth-bsc MinerAPI#286
Conversation
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>
a9f005e to
e9aa990
Compare
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>
e9aa990 to
857e869
Compare
joey0612
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add missing RPC methods to match geth-bsc's API surface, covering the
miner_namespace and twoeth_methods.1.
miner_*RPC Namespace (12 methods)Reference:
bsc/eth/api_miner.goFully Functional (shared state with
mev_namespace)miner_mevRunningboolminer_startMev()miner_stopMev()miner_addBuilderaddress,url()urlaccepted for compat, not used yet)miner_removeBuilderaddress()Informational Error (not applicable in reth-bsc architecture)
These methods return descriptive errors explaining the reth-bsc equivalent configuration approach:
miner_startminer_stopminer_setExtraminer_setGasPriceBSC_MIN_GAS_TIPenv varminer_setGasLimitBSC_GAS_LIMITenv varminer_setEtherbaseBSC_PRIVATE_KEY/BSC_KEYSTORE_PATHminer_setRecommitInterval2.
eth_coinbaseandeth_healtheth_coinbaseeth_healthtrueif the node is healthy (can provide a best block number)Note:
eth_config(EIP-7910) is already provided by reth'sEthConfigHandler— no changes needed.Implementation Details
shared.rs) so bothmev_andminer_namespaces operate on the sameArc<RwLock<HashSet<Address>>>shared::start_mev()/shared::stop_mev()for theminer_namespaceeth_coinbaseoverride: usesremove_method_from_configured("eth_coinbase")to remove reth's default unimplemented handler, then registers the BSC implementationsrc/rpc/miner.rs,src/rpc/eth_ext.rssrc/main.rsalongside existingparlia,mev,blobRPC modulesTest plan
cargo checkpassescargo clippy -p reth_bsc --tests --all-features— no warningscurl -X POST --data '{"jsonrpc":"2.0","method":"miner_mevRunning","params":[],"id":1}' http://localhost:8545miner_addBuilder/miner_removeBuilderverify shared state withmev_hasBuildereth_coinbasereturns validator address instead of "unimplemented" erroreth_healthreturns true on healthy node🤖 Generated with Claude Code