From d8ebc0d4fcd32f6735878d783f6829607934a80e Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 27 Apr 2016 09:26:33 -0700 Subject: [PATCH] fix race that could fail to persist a ban --- src/net.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 57c241865..7fa8fe525 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2604,17 +2604,22 @@ bool CBanDB::Read(banmap_t& banSet) void DumpBanlist() { - int64_t nStart = GetTimeMillis(); + CNode::SweepBanned(); // clean unused entries (if bantime has expired) - CNode::SweepBanned(); //clean unused entries (if bantime has expired) + if (!CNode::BannedSetIsDirty()) + return; + + int64_t nStart = GetTimeMillis(); CBanDB bandb; banmap_t banmap; + CNode::SetBannedSetDirty(false); CNode::GetBanned(banmap); - bandb.Write(banmap); + if (!bandb.Write(banmap)) + CNode::SetBannedSetDirty(true); LogPrint("net", "Flushed %d banned node ips/subnets to banlist.dat %dms\n", - banmap.size(), GetTimeMillis() - nStart); + banmap.size(), GetTimeMillis() - nStart); } int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {