Repository navigation
Conversation
|
@plebhash it would be very useful to have a (very) rough JDS draft that uses this interface, to see if it actually gets rid of the mirror mempool. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-12-01 14:45:03 |
a86c13e to
cf3aea1
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
Concept ACK
This could be collapsed to the response "JDS calls TxCollection::collectTxs() (this PR) with that Wtxid list" to reduce the round trip? |
cf3aea1 to
8106852
Compare
|
I added an optional @ismaelsadeeq I can also imagine a (slight) benefit in clients being able to call |
Transactions supplied through ProvideMissingTransactions.Success are typically ones the JDS node will never learn over P2P (prioritized or out-of-band transactions that don't meet its mempool policy). Without a cache, every downstream declaring a template with such a transaction -- and every retry -- pays its own ProvideMissingTransactions round. Remember them in a bounded (32 MB), least-recently-used cache keyed by wtxid, consulted only after unknownTxPos reports a transaction missing. Unlike the retired mempool mirror this involves no background synchronization and is never the source of truth: Bitcoin Core decides what is missing, and the cache merely supplies it without asking the client again. The wtxid key commits to the full serialized transaction, so one downstream cannot misrepresent a transaction requested by another; the worst a malicious downstream can do is churn the cache, which degrades to today's behavior. Confirmed transactions stop being looked up and age out on their own. Bitcoin Core itself remembering TxCollection-provided transactions (which would additionally improve relay and compact-block propagation of the solved block) is a possible future replacement; see the discussion in bitcoin/bitcoin#35671. The new bitcoin_core_ipc_jdp_io scenario asserts that a transaction provided once is remembered: a second downstream declaring it succeeds without a missing-transactions round. It runs against all backends, since the v30.x/v31.x mirror already behaves this way (previously untested). The test-harness wallet helpers build a witness-free transaction from an explicitly selected legacy coinbase output so the minimal test coinbase needs no witness commitment, and mine funding blocks in batches to stay under the RPC client timeout when several test nodes mine concurrently.
8106852 to
9bb89df
Compare
|
Rebased after #34020:
|
Point bitcoin_capnp_types_v32 at Sjors/bitcoin-capnp-types 2026/07/tx-collection (2140-dev/bitcoin-capnp-types#29), which adds the capnp bindings for the TxCollection interface introduced by bitcoin/bitcoin#35671. Revert to the 2140-dev repository (or a crates.io release) once that PR is merged.
The v32 integration test harness previously fell back to a hardcoded local build path. Since the TxCollection work depends on a Bitcoin Core build of bitcoin/bitcoin#35671, require the BITCOIN_CORE_V32_BINARY environment variable instead and explain how to produce the binary. Remove once an official Bitcoin Core release ships TxCollection and v32 follows the standard release-binary download flow.
Instead of stubbing the v32 binary, build Bitcoin Core from the bitcoin/bitcoin#35671 (TxCollection) PR branch in the Integration Tests workflow, with ccache to keep warm-cache runs fast. This follows the approach used by 2140-dev/bitcoin-capnp-types#29. Remove once an official Bitcoin Core release ships TxCollection.
Bitcoin Core's TxCollection interface (bitcoin/bitcoin#35671) lets the JDS validate an external block template directly against the node's mempool, so the v32.x JDP backend no longer needs to keep an optimistic local mempool mirror in sync via a waitNext monitor loop. This removes the mirror, the monitor task, the startup createNewBlock call, and the force-refresh retry logic, along with their staleness races (stratum-mining#268). DeclareMiningJob validation now: 1. fetches the current tip via getTip 2. calls collectTxs with the declared wtxids 3. completes the collection via addMissingTxs when the client provided missing transactions (ProvideMissingTransactions.Success) 4. asks unknownTxPos which transactions are still unknown and, if any, responds with MissingTransactions 5. calls makeTemplate with the declared coinbase (zeroed extranonce, which no contextual check depends on), so Bitcoin Core reconstructs and fully validates the block including the coinbase (BIP34 height, output value, sigops, weight, witness commitment) and returns a BlockTemplate The Success response parameters (prev_hash, nbits, min_ntime) come from the validated template's header (getBlockHeader) and the full transaction list from getBlock, preserving the response contract with jd-server for SetCustomMiningJob validation and PushSolution block reconstruction. The collection and template are destroyed once the response is assembled. Stale-tip classification compares the tip before and after validation, plus a JDS-side check of the declared BIP34 height against the expected next height so a stale job is reported as stale-chain-tip rather than the generic invalid-job that bad-cb-height would map to. Behavioral notes: - readiness now waits for IBD to finish by polling isInitialBlockDownload instead of relying on createNewBlock blocking during IBD. - a future optimization could retain the BlockTemplate and use its submitSolution method for PushSolution instead of reconstructing the full block in jd-server, which would also remove txdata from the Success response.
Transactions supplied through ProvideMissingTransactions.Success are typically ones the JDS node will never learn over P2P (prioritized or out-of-band transactions that don't meet its mempool policy). Without a cache, every downstream declaring a template with such a transaction -- and every retry -- pays its own ProvideMissingTransactions round. Remember them in a bounded (32 MB), least-recently-used cache keyed by wtxid, consulted only after unknownTxPos reports a transaction missing. Unlike the retired mempool mirror this involves no background synchronization and is never the source of truth: Bitcoin Core decides what is missing, and the cache merely supplies it without asking the client again. The wtxid key commits to the full serialized transaction, so one downstream cannot misrepresent a transaction requested by another; the worst a malicious downstream can do is churn the cache, which degrades to today's behavior. Confirmed transactions stop being looked up and age out on their own. Bitcoin Core itself remembering TxCollection-provided transactions (which would additionally improve relay and compact-block propagation of the solved block) is a possible future replacement; see the discussion in bitcoin/bitcoin#35671. The new bitcoin_core_ipc_jdp_io scenario asserts that a transaction provided once is remembered: a second downstream declaring it succeeds without a missing-transactions round. It runs against all backends, since the v30.x/v31.x mirror already behaves this way (previously untested). The test-harness wallet helpers build a witness-free transaction from an explicitly selected legacy coinbase output so the minimal test coinbase needs no witness commitment, and mine funding blocks in batches to stay under the RPC client timeout when several test nodes mine concurrently.
de11d8e to
306ce7e
Compare
|
Trivial rebase after #36807. |
`ProposeTemplate.Success` is `{request_id, template_id, prev_hash, fees}`;
`fees` is the sum of the fees of the declared transactions as
`ChainHub::check_block_proposal` computed it. This reverses 7f202e6's
field removal.
Only the validating node can derive the total: the fee of each
transaction is its inputs minus its outputs, which needs the UTXO set,
and the node computes it anyway for `bad-cb-amount`. Without it the Pool
has only the value the coinbase claims, which that check makes a lower
bound on the real total, not the total itself. Bitcoin Core's IPC does
not expose it today (`checkBlock` returns only reason, debug and result;
a `TxCollection.makeTemplate` template throws on `getTxFees`); that gap
is raised on bitcoin/bitcoin#35671 rather than designed around.
Red was E0560/E0609 (no field `fees`) on the round trip and
`expect_job_success`. Draft §2, §4.3, §6 and §7.1, Plan D (D4, D10) and
the changelog fragment say the field is returned.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
306ce7e to
fa826de
Compare
|
Rebased after #36451. |
`ProposeTemplate.Success` is `{request_id, template_id, prev_hash, fees}`;
`fees` is the sum of the fees of the declared transactions as
`ChainHub::check_block_proposal` computed it. This reverses 7f202e6's
field removal.
Only the validating node can derive the total: the fee of each
transaction is its inputs minus its outputs, which needs the UTXO set,
and the node computes it anyway for `bad-cb-amount`. Without it the Pool
has only the value the coinbase claims, which that check makes a lower
bound on the real total, not the total itself. Bitcoin Core's IPC does
not expose it today (`checkBlock` returns only reason, debug and result;
a `TxCollection.makeTemplate` template throws on `getTxFees`); that gap
is raised on bitcoin/bitcoin#35671 rather than designed around.
Red was E0560/E0609 (no field `fees`) on the round trip and
`expect_job_success`. Draft §2, §4.3, §6 and §7.1, Plan D (D4, D10) and
the changelog fragment say the field is returned.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
`ProposeTemplate.Success` is `{request_id, template_id, prev_hash, fees}`;
`fees` is the sum of the fees of the declared transactions as
`ChainHub::check_block_proposal` computed it. This reverses 7f202e6's
field removal.
Only the validating node can derive the total: the fee of each
transaction is its inputs minus its outputs, which needs the UTXO set,
and the node computes it anyway for `bad-cb-amount`. Without it the Pool
has only the value the coinbase claims, which that check makes a lower
bound on the real total, not the total itself. Bitcoin Core's IPC does
not expose it today (`checkBlock` returns only reason, debug and result;
a `TxCollection.makeTemplate` template throws on `getTxFees`); that gap
is raised on bitcoin/bitcoin#35671 rather than designed around.
Red was E0560/E0609 (no field `fees`) on the round trip and
`expect_job_success`. Draft §2, §4.3, §6 and §7.1, Plan D (D4, D10) and
the changelog fragment say the field is returned.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Add node::TxCollection to retain references to requested transactions found in the mempool. Later commits add methods to identify and supply missing transactions. BlockTemplateManager creates each collection. TxCollectionImpl owns it and implements interfaces::TxCollection for mining clients.
Co-authored-by: Enoch Azariah <[email protected]>
Now that the collection can be mutated after construction, guard the collected transactions with a mutex: IPC clients may call TxCollection methods concurrently from different threads.
Move the coinbase construction out of CreateNewBlock() into a reusable BlockAssembler::CreateCoinbaseTx() helper, so a later commit can build a coinbase when assembling a template from externally collected transactions. Derive the height from pindexPrev so callers do not need to run CreateNewBlock() to initialize the assembler's height. This does not change behavior. Review with --color-moved=dimmed-zebra. Co-authored-by: Enoch Azariah <[email protected]>
Add node::TxCollection::MakeTemplate() to assemble collected transactions in their requested order on the active tip. Validate with a dummy coinbase paying only the subsidy, using TestBlockValidity() with proof-of-work and merkle-root checks disabled. Add unit coverage for missing transactions, tip checks, transaction order, successful assembly, and rejection of transactions already mined.
Expose makeTemplate() through the mining interface and IPC. Return a BlockTemplate holding the block assembled by node::TxCollection. Externally generated templates do not provide fee, sigop, or coinbase construction metadata. Reject the corresponding getters, as well as waitNext() and interruptWait(), which manage node-generated templates. Exercise error propagation and the collect, complete, and submit workflow through IPC, including submission of the same solution to both nodes.
Add an optional coinbase argument to makeTemplate(). When provided, retain it in the template and validate the block with it. Otherwise, continue to use a node-generated dummy coinbase. Test that the supplied coinbase is preserved and that validation rejects an excessive payout or a mismatched witness commitment.
fa826de to
5094a52
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
🐙 This pull request conflicts with the target branch and needs rebase. |

The Stratum v2 spec defines a Job Declarator Server (JDS), whose job it is to approve custom miner templates. Since #34020 it can use
getTransactionsByWitnessID()to request transactions from the node, instead of maintaining its own mempool mirror (see stratum-mining/sv2-apps#911), and then request any missing transactions from the miner.The new
TxCollectioninterface introduced by this PR optimizes this further. We build and validate the block template ourselves now, based on the requested transaction list and our own mempool, so known transactions don't need to cross the IPC boundary. This also fits the draft spec for JDS custom job validation through a Template Provider.The following flow is demonstrated in stratum-mining/sv2-apps#599:
createNewBlock()IPC methodWtxids to the pool's JDSMining::collectTxs()(this PR) with thatWtxidlistCTransactionReffor each matchunknownTxPos()to learn what's missing from the collectionaddMissingTxs()which completes the collectionmakeTemplate()which reconstructs the block and validates it, optionally with the coinbase it intends to use (e.g. to check the reward amount); a node-generated dummy is used otherwise. The JDS needs the check to succeed, may relay the BIP-22 failure reason to the miner.BlockTemplatewhich works as if we generated the template ourselves, but with methods likewaitNext()disabled. The JDS can callsubmitSolution()(the sv2 spec allows for redundant block reconstruction by both the miner node and the JDS).If this sounds very similar to compact block relay: it is! In fact, it would be easy to expand the above methods to take transaction short ids instead of
Wtxid. That may be useful for the p2pool revival project, which needs a way to validate and relay weak blocks as compact blocks. The p2pool client software would need to (trivially) verify the PoW, but could use theTxCollectioninterface to reconstruct and verify the block content. That said, the SRI JDS implementation is much further along and likely to be the first consumer of this.Commits:
BlockAssembler::CreateNewBlock()Potential followups:
addMissingTxs()(optionally) insert favorable transactions into our mempoolTxCollectioncan grab them, instead of needing another round trip)