Skip to content

fix(miner): preserve valid work across mempool updates#226

Merged
ValarDragon merged 3 commits into
mainfrom
agent/preserve-valid-internal-miner-work
Jul 20, 2026
Merged

fix(miner): preserve valid work across mempool updates#226
ValarDragon merged 3 commits into
mainfrom
agent/preserve-valid-internal-miner-work

Conversation

@ValarDragon

@ValarDragon ValarDragon commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Motivation

The internal miner cancelled active Equihash solver work whenever a long-poll
block template produced a different header. Mempool-only template updates change
the transaction roots in the header, but the old block remains potentially valid
because newly received transactions do not have to be included.

An accepted transaction stream could therefore make the optional internal miner
repeatedly restart useful work even though getblocktemplate returned
submitold: true.

Solution

Use the template's submitold decision when publishing work to the internal
solver. Keep mining the current template when a changed template explicitly says
old work remains valid, and replace it when the response invalidates old work or
does not provide a reuse decision.

Identical headers remain suppressed as before. External RPC miners are unchanged;
they continue to receive the full getblocktemplate response.

Add focused coverage for initial publication, identical headers, reusable
mempool-only updates, invalidating updates, and missing submitold values. Update
the operator changelog.

Testing

  • cargo test -p zakura --features internal-miner mining_template_updates_respect_submit_old
  • cargo clippy -p zakura --features internal-miner --lib -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

Specifications & References


Note

Low Risk
Scoped to optional internal-miner template publishing; aligns with BIP 22 long-poll semantics and does not change RPC miners or consensus.

Overview
The internal miner no longer restarts Equihash work on every long-poll template whose header differs. generate_block_templates now reads submit_old from the RPC template and only pushes a new block to solvers when should_replace_mining_template says prior work is invalid—unchanged headers are still ignored, and submitold: true (typical mempool-only updates) keeps the current template so solvers are not cancelled.

Logging distinguishes a real template swap from keeping work (debug when work is preserved). A unit test covers initial publish, identical headers, reusable mempool updates, invalidating updates, and missing submit_old. The unreleased changelog records the fix. External RPC miners are unchanged.

Reviewed by Cursor Bugbot for commit 66a418e. Bugbot is set up for automated code reviews on this repo. Configure here.

@v12-auditor

v12-auditor Bot commented Jul 16, 2026

Copy link
Copy Markdown

Note

Analyzing: V12 is analyzing the changed code now.

View live progress here.

@ValarDragon
ValarDragon marked this pull request as ready for review July 19, 2026 23:01
@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_bbade51b-4efd-4e11-b5d6-0b7c605daab6)

@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_36664d42-594a-46e9-bd0b-a9519409e4ec)

@evan-forbes evan-forbes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

personally I found the title a bit confusing, but generally agree that mempool churn shouldn't have a an impact on restarting or sleeping the template

@ValarDragon

Copy link
Copy Markdown
Contributor Author

@codex fix changelog

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@ValarDragon

Copy link
Copy Markdown
Contributor Author

@codex fix changelog

…internal-miner-work

# Conflicts:
#	CHANGELOG.md
@cursor

cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_8e05f53d-abd0-4aab-b6ea-dbedf9bf5c67)

@ValarDragon
ValarDragon merged commit 902fd38 into main Jul 20, 2026
52 checks passed
@ValarDragon
ValarDragon deleted the agent/preserve-valid-internal-miner-work branch July 20, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants