Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_preciousblock.py
Show All 11 Lines | |||||
) | ) | ||||
def unidirectional_node_sync_via_rpc(node_src, node_dest): | def unidirectional_node_sync_via_rpc(node_src, node_dest): | ||||
blocks_to_copy = [] | blocks_to_copy = [] | ||||
blockhash = node_src.getbestblockhash() | blockhash = node_src.getbestblockhash() | ||||
while True: | while True: | ||||
try: | try: | ||||
assert(len(node_dest.getblock(blockhash, False)) > 0) | assert len(node_dest.getblock(blockhash, False)) > 0 | ||||
break | break | ||||
except: | except: | ||||
blocks_to_copy.append(blockhash) | blocks_to_copy.append(blockhash) | ||||
blockhash = node_src.getblockheader( | blockhash = node_src.getblockheader( | ||||
blockhash, True)['previousblockhash'] | blockhash, True)['previousblockhash'] | ||||
blocks_to_copy.reverse() | blocks_to_copy.reverse() | ||||
for blockhash in blocks_to_copy: | for blockhash in blocks_to_copy: | ||||
blockdata = node_src.getblock(blockhash, False) | blockdata = node_src.getblock(blockhash, False) | ||||
assert(node_dest.submitblock(blockdata) in (None, 'inconclusive')) | assert node_dest.submitblock(blockdata) in (None, 'inconclusive') | ||||
def node_sync_via_rpc(nodes): | def node_sync_via_rpc(nodes): | ||||
for node_src in nodes: | for node_src in nodes: | ||||
for node_dest in nodes: | for node_dest in nodes: | ||||
if node_src is node_dest: | if node_src is node_dest: | ||||
continue | continue | ||||
unidirectional_node_sync_via_rpc(node_src, node_dest) | unidirectional_node_sync_via_rpc(node_src, node_dest) | ||||
Show All 20 Lines | def run_test(self): | ||||
assert_equal(self.nodes[0].getbestblockhash(), hashZ) | assert_equal(self.nodes[0].getbestblockhash(), hashZ) | ||||
self.log.info("Mine blocks A-B-C on Node 0") | self.log.info("Mine blocks A-B-C on Node 0") | ||||
hashC = self.nodes[0].generate(3)[-1] | hashC = self.nodes[0].generate(3)[-1] | ||||
assert_equal(self.nodes[0].getblockcount(), 5) | assert_equal(self.nodes[0].getblockcount(), 5) | ||||
self.log.info("Mine competing blocks E-F-G on Node 1") | self.log.info("Mine competing blocks E-F-G on Node 1") | ||||
hashG = self.nodes[1].generate(3)[-1] | hashG = self.nodes[1].generate(3)[-1] | ||||
assert_equal(self.nodes[1].getblockcount(), 5) | assert_equal(self.nodes[1].getblockcount(), 5) | ||||
assert(hashC != hashG) | assert hashC != hashG | ||||
self.log.info("Connect nodes and check no reorg occurs") | self.log.info("Connect nodes and check no reorg occurs") | ||||
# Submit competing blocks via RPC so any reorg should occur before we | # Submit competing blocks via RPC so any reorg should occur before we | ||||
# proceed (no way to wait on inaction for p2p sync) | # proceed (no way to wait on inaction for p2p sync) | ||||
node_sync_via_rpc(self.nodes[0:2]) | node_sync_via_rpc(self.nodes[0:2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
assert_equal(self.nodes[0].getbestblockhash(), hashC) | assert_equal(self.nodes[0].getbestblockhash(), hashC) | ||||
assert_equal(self.nodes[1].getbestblockhash(), hashG) | assert_equal(self.nodes[1].getbestblockhash(), hashG) | ||||
self.log.info("Make Node0 prefer block G") | self.log.info("Make Node0 prefer block G") | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |