Skip to content

Commit 9ffc687

Browse files
committed
Merge pull request #6984
e495ed5 add documentation for exluding whitelistes peer from maxuploadtarget (Jonas Schnelli) 5760749 [docs] rename reducetraffic.md to reduce-traffic.md (Jonas Schnelli) d61fcff don't enforce maxuploadtargets disconnect for whitelisted peers (Jonas Schnelli)
2 parents 44ac42e + e495ed5 commit 9ffc687

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

doc/reducetraffic.md renamed to doc/reduce-traffic.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Reduce Traffic
22
==============
33

4-
Some node operators need to deal with bandwith caps imposed by their ISPs.
4+
Some node operators need to deal with bandwidth caps imposed by their ISPs.
55

66
By default, bitcoin-core allows up to 125 connections to different peers, 8 of
77
which are outbound. You can therefore, have at most 117 inbound connections.
@@ -22,6 +22,9 @@ Keep in mind that new nodes require other nodes that are willing to serve
2222
historic blocks. **The recommended minimum is 144 blocks per day (max. 144MB
2323
per day)**
2424

25+
Whitelisted peers will never be disconnected, although their traffic counts for
26+
calculating the target.
27+
2528
## 2. Disable "listening" (`-listen=0`)
2629

2730
Disabling listening will result in fewer nodes connected (remember the maximum of 8
@@ -30,6 +33,6 @@ blocks and transactions to fewer nodes.
3033

3134
## 3. Reduce maximum connections (`-maxconnections=<num>`)
3235

33-
Reducing the maximum connected nodes to a miniumum could be desirable if traffic
36+
Reducing the maximum connected nodes to a minimum could be desirable if traffic
3437
limits are tiny. Keep in mind that bitcoin's trustless model works best if you are
3538
connected to a handful of nodes.

doc/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ This option can be specified in MiB per day and is turned off by default
184184
(`-maxuploadtarget=0`).
185185
The recommended minimum is 144 * MAX_BLOCK_SIZE (currently 144MB) per day.
186186

187+
Whitelisted peers will never be disconnected, although their traffic counts for
188+
calculating the target.
189+
187190
A more detailed documentation about keeping traffic low can be found in
188191
[/doc/reducetraffic.md](/doc/reducetraffic.md).
189192

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)