Count epoch block txs by id and clamp block-range sampling - #2171
Open
ArturWieczorek wants to merge 2 commits into
Open
Count epoch block txs by id and clamp block-range sampling#2171ArturWieczorek wants to merge 2 commits into
ArturWieczorek wants to merge 2 commits into
Conversation
ArturWieczorek
force-pushed
the
artur/fix-dbtool-validate-check-bugs
branch
from
July 16, 2026 17:05
8669cf0 to
4073f1e
Compare
Contributor
Author
ArturWieczorek
marked this pull request as ready for review
July 16, 2026 18:30
queryEpochBlockNumbers returns block_no, but the epoch block-tx check counts transactions with queryBlockTxCount, which keys on block.id. block_no and id diverge on a real chain (an EBB has a null block_no and a positive id), so the check reads the wrong block. Assert the returned identifier counts the right block; the fix follows in the next commit.
The epoch block-tx check passed block_no to queryBlockTxCount, which keys on block.id; the two diverge on any real chain, so it reported false tx-count mismatches. queryEpochBlockNumbers now also returns the block id and the check counts by it. The block-property checks computed a random start with blkCount - 100000 in Word64, which underflowed to an absurd range on databases with fewer than 100000 blocks. Clamp the sample window to the available block count.
ArturWieczorek
force-pushed
the
artur/fix-dbtool-validate-check-bugs
branch
from
July 29, 2026 09:10
4073f1e to
a74ca68
Compare
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.
Closes #2170.
Two
cardano-db-tool validatechecks were quietly wrong. Both were only visible once the error-isolation change in #2163 stopsvalidateaborting on the first failure, so they were surfaced during review of that work.The epoch block-tx check counted transactions with
queryBlockTxCount, which keys onblock.id, but fed it theblock_noreturned byqueryEpochBlockNumbers.block_noand the surrogateblock.iddiverge on any real chain - an EBB has a nullblock_noand a positive id, and the id is just a sequence - so the check looked up the wrong block and reported false tx-count mismatches on mainnet, preprod, and preview.queryEpochBlockNumbersnow returns the block id alongsideblock_no, and the check counts by the id while still printingblock_noin the message. The sharedqueryBlockTxCountwas always correct and is used correctly by sync's genesis validation; only this validator misused it.The block-property checks (contiguous block numbers, ordered timestamps) picked a random start with
blkCount - 100000inWord64, which underflows to an enormous value on any database with fewer than 100000 blocks - local/private clusters and DBs early in their first sync. That produced absurd ranges likeBlock numbers [12258611005600085411 .. ...](and a false "ok" on the empty result). A smallsampleWindowhelper now clamps the window to the available block count, so the range is always valid. This never affected preprod, preview, or mainnet, which are all far past 100000 blocks.The first commit adds a failing regression test in the
cardano-dbIO suite that models the id/block_no divergence (a block with a nullblock_noand a positive id, one transaction) and asserts the returned identifier counts the right block; the second commit is the fix. Bug 2 was verified end to end against a small local db-sync database, where the range now readsBlock numbers [0 .. 16608]instead of the underflowed value.Marked WIP/draft. Note this overlaps
Validate/BlockTxs.hswith #2163 (which changes how the same check reports failures), so expect a small merge conflict there - the two changes are complementary: this PR fixes the check's logic, #2163 fixes its reporting and exit code. Bug 1 is only observable throughvalidateend to end once #2162 and #2163 are also present (otherwise the run crashes at, or aborts before, the later checks), so the unit test is its standalone verification here.