[net] listbanned RPC and QT should show correct banned subnets #10234

Merged
merged 2 commits into from May 2, 2017

Conversation

Projects
None yet
6 participants
Member

jnewbery commented Apr 19, 2017

The listbanned RPC and QT show entries in the connman.setBanned set, even if the entry has expired. Expired entries in the set are only swept in the following circumstances:

  • bitcoind is stopped/started
  • the setban or clearbanned RPC is called

That means that the list of banned subnets returned by listbanned is inconsistent. If the node has been stop-started or the setban/clearbanned RPC has been called, then stale entries won't be shown. If the node hasn't been stop-started and those RPCs haven't been called, then stale entries will be shown.

This PR calls SweepBanned() before GetBanned() in the listbanned RPC and QT, so all calls to GetBanned() return an up-to-date list of banned subnets.

This PR also adds a test to nodehandling to test the behaviour.

@jonasschnelli @sdaftuar

Member

theuni commented Apr 19, 2017

Nice find. Though I can't think of a good reason why we'd ever want a stale list coming out of GetBanned(). Why not just sweep there?

Member

jonasschnelli commented Apr 19, 2017

utACK ea2c925
Calling sweep from within GetBanned() looks simpler in the first place but would break the assumption that GetBanned() can never change the setBannedIsDirty to true.
No strong opinion though.

Member

jnewbery commented Apr 19, 2017

Calling sweep from within GetBanned() looks simpler in the first place but would break the assumption that GetBanned() can never change the setBannedIsDirty to true.

Right. CConnman::DumpBanlist() sets SetBannedSetDirty and then calls GetBanned() (I believe making the assumption that GetBanned() wouldn't change SetBannedSetDirty). I didn't know whether it was safe to change that.

If you think that's ok, then calling sweep from with GetBanned() is obviously tidier, and means I don't need to make SweepBanned() public.

fanquake added the P2P label Apr 19, 2017

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Apr 21, 2017

@jnewbery @luke-jr jnewbery + luke-jr [net] listbanned RPC and QT should show correct banned subnets
Github-Pull: #10234
Rebased-From: d711a38
266df5f

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Apr 21, 2017

@jnewbery @luke-jr jnewbery + luke-jr [tests] add test for listbanned only showing currently banned subnets
Github-Pull: #10234
Rebased-From: ea2c925
f52e925
Member

MarcoFalke commented Apr 23, 2017

Needs rebase

Owner

laanwj commented Apr 25, 2017

Discussion on IRC: the disconnect_ban.py test is slow until this is merged, due to https://github.com/bitcoin/bitcoin/blob/master/test/functional/disconnect_ban.py#L67

Member

jnewbery commented Apr 25, 2017

rebased with fix to disconnect_ban.py test suite.

Member

theuni commented Apr 25, 2017

@jnewbery Yea, I'd prefer to see this moved to GetBanned(). Otherwise correct usage just isn't obvious enough (as evidenced by this bug).

Ideally the sweep would be a static function operating on a banlist_t rather than this, but I don't think it's worth worrying about.

Looks like the only other change needed would be:

@@ -496,10 +499,9 @@ void CConnman::DumpBanlist()
 
     CBanDB bandb;
     banmap_t banmap;
-    SetBannedSetDirty(false);
     GetBanned(banmap);
-    if (!bandb.Write(banmap))
-        SetBannedSetDirty(true);
+    if (bandb.Write(banmap))
+        SetBannedSetDirty(false);

Note that this code is pretty racy either way. We should fix that as a follow-up.

Member

jnewbery commented Apr 28, 2017

thanks @theuni - that's definitely cleaner. I've changed this PR to use your fix.

Owner

laanwj commented May 1, 2017 edited

It fails locally here (every time, not just intermittently):

disconnect_ban.py failed, Duration: 26 s

stdout:
2017-05-01 08:21:38.048000 TestFramework (INFO): Initializing test directory /tmp/testh_zvdgd7/435
2017-05-01 08:21:39.087000 TestFramework (INFO): Test setban and listbanned RPCs
2017-05-01 08:21:39.087000 TestFramework (INFO): setban: successfully ban single IP address
2017-05-01 08:21:39.148000 TestFramework (INFO): clearbanned: successfully clear ban list
2017-05-01 08:21:39.179000 TestFramework (INFO): setban: fail to ban an already banned subnet
2017-05-01 08:21:39.184000 TestFramework (INFO): setban: fail to ban an invalid subnet
2017-05-01 08:21:39.189000 TestFramework (INFO): setban remove: fail to unban a non-banned subnet
2017-05-01 08:21:39.194000 TestFramework (INFO): setban remove: successfully unban subnet
2017-05-01 08:21:39.243000 TestFramework (INFO): setban: test persistence across node restart
2017-05-01 08:21:49.801000 TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/store/orion/projects/bitcoin/bitcoin/test/functional/test_framework/test_framework.py", line 151, in main
    self.run_test()
  File "/home/orion/projects/bitcoin/bitcoin/test/functional/disconnect_ban.py", line 67, in run_test
    assert wait_until(lambda: len(self.nodes[1].listbanned()) == 3, timeout=10)
AssertionError
2017-05-01 08:21:49.819000 TestFramework (INFO): Stopping nodes
2017-05-01 08:22:04.002000 TestFramework (WARNING): Not cleaning up dir /tmp/testh_zvdgd7/435
2017-05-01 08:22:04.003000 TestFramework (ERROR): Test failed. Test logging available at /tmp/testh_zvdgd7/435/test_
framework.log
Member

jnewbery commented May 1, 2017

@laanwj that's very strange. The test passes for me consistently, and also passes on travis. Can you try rebuilding and clearing the functional test cache. If it's still failing, can you send me the test logs?

Owner

laanwj commented May 2, 2017

Seems to work now. Strange.

@laanwj laanwj merged commit d6732d8 into bitcoin:master May 2, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@laanwj laanwj added a commit that referenced this pull request May 2, 2017

@laanwj laanwj 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
faf2dea

jnewbery deleted the jnewbery:list_banned_correctly branch May 2, 2017

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 3, 2017

@jnewbery @luke-jr jnewbery + luke-jr [tests] update disconnect_ban.py test case to work with listbanned
Github-Pull: #10234
Rebased-From: d6732d8
2d4c2cf

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 3, 2017

@jnewbery @luke-jr jnewbery + luke-jr [tests] update disconnect_ban.py test case to work with listbanned
Github-Pull: #10234
Rebased-From: d6732d8
322e904

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@jnewbery @luke-jr jnewbery + luke-jr [net] listbanned RPC and QT should show correct banned subnets
Github-Pull: #10234
Rebased-From: 77c54b2
2f2e8d7

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@jnewbery @luke-jr jnewbery + luke-jr [tests] update disconnect_ban.py test case to work with listbanned
Github-Pull: #10234
Rebased-From: d6732d8
fff3d6f

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@jnewbery @luke-jr jnewbery + luke-jr [net] listbanned RPC and QT should show correct banned subnets
Github-Pull: #10234
Rebased-From: 77c54b2
7033da5

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@jnewbery @luke-jr jnewbery + luke-jr [tests] update disconnect_ban.py test case to work with listbanned
Github-Pull: #10234
Rebased-From: d6732d8
963176b

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@luke-jr luke-jr Merge #10234, #10143 (fixes only), and #9853 via branch 'disconnect_b…
…an_fixes-0.14' into 0.14.2_fixes
2873484

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@jnewbery @luke-jr jnewbery + luke-jr [net] listbanned RPC and QT should show correct banned subnets
Github-Pull: #10234
Rebased-From: 77c54b2
d289b56

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@jnewbery @luke-jr jnewbery + luke-jr [tests] update disconnect_ban.py test case to work with listbanned
Github-Pull: #10234
Rebased-From: d6732d8
ee1a60d

@luke-jr luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jun 5, 2017

@luke-jr luke-jr Merge #10234, #10143 (fixes only), and #9853 via branch 'disconnect_b…
…an_fixes-0.14' into 0.14.2_fixes
e05799a

@nomnombtc nomnombtc added a commit to nomnombtc/bitcoin that referenced this pull request Jul 17, 2017

@jnewbery @nomnombtc jnewbery + nomnombtc [net] listbanned RPC and QT should show correct banned subnets
Github-Pull: #10234
Rebased-From: 77c54b2
d5bd983

@nomnombtc nomnombtc added a commit to nomnombtc/bitcoin that referenced this pull request Jul 17, 2017

@jnewbery @nomnombtc jnewbery + nomnombtc [tests] update disconnect_ban.py test case to work with listbanned
Github-Pull: #10234
Rebased-From: d6732d8
c8b124d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment