-
Notifications
You must be signed in to change notification settings - Fork 6
/
fork_bench.py
executable file
·58 lines (51 loc) · 1.98 KB
/
fork_bench.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
#!/usr/bin/env python3
import sys, os
sys.path.insert(1, os.path.dirname(sys.path[0]))
from eth_utils import decode_hex
from rlp.sedes import Binary, BigEndianInt
from conflux import utils
from conflux.rpc import RpcClient
from conflux.utils import encode_hex, bytes_to_int, priv_to_addr, parse_as_int
from test_framework.blocktools import create_block
from test_framework.test_framework import ConfluxTestFramework
from test_framework.mininode import *
from test_framework.util import *
class ForkBench(ConfluxTestFramework):
def set_test_params(self):
self.num_nodes = 1
def setup_network(self):
self.setup_nodes()
start_p2p_connection(self.nodes)
def run_test(self):
block_number = 8000
client = RpcClient(self.nodes[0])
start = time.time()
genesis = client.best_block_hash()
parent = genesis
# generate main chain
for i in range(block_number):
parent = client.generate_block_with_parent(parent, referee=[])
if i % 100 == 0:
self.log.info("generate %d blocks", i)
prev_end = parent
now = time.time()
self.log.info("Time to process main chain of %d blocks: %f", block_number, now - start)
start = now
# process fork
parent = genesis
for i in range(block_number + 1):
parent = client.generate_block_with_parent(parent, referee=[])
self.log.debug("block hash: %s", parent)
if i % 100 == 0:
self.log.info("generate %d blocks", i)
now = time.time()
self.log.info("Time to process fork of %d blocks: %f", block_number + 1, now - start)
# switch back to main chain
parent = prev_end
start = time.time()
for i in range(2):
parent = client.generate_block_with_parent(parent, referee=[])
now = time.time()
self.log.info("Time to switch back %f", now - start)
if __name__ == "__main__":
ForkBench().main()