Skip to content

Add consensus block size limit - #110

Closed
mtg0001 wants to merge 1 commit into
Bitflash-sh:mainfrom
mtg0001:consensus-block-size-limit
Closed

Add consensus block size limit#110
mtg0001 wants to merge 1 commit into
Bitflash-sh:mainfrom
mtg0001:consensus-block-size-limit

Conversation

@mtg0001

@mtg0001 mtg0001 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add MAX_BLOCK_SIZE = 1000000 as the consensus block-size ceiling.
  • Make CBlock::CheckBlock() validate serialized block size against that ceiling instead of the generic 32 MB serializer limit.
  • Add CBlock::CheckSizeLimits() so the rule is tested directly.
  • Add a consensus-limits self-test and include it in both Windows and Linux test targets.

Why

MAX_SIZE is the serializer safety limit, not a block consensus rule. This tree comes from Bitcoin 0.1.0, before Bitcoin added the later 1 MB block cap, so Bitflash had no real block-size ceiling beyond 32 MB.

The current chain audit found the largest real block at 34 KB across 5,709 blocks. A 1 MB cap leaves wide room for existing usage while preventing oversized blocks from becoming valid consensus history.

Consensus warning

This is a consensus rule change. Do not merge only from unit tests. Before merging, run a full validation from genesis with the proposed rule, for example a fresh sync or a full -checkblocks=0 validation against the current chain, and confirm no existing block is rejected.

I did not run that against the production data directory in this workspace because doing so would touch the local node/wallet state. This PR is prepared for audit.

Testing

  • git diff --check
  • make -f makefile.mingw tests from MSYS2 UCRT64 in src/

Bitflash-sh added a commit that referenced this pull request Aug 2, 2026
CheckBlock() validated block size against MAX_SIZE, the serializer's generic 32 MB guard rather than a block rule; MAX_BLOCK_SIZE did not exist in this tree at all, because Bitcoin's 1 MB cap arrived in 0.3.x, after the 0.1.0 this fork came from. A miner could produce a 32 MB block and every node would download, verify and store it.

Original work by mtg0001 in #110, rebased over #109 with the self-test conflict resolved, plus a comment explaining why the inherited count-against-bytes test stays.

Measured before choosing the number: 5709 blocks read from blk0001.dat give a largest block of 34,290 bytes and a median of 216, so 1 MB leaves 29x of headroom and rejects nothing that exists. A node built from this branch then synced genesis to 5706 on the live network with zero size-limit rejections and zero CheckBlock errors -- the same test that caught BIP30 rejecting a real block at height 859.
@Bitflash-sh

Copy link
Copy Markdown
Owner

Merged as #111 — your commit, rebased over #109 with the self-test conflict resolved (both PRs add a self-test and a line to each makefile's tests target, and git folded the two new functions into one).

The resync is the part I want on the record, since this is consensus. A node built from the rebased branch synced genesis → 5706 on the live network: zero size-limit rejections, zero CheckBlock errors. And the cap was checked against the chain before trusting the number — 5709 blocks read out of blk0001.dat give a largest block of 34,290 bytes against a median of 216, so 1 MB leaves 29× of headroom and rejects nothing that exists.

One thing I did not take: vtx.size() <= MAX_BLOCK_SIZE compares a transaction count against a byte limit. It is inherited from 0.1.0 and inert — a transaction serializes to more than sixty bytes, so a million of them cannot weigh under a megabyte. I left the line and wrote down why beside it: removing it would be tidier and would change nothing, which is exactly the argument that talks people into rewriting consensus code.

Closing this one in favour of #111. Thanks — this and #109 both landed today.

@Bitflash-sh Bitflash-sh closed this Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants