Skip to content

banlist: log post-swept banlist size at startup - #19470

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
fanquake:log_post_sweep_banlist_size
Jul 9, 2020
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
fanquake:log_post_sweep_banlist_size

Conversation

@fanquake

@fanquake fanquake commented Jul 8, 2020

Copy link
Copy Markdown
Member

We are currently logging the size of the banlist from before SweepBanned() has been called, meaning the value may be incorrect.

i.e banlist.dat had 1ban. That ban is swept on startup. We log "loaded 1 banned node..". Actual banlist size is 0.

We are currently logging the size of the banlist before SweepBanned()
has been called, meaning the value may be incorrect.
@laanwj

laanwj commented Jul 8, 2020

Copy link
Copy Markdown
Member

Code review ACK 0b8ba84

@jnewbery

jnewbery commented Jul 9, 2020 •

Copy link
Copy Markdown
Contributor

Code review ACK 0b8ba84

Now that the local banmap isn't being used after SetBanned(), we could change SetBanned() to take an rvalue reference and do a move, rather than the expensive copy. (not in this PR)

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 0b8ba84 m_banned is set in SetBanned and is updated by SweepBanned before the logging.

In a couple of manual checks, both master and this branch logged the correct number with 0 and 1 banned peers using setban/clearbanned, so I didn't hit the timing to produce a wrong count.

Comment thread src/banman.cpp
@@ -26,7 +26,7 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t
SweepBanned(); // sweep out unused entries

LogPrint(BCLog::NET, "Loaded %d banned node ips/subnets from banlist.dat %dms\n",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I would find this logging handy as a regular debug log LogPrintf, like the other ones in this function.

@fanquake

fanquake commented Jul 9, 2020

Copy link
Copy Markdown
Member Author

In a couple of manual checks, both master and this branch logged the correct number with 0 and 1 banned peers using setban/clearbanned, so I didn't hit the timing to produce a wrong count.

You can observe the issue on master by just setting a short ban, and restarting bitcoind. i.e:

src/bitcoind -regtest

# set a short-lived ban
src/bitcoin-cli -regtest setban "2001:4d48:ac57:400:cacf:e9ff:fe1d:1" "add" "10"

#  shutdown bitcoind, wait 11 seconds, restart bitcoind
....
2020-07-09T12:06:54.944698Z [init] SweepBanned: Removed banned node ip/subnet from banlist.dat: 2001:4d48:ac57:400:cacf:e9ff:fe1d:1/128
2020-07-09T12:06:54.944731Z [init] Loaded 1 banned node ips/subnets from banlist.dat  0ms

The loaded count is logged as 1 when it should be 0.

@jonatack

jonatack commented Jul 9, 2020

Copy link
Copy Markdown
Member

Ok, reproduced on mainnet. I wasn't shutting down bitcoind fast enough before it expired.

@fanquake
fanquake merged commit e3b3125 into bitcoin:master Jul 9, 2020
@fanquake
fanquake deleted the log_post_sweep_banlist_size branch July 9, 2020 12:32
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 26, 2021
Summary:
We are currently logging the size of the banlist before SweepBanned()
has been called, meaning the value may be incorrect.

This is a backport of [[bitcoin/bitcoin#19470 | core#19470]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9583
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 19, 2021
0b8ba84 banlist: log post-swept banlist size at startup (fanquake)

Pull request description:

  We are currently logging the size of the banlist from before `SweepBanned()` has been called, meaning the value may be incorrect.

  i.e banlist.dat had `1`ban. That ban is swept on startup. We log "loaded 1 banned node..". Actual banlist size is `0`.

ACKs for top commit:
  jonatack:
    Code review ACK 0b8ba84 `m_banned` is set in SetBanned and is updated by SweepBanned before the logging.
  laanwj:
    Code review ACK 0b8ba84
  jnewbery:
    Code review ACK 0b8ba84

Tree-SHA512: 1d6e363d6c68d7cc214dd685df3d2d27572f6a58a4c0e43c03cfbb03bc01badb6a10ecae403d137094bb316d27f33feb6be15b4e23ef1e9496cd0b3c23c21698
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants