aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.clang-format1
-rw-r--r--src/banman.cpp2
-rw-r--r--src/net.cpp9
-rw-r--r--src/net.h14
-rw-r--r--src/net_processing.cpp9
-rw-r--r--src/qt/bitcoingui.cpp1
-rw-r--r--src/wallet/bdb.cpp70
-rw-r--r--src/wallet/bdb.h39
8 files changed, 50 insertions, 95 deletions
diff --git a/src/.clang-format b/src/.clang-format
index a8f8565f80..ef7a0ef5c7 100644
--- a/src/.clang-format
+++ b/src/.clang-format
@@ -3,7 +3,6 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
-AllowAllArgumentsOnNextLine : true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
diff --git a/src/banman.cpp b/src/banman.cpp
index 2fabacda0e..8752185a60 100644
--- a/src/banman.cpp
+++ b/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",
- banmap.size(), GetTimeMillis() - n_start);
+ m_banned.size(), GetTimeMillis() - n_start);
} else {
LogPrintf("Invalid or missing banlist.dat; recreating\n");
SetBannedSetDirty(true); // force write
diff --git a/src/net.cpp b/src/net.cpp
index 0233b0fc2f..21d340b516 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1110,12 +1110,9 @@ void CConnman::DisconnectNodes()
if (pnode->GetRefCount() <= 0) {
bool fDelete = false;
{
- TRY_LOCK(pnode->cs_inventory, lockInv);
- if (lockInv) {
- TRY_LOCK(pnode->cs_vSend, lockSend);
- if (lockSend) {
- fDelete = true;
- }
+ TRY_LOCK(pnode->cs_vSend, lockSend);
+ if (lockSend) {
+ fDelete = true;
}
}
if (fDelete) {
diff --git a/src/net.h b/src/net.h
index b461470f1f..3c23763954 100644
--- a/src/net.h
+++ b/src/net.h
@@ -803,7 +803,7 @@ public:
// There is no final sorting before sending, as they are always sent immediately
// and in the order requested.
std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory);
- RecursiveMutex cs_inventory;
+ Mutex cs_inventory;
struct TxRelay {
mutable RecursiveMutex cs_filter;
@@ -982,18 +982,6 @@ public:
}
}
- void PushBlockInventory(const uint256& hash)
- {
- LOCK(cs_inventory);
- vInventoryBlockToSend.push_back(hash);
- }
-
- void PushBlockHash(const uint256 &hash)
- {
- LOCK(cs_inventory);
- vBlockHashesToAnnounce.push_back(hash);
- }
-
void CloseSocketDisconnect();
void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index d0c3c943fc..f1a89a8936 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1325,9 +1325,10 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
}
// Relay inventory, but don't relay old inventory during initial block download.
connman->ForEachNode([nNewHeight, &vHashes](CNode* pnode) {
+ LOCK(pnode->cs_inventory);
if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) {
for (const uint256& hash : reverse_iterate(vHashes)) {
- pnode->PushBlockHash(hash);
+ pnode->vBlockHashesToAnnounce.push_back(hash);
}
}
});
@@ -1604,7 +1605,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
// Trigger the peer node to send a getblocks request for the next batch of inventory
if (inv.hash == pfrom.hashContinue)
{
- // Bypass PushBlockInventory, this must send even if redundant,
+ // Send immediately. This must send even if redundant,
// and we want it right after the last block so they don't
// wait for other stuff first.
std::vector<CInv> vInv;
@@ -2664,7 +2665,7 @@ void ProcessMessage(
LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
break;
}
- pfrom.PushBlockInventory(pindex->GetBlockHash());
+ WITH_LOCK(pfrom.cs_inventory, pfrom.vInventoryBlockToSend.push_back(pindex->GetBlockHash()));
if (--nLimit <= 0)
{
// When this block is requested, we'll send an inv that'll
@@ -4082,7 +4083,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
// If the peer's chain has this block, don't inv it back.
if (!PeerHasHeader(&state, pindex)) {
- pto->PushBlockInventory(hashToAnnounce);
+ pto->vInventoryBlockToSend.push_back(hashToAnnounce);
LogPrint(BCLog::NET, "%s: sending inv peer=%d hash=%s\n", __func__,
pto->GetId(), hashToAnnounce.ToString());
}
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 3c5e8d0d07..65f226a925 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -683,6 +683,7 @@ void BitcoinGUI::removeWallet(WalletModel* walletModel)
m_wallet_selector->removeItem(index);
if (m_wallet_selector->count() == 0) {
setWalletActionsEnabled(false);
+ overviewAction->setChecked(true);
} else if (m_wallet_selector->count() == 1) {
m_wallet_selector_label_action->setVisible(false);
m_wallet_selector_action->setVisible(false);
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp
index 6ac8340a31..5f823d5906 100644
--- a/src/wallet/bdb.cpp
+++ b/src/wallet/bdb.cpp
@@ -615,42 +615,33 @@ void BerkeleyEnvironment::Flush(bool fShutdown)
bool BerkeleyDatabase::PeriodicFlush()
{
- if (IsDummy()) {
- return true;
- }
- bool ret = false;
+ // There's nothing to do for dummy databases. Return true.
+ if (IsDummy()) return true;
+
+ // Don't flush if we can't acquire the lock.
TRY_LOCK(cs_db, lockDb);
- if (lockDb)
- {
- // Don't do this if any databases are in use
- int nRefCount = 0;
- std::map<std::string, int>::iterator mit = env->mapFileUseCount.begin();
- while (mit != env->mapFileUseCount.end())
- {
- nRefCount += (*mit).second;
- mit++;
- }
+ if (!lockDb) return false;
- if (nRefCount == 0)
- {
- std::map<std::string, int>::iterator mi = env->mapFileUseCount.find(strFile);
- if (mi != env->mapFileUseCount.end())
- {
- LogPrint(BCLog::WALLETDB, "Flushing %s\n", strFile);
- int64_t nStart = GetTimeMillis();
+ // Don't flush if any databases are in use
+ for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); it++) {
+ if ((*it).second > 0) return false;
+ }
- // Flush wallet file so it's self contained
- env->CloseDb(strFile);
- env->CheckpointLSN(strFile);
+ // Don't flush if there haven't been any batch writes for this database.
+ auto it = env->mapFileUseCount.find(strFile);
+ if (it == env->mapFileUseCount.end()) return false;
- env->mapFileUseCount.erase(mi++);
- LogPrint(BCLog::WALLETDB, "Flushed %s %dms\n", strFile, GetTimeMillis() - nStart);
- ret = true;
- }
- }
- }
+ LogPrint(BCLog::WALLETDB, "Flushing %s\n", strFile);
+ int64_t nStart = GetTimeMillis();
+
+ // Flush wallet file so it's self contained
+ env->CloseDb(strFile);
+ env->CheckpointLSN(strFile);
+ env->mapFileUseCount.erase(it);
- return ret;
+ LogPrint(BCLog::WALLETDB, "Flushed %s %dms\n", strFile, GetTimeMillis() - nStart);
+
+ return true;
}
bool BerkeleyDatabase::Backup(const std::string& strDest) const
@@ -796,15 +787,13 @@ std::string BerkeleyDatabaseVersion()
return DbEnv::version(nullptr, nullptr, nullptr);
}
-bool BerkeleyBatch::ReadKey(CDataStream& key, CDataStream& value)
+bool BerkeleyBatch::ReadKey(CDataStream&& key, CDataStream& value)
{
if (!pdb)
return false;
- // Key
SafeDbt datKey(key.data(), key.size());
- // Read
SafeDbt datValue;
int ret = pdb->get(activeTxn, datKey, datValue, 0);
if (ret == 0 && datValue.get_data() != nullptr) {
@@ -814,48 +803,41 @@ bool BerkeleyBatch::ReadKey(CDataStream& key, CDataStream& value)
return false;
}
-bool BerkeleyBatch::WriteKey(CDataStream& key, CDataStream& value, bool overwrite)
+bool BerkeleyBatch::WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite)
{
if (!pdb)
return true;
if (fReadOnly)
assert(!"Write called on database in read-only mode");
- // Key
SafeDbt datKey(key.data(), key.size());
- // Value
SafeDbt datValue(value.data(), value.size());
- // Write
int ret = pdb->put(activeTxn, datKey, datValue, (overwrite ? 0 : DB_NOOVERWRITE));
return (ret == 0);
}
-bool BerkeleyBatch::EraseKey(CDataStream& key)
+bool BerkeleyBatch::EraseKey(CDataStream&& key)
{
if (!pdb)
return false;
if (fReadOnly)
assert(!"Erase called on database in read-only mode");
- // Key
SafeDbt datKey(key.data(), key.size());
- // Erase
int ret = pdb->del(activeTxn, datKey, 0);
return (ret == 0 || ret == DB_NOTFOUND);
}
-bool BerkeleyBatch::HasKey(CDataStream& key)
+bool BerkeleyBatch::HasKey(CDataStream&& key)
{
if (!pdb)
return false;
- // Key
SafeDbt datKey(key.data(), key.size());
- // Exists
int ret = pdb->exists(activeTxn, datKey, 0);
return ret == 0;
}
diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h
index 64f573047c..599319482b 100644
--- a/src/wallet/bdb.h
+++ b/src/wallet/bdb.h
@@ -195,10 +195,10 @@ class BerkeleyBatch
};
private:
- bool ReadKey(CDataStream& key, CDataStream& value);
- bool WriteKey(CDataStream& key, CDataStream& value, bool overwrite=true);
- bool EraseKey(CDataStream& key);
- bool HasKey(CDataStream& key);
+ bool ReadKey(CDataStream&& key, CDataStream& value);
+ bool WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite = true);
+ bool EraseKey(CDataStream&& key);
+ bool HasKey(CDataStream&& key);
protected:
Db* pdb;
@@ -222,65 +222,52 @@ public:
template <typename K, typename T>
bool Read(const K& key, T& value)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
- bool success = false;
- bool ret = ReadKey(ssKey, ssValue);
- if (ret) {
- // Unserialize value
- try {
- ssValue >> value;
- success = true;
- } catch (const std::exception&) {
- // In this case success remains 'false'
- }
+ if (!ReadKey(std::move(ssKey), ssValue)) return false;
+ try {
+ ssValue >> value;
+ return true;
+ } catch (const std::exception&) {
+ return false;
}
- return ret && success;
}
template <typename K, typename T>
bool Write(const K& key, const T& value, bool fOverwrite = true)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- // Value
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
ssValue.reserve(10000);
ssValue << value;
- // Write
- return WriteKey(ssKey, ssValue, fOverwrite);
+ return WriteKey(std::move(ssKey), std::move(ssValue), fOverwrite);
}
template <typename K>
bool Erase(const K& key)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- // Erase
- return EraseKey(ssKey);
+ return EraseKey(std::move(ssKey));
}
template <typename K>
bool Exists(const K& key)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- // Exists
- return HasKey(ssKey);
+ return HasKey(std::move(ssKey));
}
bool StartCursor();