forked from jgarzik/pynode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkbootstrap.py
executable file
·74 lines (56 loc) · 1.49 KB
/
mkbootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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' : '/spare/tmp/mkbootstrap.log',
'db' : '/spare/tmp/chaindb'
},
'testnet3' : {
'log' : '/spare/tmp/mkbootstraptest.log',
'db' : '/spare/tmp/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)
outf = open('bootstrap.dat', 'wb')
scanned = 0
failures = 0
for height in xrange(193000+1):
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()
outhdr = netmagic.msg_start
outhdr += struct.pack("<i", len(ser_block))
outf.write(outhdr)
outf.write(ser_block)
scanned += 1
if (scanned % 1000) == 0:
log.write("Scanned height %d (%d failures)" % (
height, failures))
log.write("Scanned %d blocks (%d failures)" % (scanned, failures))