The first thing you need to do is get pynode (python language mini-Bitcoin node) software working. This is easier on Linux, since on Windows you will need to build leveldb to use
py-leveldb, which will require lots of C++ stuff installed. I use Kubuntu 12.04 on VirtualBox, since this allows you to have a second "Bitcoin" on another virtual IP address to connect to your main computer node.
https://github.com/jgarzik/pynode(
https://bitcointalk.org/index.php?topic=94645.0)
Here are the steps to get the required python extensions on (k)ubuntu 12:
sudo apt-get install python-setuptools
sudo apt-get install python-leveldb
sudo apt-get install libevent-dev
sudo apt-get install python-all-dev
sudo easy_install greenlet
sudo easy_install geventThen download and unzip pynode to a working directory. I have it in the directory
/home/USER/pynode/, where
USER is the logon username. I also created a subdirectory
/home/USER/pynode/db for the blockchain.
You will need to create a
pynode-config file. You can cut and paste the file below, but edit the IP address to be another (your local) Bitcoin node, and change the /home/USER lines to your login user name directory:
pynode-config# hostname or IP address of network node to connect to
host=192.168.1.101
# port of network node to connect to (default: 8333)
port=8333
# JSON-RPC server user, password. Uses HTTP Basic authentication.
rpcuser=XXXX
rpcpass=YYYY
# JSON-RPC server incoming TCP port (default: 9332)
rpcport=9332
# database directory
db=/home/USER/pynode/db
# log filename, or '-' or no-value for standard output
log=/home/USER/pynode/db/node.log
# if present, import these blocks into the block database
#loadblock=/tmp/blk0001.dat
# if present, disable all signature checking in new blocks
# (disabled by default)
nosig=1
# if present, force signature checking on all blocks,
# even those normally skipped because they were prior
# to a checkpoint.
# (disabled by default)
#forcesig=1
Then run it with this command:
cd ~/pynode
./node.py pynode-configIt will download all blocks from your other Bitcoin over the network (but go much faster without re-verification).
After it is done downloading (by checking it's log file), you can abort it.
To generate a bootstrap.datFind and edit the mkbootstrap.py file, changing the log and db directories to the directories used above. Then run it, to dump a bootstrap.dat up to the checkpoint block listed on the line that says
xrange(216116...
To generate importable blocks in multi-part filesAlternately, for Bitcoins less than version 0.8.0, run my modified mkbootstrap.py file that dumps the blockchain and splits the files at exactly the same blocks and size as Bitcoin creates in it's datadir:
#!/usr/bin/python
#
# mkbootstrap.py
#
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
import sys
import Log
import MemPool
import ChainDb
import cStringIO
import struct
from bitcoin.coredefs import NETWORKS
from bitcoin.core import CBlock
from bitcoin.scripteval import *
NET_SETTINGS = {
'mainnet' : {
'log' : '/home/USER/pynode/mkbootstrap.log',
'db' : '/home/USER/pynode/db'
},
'testnet3' : {
'log' : '/home/USER/pynode/mkbootstraptest.log',
'db' : '/home/USER/pynode/chaintest'
}
}
MY_NETWORK = 'mainnet'
SETTINGS = NET_SETTINGS[MY_NETWORK]
log = Log.Log(SETTINGS['log'])
mempool = MemPool.MemPool(log)
netmagic = NETWORKS[MY_NETWORK]
chaindb = ChainDb.ChainDb(SETTINGS, SETTINGS['db'], log, mempool, netmagic,
True)
out1 = open('bootstrap.001', 'wb')
out2 = open('bootstrap.002', 'wb')
out3 = open('bootstrap.003', 'wb')
scanned = 0
failures = 0
for height in xrange(212000+1): # last block to dump (checkpoint)
heightidx = ChainDb.HeightIdx()
heightstr = str(height)
try:
heightidx.deserialize(chaindb.db.Get('height:'+heightstr))
except KeyError:
log.write("Height " + str(height) + " not found.")
continue
blkhash = heightidx.blocks[0]
block = chaindb.getblock(blkhash)
ser_block = block.serialize()
if (height % 1000 == 0 and height <= 90000) or (height % 100 == 0 and height > 90000):
print "mkbootstrap: block height " + str(height)
outhdr = netmagic.msg_start
outhdr += struct.pack("<i", len(ser_block))
if height > 210964: # write 210965- to 3rd file
out3.write(outhdr)
out3.write(ser_block)
elif height > 188528: # write 188529-210964 to 2nd file
out2.write(outhdr)
out2.write(ser_block)
else:
out1.write(outhdr)
out1.write(ser_block)
scanned += 1
if (scanned % 1000) == 1:
log.write("Scanned height %d (%d failures)" % (
height, failures))
log.write("Scanned %d blocks (%d failures)" % (scanned, failures))
This will create the "official/final/verifiable/will never change" first two blockchain files (containing blocks up to 210964), blk0001/blk0002.dat in Bitcoin up to v0.7.x will also have the same hash after you import:
>sha256sum bootstrap.*7aac5826b91b4f87a2e9534e0e38e8d64ed21aff8a4eb8ff8dde4e726e67fe1a *bootstrap.001
796f65be10ef2e5fc27b97b09f312c9f8ddd7d1c3ab0f27f356a5b1dbf5a8963 *bootstrap.002
The script will also create a bootstrap.003 with remaining blocks (up to 212000 in script). We'll ignore this one for now. The original mkbootstrap script dumped a single bootstrap.dat file up to block 193000; if a future checkpoint is set, the final part 003 of will include these blocks.
(Google for your own copy of sha256sum.exe. Put it in the Windows directory and you can run it from anywhere.)
Let's import the blocks into Bitcoin, this will take six hours with an SSD and fast CPU (3GHz Core2), even more time with regular hard drive and less CPU. Here's a Windows command line, import to a blank C:\datadir:
"C:\Program Files (x86)\Bitcoin\daemon\bitcoind.exe" -datadir=C:\datadir -loadblock=C:\bootstrap.001 -loadblock=C:\bootstrap.002 -connect=127.0.0.1 -detachdb -printtoconsoleThis will create identical block file hashes as the imported files, and will build the final index file. Bitcoin won't proceed with network download after the last block of the import, instead it will abort, since you don't have bitcoin.conf. Here is the index file's hash on 0.7.1:
1ab115fd8338f0f4d112c8465418619f1219058a2e6f9baeb7621f39b362a177 *blkindex.dat
By using this method, others can create the exact same blockchain files as you from a network download, import them and see that they get the exact same files in their data directory as you created.