Changeset View
Changeset View
Standalone View
Standalone View
test/functional/assumevalid.py
Show All 39 Lines | from test_framework.mininode import (CBlockHeader, | ||||
CTxOut, | CTxOut, | ||||
NetworkThread, | NetworkThread, | ||||
NodeConn, | NodeConn, | ||||
NodeConnCB, | NodeConnCB, | ||||
msg_block, | msg_block, | ||||
msg_headers) | msg_headers) | ||||
from test_framework.script import (CScript, OP_TRUE) | from test_framework.script import (CScript, OP_TRUE) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import (p2p_port, assert_equal) | from test_framework.util import (assert_equal) | ||||
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) | ||||
Show All 40 Lines | def assert_blockchain_height(self, node, height): | ||||
break | break | ||||
def run_test(self): | def run_test(self): | ||||
# Connect to node0 | # Connect to node0 | ||||
node0 = BaseNode() | node0 = BaseNode() | ||||
connections = [] | connections = [] | ||||
connections.append( | connections.append( | ||||
NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], node0)) | NodeConn('127.0.0.1', self.p2p_port(0), self.nodes[0], node0)) | ||||
node0.add_connection(connections[0]) | node0.add_connection(connections[0]) | ||||
NetworkThread().start() # Start up network handling in another thread | NetworkThread().start() # Start up network handling in another thread | ||||
node0.wait_for_verack() | node0.wait_for_verack() | ||||
# Build the blockchain | # Build the blockchain | ||||
self.tip = int(self.nodes[0].getbestblockhash(), 16) | self.tip = int(self.nodes[0].getbestblockhash(), 16) | ||||
self.block_time = self.nodes[0].getblock( | self.block_time = self.nodes[0].getblock( | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
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.start_node(1, extra_args=["-assumevalid=" + hex(block102.sha256)]) | self.start_node(1, extra_args=["-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', self.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.start_node(2, extra_args=["-assumevalid=" + hex(block102.sha256)]) | self.start_node(2, extra_args=["-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', self.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]) | ||||
node0.send_header_for_blocks(self.blocks[2000:]) | node0.send_header_for_blocks(self.blocks[2000:]) | ||||
node1.send_header_for_blocks(self.blocks[0:2000]) | node1.send_header_for_blocks(self.blocks[0:2000]) | ||||
node1.send_header_for_blocks(self.blocks[2000:]) | node1.send_header_for_blocks(self.blocks[2000:]) | ||||
Show All 21 Lines |