Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_maxuploadtarget.py
Show All 11 Lines | |||||
""" | """ | ||||
from collections import defaultdict | from collections import defaultdict | ||||
import time | import time | ||||
from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE | from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE | ||||
from test_framework.blocktools import mine_big_block | from test_framework.blocktools import mine_big_block | ||||
from test_framework.messages import CInv, msg_getdata | from test_framework.messages import CInv, msg_getdata | ||||
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 assert_equal | from test_framework.util import assert_equal | ||||
class TestP2PConn(P2PInterface): | class TestP2PConn(P2PInterface): | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.block_receive_map = defaultdict(int) | self.block_receive_map = defaultdict(int) | ||||
Show All 30 Lines | def run_test(self): | ||||
# p2p_conns[0] will only request old blocks | # p2p_conns[0] will only request old blocks | ||||
# p2p_conns[1] will only request new blocks | # p2p_conns[1] will only request new blocks | ||||
# p2p_conns[2] will test resetting the counters | # p2p_conns[2] will test resetting the counters | ||||
p2p_conns = [] | p2p_conns = [] | ||||
for _ in range(3): | for _ in range(3): | ||||
p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn())) | p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn())) | ||||
network_thread_start() | |||||
for p2pc in p2p_conns: | for p2pc in p2p_conns: | ||||
p2pc.wait_for_verack() | p2pc.wait_for_verack() | ||||
# Test logic begins here | # Test logic begins here | ||||
# Now mine a big block | # Now mine a big block | ||||
mine_big_block(self.nodes[0], self.utxo_cache) | mine_big_block(self.nodes[0], self.utxo_cache) | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# stop and start node 0 with 1MB maxuploadtarget, whitelist 127.0.0.1 | # stop and start node 0 with 1MB maxuploadtarget, whitelist 127.0.0.1 | ||||
self.log.info("Restarting nodes with -whitelist=127.0.0.1") | self.log.info("Restarting nodes with -whitelist=127.0.0.1") | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.start_node(0, ["-whitelist=127.0.0.1", | self.start_node(0, ["-whitelist=127.0.0.1", | ||||
"-maxuploadtarget=1", "-blockmaxsize=999000"]) | "-maxuploadtarget=1", "-blockmaxsize=999000"]) | ||||
# Reconnect to self.nodes[0] | # Reconnect to self.nodes[0] | ||||
self.nodes[0].add_p2p_connection(TestP2PConn()) | self.nodes[0].add_p2p_connection(TestP2PConn()) | ||||
network_thread_start() | |||||
self.nodes[0].p2p.wait_for_verack() | self.nodes[0].p2p.wait_for_verack() | ||||
# retrieve 20 blocks which should be enough to break the 1MB limit | # retrieve 20 blocks which should be enough to break the 1MB limit | ||||
getdata_request.inv = [CInv(2, big_new_block)] | getdata_request.inv = [CInv(2, big_new_block)] | ||||
for i in range(20): | for i in range(20): | ||||
self.nodes[0].p2p.send_message(getdata_request) | self.nodes[0].p2p.send_message(getdata_request) | ||||
self.nodes[0].p2p.sync_with_ping() | self.nodes[0].p2p.sync_with_ping() | ||||
assert_equal( | assert_equal( | ||||
Show All 13 Lines |