Bitcoin Forum
September 20, 2018, 09:41:35 AM *
News: ♦♦ Bitcoin Core users must update to 0.16.3 [Torrent]. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Where/how is on disk/network block size determined and stored?  (Read 246 times)
akahuddle
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
November 03, 2017, 05:28:48 PM
 #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.
1537436495
Hero Member
*
Offline Offline

Posts: 1537436495

View Profile Personal Message (Offline)

Ignore
1537436495
Reply with quote  #2

1537436495
Report to moderator
1537436495
Hero Member
*
Offline Offline

Posts: 1537436495

View Profile Personal Message (Offline)

Ignore
1537436495
Reply with quote  #2

1537436495
Report to moderator
1537436495
Hero Member
*
Offline Offline

Posts: 1537436495

View Profile Personal Message (Offline)

Ignore
1537436495
Reply with quote  #2

1537436495
Report to moderator
Einax Airdrops and Bounties made easy! List your ERC-20 token
FREE
ETH markets launching soon!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 1526
Merit: 1631


3F1Y9yquzvY6RWvKbw2n2zeo9V5mvBhADU


View Profile WWW
November 03, 2017, 09:38:13 PM
 #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
Newbie
*
Offline Offline

Activity: 2
Merit: 0


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

Perfect, thanks!
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!