Skip to content

types: fix getblockstats doc for v21 and later#592

Open
satsfy wants to merge 1 commit into
rust-bitcoin:masterfrom
satsfy:fix-getblockstats-txs-doc
Open

types: fix getblockstats doc for v21 and later#592
satsfy wants to merge 1 commit into
rust-bitcoin:masterfrom
satsfy:fix-getblockstats-txs-doc

Conversation

@satsfy
Copy link
Copy Markdown
Contributor

@satsfy satsfy commented May 15, 2026

Docs are wrong in getblockstats txs field.

The txs field counts all transactions in the block, including the coinbase. Core's source passes block.vtx.size() directly, which includes the coinbase transaction at index 0. Bitcoin Core doc agrees.

Example, I just called

bitcoin-cli -regtest generatetoaddress 101 (bitcoin-cli -regtest getnewaddress)

Now I run

bitcoin-cli -regtest getblockstats 50 | grep "\"txs\""
  "txs": 1,

Returns 1 because that is the coinbase transaction.

Also, swtotal_weight and total_weight fields say "divided by segwit scale factor (4)" but it was dropped from the Core docs at v21 and should not appear in v21 or later.

@satsfy satsfy force-pushed the fix-getblockstats-txs-doc branch from 111605e to 01fc4f2 Compare May 15, 2026 19:23
Copy link
Copy Markdown
Collaborator

@jamillambert jamillambert left a comment

Choose a reason for hiding this comment

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

I checked the docs and it looks like this changed in v20, i.e. v17-19 say (excluding coinbase). I didn't check if it actually changed or if the docs were fixed. I say this because I know of other cases where the docs in v17 or so were incorrect.

@satsfy satsfy force-pushed the fix-getblockstats-txs-doc branch from 01fc4f2 to 120427f Compare May 18, 2026 23:50
@satsfy
Copy link
Copy Markdown
Contributor Author

satsfy commented May 18, 2026

Great catch, my bad for letting that slip

So in version v20 it says excluding.
In version v21 it says including.

Also fix swtotal_weight and total_weight in and later because the phrase "divided by segwit scale factor (4)" was dropped from the Core docs at v21 and should not appear in v21+.

The txs field in v21+ was documented as "excluding coinbase" but Core's
docs changed the wording at v21 to "including coinbase".

Add a getblockstats struct to v21 with the corrected doc. v22-v24
export from v21 now. Also fix swtotal_weight and total_weight in v21
and later because the phrase "divided by segwit scale factor (4)" was
dropped from the Core docs at v21 and should not appear in v21 or later,
including the model.
@satsfy satsfy force-pushed the fix-getblockstats-txs-doc branch from 120427f to d1c30f3 Compare May 18, 2026 23:58
@satsfy satsfy changed the title types: fix getblockstats txs field doc types: fix getblockstats doc for v21 and later May 18, 2026
@jamillambert
Copy link
Copy Markdown
Collaborator

So in version v20 it says excluding. In version v21 it says including.

I just checked again to see why we get a different version where this changed and it changed between 20.1 and 20.2. We use 20.2 in types.

@tcharding
Copy link
Copy Markdown
Member

I read the PR description and it reads like this is a docs only fix but then the patch diff is big and there are loads of code changes. Is this PR introducing new types just to fix the docs? If so this is a policy change for the repo and cannot be done lightly. Looks like this is tackling the problems outline in #457 and #59 but only partially. If so we need a more principled approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants