Skip to content

Commit faf2dea

Browse files
committed
Merge #10234: [net] listbanned RPC and QT should show correct banned subnets
d6732d8 [tests] update disconnect_ban.py test case to work with listbanned (John Newbery) 77c54b2 [net] listbanned RPC and QT should show correct banned subnets (John Newbery) Tree-SHA512: edd0e43377d456260d2697213c2829f8483630f3a668b6707d52605faefa610d951d10e6f22a95eff483cbd14faa8ac9b69fa7d3c0b5735c5f3df23fd71282e0
2 parents a3e756b + d6732d8 commit faf2dea

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/net.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ void CConnman::DumpBanlist()
418418

419419
CBanDB bandb;
420420
banmap_t banmap;
421-
SetBannedSetDirty(false);
422421
GetBanned(banmap);
423-
if (!bandb.Write(banmap))
424-
SetBannedSetDirty(true);
422+
if (bandb.Write(banmap)) {
423+
SetBannedSetDirty(false);
424+
}
425425

426426
LogPrint(BCLog::NET, "Flushed %d banned node ips/subnets to banlist.dat %dms\n",
427427
banmap.size(), GetTimeMillis() - nStart);
@@ -541,6 +541,8 @@ bool CConnman::Unban(const CSubNet &subNet) {
541541
void CConnman::GetBanned(banmap_t &banMap)
542542
{
543543
LOCK(cs_setBanned);
544+
// Sweep the banlist so expired bans are not returned
545+
SweepBanned();
544546
banMap = setBanned; //create a thread safe copy
545547
}
546548

test/functional/disconnect_ban.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def run_test(self):
3030
self.log.info("setban: successfully ban single IP address")
3131
assert_equal(len(self.nodes[1].getpeerinfo()), 2) # node1 should have 2 connections to node0 at this point
3232
self.nodes[1].setban("127.0.0.1", "add")
33-
wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 0)
33+
assert wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 0, timeout=10)
3434
assert_equal(len(self.nodes[1].getpeerinfo()), 0) # all nodes must be disconnected at this point
3535
assert_equal(len(self.nodes[1].listbanned()), 1)
3636

@@ -64,7 +64,7 @@ def run_test(self):
6464
self.nodes[1].setban("2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/19", "add", 1000) # ban for 1000 seconds
6565
listBeforeShutdown = self.nodes[1].listbanned()
6666
assert_equal("192.168.0.1/32", listBeforeShutdown[2]['address'])
67-
wait_until(lambda: len(self.nodes[1].listbanned()) == 3)
67+
assert wait_until(lambda: len(self.nodes[1].listbanned()) == 3, timeout=10)
6868

6969
stop_node(self.nodes[1], 1)
7070

@@ -78,7 +78,7 @@ def run_test(self):
7878
self.nodes[1].clearbanned()
7979
connect_nodes_bi(self.nodes, 0, 1)
8080

81-
self.log.info("Test disconnectrnode RPCs")
81+
self.log.info("Test disconnectnode RPCs")
8282

8383
self.log.info("disconnectnode: fail to disconnect when calling with address and nodeid")
8484
address1 = self.nodes[0].getpeerinfo()[0]['addr']
@@ -91,7 +91,7 @@ def run_test(self):
9191
self.log.info("disconnectnode: successfully disconnect node by address")
9292
address1 = self.nodes[0].getpeerinfo()[0]['addr']
9393
self.nodes[0].disconnectnode(address=address1)
94-
wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1)
94+
assert wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1, timeout=10)
9595
assert not [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
9696

9797
self.log.info("disconnectnode: successfully reconnect node")
@@ -102,7 +102,7 @@ def run_test(self):
102102
self.log.info("disconnectnode: successfully disconnect node by node id")
103103
id1 = self.nodes[0].getpeerinfo()[0]['id']
104104
self.nodes[0].disconnectnode(nodeid=id1)
105-
wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1)
105+
assert wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1, timeout=10)
106106
assert not [node for node in self.nodes[0].getpeerinfo() if node['id'] == id1]
107107

108108
if __name__ == '__main__':

0 commit comments

Comments
 (0)