Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_assumevalid.py
Show All 36 Lines | from test_framework.messages import ( | ||||
CBlockHeader, | CBlockHeader, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
msg_block, | msg_block, | ||||
msg_headers, | msg_headers, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import P2PInterface | ||||
network_thread_join, | |||||
network_thread_start, | |||||
P2PInterface, | |||||
) | |||||
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.txtools import pad_tx | from test_framework.txtools import pad_tx | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
class BaseNode(P2PInterface): | class BaseNode(P2PInterface): | ||||
def send_header_for_blocks(self, new_blocks): | def send_header_for_blocks(self, new_blocks): | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def assert_blockchain_height(self, node, height): | ||||
assert False, "blockchain too long: {}".format(current_height) | assert False, "blockchain too long: {}".format(current_height) | ||||
elif current_height == height: | elif current_height == height: | ||||
break | break | ||||
def run_test(self): | def run_test(self): | ||||
# Connect to node0 | # Connect to node0 | ||||
p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) | p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) | ||||
network_thread_start() | |||||
self.nodes[0].p2p.wait_for_verack() | self.nodes[0].p2p.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( | ||||
self.nodes[0].getbestblockhash())['time'] + 1 | self.nodes[0].getbestblockhash())['time'] + 1 | ||||
self.blocks = [] | self.blocks = [] | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.tip, create_coinbase(height), self.block_time) | self.tip, create_coinbase(height), self.block_time) | ||||
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 | ||||
# We're adding new connections so terminate the network thread | |||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
network_thread_join() | |||||
# 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)]) | ||||
self.start_node(2, extra_args=["-assumevalid=" + hex(block102.sha256)]) | self.start_node(2, extra_args=["-assumevalid=" + hex(block102.sha256)]) | ||||
p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) | p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) | ||||
p2p1 = self.nodes[1].add_p2p_connection(BaseNode()) | p2p1 = self.nodes[1].add_p2p_connection(BaseNode()) | ||||
p2p2 = self.nodes[2].add_p2p_connection(BaseNode()) | p2p2 = self.nodes[2].add_p2p_connection(BaseNode()) | ||||
network_thread_start() | |||||
p2p0.wait_for_verack() | p2p0.wait_for_verack() | ||||
p2p1.wait_for_verack() | p2p1.wait_for_verack() | ||||
p2p2.wait_for_verack() | p2p2.wait_for_verack() | ||||
# send header lists to all three nodes | # send header lists to all three nodes | ||||
p2p0.send_header_for_blocks(self.blocks[0:2000]) | p2p0.send_header_for_blocks(self.blocks[0:2000]) | ||||
p2p0.send_header_for_blocks(self.blocks[2000:]) | p2p0.send_header_for_blocks(self.blocks[2000:]) | ||||
p2p1.send_header_for_blocks(self.blocks[0:2000]) | p2p1.send_header_for_blocks(self.blocks[0:2000]) | ||||
Show All 22 Lines |