Skip to content

BIP155: CompactSize vs VARINT

Vasil Dimov edited this page Aug 11, 2020 · 1 revision

Currently BIP155 specifies to use VARINT for time and services. The source code in pull/19031 also uses VARINT.

CompactSize is used in the P2P protocol and is documented here: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer

Overview of the encodings wrt time and services

time

  • Currently stored in 4 bytes, but would require more after 2038 (if interpreted as signed 4 byte integer; if interpreted as unsigned then 4 bytes are enough until year 2106)
  • VARINT would change it to 5 bytes today and remain 5 bytes after 2038 (unsigned)
  • CompactSize would change it to 5 bytes today and remain 5 bytes after 2038 (unsigned)

services

  • Currently stored in 8 bytes, but only holding numbers up to 1039
  • VARINT would change it to

Option1: Leave BIP155 and the code as is

  • con: would introduce a new "compressed" integer encoding in the P2P layer

Option2: Change BIP155 and the code to use CompactSize

  • pro: CompactSize is already used in the P2P protocol and is documented.