Repository navigation
dash: getblocktemplate txids follow the Dash Core v24 stable-txid rule for asset unlocks - #2363
Merged
Merged
Conversation
The dashd-fallback template took each transaction's id from a "txid" key
that Dash getblocktemplate does not send, so it always fell back to the
SHA256d of the entry's bytes. From Dash Core v24 that is not the txid of a
version 2 asset unlock: GetHash zeroes the unlock's quorum signing info,
and the SHA256d of the whole bytes is its instance hash. m_tx_hashes feeds
the stratum merkle branches, so every job over a dashd template carrying a
v2 unlock had a header root dashd rejects (bad-txnmrklroot), and a block
found on it would be lost.
The per-entry rule now lives in coin/gbt_transactions.hpp:
- bytes that deserialize completely: dash_txid of the parsed tx, the same
derivation the embedded build and every other hash site use; dashd's
"hash" is cross-checked and a disagreement is logged once per txid;
- bytes that do not deserialize (or leave trailing bytes): dashd's "hash";
- neither: the SHA256d of the bytes, logged.
The embedded-vs-dashd tx-root cross-check now folds the same ids on both
sides.
Tests (test_dash_share_hash_link): two real testnet blocks with v2
unlocks, 1599900 and 1599924, fed through the reader as {data, hash}
entries: every id equals dashd's txid, the fold and the stratum branch
ascent equal the committed header root, and the old rule folds the
instance-hash root instead; plus the no-"hash", unparsable-bytes and
disagreeing-hash cases.
TemplateBodiesMemo (build_producer_job) handed out a stored body vector whenever a template's tx-hash list and body count matched, on the premise that a txid is the hash of its whole body. A v24 version 2 asset unlock breaks that: every re-signed instance of one withdrawal shares one txid with other bytes. Now that dashd templates are read with that txid too, two templates over the same ids could differ in an unlock's bytes, and the memo could serve the previous instance's bytes under the new template (an expired unlock in the block body, and a CbTx merkleRootAssetUnlocks over other bytes). The memo now also requires byte equality of every body whose txid may leave bytes out (txid_may_omit_body_bytes, every type-9 body), through bodies_match_under_equal_txids in coin/rpc_data.hpp. The template store's reuse rule (template_tx_hex_reusable) already applied that check and now calls the same predicate; its behaviour is unchanged. Tests (test_dash_share_hash_link): a re-signed instance of a real v2 unlock from testnet block 1599900 keeps its stable txid and changes its instance hash; the memo returns each instance's own bytes while the first instance's vector is still held, and the store's reuse rule refuses the re-signed body.
…sh_txid An entry's "hash" is Core's own GetHash of the very bytes the block body carries, so it is the id the validator recomputes. When it is present it is now the id served. dash_txid of the parsed bytes is still computed and cross-checked: a disagreement can only mean a defect in dash_txid (which the embedded build and every other hash site use), so it is logged as an error once per txid with the running count of disagreeing entries read since start. Without a "hash", dash_txid of the parsed bytes stays the rule, and the SHA256d of the bytes the last resort. Tests: DisagreeingHashIsReportedAndDashdHashDecides (renamed from DisagreeingHashIsReportedAndTheBytesDecide) serves the disagreeing "hash", reports the derived txid next to it, and keeps an agreeing entry unreported; gbt_entry_txid without a "hash" still uses the bytes.
…der bodies
Producer job cache (mint_runloop.hpp ProducerJobCache::find): a hit now
also needs the template's CbTx payload to equal the cached job's. A v24
version 2 asset unlock that dashd re-signs at the same tip keeps its txid,
so the tip, height, payment amount and tx-hash list all stay equal, while
the cached gentx's merkleRootAssetUnlocks commits the previous instance.
Served with the current bodies, a found block would be rejected as
bad-cbtx-assetunlockmerkleroot. The payload commits the instances, so a
re-signed unlock is now a miss (a drift) and the job is rebuilt.
Finder bodies (reconstruct_won_block.hpp v36_finder_block_bodies): a body
whose txid may leave bytes out (every type-9 body) must parse completely
and its dash_txid must equal the listed txid; every other body still
hashes to it. With stable txids in the template, the re-broadcast arm
refused every block that carried a version 2 unlock.
getblocktemplate reader (gbt_transactions.hpp):
- an entry without a "data" string, or with an empty or non-hex body,
fails the whole read and leaves the work data untouched instead of
being skipped;
- a "hash" that is not a 64-char hex id is treated as absent and
reported;
- a "txid" that differs from "hash" is reported ("hash" is served).
rpc.cpp logs one summary line per template read with disagreements and a
detail line per txid the first time; the remembered set stops growing at
its cap instead of being cleared.
Comments updated at main_dash.cpp (cache hit rule) and block_producer.hpp
(coinbase txid).
Tests: ProducerJobCacheMissesOnAResignedUnlock (the real CbTx v4 payload of
testnet block 1599900 against the same block with one unlock re-signed),
FinderBodiesAcceptRealV2Unlocks (block 1599900 through
v36_finder_block_bodies; a type-9 body with trailing bytes is refused),
and reader KATs for entries without bytes, malformed hashes and a
differing txid.
Owner
Author
|
Gate run on .198 for head b811235 (Release, BLS on, -j6), completed 08:31 UTC. All suites rc=0, 0 warnings in touched files:
Mutants. Each was applied alone and rebuilt, and each was expected to turn a test RED:
12/12 RED, no survivors. A clean rebuild afterwards passes again: DashGbtStableTxid 15/15, DashV36FinderBlock 6/6. |
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.
What this changes
1. The txids of a dashd
getblocktemplatereply (coin/gbt_transactions.hpp, used byNodeRPC::getwork).Each transaction's id is now the id the block's merkle root commits to:
"hash": dashd's"hash". It is Core's ownGetHash()of the very bytes the block body carries, so it is the id the validator recomputes. When the bytes also deserialize completely,dash_txidof the parsed tx is cross-checked against it; a disagreement can only mean a defect indash_txid(which the embedded build uses too), so it is logged as an error once per txid, with the running count of disagreeing entries;"hash", bytes that deserialize completely (no trailing bytes):dash_txidof the parsed tx — the same derivation the embedded build and every other tx-hash site of the node already use;An entry without a
"data"string, or with an empty or non-hex body, fails the whole read and leaves the work data untouched (a template that silently dropped one of dashd's txs would no longer be dashd's template). A"hash"that is not a 64-char hex id is treated as absent and reported; a"txid"that differs from"hash"is reported ("hash"is served). Disagreements are logged as one summary line per template read plus one detail line per txid the first time; the remembered set stops growing at its cap instead of being cleared, so a systemic defect cannot flood the log.Before, the reader looked for a
"txid"key, which Dashgetblocktemplatedoes not send (its entries carrydata,hash,depends,fee,sigops), and so always used the SHA256d of the entry's bytes.2. The producer-job body memo (
TemplateBodiesMemo,mint_runloop.hpp).It reused a stored body vector whenever the tx-hash list and the body count matched. It now also requires byte equality of every body whose txid may leave bytes out (every type-9 body), through
bodies_match_under_equal_txidsincoin/rpc_data.hpp. The template store's reuse rule (template_tx_hex_reusable) already applied this check and now calls the same predicate (behaviour unchanged).3. The producer job cache (
ProducerJobCache::find,mint_runloop.hpp).A hit now also needs the template's CbTx payload to equal the cached job's. A version 2 unlock that dashd re-signs at the same tip keeps its txid, so tip, height, payment amount and tx-hash list all stay equal while the cached gentx's
merkleRootAssetUnlockscommits the previous instance; served with the current bodies, a found block would be rejected asbad-cbtx-assetunlockmerkleroot. The payload commits the instances, so a re-signed unlock is a miss and the job is rebuilt.4. The finder's block bodies (
v36_finder_block_bodies,reconstruct_won_block.hpp).A body whose txid may leave bytes out (every type-9 body) must parse completely and its
dash_txidmust equal the listed txid; every other body still hashes to it. With stable txids in the template, the redundant re-broadcast arm refused every block carrying a version 2 unlock (the stratum arm still submitted).5. The embedded-vs-dashd tx-root cross-check (
work_source.cpp,compute_merkle_root(m_tx_hashes)on both sides) now folds the same ids on both sides; before, a dashd template carrying a version 2 unlock folded instance hashes against the embedded build's txids.Why
From Dash Core v24, the txid (
CTransaction::GetHash) of a version 2 asset unlock is computed with its 132 bytes of quorum signing info zeroed, so that every re-signed instance of one withdrawal keeps one txid. The SHA256d of its full bytes is its instance hash (committed separately by the CbTx v4merkleRootAssetUnlocks).m_tx_hashesfeeds the stratum merkle branches, so every job built over a dashd template that carried a version 2 unlock had a header root dashd rejects withbad-txnmrklroot. A block found on such a job would be lost; it cannot be repaired at submit time because the proof of work covers the header.On the v24 testnet shadow, every dashd-template proposal that carried version 2 unlocks was rejected
bad-txnmrklroot(34 of 34), while embedded templates and dashd templates without unlocks were accepted. A live capture proposed the same block body twice: with the node's served root,bad-txnmrklroot; with the root folded over dashd's txids, accepted.The memo change is required by (1): once dashd templates are read with the stable txid, two templates over the same ids can differ in an unlock's bytes (a re-signed instance), and the memo could otherwise hand a job the previous instance's bytes.
Review fixes
An independent review asked for (3) and (4) above, the reader hardening (entries without bytes fail the read, malformed
"hash", differing"txid"), the bounded disagreement log, and comment fixes atmain_dash.cpp(cache hit rule),block_producer.hpp(coinbase txid) andreconstruct_won_block.hpp(body rule). All are in the last commit.Follow-up (not in this PR): the share-relay known-tx store (
known_txs_retention.hpp,register_template_txs) keys bodies by txid and keeps the first body it saw for a template; a re-signed version 2 unlock under the same txid can leave the previous instance's bytes there for relay.Exposure
getblocktemplate— the dashd-fallback arm of an embedded node, or a node without the embedded arm — at heights where dashd's template holds a version 2 asset unlock. On an embedded node this is systematic, not occasional: the embedded build leaves pending asset unlocks out, the creditPool cross-check then declines, and the dashd template is served at exactly those heights.bad-assetunlocktx-version-2), and a version 1 unlock's txid is the SHA256d of its bytes, so mainnet is unaffected today.dash_txidalready).Tests
All in
test_dash_share_hash_link(allowlisted target), on two real Dash Core 24.0.2 testnet blocks stored with the existing generator (tools/dash/gen_replay_kat.py block):test/data/dash_block_testnet_1599900.inc(16 txs, 11 version 2 unlocks) andtest/data/dash_block_testnet_1599924.inc(48 txs, 9 version 2 unlocks; the block that closed the height of the live capture above), with dashd's own txid lists and merkle roots intest/data/dash_block_testnet_txids_1599900_1599924.inc.DashGbtStableTxid.*)FixturesAreRealV2UnlockBlocksdash_txidof every tx equals dashd's txid; the SHA256d of the bytes differs from it exactly for the v2 unlocks (11 and 9)Block1599900EntriesReadWithDashdTxidsm_tx_hashes[i]== dashd'shash(e.g.1dcf9b62…c422, not the instance hashec92ca6b…8e3a); [coinbase txid] + ids and the stratum branch ascent == the committed rootabd5d782cd7d0071a6f63472426074053eb5703dd74d70fff500da4d22c0f827Block1599924EntriesReadWithDashdTxidsaf091c1bccc019d924511cdfa4f4925bd80752a23fa18694b4dbfea02acf71a2OldRuleFoldsTheRejectedRootFixedRuleTheCommittedOne257a0908…6989,f9282862…59ea), not the header root; the fixed reader folds the header rootWithoutGbtHashTheStableTxidIsDerivedhashstill get dashd's txids (derived withdash_txid)UnparsableBytesUseDashdHashhash; with nohasheither, the SHA256d of the bytes; both reported; the body is kept verbatimBareStringEntriesReadAndEntriesWithoutBytesFailTheRead"data", with non-string, empty, odd-length or non-hex"data", or a non-entry value fails the read and leaves the work data untouchedMalformedHashIsTreatedAsAbsentAndReported"hash"that is short, long, non-hex or not a string is ignored (the bytes decide) and reportedTxidThatDiffersFromHashIsReportedHashServed"hash"is served; a differing"txid"is reported, an equal one is notDisagreeingHashIsReportedAndDashdHashDecideshashthat differs from the bytes'dash_txidis served, and reported with the derived txid next to it; an agreeing entry is not reported; without ahashthe bytes decideEmbeddedAndDashdBodyFoldsAgreeOverTheSameTxsResignedUnlockSharesTheTxidNotTheBytesBodiesMemoNeverServesAResignedUnlockWithOldBytesTemplateStoreReuseRejectsAResignedUnlockProducerJobCacheMissesOnAResignedUnlockmerkleRootAssetUnlocks) is a miss (drift); the original template still hitsDashV36FinderBlock.FinderBodiesAcceptRealV2Unlocks(test_dash_node)v36_finder_block_bodiesunder a merkle link over dashd's txids; a type-9 body with trailing bytes is refusedMutants (each must turn named KATs RED)
hashignored when the bytes do not deserializeUnparsableBytesUseDashdHashUnparsableBytesUseDashdHashhashis not reportedDisagreeingHashIsReportedAndDashdHashDecidesdash_txidserved over dashd'shash)DisagreeingHashIsReportedAndDashdHashDecides"hash"is accepted"txid"is not reportedBodiesMemoNeverServesAResignedUnlockWithOldBytestxid_may_omit_body_bytes)ResignedUnlockSharesTheTxidNotTheBytes,BodiesMemoNeverServesAResignedUnlockWithOldBytes,TemplateStoreReuseRejectsAResignedUnlockSuites
Release, BLS on. 0 warnings in the touched files.
test_dash_share_hash_link(incl. the 12 new KATs)test_dash_stratum_work_sourcetest_dash_work_sourcetest_dash_get_worktest_dash_embedded_gbttest_dash_mempooltest_dash_nodetest_dash_node_coin_statetest_dash_block_producercore_test