Skip to content

Support external miners over RPC - #112

Merged
motoZ-crypto merged 14 commits into
masterfrom
support-external-miner
Jul 1, 2026
Merged

Support external miners over RPC#112
motoZ-crypto merged 14 commits into
masterfrom
support-external-miner

Conversation

@motoZ-crypto

Copy link
Copy Markdown
Collaborator

Consensus

  • Swap the sha256pow crate for poscan-pow
  • Drop sp-core from poscan so its work golden rides wasm

External mining

  • Add mining_* RPC for external miners to pull work and submit seals

Internal miner

  • Mine across multiple threads

Tuning

  • Lower the initial difficulty

Closes #105

poscan only borrowed H256 and U256 from sp-core, and sp-core drags a
native secp256k1 C build that will not cross compile to wasm32-wasip1.
Swapping to primitive-types, which sp-core merely re-exports, removes that
block, so the work golden now runs directly under wasmtime next to native.
The on chain s value stays bit identical because the types are the same.

This makes the wasm determinism gate a direct check on the work value s
itself instead of a proxy on the scan features, run on both x86_64 and
aarch64 in CI.
External miners pull the current task over mining_getTask and submit a found seal over mining_submitSeal, running the scan outside the node.

--miner sets the reward address and exposes the mining rpc. --node-miner additionally runs the in process scan loop so the node mines locally.
The mining worker now stacks a fresh task every second instead of overwriting the last one. A miner can submit a seal for any task still tied to the current head, old or new, and a new block clears them all.

External miners can subscribe to mining_subscribeTask for a task pushed every second, alongside the mining_getTask pull and the mining_submitSeal submit.
- move seal import off the rpc reactor with spawn_blocking so a flood of
  submissions cannot stall the async executor
- collapse the per head task store into one bounded deque, capped so a stalled
  head stops leaking a proposal every tick
- hold the proposal budget to the worker tick so authoring keeps a one second
  cadence even under load
`--node-miner` now takes an optional thread count. The bare flag spreads the
scan across all cores; a number caps it. Each thread walks its own slice of the
nonce space by stride, so no two threads repeat the same work.
Each scan thread submitted its own seal, so concurrent imports for the same
head drained the WASM runtime instance pool. Threads now share a claim guard
and only one submits per pre_hash.
@motoZ-crypto motoZ-crypto added this to the Alpha-0.3 milestone Jun 30, 2026
@motoZ-crypto motoZ-crypto self-assigned this Jun 30, 2026
@motoZ-crypto motoZ-crypto added T-enhancement New feature or request A-consensus Consensus mechanism (Generally) A-node Node binary, service layer, CLI A-pow POW block production, mining algorithm T-ci CI/CD, build, Dockerfile labels Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@motoZ-crypto, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 77c56d8a-e95b-4f9b-ada1-8ec8dacde24c

📥 Commits

Reviewing files that changed from the base of the PR and between bfaef4f and b4d5d62.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • Cargo.toml
  • README.md
  • consensus/poscan-pow/Cargo.toml
  • consensus/poscan-pow/src/lib.rs
  • consensus/sc-consensus-pow/src/lib.rs
  • consensus/sc-consensus-pow/src/worker.rs
  • consensus/sha256pow/src/lib.rs
  • node/Cargo.toml
  • node/src/cli.rs
  • node/src/command.rs
  • node/src/main.rs
  • node/src/mining_rpc.rs
  • node/src/rpc.rs
  • node/src/service.rs
  • runtime/Cargo.toml
  • runtime/src/apis.rs
  • runtime/src/genesis_config_presets.rs
  • zombienet/integration/zombienet.toml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch support-external-miner

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Jun 30, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in bfaef4f...b4d5d62 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Jun 30, 2026 5:29p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

builds.pop_front();
}
let live = builds.len();
drop(builds);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using `drop` with type that implements `Copy`


For types that implement the Copy trait, std::mem::forget (or
std::mem::drop) effectively does nothing because the type is copied into the
function call, and the newly copied type is forgotten (or dropped).
Additionally, Copy types do not have destructors; there is nothing for
std::mem::forget or (or std::mem::drop) to do.

Comment thread node/src/command.rs

let node_miner = match cli.node_miner {
None => 0,
Some(0) => std::thread::available_parallelism().map(|c| c.get()).unwrap_or(1),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Called `.map().unwrap_or()` on a `Result` value, use `.map_or(, )`


Chains of the form .map(..).unwrap_or(..) can be simplified to use .map_or(..). These shorthands
are available on Result as well as Option. Replace:

  • .map(<f>).unwrap_or(<g>) with .map_or(<g>, <f>)
  • .map(<f>).unwrap_or_else(<g>) with .map_or_else(<g>, <f>)

@motoZ-crypto
motoZ-crypto merged commit 1f87f20 into master Jul 1, 2026
5 of 6 checks passed
@motoZ-crypto
motoZ-crypto deleted the support-external-miner branch July 1, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-consensus Consensus mechanism (Generally) A-node Node binary, service layer, CLI A-pow POW block production, mining algorithm T-ci CI/CD, build, Dockerfile T-enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for external miner

1 participant