Skip to content

Commit

Permalink
Merge pull request #5523 from vijaydasmp/bp22_12
Browse files Browse the repository at this point in the history
backport: Merge bitcoin#20816,20844,20584,14501,18669
  • Loading branch information
PastaPastaPasta authored Aug 30, 2023
2 parents 41ddf5a + 2bacbcf commit 27eecea
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 105 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,13 @@ if test x$TARGET_OS != xwindows; then
fi
fi

dnl LevelDB platform checks
AC_MSG_CHECKING(for fdatasync)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]],
[[ fdatasync(0); ]])],
[ AC_MSG_RESULT(yes); HAVE_FDATASYNC=1 ],
[ AC_MSG_RESULT(no); HAVE_FDATASYNC=0 ]
)
AC_DEFINE_UNQUOTED([HAVE_FDATASYNC], [$HAVE_FDATASYNC], [Define to 1 if fdatasync is available.])

AC_MSG_CHECKING(for F_FULLFSYNC)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <fcntl.h>]],
Expand Down
2 changes: 1 addition & 1 deletion src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
return CAddrInfo();
}

CAddrInfo& newInfo = mapInfo[id_new];
const CAddrInfo& newInfo = mapInfo[id_new];

// which tried bucket to move the entry to
int tried_bucket = newInfo.GetTriedBucket(nKey, m_asmap);
Expand Down
1 change: 1 addition & 0 deletions src/flatfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize)
fclose(file);
return error("%s: failed to commit file %d", __func__, pos.nFile);
}
DirectoryCommit(m_dir);

fclose(file);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void SetupServerArgs(NodeContext& node)
argsman.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);

argsman.AddArg("-debug=<category>", "Output debugging information (default: -nodebug, supplying <category> is optional). "
"If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + ListLogCategories() + ".", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
"If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + LogInstance().LogCategoriesString() + ".", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-debugexclude=<category>", strprintf("Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except one or more specified categories."), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-disablegovernance", strprintf("Disable governance validation (0-1, default: %u)", 0), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
Expand Down
43 changes: 4 additions & 39 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,56 +197,21 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
return false;
}

std::string ListLogCategories()
std::vector<LogCategory> BCLog::Logger::LogCategoriesList() const
{
std::string ret;
int outcount = 0;
std::vector<LogCategory> ret;
for (const CLogCategoryDesc& category_desc : LogCategories) {
// Omit the special cases.
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL && category_desc.flag != BCLog::DASH) {
if (outcount != 0) ret += ", ";
ret += category_desc.category;
outcount++;
}
}
return ret;
}

std::vector<CLogCategoryActive> ListActiveLogCategories()
{
std::vector<CLogCategoryActive> ret;
for (const CLogCategoryDesc& category_desc : LogCategories) {
// Omit the special cases.
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL && category_desc.flag != BCLog::DASH) {
CLogCategoryActive catActive;
LogCategory catActive;
catActive.category = category_desc.category;
catActive.active = LogAcceptCategory(category_desc.flag);
catActive.active = WillLogCategory(category_desc.flag);
ret.push_back(catActive);
}
}
return ret;
}

std::string ListActiveLogCategoriesString()
{
if (LogInstance().GetCategoryMask() == BCLog::NONE)
return "0";
if (LogInstance().GetCategoryMask() == BCLog::ALL)
return "1";

std::string ret;
int outcount = 0;
for (const CLogCategoryDesc& category_desc : LogCategories) {
// Omit the special cases.
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL && category_desc.flag != BCLog::DASH && LogAcceptCategory(category_desc.flag)) {
if (outcount != 0) ret += ", ";
ret += category_desc.category;
outcount++;
}
}
return ret;
}

std::string BCLog::Logger::LogTimestampStr(const std::string& str)
{
std::string strStamped;
Expand Down
20 changes: 9 additions & 11 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fs.h>
#include <tinyformat.h>
#include <threadsafety.h>
#include <util/string.h>

#include <atomic>
#include <cstdint>
Expand All @@ -26,8 +27,7 @@ extern const char * const DEFAULT_DEBUGLOGFILE;
extern bool fLogThreadNames;
extern bool fLogIPs;

struct CLogCategoryActive
{
struct LogCategory {
std::string category;
bool active;
};
Expand Down Expand Up @@ -157,6 +157,13 @@ namespace BCLog {
bool DisableCategory(const std::string& str);

bool WillLogCategory(LogFlags category) const;
/** Returns a vector of the log categories */
std::vector<LogCategory> LogCategoriesList() const;
/** Returns a string with the log categories */
std::string LogCategoriesString() const
{
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
};

bool DefaultShrinkDebugFile() const;
};
Expand All @@ -171,15 +178,6 @@ static inline bool LogAcceptCategory(BCLog::LogFlags category)
return LogInstance().WillLogCategory(category);
}

/** Returns a string with the log categories. */
std::string ListLogCategories();

/** Returns a string with the list of active log categories */
std::string ListActiveLogCategoriesString();

/** Returns a vector of the active log categories. */
std::vector<CLogCategoryActive> ListActiveLogCategories();

/** Return true if str parses as a log category and set the flag */
bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str);

Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOp
// Perform transaction-level checks before adding to block:
// - transaction finality (locktime)
// - safe TXs in regard to ChainLocks
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package)
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
{
for (CTxMemPool::txiter it : package) {
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
Expand Down
2 changes: 1 addition & 1 deletion src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class BlockAssembler
* locktime
* These checks should always succeed, and they're here
* only as an extra check in case of suboptimal node configuration */
bool TestPackageTransactions(const CTxMemPool::setEntries& package);
bool TestPackageTransactions(const CTxMemPool::setEntries& package) const;
/** Return true if given transaction from mapTx has already been evaluated,
* or if the transaction's cached data in mapTx is incorrect. */
bool SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs);
Expand Down
25 changes: 14 additions & 11 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,11 +1399,16 @@ void CConnman::CalculateNumConnectionsChangedStats()
mapSentBytesMsgStats[NET_MESSAGE_COMMAND_OTHER] = 0;
auto vNodesCopy = CopyNodeVector(CConnman::FullyConnectedOnly);
for (auto pnode : vNodesCopy) {
LOCK(pnode->cs_vRecv);
for (const mapMsgCmdSize::value_type &i : pnode->mapRecvBytesPerMsgCmd)
mapRecvBytesMsgStats[i.first] += i.second;
for (const mapMsgCmdSize::value_type &i : pnode->mapSendBytesPerMsgCmd)
mapSentBytesMsgStats[i.first] += i.second;
{
LOCK(pnode->cs_vRecv);
for (const mapMsgCmdSize::value_type &i : pnode->mapRecvBytesPerMsgCmd)
mapRecvBytesMsgStats[i.first] += i.second;
}
{
LOCK(pnode->cs_vSend);
for (const mapMsgCmdSize::value_type &i : pnode->mapSendBytesPerMsgCmd)
mapSentBytesMsgStats[i.first] += i.second;
}
if(pnode->fClient)
spvNodes++;
else
Expand Down Expand Up @@ -1436,7 +1441,7 @@ void CConnman::CalculateNumConnectionsChangedStats()
statsClient.gauge("peers.torConnections", torNodes, 1.0f);
}

void CConnman::InactivityCheck(CNode *pnode)
void CConnman::InactivityCheck(CNode *pnode) const
{
int64_t nTime = GetSystemTimeInSeconds();
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)
Expand Down Expand Up @@ -1877,11 +1882,9 @@ void CConnman::SocketHandler()
break;
}

LOCK(pnode->cs_vSend);
size_t nBytes = SocketSendData(pnode);
if (nBytes) {
RecordBytesSent(nBytes);
}
// Send data
size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode));
if (bytes_sent) RecordBytesSent(bytes_sent);
}

ReleaseNodeVector(vErrorNodes);
Expand Down
10 changes: 6 additions & 4 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ friend class CNode;
void DisconnectNodes();
void NotifyNumConnectionsChanged();
void CalculateNumConnectionsChangedStats();
void InactivityCheck(CNode *pnode);
void InactivityCheck(CNode *pnode) const;
bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
#ifdef USE_KQUEUE
void SocketEventsKqueue(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);
Expand Down Expand Up @@ -1026,8 +1026,10 @@ class CNode
NetPermissionFlags m_permissionFlags{ PF_NONE };
std::atomic<ServiceFlags> nServices{NODE_NONE};
SOCKET hSocket GUARDED_BY(cs_hSocket);
size_t nSendSize{0}; // total size of all vSendMsg entries
size_t nSendOffset{0}; // offset inside the first vSendMsg already sent
/** Total size of all vSendMsg entries */
size_t nSendSize GUARDED_BY(cs_vSend){0};
/** Offset inside the first vSendMsg already sent */
size_t nSendOffset GUARDED_BY(cs_vSend){0};
uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
std::list<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
std::atomic<size_t> nSendMsgSize{0};
Expand Down Expand Up @@ -1119,7 +1121,7 @@ class CNode
Network ConnectedThroughNetwork() const;

protected:
mapMsgCmdSize mapSendBytesPerMsgCmd;
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);

public:
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, CTxMemPool

NodeContext& EnsureAnyNodeContext(const CoreContext& context)
{
auto* node_context = GetContext<NodeContext>(context);
auto* const node_context = GetContext<NodeContext>(context);
if (!node_context) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node context not found");
}
Expand Down
9 changes: 4 additions & 5 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static UniValue debug(const JSONRPCRequest& request)
{
RPCHelpMan{"debug",
"Change debug category on the fly. Specify single category or use '+' to specify many.\n"
"The valid debug categories are: " + ListLogCategories() + ".\n"
"The valid logging categories are: " + LogInstance().LogCategoriesString() + ".\n"
"libevent logging is configured on startup and cannot be modified by this RPC during runtime.\n"
"There are also a few meta-categories:\n"
" - \"all\", \"1\" and \"\" activate all categories at once;\n"
Expand Down Expand Up @@ -72,7 +72,7 @@ static UniValue debug(const JSONRPCRequest& request)
}
}

return "Debug mode: " + ListActiveLogCategoriesString();
return "Debug mode: " + LogInstance().LogCategoriesString();
}

static UniValue mnsync(const JSONRPCRequest& request)
Expand Down Expand Up @@ -1228,7 +1228,7 @@ static UniValue logging(const JSONRPCRequest& request)
"When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
"The arguments are evaluated in order \"include\", \"exclude\".\n"
"If an item is both included and excluded, it will thus end up being excluded.\n"
"The valid logging categories are: " + ListLogCategories() + "\n"
"The valid logging categories are: " + LogInstance().LogCategoriesString() + "\n"
"In addition, the following are available as category names with special meanings:\n"
" - \"all\", \"1\" : represent all logging categories.\n"
" - \"dash\" activates all Dash-specific categories at once.\n"
Expand Down Expand Up @@ -1282,8 +1282,7 @@ static UniValue logging(const JSONRPCRequest& request)
}

UniValue result(UniValue::VOBJ);
std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories();
for (const auto& logCatActive : vLogCatActive) {
for (const auto& logCatActive : LogInstance().LogCategoriesList()) {
result.pushKV(logCatActive.category, logCatActive.active);
}

Expand Down
4 changes: 2 additions & 2 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ class ConditionStack {
uint32_t m_first_false_pos = NO_FALSE;

public:
bool empty() { return m_stack_size == 0; }
bool all_true() { return m_first_false_pos == NO_FALSE; }
bool empty() const { return m_stack_size == 0; }
bool all_true() const { return m_first_false_pos == NO_FALSE; }
void push_back(bool f)
{
if (m_first_false_pos == NO_FALSE && !f) {
Expand Down
2 changes: 1 addition & 1 deletion src/script/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, C
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType)
{
assert(nIn < txTo.vin.size());
CTxIn& txin = txTo.vin[nIn];
const CTxIn& txin = txTo.vin[nIn];
assert(txin.prevout.n < txFrom.vout.size());
const CTxOut& txout = txFrom.vout[txin.prevout.n];

Expand Down
8 changes: 4 additions & 4 deletions src/test/checkqueue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static const unsigned int QUEUE_BATCH_SIZE = 128;
static const int SCRIPT_CHECK_THREADS = 3;

struct FakeCheck {
bool operator()()
bool operator()() const
{
return true;
}
Expand All @@ -45,7 +45,7 @@ struct FailingCheck {
bool fails;
FailingCheck(bool _fails) : fails(_fails){};
FailingCheck() : fails(true){};
bool operator()()
bool operator()() const
{
return !fails;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ struct UniqueCheck {
struct MemoryCheck {
static std::atomic<size_t> fake_allocated_memory;
bool b {false};
bool operator()()
bool operator()() const
{
return true;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ struct FrozenCleanupCheck {
// Freezing can't be the default initialized behavior given how the queue
// swaps in default initialized Checks.
bool should_freeze {false};
bool operator()()
bool operator()() const
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,12 @@ TestChainSetup::~TestChainSetup()
SetMockTime(0);
}

CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx)
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const
{
return FromTx(MakeTransactionRef(tx));
}

CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef& tx)
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef& tx) const
{
return CTxMemPoolEntry(tx, nFee, nTime, nHeight,
spendsCoinbase, sigOpCount, lp);
Expand Down
4 changes: 2 additions & 2 deletions src/test/util/setup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ struct TestMemPoolEntryHelper
nFee(0), nTime(0), nHeight(1),
spendsCoinbase(false), sigOpCount(1) { }

CTxMemPoolEntry FromTx(const CMutableTransaction& tx);
CTxMemPoolEntry FromTx(const CTransactionRef& tx);
CTxMemPoolEntry FromTx(const CMutableTransaction& tx) const;
CTxMemPoolEntry FromTx(const CTransactionRef& tx) const;

// Change the default value
TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
Expand Down
Loading

0 comments on commit 27eecea

Please sign in to comment.