mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-09 09:51:08 +02:00
Merge bitcoin/bitcoin#24168: Fix some race conditions in BanMan::DumpBanlist()
99a6b699cd
Fix race condition for SetBannedSetDirty() calls (Hennadii Stepanov)83c7646715
Avoid calling BanMan::SweepBanned() twice in a row (Hennadii Stepanov)33bda6ab87
Fix data race condition in BanMan::DumpBanlist() (Hennadii Stepanov)5e20e9ec38
Prevent possible concurrent CBanDB::Write() calls (Hennadii Stepanov) Pull request description: This PR split from bitcoin/bitcoin#24097 with some additions. This makes the following switch from `RecursiveMutex` to `Mutex` a pure refactoring. See details in commit messages. ACKs for top commit: w0xlt: reACK99a6b69
shaavan: ACK99a6b699cd
Tree-SHA512: da4e7268c7bd3424491f446145f18af4ccfc804023d0a7fe70e1462baab550a5e44f9159f8b9f9c7820d2c6cb6447b63883616199e4d9d439ab9ab1b67c7201b
This commit is contained in:
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
#include <node/ui_interface.h>
|
#include <node/ui_interface.h>
|
||||||
|
#include <sync.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
@ -39,18 +40,23 @@ BanMan::~BanMan()
|
|||||||
|
|
||||||
void BanMan::DumpBanlist()
|
void BanMan::DumpBanlist()
|
||||||
{
|
{
|
||||||
SweepBanned(); // clean unused entries (if bantime has expired)
|
static Mutex dump_mutex;
|
||||||
|
LOCK(dump_mutex);
|
||||||
if (!BannedSetIsDirty()) return;
|
|
||||||
|
|
||||||
int64_t n_start = GetTimeMillis();
|
|
||||||
|
|
||||||
banmap_t banmap;
|
banmap_t banmap;
|
||||||
GetBanned(banmap);
|
{
|
||||||
if (m_ban_db.Write(banmap)) {
|
LOCK(m_cs_banned);
|
||||||
|
SweepBanned();
|
||||||
|
if (!BannedSetIsDirty()) return;
|
||||||
|
banmap = m_banned;
|
||||||
SetBannedSetDirty(false);
|
SetBannedSetDirty(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t n_start = GetTimeMillis();
|
||||||
|
if (!m_ban_db.Write(banmap)) {
|
||||||
|
SetBannedSetDirty(true);
|
||||||
|
}
|
||||||
|
|
||||||
LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
|
LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
|
||||||
GetTimeMillis() - n_start);
|
GetTimeMillis() - n_start);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user