TeachMeBitcoin

BIP154 & CompactSize History

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

BIP154 & CompactSize History

The term "VarInt" is actually used to describe two different things in the Bitcoin codebase. This ambiguity has led to significant confusion for developers.

1. CompactSize (The P2P Format)

What we have been describing—the FD, FE, FF markers—is technically called CompactSize in the Bitcoin Core source code.

2. VarInt (The Database Format)

There is another format, properly called VarInt (or Base-128 VarInt), used inside the local database (LevelDB) on your hard drive.

3. BIP154: Rate Limiting

BIP154 discusses the impact of VarInts on network peer management.

4. The "Variable-Length" Philosophy

Satoshi's use of variable-length structures was a radical departure from the fixed-length record formats used in traditional finance (like ISO 8583).

5. Developer Checklist

When someone says "VarInt," you should ask:

  1. "Do you mean the CompactSize used in transactions?" (Usually Yes).

  2. "Do you mean the Base-128 VarInt used in LevelDB?" (Only if you are writing database code).

Context Name in Code Marker Type
P2P / Blocks CompactSize Prefix Byte (FD, FE, FF)
Local Database VarInt MSB Bit (Base-128)

In the final section, we will build a Python VarInt Auditor.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!