Repository navigation
dgb: jobs and won blocks carry the template's transactions (python inclusion rules, block limits) - #2372
Merged
Conversation
coin/merkle_link.hpp, exactly as p2pool bitcoin/data.py:
- coinbase_merkle_branch(h) = calculate_merkle_link([None] + h, 0)[branch]
(the coinbase leaf's stratum branch, duplicate-last tree);
- check_coinbase_merkle_branch(c, b) = check_merkle_link(c, {0, b});
- witness_merkle_root(w) = merkle_hash([0] + w).
Pinned (dgb_work_source_test): DgbTxInclusion.MerklePiecesMatchThe
PythonOracle, the oracle's own outputs for 0..7 transactions.
coin/job_tx_set.hpp (p2pool-dgb-scrypt helper.py, data.py): - JobTx from its served bytes (with witness): txid (stripped), the transaction hash hash256(data), wtxid (the data hash with a non-empty witness, else the txid), stripped size, fee; - python_inclusion: template order, stop at the first transaction past BLOCK_MAX_SIZE 32000000 / BLOCK_MAX_WEIGHT 128000000 (header 80, gentx estimate 50000 / 200000, slack 500 / 2000; weight 4 x stripped size); the subsidy is coinbasevalue less the removed fees when all are known, else SUBSIDY(height) + the known included fees; - segwit_data_of: txid_merkle_link over [None] + txids, wtxid_merkle_root = merkle_hash([0] + wtxids); stratum_branch_of over txids; share_merkle_branch_of over the data hashes. Pinned (dgb_work_source_test): DgbTxInclusion.TheTxSetMatchesThePython Oracle (3 legacy + 2 witness transactions: ids, segwit_data, branches, header root, all from the oracle), InclusionAndSubsidyAreThePythonRules.
…to them A DGB block's transactions come from one source with its header: - a header from digibyted (GBT) carries digibyted's own body: its transactions[] and coinbasevalue (GbtTip now keeps both); - a header from the embedded chain carries the embedded mempool's selection (fee-known, inputs in the UTXO view) only with --embedded-txs (embedded.dgb_txs, default off), else none. None: coinbase-only, the subsidy alone, as before. The job takes the template's transactions after python's inclusion rule and claims python's share subsidy (coin::python_inclusion). The job's snapshot carries the stratum branches over their txids, their bytes (tx_data), the wtxid root and the frozen branches/root. The producer's segwit_data is the transactions' (ConnJobRequest::segwit_data: txid_merkle_link over [None] + txids, wtxid_merkle_root over [0] + wtxids), with the P2Pool witness commitment over that root. The mint takes the same: MintShareInputs gains witness_root, the share's merkle_link branch (python's, over the data hashes) and tx_data. The mint's header merkle root is over segwit_data.txid_merkle_link (python Share.__init__). An empty set is byte-identical to before. Pinned: - DgbMintRoundTrip.AJobWithTransactionsMintsAShareTheRefCheckAccepts (V35, the oracle's 3 legacy + 2 witness transactions and none: the ref check accepts the minted share, its header is the miner's, its generation transaction the coinbase hashed, its segwit_data, merkle_link and subsidy python's); - DgbWorkSource.WorkTemplateServesRealV4BitsAndPrevhash (the template's transactions: none by default, the embedded selection with --embedded-txs, digibyted's body with its header, never mixed).
…plate's body with the embedded header
coin::GbtPoller fetches digibyted's getblocktemplate (rules segwit, algo
scrypt) on a thread and connection of its own, every 2 s:
- connect bounded at 5 s, each request at 10 s; a failure closes the
connection and the next try backs off 1 s doubling to 30 s;
- stop() cancels a pending request and joins promptly;
- each template {previousblockhash, bits, height, transactions[],
coinbasevalue} is published as one immutable value.
The work source reads only the published value once a poller is bound
(set_gbt_poller_bound, publish_gbt): the GBT fallback never requests on
the stratum IO thread, and a value older than kGbtBodyFreshSec (4 s, two
poll periods) is not served. An embedded header whose prevhash and height
the fresh published template matches takes that template's body (its
transactions and coinbasevalue), as python takes digibyted's; otherwise
the embedded opt-in selection or none. Each change of that state is
logged once. main_dgb starts the poller when digibyted creds are armed
(replacing the in-thread GBT seam) and stops it before the work source.
Pinned (dgb_work_source_test): DgbGbtPoller.PublishesTheTemplateWithItsBody,
AHungHostIsCutOffStopsPromptlyAndRecovers, TheWorkSourceReadsOnlyThe
PublishedTemplate; DgbWorkSource.WorkTemplateServesRealV4BitsAndPrevhash
(an agreeing template's body with the embedded header; one for another
block is not used).
- Stratum arm: the job's body (tx_data) goes out under the miner's header, as before for a job with branches; now jobs have them. - Sharechain arm: the mint records each share's block body (the job's transactions) in the TemplateCapture, keyed by the share hash, before it broadcasts the share. The rebuild of a won share then has the share's header hash and is relayed; without the record it is another block and is not. Pinned: DgbMintRoundTrip.AWonBlockWithTransactionsCarriesThemOnBothArms (V35, the oracle's 3 legacy + 2 witness transactions: both arms send the same block, with the share's hash and all 5 transactions; no record, no relay); DgbMainWiring.TheMintRecordsTheShareBodyAndTheGbtPollerIsBound.
- Forward (DgbOracleVectors): every fourth job carries digibyted's body: the oracle's 3 legacy + 2 witness transactions with their fees and coinbasevalue = subsidy + fees. The job's branches, tx_data and witness root reach the submit as the stratum server carries them, and the python oracle checks every minted share. Coverage pin: at least 25 shares carry a non-empty segwit_data link. - Reverse (mint_vectors.py): every fourth share is minted by python's own generate_transaction over the same 5 transactions (known_txs, fees), so python computes the segwit_data and the share's merkle_link, and the header's merkle root is over the txid link. c2pool verifies them (DgbOracleReverse). The script fails if fewer than 25 shares carry transactions.
build_coinbase wrote each stratum merkle branch from uint256::begin(), which is not the byte data: it reads the 32 internal bytes (data()), the wire form python and the core stratum server use.
The digibyted-body template of WorkTemplateServesRealV4BitsAndPrevhash is gbt_body_tpl; gbt is the earlier GBT-fallback template.
…node's parameter - DgbGbtPoller.AHungHostIsCutOffStopsPromptlyAndRecovers: a stopped poller makes no request, so recovery is pinned in the running loop: no template is published while the host hangs (failures counted), one is once it answers, and stop() returns promptly while a request hangs. - DgbV35Hold.V36SharesAreRefusedWhileHeld finds run_node's "bool v36_ratchet = false," (--embedded-txs follows it now).
DigiByte Core reads getblocktemplate's mining algo from params[1]
(rpc/mining.cpp), and python's p2pool-dgb sends it there: the params are
[{"rules": [...]}, "scrypt"] (coin::make_gbt_params, DGB_GBT_ALGO), for the
GBT poller and NodeRPC::getblocktemplate. An "algo" key inside the request
object is not read, so a digibyted run with another -algo served that
algo's bits.
Pinned: DgbRpcRequest.GbtCarriesSeparateScryptAlgo (params[1] "scrypt", no
"algo" in the request); DgbGbtPoller.PublishesTheTemplateWithItsBody (every
request the fake digibyted sees has params[1] "scrypt").
- stop() posted a cancel holding the stream's raw pointer; a stream closed before that handler ran (it runs on the next start()) was freed. The handler now cancels whatever stream is current, under the stream lock; the loop closes its stream when it stops, and start() runs any such handler before the first request, with no stream open. - A reply is read with a body limit of kGbtResponseLimit (64 MB); beast's 8 MB default refused a near-full witness-heavy template, so every poll failed. Pinned: DgbGbtPoller.StartAfterStopCyclesCleanly (six start/stop cycles, alternately answered and hung: each answered cycle publishes, each stop returns within 1 s), run under TSan as well.
- A job's transactions are a prefix of the template's (a transaction's
parents come before it, so they stay in), chosen for the coinbase the
producer builds:
- a coinbase without the BIP141 witness commitment (a V36 share) takes
no witness transaction: the prefix before the first one;
- the block fits MAX_BLOCK_WEIGHT 4,000,000 and MAX_BLOCK_SIGOPS_COST
80,000 beside the job's own coinbase (its size and legacy sigop cost;
GBT's per-transaction sigops, else the legacy count x 4).
When the prefix is shorter than python's inclusion, the subsidy is
python's rule for it (coinbasevalue less the fees left out) and the
coinbase is built again for it: a coinbase never claims fees of
transactions the block leaves out.
- coinbasevalue below the fees left out (python raises): coinbase-only.
- A template's transactions are parsed once (coin::TemplateBody, on the
publisher's thread or the fallback's cache fill), and every job on it
shares the parsed set and one hex vector; JobBlock carries the body and
a count.
- A fee or sigops in GBT JSON is a non-negative integer, signed or
unsigned.
- A published template that is another block bumps the work generation
at once; another transaction set at most once per kGbtTxRefreshSec (15 s).
- The mint records a share's body for the won-block rebuild only when the
share is a block (MintShareInputs::won_block), and before the tracker
lock is released.
- --embedded-txs / embedded.dgb_txs is withdrawn: an embedded header takes
an agreeing digibyted template's body, else none.
Pinned: DgbMintRoundTrip.AV36JobTakesNoWitnessTransactions (V36 with the
oracle set: 1 transaction, the fees left out not claimed, a won block with
no witness data under the share's hash; witness first: coinbase-only),
AJobBodyFitsTheBlockLimitsBesideItsCoinbase (sigops 2 x 39,999 plus the
coinbase's: 1; 2 x 30,000: 2; signed JSON fees counted; the share's
subsidy), JobsOnOneTemplateShareItsBody; DgbTxInclusion.
ABodyIsThePrefixWithinTheBlockLimits, TheTemplateBodyIsParsedOnce,
InclusionAndSubsidyAreThePythonRules (coinbasevalue below the fees left
out); DgbGbtPoller.APublishedTemplateMovesTheWork; DgbMainWiring (the body
recorded for a block share, before the unlock).
The transaction-set refresh period a published template moves the work at is part of the work source's interface (the KAT reads it).
…ops is the block's - publish_gbt moves the work at once for another block (prevhash, height, bits) and starts the body's refresh period then; another body (the transaction set or coinbasevalue) moves it at most once per kGbtTxRefreshSec (15 s). Before, a coinbasevalue change (every fee change) moved it at once, a clean job every poll. - A GBT transaction without "sigops" counts the whole block's sigop cost (kDgbMaxBlockSigopsCost): the body stops before it. - A coinbase whose sigop count cannot be read leaves no room: a coinbase-only body. - The work source shares digibyted's template (a shared_ptr from the poller's publish or the fallback cache) instead of copying it per template. Pinned: DgbGbtPoller.APublishedTemplateMovesTheWork (a coinbasevalue change on the same block: none within 15 s, then one; another prevhash at the same height and other bits: at once); DgbMintRoundTrip. AJobBodyFitsTheBlockLimitsBesideItsCoinbase (an entry without sigops ends the body); DgbTxInclusion.TheTemplateBodyIsParsedOnce.
This was referenced Nov 29, 2026
stop() stops the poller's io_context, so a connect, write or read in flight returns from run() unfinished; the call that started it returned and its stack (the request, the response buffer and parser, the outcome flags) was gone, and close_stream() destroyed the stream. The aborted operation completed on the next run -- the next start()'s poll() -- and its handler read that freed memory (ASan: SEGV in DgbGbtPoller.StartAfterStopCyclesCleanly). The stream is a shared_ptr, and each operation's state (Connect: the stream and the outcome; Exchange: the stream, the request, the buffer, the parser and the flags) is owned by its handlers, so an interrupted operation completes later on its own state. Pinned: DgbGbtPoller.AStopDuringARequestLeavesNothingForTheNextStart (a stop with the read pending, then a start that serves, three rounds), StartAfterStopCyclesCleanly.
The DOGE block's comments and its embedded.doge_utxo_full entry are master's again; this branch adds no catalog parameter.
frstrtr
added a commit
that referenced
this pull request
Nov 29, 2026
This was referenced Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DGB jobs carry the template's transactions; won blocks include them. Before, every DGB block was coinbase-only.
Rules
Tests