Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-sync-chain.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2018 The Bitcoin developers | # Copyright (c) 2018 The Bitcoin 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 that a node receiving many (potentially out of order) blocks exits | Test that a node receiving many (potentially out of order) blocks exits | ||||
initial block download (IBD; this occurs once it has passed minimumchainwork) | initial block download (IBD; this occurs once it has passed minimumchainwork) | ||||
and continues to sync without seizing. | and continues to sync without seizing. | ||||
""" | """ | ||||
import random | import random | ||||
from test_framework.blocktools import create_block, create_coinbase | from test_framework.blocktools import create_block, create_coinbase | ||||
from test_framework.messages import CBlockHeader, msg_block, msg_headers | from test_framework.messages import CBlockHeader, msg_block, msg_headers | ||||
from test_framework.mininode import network_thread_start, P2PInterface | from test_framework.mininode import P2PInterface | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import p2p_port, wait_until | from test_framework.util import wait_until | ||||
NUM_IBD_BLOCKS = 50 | NUM_IBD_BLOCKS = 50 | ||||
class BaseNode(P2PInterface): | class BaseNode(P2PInterface): | ||||
def send_header(self, block): | def send_header(self, block): | ||||
msg = msg_headers() | msg = msg_headers() | ||||
msg.headers = [CBlockHeader(block)] | msg.headers = [CBlockHeader(block)] | ||||
self.send_message(msg) | self.send_message(msg) | ||||
def send_block(self, block): | def send_block(self, block): | ||||
self.send_message(msg_block(block)) | self.send_message(msg_block(block)) | ||||
class SyncChainTest(BitcoinTestFramework): | class SyncChainTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
# Setting minimumchainwork makes sure we test IBD as well as post-IBD | # Setting minimumchainwork makes sure we test IBD as well as post-IBD | ||||
self.extra_args = [ | self.extra_args = [ | ||||
["-minimumchainwork={:#x}".format(202 + 2 * NUM_IBD_BLOCKS)]] | ["-minimumchainwork={:#x}".format(202 + 2 * NUM_IBD_BLOCKS)]] | ||||
def run_test(self): | def run_test(self): | ||||
node0conn = BaseNode() | |||||
node0conn.peer_connect('127.0.0.1', p2p_port(0)) | |||||
network_thread_start() | |||||
node0conn.wait_for_verack() | |||||
node0 = self.nodes[0] | node0 = self.nodes[0] | ||||
node0conn = node0.add_p2p_connection(BaseNode()) | |||||
node0.p2p.wait_for_verack() | |||||
tip = int(node0.getbestblockhash(), 16) | tip = int(node0.getbestblockhash(), 16) | ||||
height = node0.getblockcount() + 1 | height = node0.getblockcount() + 1 | ||||
time = node0.getblock(node0.getbestblockhash())['time'] + 1 | time = node0.getblock(node0.getbestblockhash())['time'] + 1 | ||||
blocks = [] | blocks = [] | ||||
for i in range(NUM_IBD_BLOCKS * 2): | for i in range(NUM_IBD_BLOCKS * 2): | ||||
block = create_block(tip, create_coinbase(height), time) | block = create_block(tip, create_coinbase(height), time) | ||||
Show All 22 Lines |