This repository was archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathq_avg_size.py
executable file
·78 lines (59 loc) · 1.55 KB
/
q_avg_size.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
74
75
76
77
#!/usr/bin/python
#
# q_avg_size.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/q_avg_size.log',
'db' : '/spare/tmp/chaindb'
},
'testnet3' : {
'log' : '/spare/tmp/q_avg_sizetest.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)
scanned = 0
failures = 0
n_sizes = 0
size_total = 0
for height in xrange(chaindb.getheight()+1):
if height < 200000:
continue
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)
byte_size = 80 + (len(block.vtx) * 32)
n_sizes += 1
size_total += byte_size
scanned += 1
if (scanned % 1000) == 0:
log.write("Scanned height %d (%d failures)" % (
height, failures))
log.write("Scanned %d blocks (%d failures)" % (scanned, failures))
avg_size = 1.0 * size_total / n_sizes
log.write("Average block summary size: %.2f" % (avg_size,))