This adds the following commits:
- remove unnecessary check for whether SegWit is active
- drop no longer relevant warning about missing sigops field
- warn that CheckBlock() underestimates sigops
- ~mark
default_witness_commitment
result field as not optional~ (Update 2024-01-09: incorrect, dropped)
Based on #26201, because it touches and adds a relevant test to getblocktemplate
. I can unrebase and pick the test if that PR doesn’t make it.
Earlier description, just historical context now.
Sigops
Two recent F2Pool blocks violated the sigops limit. Both by 3.
I suspect they were not using getblocktemplate
. If you look at the template right before the valid block at the same height, which was produced two minutes later, you’ll see that it matches the block with 3 small transactions difference. In other words, the valid block producer likely did use getblocktemplate
around the same time and did not experience an issue.
It’s also clear by looking at Mempool.Space that the valid block excluded many large bare multisig transactions. Those transactions paid more than enough in fees to be included, but we would have excluded them due to running out of sigops.
As can be seen in BlockAssembler::addPackageTxs
and TestPackage
we simply don’t add a package to the block if it doesn’t fit the remaining weight or sigops. Custom block construction software might not do that. I initially though they might have forgotten to check SegWit related sigops, but that seems unlikely given that they were only off by 3 in both blocks.
I suspect their mistake was to not count the number of sigops in the coinbase: it pays to legacy P2PKH which uses 4 sigops. Our code reserves 400 sigops for the coinbase, so would not have caused this.
Update 2024-01-09: I dropped the extra debug fields mentioned here
Anyway, while checking our code I added a few extra fields to the block statistics of~ getblocktemplate
:
sigops
: total sigops for the block excluding the coinbasecoinbase_reserved_sigops
: how many sigops we reserve for the coinbase (400)weightlimit
coinbase_reserved_weight
~I added a belt and suspenders check for the sigops limit in the RPC code.~ (update 2024-01-09: dropped) Note that we already check it when adding packages to a block and in TestBlockValidity
.
Segwit
~I also removed the need to set {"rules": "!segwit"}
, the generation of pre-segwit blocks, and the test code that checks activation.~ update 2023-08-18: commit removed