forked from jgarzik/pynode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbck.py
executable file
·64 lines (48 loc) · 1.3 KB
/
dbck.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
#!/usr/bin/python
#
# dbck.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
from bitcoin.coredefs import NETWORKS
from bitcoin.core import CBlock
from bitcoin.scripteval import *
NET_SETTINGS = {
'mainnet' : {
'log' : '/spare/tmp/dbck.log',
'db' : '/spare/tmp/chaindb'
},
'testnet3' : {
'log' : '/spare/tmp/dbcktest.log',
'db' : '/spare/tmp/chaintest'
}
}
MY_NETWORK = 'mainnet'
SETTINGS = NET_SETTINGS[MY_NETWORK]
log = Log.Log(SETTINGS['log'])
mempool = MemPool.MemPool(log)
chaindb = ChainDb.ChainDb(SETTINGS['db'], log, mempool, NETWORKS[MY_NETWORK])
scanned = 0
failures = 0
for height in xrange(chaindb.getheight()):
heightidx = ChainDb.HeightIdx()
heightidx.deserialize(chaindb.height[str(height)])
blkhash = heightidx.blocks[0]
ser_hash = ser_uint256(blkhash)
f = cStringIO.StringIO(chaindb.blocks[ser_hash])
block = CBlock()
block.deserialize(f)
if not block.is_valid():
log.write("block %064x failed" % (blkhash,))
failures += 1
scanned += 1
if (scanned % 1000) == 0:
log.write("Scanned height %d (%d failures)" % (
height, failures))
log.write("Scanned %d blocks (%d failures)" % (scanned, failures))