Bitcoin Forum
September 27, 2018, 11:22:27 PM *
News: ♦♦ New info! Bitcoin Core users absolutely must upgrade to previously-announced 0.16.3 [Torrent]. All Bitcoin users should temporarily trust confirmations slightly less. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: How to memory map blkindex.dat?  (Read 545 times)
cloudboy
Hero Member
*****
Offline Offline

Activity: 689
Merit: 500


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?
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1538090547
Hero Member
*
Offline Offline

Posts: 1538090547

View Profile Personal Message (Offline)

Ignore
1538090547
Reply with quote  #2

1538090547
Report to moderator
1538090547
Hero Member
*
Offline Offline

Posts: 1538090547

View Profile Personal Message (Offline)

Ignore
1538090547
Reply with quote  #2

1538090547
Report to moderator
TierNolan
Legendary
*
Offline Offline

Activity: 1190
Merit: 1001


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
Hero Member
*****
Offline Offline

Activity: 689
Merit: 500


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: 250


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:  

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!