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

pull jnewbery wants to merge 2 commits into bitcoin:master from jnewbery:list_banned_correctly changing 2 files +10 −8
  1. jnewbery commented at 4:59 PM on April 19, 2017: member

    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

  2. theuni commented at 5:07 PM on April 19, 2017: member

    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?

  3. jonasschnelli commented at 5:12 PM on April 19, 2017: contributor

    utACK ea2c925c99969d06320495afbf1188f54e25e015 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.

  4. jnewbery commented at 5:25 PM on April 19, 2017: member

    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.

  5. fanquake added the label P2P on Apr 19, 2017
  6. luke-jr referenced this in commit 266df5ffab on Apr 21, 2017
  7. luke-jr referenced this in commit f52e9257af on Apr 21, 2017
  8. MarcoFalke commented at 3:22 PM on April 23, 2017: member

    Needs rebase

  9. laanwj commented at 1:49 PM on April 25, 2017: member

    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

  10. jnewbery force-pushed on Apr 25, 2017
  11. jnewbery commented at 2:12 PM on April 25, 2017: member

    rebased with fix to disconnect_ban.py test suite.

  12. theuni commented at 2:48 PM on April 25, 2017: member

    @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.

  13. [net] listbanned RPC and QT should show correct banned subnets 77c54b270d
  14. [tests] update disconnect_ban.py test case to work with listbanned d6732d832a
  15. jnewbery force-pushed on Apr 28, 2017
  16. jnewbery commented at 3:25 PM on April 28, 2017: member

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

  17. laanwj commented at 10:28 AM on May 1, 2017: member

    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
    
  18. jnewbery commented at 5:48 PM on May 1, 2017: member

    @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?

  19. laanwj commented at 4:35 PM on May 2, 2017: member

    Seems to work now. Strange.

  20. laanwj merged this on May 2, 2017
  21. laanwj closed this on May 2, 2017

  22. laanwj referenced this in commit faf2dea5ea on May 2, 2017
  23. jnewbery deleted the branch on May 2, 2017
  24. luke-jr referenced this in commit 2d4c2cf1e8 on Jun 3, 2017
  25. luke-jr referenced this in commit 322e904b88 on Jun 3, 2017
  26. luke-jr referenced this in commit 2f2e8d7af0 on Jun 5, 2017
  27. luke-jr referenced this in commit fff3d6fbaf on Jun 5, 2017
  28. luke-jr referenced this in commit 7033da5fbe on Jun 5, 2017
  29. luke-jr referenced this in commit 963176b3d9 on Jun 5, 2017
  30. luke-jr referenced this in commit 28734848dd on Jun 5, 2017
  31. luke-jr referenced this in commit d289b564e3 on Jun 5, 2017
  32. luke-jr referenced this in commit ee1a60d156 on Jun 5, 2017
  33. luke-jr referenced this in commit e05799a381 on Jun 5, 2017
  34. nomnombtc referenced this in commit d5bd983289 on Jul 17, 2017
  35. nomnombtc referenced this in commit c8b124d782 on Jul 17, 2017
  36. PastaPastaPasta referenced this in commit 3987f162ea on Jun 10, 2019
  37. PastaPastaPasta referenced this in commit ed949c289a on Jun 10, 2019
  38. PastaPastaPasta referenced this in commit e95b4f794f on Jun 10, 2019
  39. PastaPastaPasta referenced this in commit a9b50b7a01 on Jun 10, 2019
  40. PastaPastaPasta referenced this in commit bdd55a3aff on Jun 10, 2019
  41. PastaPastaPasta referenced this in commit 7e79fa9087 on Jun 11, 2019
  42. PastaPastaPasta referenced this in commit 3bf8c0f845 on Jun 11, 2019
  43. PastaPastaPasta referenced this in commit eb65b08e80 on Jun 12, 2019
  44. PastaPastaPasta referenced this in commit 7a9030db00 on Jun 14, 2019
  45. PastaPastaPasta referenced this in commit 0ffa1e41ac on Jun 14, 2019
  46. PastaPastaPasta referenced this in commit c1b7b65616 on Jun 14, 2019
  47. PastaPastaPasta referenced this in commit 146cae9569 on Jun 14, 2019
  48. PastaPastaPasta referenced this in commit e526914103 on Jun 15, 2019
  49. PastaPastaPasta referenced this in commit 4712fe491f on Jun 19, 2019
  50. barrystyle referenced this in commit 7f27855c86 on Jan 22, 2020
  51. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-30 12:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me