~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to qa/rpc-tests/maxuploadtarget.py

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python2
2
 
#
3
 
# Distributed under the MIT/X11 software license, see the accompanying
 
1
#!/usr/bin/env python3
 
2
# Copyright (c) 2015-2016 The Bitcoin Core developers
 
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
 
#
6
5
 
7
6
from test_framework.mininode import *
8
7
from test_framework.test_framework import BitcoinTestFramework
9
8
from test_framework.util import *
10
 
from test_framework.comptool import wait_until
11
9
import time
12
10
 
13
11
'''
82
80
        return success
83
81
 
84
82
class MaxUploadTest(BitcoinTestFramework):
85
 
    def __init__(self):
86
 
        self.utxo = []
87
 
        self.txouts = gen_return_txouts()
88
83
 
89
84
    def add_options(self, parser):
90
85
        parser.add_option("--testbinary", dest="testbinary",
91
86
                          default=os.getenv("BITCOIND", "bitcoind"),
92
87
                          help="bitcoind binary to test")
93
88
 
94
 
    def setup_chain(self):
95
 
        initialize_chain_clean(self.options.tmpdir, 2)
 
89
    def __init__(self):
 
90
        super().__init__()
 
91
        self.setup_clean_chain = True
 
92
        self.num_nodes = 1
 
93
 
 
94
        self.utxo = []
 
95
        self.txouts = gen_return_txouts()
96
96
 
97
97
    def setup_network(self):
98
98
        # Start a node with maxuploadtarget of 200 MB (/24h)
99
99
        self.nodes = []
100
 
        self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-maxuploadtarget=200", "-blockmaxsize=999000"]))
 
100
        self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-maxuploadtarget=800", "-blockmaxsize=999000"]))
101
101
 
102
102
    def mine_full_block(self, node, address):
103
103
        # Want to create a full block
104
104
        # We'll generate a 66k transaction below, and 14 of them is close to the 1MB block limit
105
 
        for j in xrange(14):
 
105
        for j in range(14):
106
106
            if len(self.utxo) < 14:
107
107
                self.utxo = node.listunspent()
108
108
            inputs=[]
140
140
        test_nodes = []
141
141
        connections = []
142
142
 
143
 
        for i in xrange(3):
 
143
        for i in range(3):
144
144
            test_nodes.append(TestNode())
145
145
            connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test_nodes[i]))
146
146
            test_nodes[i].add_connection(connections[i])
175
175
        getdata_request = msg_getdata()
176
176
        getdata_request.inv.append(CInv(2, big_old_block))
177
177
 
178
 
        max_bytes_per_day = 200*1024*1024
179
 
        daily_buffer = 144 * 1000000
 
178
        max_bytes_per_day = 800*1024*1024
 
179
        daily_buffer = 144 * 4000000
180
180
        max_bytes_available = max_bytes_per_day - daily_buffer
181
 
        success_count = max_bytes_available / old_block_size
 
181
        success_count = max_bytes_available // old_block_size
182
182
 
183
 
        # 144MB will be reserved for relaying new blocks, so expect this to
184
 
        # succeed for ~70 tries.
185
 
        for i in xrange(success_count):
 
183
        # 576MB will be reserved for relaying new blocks, so expect this to
 
184
        # succeed for ~235 tries.
 
185
        for i in range(success_count):
186
186
            test_nodes[0].send_message(getdata_request)
187
187
            test_nodes[0].sync_with_ping()
188
188
            assert_equal(test_nodes[0].block_receive_map[big_old_block], i+1)
190
190
        assert_equal(len(self.nodes[0].getpeerinfo()), 3)
191
191
        # At most a couple more tries should succeed (depending on how long 
192
192
        # the test has been running so far).
193
 
        for i in xrange(3):
 
193
        for i in range(3):
194
194
            test_nodes[0].send_message(getdata_request)
195
195
        test_nodes[0].wait_for_disconnect()
196
196
        assert_equal(len(self.nodes[0].getpeerinfo()), 2)
197
 
        print "Peer 0 disconnected after downloading old block too many times"
 
197
        print("Peer 0 disconnected after downloading old block too many times")
198
198
 
199
199
        # Requesting the current block on test_nodes[1] should succeed indefinitely,
200
200
        # even when over the max upload target.
201
 
        # We'll try 200 times
 
201
        # We'll try 800 times
202
202
        getdata_request.inv = [CInv(2, big_new_block)]
203
 
        for i in xrange(200):
 
203
        for i in range(800):
204
204
            test_nodes[1].send_message(getdata_request)
205
205
            test_nodes[1].sync_with_ping()
206
206
            assert_equal(test_nodes[1].block_receive_map[big_new_block], i+1)
207
207
 
208
 
        print "Peer 1 able to repeatedly download new block"
 
208
        print("Peer 1 able to repeatedly download new block")
209
209
 
210
210
        # But if test_nodes[1] tries for an old block, it gets disconnected too.
211
211
        getdata_request.inv = [CInv(2, big_old_block)]
213
213
        test_nodes[1].wait_for_disconnect()
214
214
        assert_equal(len(self.nodes[0].getpeerinfo()), 1)
215
215
 
216
 
        print "Peer 1 disconnected after trying to download old block"
 
216
        print("Peer 1 disconnected after trying to download old block")
217
217
 
218
 
        print "Advancing system time on node to clear counters..."
 
218
        print("Advancing system time on node to clear counters...")
219
219
 
220
220
        # If we advance the time by 24 hours, then the counters should reset,
221
221
        # and test_nodes[2] should be able to retrieve the old block.
225
225
        test_nodes[2].sync_with_ping()
226
226
        assert_equal(test_nodes[2].block_receive_map[big_old_block], 1)
227
227
 
228
 
        print "Peer 2 able to download old block"
 
228
        print("Peer 2 able to download old block")
229
229
 
230
230
        [c.disconnect_node() for c in connections]
231
231
 
232
232
        #stop and start node 0 with 1MB maxuploadtarget, whitelist 127.0.0.1
233
 
        print "Restarting nodes with -whitelist=127.0.0.1"
 
233
        print("Restarting nodes with -whitelist=127.0.0.1")
234
234
        stop_node(self.nodes[0], 0)
235
235
        self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-whitelist=127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000"])
236
236
 
238
238
        test_nodes = []
239
239
        connections = []
240
240
 
241
 
        for i in xrange(3):
 
241
        for i in range(3):
242
242
            test_nodes.append(TestNode())
243
243
            connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test_nodes[i]))
244
244
            test_nodes[i].add_connection(connections[i])
248
248
 
249
249
        #retrieve 20 blocks which should be enough to break the 1MB limit
250
250
        getdata_request.inv = [CInv(2, big_new_block)]
251
 
        for i in xrange(20):
 
251
        for i in range(20):
252
252
            test_nodes[1].send_message(getdata_request)
253
253
            test_nodes[1].sync_with_ping()
254
254
            assert_equal(test_nodes[1].block_receive_map[big_new_block], i+1)
258
258
        test_nodes[1].wait_for_disconnect()
259
259
        assert_equal(len(self.nodes[0].getpeerinfo()), 3) #node is still connected because of the whitelist
260
260
 
261
 
        print "Peer 1 still connected after trying to download old block (whitelisted)"
 
261
        print("Peer 1 still connected after trying to download old block (whitelisted)")
262
262
 
263
263
        [c.disconnect_node() for c in connections]
264
264