Skip to content

Add getTransactionsByTxID() and getTransactionsByWitnessID()#11

Merged
Sjors merged 1 commit into
2140-dev:masterfrom
Sjors:2026/02/gettransactions
Jul 8, 2026
Merged

Add getTransactionsByTxID() and getTransactionsByWitnessID()#11
Sjors merged 1 commit into
2140-dev:masterfrom
Sjors:2026/02/gettransactions

Conversation

@Sjors

@Sjors Sjors commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

This adds getTransactionsByTxID() and getTransactionsByWitnessID() which are introduced by bitcoin/bitcoin#34020.

To be merged after:

@Sjors Sjors force-pushed the 2026/02/gettransactions branch 2 times, most recently from 210007c to b15d4e9 Compare March 5, 2026 18:02
@Sjors

Sjors commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator Author

@rustaceanrob can you trigger a CI run?

@Sjors Sjors force-pushed the 2026/02/gettransactions branch from b15d4e9 to c89092d Compare March 5, 2026 18:54
@Sjors

Sjors commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator Author

I'll probably make a separate PR for 864c113 after #9 lands to get that over with and keep this PR focussed.

@Sjors Sjors force-pushed the 2026/02/gettransactions branch from c89092d to 774dc9f Compare March 6, 2026 13:45
@Sjors

Sjors commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased after #9.

@rustaceanrob

Copy link
Copy Markdown
Member

Needs rebase

@Sjors Sjors force-pushed the 2026/02/gettransactions branch from 774dc9f to 7107ace Compare March 10, 2026 14:30
@Sjors

Sjors commented Mar 10, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased on top of #14 (and after #15).

@Sjors Sjors force-pushed the 2026/02/gettransactions branch 2 times, most recently from fac93e4 to c98e1b9 Compare March 11, 2026 15:40
@Sjors

Sjors commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased now that #14 landed.

@Sjors Sjors force-pushed the 2026/02/gettransactions branch from c98e1b9 to e865c6c Compare April 27, 2026 13:22
@Sjors

Sjors commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased (no change) to do another run against the latest bitcoin/bitcoin#34020.

@Sjors Sjors force-pushed the 2026/02/gettransactions branch from e865c6c to dcd32ee Compare May 28, 2026 17:59
@Sjors

Sjors commented May 28, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased and updated to match the latest Bitcoin Core version.

@Sjors Sjors force-pushed the 2026/02/gettransactions branch from dcd32ee to 16776be Compare May 28, 2026 18:35
@Sjors

Sjors commented May 28, 2026

Copy link
Copy Markdown
Collaborator Author

Rewrote history to base it on #12, until that lands.

@Sjors Sjors force-pushed the 2026/02/gettransactions branch from 16776be to 457adb0 Compare July 7, 2026 07:45
@Sjors

Sjors commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased after #12 and #26.

achow101 added a commit to bitcoin/bitcoin that referenced this pull request Jul 7, 2026
9784818 mining: add getTransactionsByWitnessID() IPC method (Sjors Provoost)
d282ae6 mining: add getTransactionsByTxID() IPC method (Sjors Provoost)
0d5e4d4 test: restart node after IPC option override test (Sjors Provoost)
f16b361 ipc: Serialize null CTransactionRef as empty Data (Sjors Provoost)
0f466e1 mempool: add lookup by witness hash (Sjors Provoost)

Pull request description:

  For Stratum v2 custom job declaration to be bandwidth efficient, the pool can request[^0] only the transactions that it doesn't know about.

  The spec doesn't specify how this is achieved, but one method is to call the `getrawtransaction` RPC on each transaction id listed in [DeclareMiningJob](https://stratumprotocol.org/specification/06-Job-Declaration-Protocol?query=DeclareMiningJob#644-declareminingjob-client-server) (or a subset if the pool software maintains a cache). Using RPC is inefficient, made worse by the need to make multiple calls. It also doesn't support queuing by witness id (yet, see #34013).

  This PR introduces two new IPC methods:

  - `getTransactionsById()`: takes a list of `Txid`'s
  - `getTransactionsByWitnessID()`: : takes a list of `Wtxid`'s

  Both return a list of serialised transactions. An empty element is returned for transactions that were not found.

  Unlike the RPC counterpart, the IPC methods do not take advantage of `-txindex`. This could be done in a followup. For `Wtxid` that would involve adding a `-witnesstxindex`.

  I thought about having a single (or overloaded) `getTransactions()` that works with both `Txid` and `Wtxid`, but I prefer that clients are intentional about which one they want.

  A unit and functional test cover the new functionality.

  Sv2 probably only needs `getTransactionsByWitnessID()`, but it's easy enough to just add both.

  To rest with Rust use:
  - 2140-dev/bitcoin-capnp-types#11

  [^0]: there's two reasons the pool requests these transactions: to approve the template and to broadcast the block if a solution is found (the miner will also broadcast via their template provider). See also stratum-mining/sv2-spec#170

ACKs for top commit:
  achow101:
    ACK 9784818
  sedited:
    Re-ACK 9784818
  ViniciusCestarii:
    Re-ACK  9784818
  ismaelsadeeq:
    Code review ACK 9784818

Tree-SHA512: 3c6ceb572ab7d8bd090a8f31b5e331304a7a19a3d1f1551c9c2e1ee41339d76f96ca6c41bd634c87fca0a969e7d9bfa6a16c26fb06c0dd2315f6ca1c76a16a31
Add Mining interface methods getTransactionsByTxID and
getTransactionsByWitnessID to the capnp schema.

Expand integration tests to call both methods with empty inputs, a real
mempool transaction id and witness id, and unknown ids, verifying serialized
transaction bytes for hits and empty results for misses.
@Sjors Sjors force-pushed the 2026/02/gettransactions branch from 457adb0 to 6e4c998 Compare July 8, 2026 06:16
@Sjors Sjors marked this pull request as ready for review July 8, 2026 06:16
@Sjors

Sjors commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

bitcoin/bitcoin#34020 landed so I'll merge this if CI passes.

@Sjors Sjors merged commit 6e4c998 into 2140-dev:master Jul 8, 2026
1 check passed
@Sjors Sjors mentioned this pull request Jul 8, 2026
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.

2 participants