Bitcoin Forum
May 09, 2024, 01:18:51 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Where/how is on disk/network block size determined and stored?  (Read 344 times)
akahuddle (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 1


View Profile
November 03, 2017, 05:28:48 PM
Merited by ABCbits (1)
 #1

Searching google and the forums for this answer mostly matches block size debate questions, which is not what I'm after.

When a block is transmitted across the network or stored on disk:

1. Where is the size of the actual block stored in the message? Do you just send a TCP message ahead of the block that says "hey, the next block is 875,489 bytes long!" or is it encoded somewhere in to the block structure itself (apparently it isn't in the block header)?
2. Similarly, on disk, where is the record of how big each block is (so the filesystem knows how much data to read)? Is that in the chain state database, or it is stored in the BLK*.dat files themselves? Or somewhere else?

Basically, I'm trying to understand, from a systems programming perspective, how you tell the storage/TCP layers how much data to read and write from/to disk/network.
1715260731
Hero Member
*
Offline Offline

Posts: 1715260731

View Profile Personal Message (Offline)

Ignore
1715260731
Reply with quote  #2

1715260731
Report to moderator
1715260731
Hero Member
*
Offline Offline

Posts: 1715260731

View Profile Personal Message (Offline)

Ignore
1715260731
Reply with quote  #2

1715260731
Report to moderator
Every time a block is mined, a certain amount of BTC (called the subsidy) is created out of thin air and given to the miner. The subsidy halves every four years and will reach 0 in about 130 years.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715260731
Hero Member
*
Offline Offline

Posts: 1715260731

View Profile Personal Message (Offline)

Ignore
1715260731
Reply with quote  #2

1715260731
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
November 03, 2017, 09:38:13 PM
Merited by ABCbits (2)
 #2

1. Where is the size of the actual block stored in the message? Do you just send a TCP message ahead of the block that says "hey, the next block is 875,489 bytes long!" or is it encoded somewhere in to the block structure itself (apparently it isn't in the block header)?
Bitcoin has several P2P network messages, one of which is the Block message. Each P2P message (not just the block message) has a message header which contains information about the rest of the message, including the size in bytes of the message. You can read about the message header here: https://bitcoin.org/en/developer-reference#message-headers

2. Similarly, on disk, where is the record of how big each block is (so the filesystem knows how much data to read)? Is that in the chain state database, or it is stored in the BLK*.dat files themselves? Or somewhere else?
The blocks are stored disk as they are received over the network (without the P2P message header) with an additional compact size unsigned integer before the block indicating its length.

akahuddle (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 1


View Profile
November 03, 2017, 09:54:38 PM
 #3

Perfect, thanks!
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!