Merge bitcoin/bitcoin#20966: banman: save the banlist in a JSON format on disk

bb719a08db style: remove () from assert in rpc_setban.py (Vasil Dimov)
24b10ebda3 doc: fix grammar in doc/files.md (Vasil Dimov)
dd4e957dcd test: ensure banlist can be read from disk after restart (Vasil Dimov)
d197977ae2 banman: save the banlist in a JSON format on disk (Vasil Dimov)

Pull request description:

  Save the banlist in `banlist.json` instead of `banlist.dat`.

  This makes it possible to store Tor v3 entries in the banlist on disk
  (and any other addresses that cannot be serialized in addrv1 format).

  Only read `banlist.dat` if it exists and `banlist.json` does not exist (first start after an upgrade).

  Supersedes https://github.com/bitcoin/bitcoin/pull/20904
  Resolves https://github.com/bitcoin/bitcoin/issues/19748

ACKs for top commit:
  jonatack:
    Code review re-ACK bb719a08db per `git range-diff 6a67366 4b52c72 bb719a0`
  achow101:
    Code Review ACK bb719a08db

Tree-SHA512: fc135c3a1fe20bcf5d008ce6bea251b4135e56c78bf8f750b4bd8144c095b81ffe165133cdc7e4715875eec7e7c4e13ad9f5d2450b21102af063d7c8abf716b6
This commit is contained in:
MarcoFalke
2021-06-23 10:01:50 +02:00
10 changed files with 193 additions and 49 deletions

View File

@@ -22,7 +22,7 @@ class SetBanTests(BitcoinTestFramework):
# Node 0 connects to Node 1, check that the noban permission is not granted
self.connect_nodes(0, 1)
peerinfo = self.nodes[1].getpeerinfo()[0]
assert(not 'noban' in peerinfo['permissions'])
assert not "noban" in peerinfo["permissions"]
# Node 0 get banned by Node 1
self.nodes[1].setban("127.0.0.1", "add")
@@ -36,27 +36,40 @@ class SetBanTests(BitcoinTestFramework):
self.restart_node(1, ['-whitelist=127.0.0.1'])
self.connect_nodes(0, 1)
peerinfo = self.nodes[1].getpeerinfo()[0]
assert('noban' in peerinfo['permissions'])
assert "noban" in peerinfo["permissions"]
# If we remove the ban, Node 0 should be able to reconnect even without noban permission
self.nodes[1].setban("127.0.0.1", "remove")
self.restart_node(1, [])
self.connect_nodes(0, 1)
peerinfo = self.nodes[1].getpeerinfo()[0]
assert(not 'noban' in peerinfo['permissions'])
assert not "noban" in peerinfo["permissions"]
self.log.info("Test that a non-IP address can be banned/unbanned")
node = self.nodes[1]
tor_addr = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"
ip_addr = "1.2.3.4"
assert(not self.is_banned(node, tor_addr))
assert(not self.is_banned(node, ip_addr))
assert not self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)
node.setban(tor_addr, "add")
assert(self.is_banned(node, tor_addr))
assert(not self.is_banned(node, ip_addr))
assert self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)
self.log.info("Test the ban list is preserved through restart")
self.restart_node(1)
assert self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)
node.setban(tor_addr, "remove")
assert(not self.is_banned(self.nodes[1], tor_addr))
assert(not self.is_banned(node, ip_addr))
assert not self.is_banned(self.nodes[1], tor_addr)
assert not self.is_banned(node, ip_addr)
self.restart_node(1)
assert not self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)
if __name__ == '__main__':
SetBanTests().main()