Bitcoin Forum
May 27, 2024, 10:40:30 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Why is VARINT not used in serialization of CBlockHeader and other core classes?  (Read 952 times)
tinkert85 (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
October 02, 2014, 03:38:53 PM
 #1

What is the reason that CVarInt isn't used for serialization in the core classes in bitcoin?

Som examples would be:
CBlockHeader.nVersion
CTransaction.nVersion
CTransaction.nLockTime
COutPoint.n

I understand that CVarInt is only used for the "internal" storage types (CTxInUndo, CDiskBlockIndex and others) but I fail to see why.

Does it have something to do with that the classes that are serialized over network shouldn't use compressed forms, or is there a tradeoff with compressed storage space vs. computational overhead in compressing/decompressing?

Or is it just a legacy thing, that the protocol didn't compress from the start and the format has stuck around since then?



CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1078


Ian Knowles - CIYAM Lead Developer


View Profile WWW
October 02, 2014, 03:49:09 PM
 #2

Or is it just a legacy thing, that the protocol didn't compress from the start and the format has stuck around since then?

My guess would be that - personally I really dislike "binary" protocols (and the internet mostly doesn't use them) as you just end up with a lot of headaches with serialization.

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
tinkert85 (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
October 02, 2014, 04:02:29 PM
 #3

Thank you for the quick reply!

That is a good reason and a good guess. But, the block format already uses some "byte compressed" integers, notably the size of all vectors, vtx, vin and vout. That format is as far as I understand called compact size and differs some from the CVarInt class.

Below is a snippet from the protocol specification where they explicitly say that the CVarInt only is used for local storage, but doesn't say why.

https://en.bitcoin.it/wiki/Protocol_specification#Variable_length_integer
"Modern BitcoinQT has also CVarInt class which implements even more compact integer for the purpose of local storage (which is incompatible with "CompactSize" described here). CVarInt is not a part of the protocol."

Any ideas regarding the above quote?
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1078


Ian Knowles - CIYAM Lead Developer


View Profile WWW
October 02, 2014, 04:42:27 PM
 #4

Any ideas regarding the above quote?

Sorry - I don't know exactly why that might be (endian issues perhaps?).

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
tacotime
Legendary
*
Offline Offline

Activity: 1484
Merit: 1005



View Profile
October 02, 2014, 05:10:54 PM
 #5

My guess is because they make determinism easier in terms of the block header or tx structure. There have been some minor irritations around CryptoNote with using varint in the block headers. For instance, some programmers for miners presumed incoming header payload sizes of 80 bytes, but if the difficulty overflows you end up with 81 bytes. Thus when the header overflowed 80 bytes due to difficulty miners broke.

Code:
XMR: 44GBHzv6ZyQdJkjqZje6KLZ3xSyN1hBSFAnLP6EAqJtCRVzMzZmeXTC2AHKDS9aEDTRKmo6a6o9r9j86pYfhCWDkKjbtcns
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!