Skip to content

contrib: support injecting custom txs to signet miner#111

Open
ajtowns wants to merge 3 commits intobitcoin-inquisition:29.xfrom
ajtowns:202603-inq29-customblock
Open

contrib: support injecting custom txs to signet miner#111
ajtowns wants to merge 3 commits intobitcoin-inquisition:29.xfrom
ajtowns:202603-inq29-customblock

Conversation

@ajtowns
Copy link
Copy Markdown

@ajtowns ajtowns commented Mar 25, 2026

Adds --custom-block-dir to signet miner, which allows specifying a directory containing files 12345.json (ie, block-height-dot-json). Those json files can specify a json object of {"txs": [txhex,txhex,...]} which will result in the miner attempting to build a block that only contains the given txs, and burns all their fees (only claiming the block subsidy). The block will be verified via getblocktemplate in proposal mode before signing or applying proof of work, and falls back to attempting a regular block if that fails. In future the json file could potentially add additional fields to control coinbase values or header fields. Replaces #107. Tested on block 297073.

@ajtowns
Copy link
Copy Markdown
Author

ajtowns commented Mar 25, 2026

cc @theStack

Co-Authored-By: Anthony Towns <aj@erisian.com.au>
@ajtowns ajtowns force-pushed the 202603-inq29-customblock branch from 27a4e73 to f222707 Compare March 25, 2026 07:32
@DrahtBot
Copy link
Copy Markdown
Collaborator

DrahtBot commented Mar 25, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@theStack
Copy link
Copy Markdown

Concept ACK, makes sense to have a more flexible solution.

Thanks for mining the block!

Comment on lines +346 to +347
# can't easily calculate fees to collect, so just burn them
tmpl["coinbasevalue"] = int(50_0000_0000 >> (tmpl["height"] // 210000))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I was about to suggest calculating the fees with repeated gettxout RPC calls with all the inputs' prevout fields passed each, but that's probably very slow for larger blocks with many inputs and wouldn't work anyways, if UTXOs are spent that are created within the same block... seems fine to burn anyways, I guess.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well the python code could detect the txouts that are created and spent in the same block, so that part would be fine, I think. Could maybe batch the gettxout RPC calls into a single request (or one request per X txouts) to be a little less slow?

fanquake added a commit to bitcoin/bitcoin that referenced this pull request Mar 31, 2026
…sult field

12c3c3f test: mining: add coverage for GBT's "coinbasevalue" result field (Sebastian Falbesoner)

Pull request description:

  This PR adds missing coverage for the "coinbasevalue" result field of the `getblocktemplate` RPC call. Specifically, the introduced test checks that the value is set to claim the full block reward (subsidy plus fees). Can be verified with the following patch, which succeeds on master and fails on the PR branch:

  ```diff
  diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
  index a935810..ba9ac9dadb 100644
  --- a/src/rpc/mining.cpp
  +++ b/src/rpc/mining.cpp
  @@ -998,7 +998,7 @@ static RPCHelpMan getblocktemplate()
       result.pushKV("previousblockhash", block.hashPrevBlock.GetHex());
       result.pushKV("transactions", std::move(transactions));
       result.pushKV("coinbaseaux", std::move(aux));
  -    result.pushKV("coinbasevalue", block.vtx[0]->vout[0].nValue);
  +    result.pushKV("coinbasevalue", block.vtx[0]->vout[0].nValue - 1);
       result.pushKV("longpollid", tip.GetHex() + ToString(nTransactionsUpdatedLast));
       result.pushKV("target", hashTarget.GetHex());
       result.pushKV("mintime", GetMinimumTime(pindexPrev, consensusParams.DifficultyAdjustmentInterval()));

  ```

  I'm not sure how relevant this field is nowadays in real-world mining scenarios (we use it for the signet miner at least), but it seems useful to have a test for it anyways. Stumbled upon this while looking at bitcoin-inquisition#111.

ACKs for top commit:
  maflcko:
    lgtm ACK 12c3c3f
  Sjors:
    ACK 12c3c3f

Tree-SHA512: ae10f63c99b21cf7771feefe3d0e47b2e0d511aceb344cf11efa9182d78f2960f1e079797b8a36db110a3c54acb27a3706413a710a74bf56aed29ea162a6aab2
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.

3 participants