Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_unrequested_blocks.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test processing of unrequested blocks. | |||||
import time | |||||
from test_framework.blocktools import ( | |||||
create_block, | |||||
create_coinbase, | |||||
create_transaction, | |||||
) | |||||
from test_framework.messages import ( | |||||
CBlockHeader, | |||||
CInv, | |||||
msg_block, | |||||
msg_headers, | |||||
msg_inv, | |||||
) | |||||
from test_framework.mininode import ( | |||||
mininode_lock, | |||||
network_thread_join, | |||||
network_thread_start, | |||||
P2PInterface, | |||||
) | |||||
from test_framework.test_framework import BitcoinTestFramework | |||||
from test_framework.util import ( | |||||
assert_equal, | |||||
assert_raises_rpc_error, | |||||
connect_nodes, | |||||
sync_blocks, | |||||
) | |||||
''' | |||||
AcceptBlockTest -- test processing of unrequested blocks. | |||||
Setup: two nodes, node0+node1, not connected to each other. Node1 will have | Setup: two nodes, node0+node1, not connected to each other. Node1 will have | ||||
nMinimumChainWork set to 0x10, so it won't process low-work unrequested blocks. | nMinimumChainWork set to 0x10, so it won't process low-work unrequested blocks. | ||||
We have one P2PInterface connection to node0 called test_node, and one to node1 | We have one P2PInterface connection to node0 called test_node, and one to node1 | ||||
called min_work_node. | called min_work_node. | ||||
The test: | The test: | ||||
Show All 30 Lines | |||||
8. Create a fork which is invalid at a height longer than the current chain | 8. Create a fork which is invalid at a height longer than the current chain | ||||
(ie to which the node will try to reorg) but which has headers built on top | (ie to which the node will try to reorg) but which has headers built on top | ||||
of the invalid block. Check that we get disconnected if we send more headers | of the invalid block. Check that we get disconnected if we send more headers | ||||
on the chain the node now knows to be invalid. | on the chain the node now knows to be invalid. | ||||
9. Test Node1 is able to sync when connected to node0 (which should have sufficient | 9. Test Node1 is able to sync when connected to node0 (which should have sufficient | ||||
work on its chain). | work on its chain). | ||||
''' | """ | ||||
import time | |||||
from test_framework.blocktools import ( | |||||
create_block, | |||||
create_coinbase, | |||||
create_transaction, | |||||
) | |||||
from test_framework.messages import ( | |||||
CBlockHeader, | |||||
CInv, | |||||
msg_block, | |||||
msg_headers, | |||||
msg_inv, | |||||
) | |||||
from test_framework.mininode import ( | |||||
mininode_lock, | |||||
network_thread_join, | |||||
network_thread_start, | |||||
P2PInterface, | |||||
) | |||||
from test_framework.test_framework import BitcoinTestFramework | |||||
from test_framework.util import ( | |||||
assert_equal, | |||||
assert_raises_rpc_error, | |||||
connect_nodes, | |||||
sync_blocks, | |||||
) | |||||
class AcceptBlockTest(BitcoinTestFramework): | class AcceptBlockTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-noparkdeepreorg"], | self.extra_args = [["-noparkdeepreorg"], | ||||
▲ Show 20 Lines • Show All 277 Lines • Show Last 20 Lines |