Skip to content

Commit d61fcff

Browse files
committed
don't enforce maxuploadtargets disconnect for whitelisted peers
1 parent dbd2c13 commit d61fcff

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

qa/rpc-tests/maxuploadtarget.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def run_test(self):
195195
daily_buffer = 144 * 1000000
196196
max_bytes_available = max_bytes_per_day - daily_buffer
197197
success_count = max_bytes_available / old_block_size
198-
198+
199199
# 144MB will be reserved for relaying new blocks, so expect this to
200200
# succeed for ~70 tries.
201201
for i in xrange(success_count):
@@ -228,7 +228,7 @@ def run_test(self):
228228
test_nodes[1].send_message(getdata_request)
229229
test_nodes[1].wait_for_disconnect()
230230
assert_equal(len(self.nodes[0].getpeerinfo()), 1)
231-
231+
232232
print "Peer 1 disconnected after trying to download old block"
233233

234234
print "Advancing system time on node to clear counters..."
@@ -245,5 +245,38 @@ def run_test(self):
245245

246246
[c.disconnect_node() for c in connections]
247247

248+
#stop and start node 0 with 1MB maxuploadtarget, whitelist 127.0.0.1
249+
print "Restarting nodes with -whitelist=127.0.0.1"
250+
stop_node(self.nodes[0], 0)
251+
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-whitelist=127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000"])
252+
253+
#recreate/reconnect 3 test nodes
254+
test_nodes = []
255+
connections = []
256+
257+
for i in xrange(3):
258+
test_nodes.append(TestNode())
259+
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test_nodes[i]))
260+
test_nodes[i].add_connection(connections[i])
261+
262+
NetworkThread().start() # Start up network handling in another thread
263+
[x.wait_for_verack() for x in test_nodes]
264+
265+
#retrieve 20 blocks which should be enough to break the 1MB limit
266+
getdata_request.inv = [CInv(2, big_new_block)]
267+
for i in xrange(20):
268+
test_nodes[1].send_message(getdata_request)
269+
test_nodes[1].sync_with_ping()
270+
assert_equal(test_nodes[1].block_receive_map[big_new_block], i+1)
271+
272+
getdata_request.inv = [CInv(2, big_old_block)]
273+
test_nodes[1].send_message(getdata_request)
274+
test_nodes[1].wait_for_disconnect()
275+
assert_equal(len(self.nodes[0].getpeerinfo()), 3) #node is still connected because of the whitelist
276+
277+
print "Peer 1 still connected after trying to download old block (whitelisted)"
278+
279+
[c.disconnect_node() for c in connections]
280+
248281
if __name__ == '__main__':
249282
MaxUploadTest().main()

src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3867,8 +3867,9 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
38673867
}
38683868
}
38693869
// disconnect node in case we have reached the outbound limit for serving historical blocks
3870+
// never disconnect whitelisted nodes
38703871
static const int nOneWeek = 7 * 24 * 60 * 60; // assume > 1 week = historical
3871-
if (send && CNode::OutboundTargetReached(true) && ( ((pindexBestHeader != NULL) && (pindexBestHeader->GetBlockTime() - mi->second->GetBlockTime() > nOneWeek)) || inv.type == MSG_FILTERED_BLOCK) )
3872+
if (send && CNode::OutboundTargetReached(true) && ( ((pindexBestHeader != NULL) && (pindexBestHeader->GetBlockTime() - mi->second->GetBlockTime() > nOneWeek)) || inv.type == MSG_FILTERED_BLOCK) && !pfrom->fWhitelisted)
38723873
{
38733874
LogPrint("net", "historical block serving limit reached, disconnect peer=%d\n", pfrom->GetId());
38743875

0 commit comments

Comments
 (0)