Changeset View
Changeset View
Standalone View
Standalone View
test/functional/assumevalid.py
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
class BaseNode(NodeConnCB): | class BaseNode(NodeConnCB): | ||||
def send_header_for_blocks(self, new_blocks): | def send_header_for_blocks(self, new_blocks): | ||||
headers_message = msg_headers() | headers_message = msg_headers() | ||||
headers_message.headers = [CBlockHeader(b) for b in new_blocks] | headers_message.headers = [CBlockHeader(b) for b in new_blocks] | ||||
self.send_message(headers_message) | self.send_message(headers_message) | ||||
class AssumeValidTest(BitcoinTestFramework): | class AssumeValidTest(BitcoinTestFramework): | ||||
def __init__(self): | def set_test_params(self): | ||||
super().__init__() | |||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 3 | self.num_nodes = 3 | ||||
def setup_network(self): | def setup_network(self): | ||||
self.add_nodes(3) | |||||
# Start node0. We don't start the other nodes yet since | # Start node0. We don't start the other nodes yet since | ||||
# we need to pre-mine a block with an invalid transaction | # we need to pre-mine a block with an invalid transaction | ||||
# signature so we can pass in the block hash as assumevalid. | # signature so we can pass in the block hash as assumevalid. | ||||
self.nodes = [self.start_node(0, self.options.tmpdir)] | self.start_node(0) | ||||
def send_blocks_until_disconnected(self, node): | def send_blocks_until_disconnected(self, node): | ||||
"""Keep sending blocks to the node until we're disconnected.""" | """Keep sending blocks to the node until we're disconnected.""" | ||||
for i in range(len(self.blocks)): | for i in range(len(self.blocks)): | ||||
try: | try: | ||||
node.send_message(msg_block(self.blocks[i])) | node.send_message(msg_block(self.blocks[i])) | ||||
except IOError as e: | except IOError as e: | ||||
assert str(e) == 'Not connected, no pushbuf' | assert str(e) == 'Not connected, no pushbuf' | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
block.nVersion = 4 | block.nVersion = 4 | ||||
block.solve() | block.solve() | ||||
self.blocks.append(block) | self.blocks.append(block) | ||||
self.tip = block.sha256 | self.tip = block.sha256 | ||||
self.block_time += 1 | self.block_time += 1 | ||||
height += 1 | height += 1 | ||||
# Start node1 and node2 with assumevalid so they accept a block with a bad signature. | # Start node1 and node2 with assumevalid so they accept a block with a bad signature. | ||||
self.nodes.append(self.start_node(1, self.options.tmpdir, | self.start_node(1, extra_args=["-assumevalid=" + hex(block102.sha256)]) | ||||
["-assumevalid=" + hex(block102.sha256)])) | |||||
node1 = BaseNode() # connects to node1 | node1 = BaseNode() # connects to node1 | ||||
connections.append( | connections.append( | ||||
NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], node1)) | NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], node1)) | ||||
node1.add_connection(connections[1]) | node1.add_connection(connections[1]) | ||||
node1.wait_for_verack() | node1.wait_for_verack() | ||||
self.nodes.append(self.start_node(2, self.options.tmpdir, | self.start_node(2, extra_args=["-assumevalid=" + hex(block102.sha256)]) | ||||
["-assumevalid=" + hex(block102.sha256)])) | |||||
node2 = BaseNode() # connects to node2 | node2 = BaseNode() # connects to node2 | ||||
connections.append( | connections.append( | ||||
NodeConn('127.0.0.1', p2p_port(2), self.nodes[2], node2)) | NodeConn('127.0.0.1', p2p_port(2), self.nodes[2], node2)) | ||||
node2.add_connection(connections[2]) | node2.add_connection(connections[2]) | ||||
node2.wait_for_verack() | node2.wait_for_verack() | ||||
# send header lists to all three nodes | # send header lists to all three nodes | ||||
node0.send_header_for_blocks(self.blocks[0:2000]) | node0.send_header_for_blocks(self.blocks[0:2000]) | ||||
Show All 24 Lines |