Skip to content

WIP bitcoin_core_sv2 leverages getTransactionsByWtxid#625

Draft
plebhash wants to merge 17 commits into
stratum-mining:mainfrom
plebhash:2026-07-09-get-transactions-by-wtxid
Draft

WIP bitcoin_core_sv2 leverages getTransactionsByWtxid#625
plebhash wants to merge 17 commits into
stratum-mining:mainfrom
plebhash:2026-07-09-get-transactions-by-wtxid

Conversation

@plebhash

@plebhash plebhash commented Jul 17, 2026

Copy link
Copy Markdown
Member

plebhash added 14 commits July 16, 2026 14:16
…idation context

Restrict DeclareMiningJob stale-chain-tip classification to actual
prev_hash drift and simplify related context state.

- classify stale-tip strictly by prev_hash drift (v30x + v31x)
- remove redundant min_ntime from ValidationContext
- make jd-server drift checks prev_hash-only
- prune now-unused BIP34 mempool plumbing/logging
- remove unused timestamp from JdResponse::Success
- keep timestamp handling local to handler checkBlock assembly
- rename remaining timestamp references to ntime for clarity
…mempool_mirror_prev_hash

Replace the expensive createNewBlock call (which assembles a full block
template with mempool transactions) with a lightweight getTip query.
Only the prev_hash is needed for stale-tip detection, so updating just
the mirror's prev_hash via getTip is sufficient when the tip changed.

Rename force_update_mempool_mirror to force_update_mempool_mirror_prev_hash
to make the narrowed scope explicit.
…in-tip

When a declared job is already stale at arrival (coinbase built from an
old tip), checkBlock returns bad-cb-height but prev_hash may not have
drifted during validation.  Treat this rejection as stale-chain-tip so
that JDC's non-fatal stale path is exercised instead of triggering a
fallback.
BIP34 mismatch is no longer detectable on `BitcoinCoreSv2JDP`, which now solely relies on `prev_hash` to detect chain tip drifts

that is fine, because if BIP34 drifted, `prev_hash` will be inevitably different

that's why we're changing the shape of `assert_jdp_stale_chain_tip_scenario`
Cover the path where a declared job uses a coinbase built from a
previous tip that is no longer the current tip at validation time.
In this scenario checkBlock rejects with bad-cb-height while no
in-handler prev_hash drift occurs, so the handler must map the
rejection to stale-chain-tip.
Bitcoin Core submitBlock requires a fully assembled block, so JDS must retain non-coinbase transaction bodies from DeclareMiningJob validation.

As a prerequisite for upcoming PushSolution handling with v32 IPC support, JdResponse::Success now carries txdata and no longer returns redundant txid_list.

JDS derives txids directly from txdata when validating merkle-root/merkle-path consistency for SetCustomMiningJob, without storing an extra txid cache in DeclaredCustomJob.

This addresses an earlier design blindspot and does not change v30/v31 validation behavior.
Reconstruct a full block at JDS when receiving PushSolution and submit it to Bitcoin Core via submitBlock.

Follow the clarified Job Declaration semantics from sv2-spec.

Reference: stratum-mining/sv2-spec#188

Reference: stratum-mining/sv2-spec#189

Design choice (KISS): JDS keeps only the latest declared custom job per downstream connection and only attempts PushSolution propagation against that entry. It does not attempt propagation for previously declared jobs.
Move MempoolMirror from v32x_v31x_v30x into a new v31x_v30x shared module tree, reflecting that it is only used by v30.x / v31.x runtimes.

Update import paths across v30.x, v31.x, and v32.x to point at the new module locations.
@plebhash plebhash changed the title bitcoin_core_sv2 leverages getTransactionsByWtxid WIP: bitcoin_core_sv2 leverages getTransactionsByWtxid Jul 17, 2026
@plebhash plebhash changed the title WIP: bitcoin_core_sv2 leverages getTransactionsByWtxid WIP bitcoin_core_sv2 leverages getTransactionsByWtxid Jul 17, 2026
Comment on lines +353 to +356
let request = format!(
"{{\"jsonrpc\":\"2.0\",\"id\":\"v32-jdp-chain-tip\",\"method\":\"getblockheader\",\"params\":[\"{}\",false]}}",
tip_hash
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

note to self:

updating ChainTipState with nbits from getblockheader causes issues whenever there's a difficulty adjustment

we should also call getmininginfo and use next.bits instead

plebhash added 3 commits July 19, 2026 14:54
Replace shared-v31 DeclareMiningJob handling for v32.x with a version-specific implementation that fetches declared transactions from Bitcoin Core via getTransactionsByWitnessID on every call.

v32.x no longer maintains a local mempool mirror for transaction data. Instead it uses a lightweight ChainTipState that tracks prev_hash, nbits, and ntime (no tx cache). A dedicated v32.x background monitor refreshes this state via waitNext.

Missing transactions are detected by empty responses from Core's witness-id lookup, with ProvideMissingTransactionsSuccess payloads supplementing the per-request map on retry.
Move v31.x JDP declare handler and background monitor from shared v32x_v31x sources into v31x-local modules. The only cross-version JDP artifact remaining between v31.x and v32.x is the shared error definition included via #[path].

Remove the now-unused v32x_v31x/job_declaration_protocol/handlers.rs and drop the v32x_v31x namespace marker module.
@plebhash
plebhash force-pushed the 2026-07-09-get-transactions-by-wtxid branch from 8c79db8 to 64fa59b Compare July 19, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bitcoin_core_sv2::BitcoinCoreSv2JDP should leverage getTransactionsByWTxID

1 participant