Merge pull request #4869 from PastaPastaPasta/develop-trivial-2022-06-07

backport: trivial backports 2022 06 07
This commit is contained in:
UdjinM6 2022-06-08 01:40:10 +03:00 committed by GitHub
commit 89ecf90ee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 101 additions and 85 deletions

View File

@ -188,6 +188,7 @@ $(BITCOIN_WALLET_BIN): FORCE
if USE_LCOV
LCOV_FILTER_PATTERN = \
-p "/usr/local/" \
-p "/usr/include/" \
-p "/usr/lib/" \
-p "/usr/lib64/" \

View File

@ -401,6 +401,7 @@ if test "x$enable_werror" = "xyes"; then
AX_CHECK_COMPILE_FLAG([-Werror=shadow-field],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=shadow-field"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=switch],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=switch"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=thread-safety],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=thread-safety"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=range-loop-analysis],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=range-loop-analysis"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=unused-variable],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unused-variable"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=date-time],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=date-time"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=return-type],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=return-type"],,[[$CXXFLAG_WERROR]])

View File

@ -1704,8 +1704,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
node.scheduler = MakeUnique<CScheduler>();
// Start the lightweight task scheduler thread
CScheduler::Function serviceLoop = [&node]{ node.scheduler->serviceQueue(); };
threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
threadGroup.create_thread([&] { TraceThread("scheduler", [&] { node.scheduler->serviceQueue(); }); });
// Gather some entropy once per minute.
node.scheduler->scheduleEvery([]{
@ -2069,7 +2068,6 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
bool failed_chainstate_init = false;
for (CChainState* chainstate : chainman.GetAll()) {
LogPrintf("Initializing chainstate %s\n", chainstate->ToString());
chainstate->InitCoinsDB(
/* cache_size_bytes */ nCoinDBCache,
/* in_memory */ false,

View File

@ -28,7 +28,7 @@ void CQuorumSnapshot::ToJson(UniValue& obj) const
//TODO Check this function if correct
obj.setObject();
UniValue activeQ(UniValue::VARR);
for (const auto& h : activeQuorumMembers) {
for (const bool h : activeQuorumMembers) {
// cppcheck-suppress useStlAlgorithm
activeQ.push_back(h);
}

View File

@ -2042,7 +2042,7 @@ static UniValue getblockstats(const JSONRPCRequest& request)
{RPCResult::Type::NUM, "total_out", "Total amount in all outputs (excluding coinbase and thus reward [ie subsidy + totalfee])"},
{RPCResult::Type::NUM, "total_size", "Total size of all non-coinbase transactions"},
{RPCResult::Type::NUM, "totalfee", "The fee total"},
{RPCResult::Type::NUM, "txs", "The number of transactions (excluding coinbase)"},
{RPCResult::Type::NUM, "txs", "The number of transactions (including coinbase)"},
{RPCResult::Type::NUM, "utxo_increase", "The increase/decrease in the number of unspent outputs"},
{RPCResult::Type::NUM, "utxo_size_inc", "The increase/decrease in size for the utxo index (not discounting op_return and similar)"},
}},

View File

@ -279,7 +279,7 @@ static UniValue addnode(const JSONRPCRequest& request)
else if(strCommand == "remove")
{
if(!node.connman->RemoveAddedNode(strNode))
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
}
return NullUniValue;

View File

@ -83,11 +83,13 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
"dummy",
"-printtoconsole=0",
"-logtimemicros",
"-logthreadnames",
"-debug",
"-debugexclude=libevent",
"-debugexclude=leveldb",
},
extra_args);
util::ThreadRename("test");
fs::create_directories(m_path_root);
gArgs.ForceSetArg("-datadir", m_path_root.string());
ClearDatadirCache();
@ -150,7 +152,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
// We have to run a scheduler thread to prevent ActivateBestChain
// from blocking due to queue overrun.
threadGroup.create_thread([&]{ m_node.scheduler->serviceQueue(); });
threadGroup.create_thread([&] { TraceThread("scheduler", [&] { m_node.scheduler->serviceQueue(); }); });
GetMainSignals().RegisterBackgroundSignalScheduler(*m_node.scheduler);
pblocktree.reset(new CBlockTreeDB(1 << 20, true));

View File

@ -415,57 +415,52 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].size() == 3);
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].size() == 2);
BOOST_CHECK(test_args.m_settings.ro_config[""].count("a")
&& test_args.m_settings.ro_config[""].count("b")
&& test_args.m_settings.ro_config[""].count("ccc")
&& test_args.m_settings.ro_config[""].count("d")
&& test_args.m_settings.ro_config[""].count("fff")
&& test_args.m_settings.ro_config[""].count("ggg")
&& test_args.m_settings.ro_config[""].count("h")
&& test_args.m_settings.ro_config[""].count("i")
);
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].count("ccc")
&& test_args.m_settings.ro_config["sec1"].count("h")
&& test_args.m_settings.ro_config["sec2"].count("ccc")
&& test_args.m_settings.ro_config["sec2"].count("iii")
);
BOOST_CHECK(test_args.m_settings.ro_config[""].count("a"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("b"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("d"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("fff"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("ggg"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("h"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("i"));
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].count("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].count("h"));
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].count("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].count("iii"));
BOOST_CHECK(test_args.IsArgSet("-a")
&& test_args.IsArgSet("-b")
&& test_args.IsArgSet("-ccc")
&& test_args.IsArgSet("-d")
&& test_args.IsArgSet("-fff")
&& test_args.IsArgSet("-ggg")
&& test_args.IsArgSet("-h")
&& test_args.IsArgSet("-i")
&& !test_args.IsArgSet("-zzz")
&& !test_args.IsArgSet("-iii")
);
BOOST_CHECK(test_args.IsArgSet("-a"));
BOOST_CHECK(test_args.IsArgSet("-b"));
BOOST_CHECK(test_args.IsArgSet("-ccc"));
BOOST_CHECK(test_args.IsArgSet("-d"));
BOOST_CHECK(test_args.IsArgSet("-fff"));
BOOST_CHECK(test_args.IsArgSet("-ggg"));
BOOST_CHECK(test_args.IsArgSet("-h"));
BOOST_CHECK(test_args.IsArgSet("-i"));
BOOST_CHECK(!test_args.IsArgSet("-zzz"));
BOOST_CHECK(!test_args.IsArgSet("-iii"));
BOOST_CHECK(test_args.GetArg("-a", "xxx") == ""
&& test_args.GetArg("-b", "xxx") == "1"
&& test_args.GetArg("-ccc", "xxx") == "argument"
&& test_args.GetArg("-d", "xxx") == "e"
&& test_args.GetArg("-fff", "xxx") == "0"
&& test_args.GetArg("-ggg", "xxx") == "1"
&& test_args.GetArg("-h", "xxx") == "0"
&& test_args.GetArg("-i", "xxx") == "1"
&& test_args.GetArg("-zzz", "xxx") == "xxx"
&& test_args.GetArg("-iii", "xxx") == "xxx"
);
BOOST_CHECK_EQUAL(test_args.GetArg("-a", "xxx"), "");
BOOST_CHECK_EQUAL(test_args.GetArg("-b", "xxx"), "1");
BOOST_CHECK_EQUAL(test_args.GetArg("-ccc", "xxx"), "argument");
BOOST_CHECK_EQUAL(test_args.GetArg("-d", "xxx"), "e");
BOOST_CHECK_EQUAL(test_args.GetArg("-fff", "xxx"), "0");
BOOST_CHECK_EQUAL(test_args.GetArg("-ggg", "xxx"), "1");
BOOST_CHECK_EQUAL(test_args.GetArg("-h", "xxx"), "0");
BOOST_CHECK_EQUAL(test_args.GetArg("-i", "xxx"), "1");
BOOST_CHECK_EQUAL(test_args.GetArg("-zzz", "xxx"), "xxx");
BOOST_CHECK_EQUAL(test_args.GetArg("-iii", "xxx"), "xxx");
for (const bool def : {false, true}) {
BOOST_CHECK(test_args.GetBoolArg("-a", def)
&& test_args.GetBoolArg("-b", def)
&& !test_args.GetBoolArg("-ccc", def)
&& !test_args.GetBoolArg("-d", def)
&& !test_args.GetBoolArg("-fff", def)
&& test_args.GetBoolArg("-ggg", def)
&& !test_args.GetBoolArg("-h", def)
&& test_args.GetBoolArg("-i", def)
&& test_args.GetBoolArg("-zzz", def) == def
&& test_args.GetBoolArg("-iii", def) == def
);
BOOST_CHECK(test_args.GetBoolArg("-a", def));
BOOST_CHECK(test_args.GetBoolArg("-b", def));
BOOST_CHECK(!test_args.GetBoolArg("-ccc", def));
BOOST_CHECK(!test_args.GetBoolArg("-d", def));
BOOST_CHECK(!test_args.GetBoolArg("-fff", def));
BOOST_CHECK(test_args.GetBoolArg("-ggg", def));
BOOST_CHECK(!test_args.GetBoolArg("-h", def));
BOOST_CHECK(test_args.GetBoolArg("-i", def));
BOOST_CHECK(test_args.GetBoolArg("-zzz", def) == def);
BOOST_CHECK(test_args.GetBoolArg("-iii", def) == def);
}
BOOST_CHECK(test_args.GetArgs("-a").size() == 1
@ -501,13 +496,12 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
test_args.SelectConfigNetwork("sec1");
// same as original
BOOST_CHECK(test_args.GetArg("-a", "xxx") == ""
&& test_args.GetArg("-b", "xxx") == "1"
&& test_args.GetArg("-fff", "xxx") == "0"
&& test_args.GetArg("-ggg", "xxx") == "1"
&& test_args.GetArg("-zzz", "xxx") == "xxx"
&& test_args.GetArg("-iii", "xxx") == "xxx"
);
BOOST_CHECK_EQUAL(test_args.GetArg("-a", "xxx"), "");
BOOST_CHECK_EQUAL(test_args.GetArg("-b", "xxx"), "1");
BOOST_CHECK_EQUAL(test_args.GetArg("-fff", "xxx"), "0");
BOOST_CHECK_EQUAL(test_args.GetArg("-ggg", "xxx"), "1");
BOOST_CHECK_EQUAL(test_args.GetArg("-zzz", "xxx"), "xxx");
BOOST_CHECK_EQUAL(test_args.GetArg("-iii", "xxx"), "xxx");
// d is overridden
BOOST_CHECK(test_args.GetArg("-d", "xxx") == "eee");
// section-specific setting
@ -522,14 +516,13 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
test_args.SelectConfigNetwork("sec2");
// same as original
BOOST_CHECK(test_args.GetArg("-a", "xxx") == ""
&& test_args.GetArg("-b", "xxx") == "1"
&& test_args.GetArg("-d", "xxx") == "e"
&& test_args.GetArg("-fff", "xxx") == "0"
&& test_args.GetArg("-ggg", "xxx") == "1"
&& test_args.GetArg("-zzz", "xxx") == "xxx"
&& test_args.GetArg("-h", "xxx") == "0"
);
BOOST_CHECK(test_args.GetArg("-a", "xxx") == "");
BOOST_CHECK(test_args.GetArg("-b", "xxx") == "1");
BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e");
BOOST_CHECK(test_args.GetArg("-fff", "xxx") == "0");
BOOST_CHECK(test_args.GetArg("-ggg", "xxx") == "1");
BOOST_CHECK(test_args.GetArg("-zzz", "xxx") == "xxx");
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0");
// section-specific setting
BOOST_CHECK(test_args.GetArg("-iii", "xxx") == "2");
// section takes priority for multiple values

View File

@ -52,8 +52,6 @@ std::set<std::string> RenameEnMasse(int num_threads)
*/
BOOST_AUTO_TEST_CASE(util_threadnames_test_rename_threaded)
{
BOOST_CHECK_EQUAL(util::ThreadGetInternalName(), "");
#if !defined(HAVE_THREAD_LOCAL)
// This test doesn't apply to platforms where we don't have thread_local.
return;

View File

@ -64,11 +64,11 @@ struct SettingsSpan {
explicit SettingsSpan(const SettingsValue& value) noexcept : SettingsSpan(&value, 1) {}
explicit SettingsSpan(const SettingsValue* data, size_t size) noexcept : data(data), size(size) {}
explicit SettingsSpan(const std::vector<SettingsValue>& vec) noexcept;
const SettingsValue* begin() const; //<! Pointer to first non-negated value.
const SettingsValue* end() const; //<! Pointer to end of values.
bool empty() const; //<! True if there are any non-negated values.
bool last_negated() const; //<! True if the last value is negated.
size_t negated() const; //<! Number of negated values.
const SettingsValue* begin() const; //!< Pointer to first non-negated value.
const SettingsValue* end() const; //!< Pointer to end of values.
bool empty() const; //!< True if there are any non-negated values.
bool last_negated() const; //!< True if the last value is negated.
size_t negated() const; //!< Number of negated values.
const SettingsValue* data = nullptr;
size_t size = 0;

View File

@ -485,7 +485,7 @@ void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
std::string ArgsManager::GetHelpMessage() const
{
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
const bool show_debug = GetBoolArg("-help-debug", false);
std::string usage = "";
LOCK(cs_args);
@ -894,7 +894,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
// If datadir is changed in .conf file:
ClearDatadirCache();
if (!CheckDataDirOption()) {
error = strprintf("specified data directory \"%s\" does not exist.", gArgs.GetArg("-datadir", ""));
error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", ""));
return false;
}
return true;

View File

@ -17,6 +17,11 @@ static const char *HEADER_END = "HEADER=END";
static const char *DATA_END = "DATA=END";
typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
static bool KeyFilter(const std::string& type)
{
return WalletBatch::IsKeyType(type) || type == DBKeys::HDCHAIN;
}
bool RecoverDatabaseFile(const fs::path& file_path, bilingual_str& error, std::vector<bilingual_str>& warnings)
{
std::string filename;
@ -132,9 +137,9 @@ bool RecoverDatabaseFile(const fs::path& file_path, bilingual_str& error, std::v
{
// Required in LoadKeyMetadata():
LOCK(dummyWallet.cs_wallet);
fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue, strType, strErr);
fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue, strType, strErr, KeyFilter);
}
if (!WalletBatch::IsKeyType(strType) && strType != DBKeys::HDCHAIN) {
if (!KeyFilter(strType)) {
continue;
}
if (!fReadOK)

View File

@ -222,13 +222,17 @@ public:
static bool
ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
CWalletScanState &wss, std::string& strType, std::string& strErr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
CWalletScanState &wss, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
{
try {
// Unserialize
// Taking advantage of the fact that pair serialization
// is just the two items serialized one after the other
ssKey >> strType;
// If we have a filter, check if this matches the filter
if (filter_fn && !filter_fn(strType)) {
return true;
}
if (strType == DBKeys::NAME) {
std::string strAddress;
ssKey >> strAddress;
@ -489,11 +493,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
return true;
}
bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr)
bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn)
{
CWalletScanState dummy_wss;
LOCK(pwallet->cs_wallet);
return ReadKeyValue(pwallet, ssKey, ssValue, dummy_wss, strType, strErr);
return ReadKeyValue(pwallet, ssKey, ssValue, dummy_wss, strType, strErr, filter_fn);
}
bool WalletBatch::IsKeyType(const std::string& strType)

View File

@ -233,8 +233,11 @@ private:
//! Compacts BDB state so that wallet.dat is self-contained (if there are changes)
void MaybeCompactWalletDB();
//! Callback for filtering key types to deserialize in ReadKeyValue
using KeyFilterFn = std::function<bool(const std::string&)>;
//! Unserialize a given Key-Value pair and load it into the wallet
bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr);
bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr);
/** Return whether a wallet database is currently loaded. */
bool IsWalletLoaded(const fs::path& wallet_path);

View File

@ -130,7 +130,7 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
std::vector<bilingual_str> warnings;
bool ret = RecoverDatabaseFile(path, error, warnings);
if (!ret) {
for (const auto warning : warnings) {
for (const auto& warning : warnings) {
tfm::format(std::cerr, "%s\n", warning.original);
}
if (!error.empty()) {

View File

@ -140,6 +140,13 @@ class NetTest(BitcoinTestFramework):
added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
assert_equal(len(added_nodes), 1)
assert_equal(added_nodes[0]['addednode'], ip_port)
# check that node cannot be added again
assert_raises_rpc_error(-23, "Node already added", self.nodes[0].addnode, node=ip_port, command='add')
# check that node can be removed
self.nodes[0].addnode(node=ip_port, command='remove')
assert_equal(self.nodes[0].getaddednodeinfo(), [])
# check that trying to remove the node again returns an error
assert_raises_rpc_error(-24, "Node could not be removed", self.nodes[0].addnode, node=ip_port, command='remove')
# check that a non-existent node returns an error
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')

View File

@ -8,3 +8,6 @@ leak:libqminimal
leak:libQt5Core
leak:libQt5Gui
leak:libQt5Widgets
# false-positive due to use of secure_allocator<>
leak:GetRNGState

View File

@ -23,3 +23,4 @@ deadlock:src/qt/test/*
# External libraries
deadlock:libdb
race:libzmq
race:epoll_ctl # https://github.com/bitcoin/bitcoin/pull/20218