Bitcoin Forum
December 14, 2024, 05:09:08 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to memory map blkindex.dat?  (Read 639 times)
cloudboy (OP)
Hero Member
*****
Offline Offline

Activity: 690
Merit: 501


View Profile
May 21, 2015, 01:07:09 PM
 #1

Hi,

I want to mmap blkindex.dat to have a pointer to each CBlockIndex in the file. I see there are the 4 magic bytes at the beginning, followed by some zeroes and then the genesis block. Anybody familiar with the exact layout?
TierNolan
Legendary
*
Offline Offline

Activity: 1232
Merit: 1104


View Profile
May 21, 2015, 03:38:44 PM
 #2

It follows the network protocol.  They take the network serialization and dump it to disk.  Unused space at the end of the file is left as all zeros.

Protocol messages have this format.

Blocks are "block" type (and all zeros) for the command.

Blocks are given here.

1LxbG5cKXzTwZg9mjL3gaRE835uNQEteWF
cloudboy (OP)
Hero Member
*****
Offline Offline

Activity: 690
Merit: 501


View Profile
May 21, 2015, 03:55:31 PM
 #3

It follows the network protocol.  They take the network serialization and dump it to disk.  Unused space at the end of the file is left as all zeros.

Protocol messages have this format.

Blocks are "block" type (and all zeros) for the command.

Blocks are given here.

Got it! Thanks
altcoinex
Sr. Member
****
Offline Offline

Activity: 293
Merit: 251


Director - www.cubeform.io


View Profile WWW
May 21, 2015, 04:06:24 PM
 #4

To clarify,  As mentioned the blk*.dat are the actual dumped blocks.
The format is:

4 bytes: network message start (0xf9, 0xbe, 0xb4, 0xd9)
4 bytes: block size N (little endian)
N bytes: block raw data (see https://en.bitcoin.it/wiki/Protocol_specification#block)

However, the blkindex.dat is a berkely db file, not a raw dump and contains where and in which blk*.dat file the block is contained.

--edit-- Note: this applies to versions <0.8 as the format was changed.


                                     ╓╢╬╣╣╖
                                   ┌║██████║∩
                                   ]█████████
                                    ╜██████╝`
                                      ╙╜╜╜`
                                   ╓╥@@@@@@╥╓
         ╓╖@@╖,                 ,@║██████████╢@,                 ,╓@@╖╓
       ╓╢██████╢.              ╓╢███████████████╖               ║╢█████║╓
       ║█████████    ,,╓╓,,   ┌║█████████████████┐   ,,╓╓,,    ]█████████
       └╢██████║` ╓╢║██████╢║∩``╙╙╙╙╙╙╙╙╙╙╙╙╙╙╙╙╙`»╢╢██████╢║╖  ║███████╜
         "╜╜╜╜` ╖╢█████████╣╜                      └╢██████████@ `╜╜╜╜╜
               ║██████████╜                          ╙╢██████████
              ┌█████████╜                              ╙╢█████████
              └███████╨`                                 ╜████████
               ║████╨╜                                    `╢█████
                ╙╢╣╜                                        └╢█╜
                ,,                                            ,,
             ╓@║██┐                                          ┌██║@╓
            ╢██████                                          ]█████H
           ╢███████∩                                        ┌████████
  ╓@@@@╓   █████████                                        ║████████`  ╓@@@@╖
╓╢██████║. █████████∩                                      ┌█████████ ,║███████╖
██████████ └█████████                                      ██████████ ]█████████
`║██████╜`  └╢████████                                    ┌███████╣╜   ╙██████╨`
  `╙╜╜╙`      `╙╨╢████                                    █████╝╜`       `╙╜╜`
                      ]@╓                              ╓╖H
                      ███╢║@╓,                    ,╓@╢╢███`
                      ████████╢@╖╓.           ╓╖@║████████`
                      ]███████████╢║@╓,  ,╓@╢╢████████████
                       ╙╢█████████████╨` ╜██████████████╜
                         ╙╝╢███████║╜`    `╜║████████╝╜`
                     ,╓@@@╓  `²╙``             `╙²`  ╓@@@╖,
                    ║╢█████╢H                      ╓╢██████H
                    █████████                      █████████`
                    ╙╢██████╜                      ╙╢██████╜
                      └╨╩╝┘                          └╨╩╝╜
WINFLOW.
██
██
██
██
██
██
██
██
██
██
██
██
██
..
██
██
██
██
██
██
██
██
██
██
██
██
██
.
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!