mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:17:38 +00:00
mining: add precious option to IPC block submission #35300
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35300
Loading…
Reference in a new issue
No description provided.
Delete branch "ipc-submit-block-precious"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds a
preciousflag to the IPC Mining submitBlock and submitSolution methods, as suggested in https://github.com/bitcoin/bitcoin/pull/34644#discussion_r3247072448. Built on top https://github.com/bitcoin/bitcoin/pull/34644.With this change, IPC mining clients can submit and prefer a block in one IPC call, instead of submitting it over IPC and then using the
preciousblockRPC separately.By default, same-work side blocks keep the existing behavior:
submitBlockreports duplicate/inconclusive cases as failure with a reason, whilesubmitSolutioncontinues to return true whenProcessNewBlockaccepts or already knows the block.Includes unit and IPC functional coverage for default behavior, precious reorgs, active-tip no-op submissions, and invalid-block rejection.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/25951528963/job/76290253269LLM reason (✨ experimental): CI failed due to a C++ build error:
src/node/miner.cppwould not compile (clang: passingCBlockIndex*whereconst CBlockIndex&is required inchainman.ActiveChain().Contains).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Maybe do this after #34672?
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
There's some game theory miners should contemplate before using this though:
It's clearly rational to prefer your own block for p2p relay, but it's less obvious that you should mine the next block on it.
That might be a sunk-cost fallacy. If you saw the other block first, it's a good assumption that the rest of the network also saw it first.
In a Job Declaration scenario, the main criterion for which block to build on should be the side of the fork the pool picked. Unfortunately afaik the sv2 protocol doesn't currently communicate that (cc @plebhash).
In a1f8966316dcd0807d0ee612327d4a822c89177f test: cover precious mining submissions: mmm, I don't think
preciousshould change the behavior if the block is duplicate, so just returnduplicate?Similarly, if we already had it, but it wasn't the tip, and we then switch the tip over,
duplicatestill seems like the correct response.In a1f8966316dcd0807d0ee612327d4a822c89177f test: cover precious mining submissions: this seems to be the main use case, so maybe cover it at the start of the test?
In general this test is massive, so maybe split it?
In a1f8966316dcd0807d0ee612327d4a822c89177f test: cover precious mining submissions: since we expect more or less the same behavior as
SubmitBlock, perhaps it's better to interleave the test? (and then have separate tests for each scenario, rather than for each method)Concept ACK
Adding
precious=trueto submitBlock and submitSolution, allows IPC mining clients atomically submit and prefer a same-work block in one go instead of a separatepreciousblockRPC call.The
ActivateBestChain_refactor is a clean prerequisite (so in commit 2PreciousBlockcan call it directly).Left some nits (none blocking).
nit: perhaps worth clarifying that this includes blocks that are ancestors of the active tip, not just the tip itself, so callers don't assume
result=trueimplies a reorg occurred? (If I understand it correctly)nit: same as the above.
nit:
connectedis silently unused. A[[maybe_unused]]attribute or a brief comment(// RPC callers don't need to distinguish connected vs not) would help the next reader I think...nit:
make_block_variant,assert_chain_tip, andassert_submit_blocknone of them access self — all should be@staticmethod🐙 This pull request conflicts with the target branch and needs rebase.
Done. Thanks.
Done. Thanks.
Done. Thanks.
Done. Thanks.
Done. Thanks.
Done. Thanks.
Done. Thanks.
Rebased. All suggestions addressed. Ready for review.
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
Reviewed with @johnnyasantoss.
There's no issue with the majority of the hash rate on the other side because a miner (or pool) is always mining against the rest of the network hash rate. So the odds of finding the next block are the same on either side, only the payout differs: 2 blocks on your own tip vs 1 on the other.
Concept ACK
22aeff71e8I've reviewed the code but I'm not that confident in my cpp skills so I'll refrain from commenting it.
cc @Sjors @0xB10C
Ran some thought experiments together with @ViniciusCestarii to understand whether
precious=truealways would be ideal. Thinking with context from this tweet1 regarding deep reorg viabtc vs. antpool2.Seems it would be extremely unlikely to lose reward from working on a template on top of your own past work. Given that if the network finds a block the miner would revert to it and switch the template to the new best chain.
The miner would have to find an alternative block in the same timing as the rest of the network and then find another subsequent block on right after the network extends the other chain(!) to then get reorg'd and lose work. This seems like a black swan event. Chances of finding a block are related to hashrate and not prevhash so there's no waste in doubling down on your template AFAICT. Your odds at prevhash 0A and 0B are the same.
Electricity spent trying to find 1A and finding 1B would be the same regardless if the network sends you 1B, but on the other side reward finding 1A is roughly twice of that working on 1B.
maybe there's something we are not grasping, but intuitively
precious=truemakes a lot of sense.https://x.com/0xB10C/status/1804143652962185531 ↩︎
https://b10c.me/blog/014-mining-pool-behavior-during-forks/ ↩︎
I don't have the full context of the PR, but I agree with @johnnyasantoss @ViniciusCestarii here. If you don't mine on your own block, the maximum you can win is the next block. If you mine on your own block, you can win the last and the next block. Chances of finding the next block don't change, in both cases it's equal to your share of network hashrate.
Base:
acdb32693417c1b6596edfbdd19ab793c010d34fHead:
cac6117bfa3e5f70028affff9155cbb96466e8b4No verified findings are available from this review.
Review coverage was incomplete. adversarial: Stage budget exhausted before the review completed. adversarial_glm: Stage budget exhausted before the review completed.
Full review report
🐙 This pull request conflicts with the target branch and needs rebase.