mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #20584: Declare de facto const reference variables/member functions as const
31b136e5802e1b1e5f9a9589736afe0652f34da2 Don't declare de facto const reference variables as non-const (practicalswift) 1c65c075ee4c7f98d9c1fac5ed7576b96374d4e9 Don't declare de facto const member functions as non-const (practicalswift) Pull request description: _Meta: This is the second and final part of the `const` refactoring series (part one: #20581). **I promise: no more refactoring PRs from me in a while! :)** I'll now go back to focusing on fuzzing/hardening!_ Changes in this PR: * Don't declare de facto const member functions as non-const * Don't declare de facto const reference variables as non-const Awards for finding candidates for the above changes go to: * `clang-tidy`'s [`readability-make-member-function-const`](https://clang.llvm.org/extra/clang-tidy/checks/readability-make-member-function-const.html) check ([list of `clang-tidy` checks](https://clang.llvm.org/extra/clang-tidy/checks/list.html)) * `cppcheck`'s `constVariable` check ([list of `cppcheck` checks](https://sourceforge.net/p/cppcheck/wiki/ListOfChecks/)) See #18920 for instructions on how to analyse Bitcoin Core using Clang Static Analysis, `clang-tidy` and `cppcheck`. ACKs for top commit: ajtowns: ACK 31b136e5802e1b1e5f9a9589736afe0652f34da2 jonatack: ACK 31b136e5802e1b1e5f9a9589736afe0652f34da2 theStack: ACK 31b136e5802e1b1e5f9a9589736afe0652f34da2 ❄️ Tree-SHA512: f58f8f00744219426874379e9f3e9331132b9b48e954d24f3a85cbb858fdcc98009ed42ef7e7b4619ae8af9fc240a6d8bfc1c438db2e97b0ecd722a80dcfeffe
This commit is contained in:
parent
e554d3a02e
commit
a298eb2b93
@ -725,7 +725,7 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
|
|||||||
return CAddrInfo();
|
return CAddrInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
CAddrInfo& newInfo = mapInfo[id_new];
|
const CAddrInfo& newInfo = mapInfo[id_new];
|
||||||
|
|
||||||
// which tried bucket to move the entry to
|
// which tried bucket to move the entry to
|
||||||
int tried_bucket = newInfo.GetTriedBucket(nKey, m_asmap);
|
int tried_bucket = newInfo.GetTriedBucket(nKey, m_asmap);
|
||||||
|
@ -158,9 +158,9 @@ namespace BCLog {
|
|||||||
|
|
||||||
bool WillLogCategory(LogFlags category) const;
|
bool WillLogCategory(LogFlags category) const;
|
||||||
/** Returns a vector of the log categories */
|
/** Returns a vector of the log categories */
|
||||||
std::vector<LogCategory> LogCategoriesList();
|
std::vector<LogCategory> LogCategoriesList() const;
|
||||||
/** Returns a string with the log categories */
|
/** Returns a string with the log categories */
|
||||||
std::string LogCategoriesString()
|
std::string LogCategoriesString() const
|
||||||
{
|
{
|
||||||
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
|
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
|
||||||
};
|
};
|
||||||
|
@ -290,7 +290,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOp
|
|||||||
// Perform transaction-level checks before adding to block:
|
// Perform transaction-level checks before adding to block:
|
||||||
// - transaction finality (locktime)
|
// - transaction finality (locktime)
|
||||||
// - safe TXs in regard to ChainLocks
|
// - 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) {
|
for (CTxMemPool::txiter it : package) {
|
||||||
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
|
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
|
||||||
|
@ -205,7 +205,7 @@ private:
|
|||||||
* locktime
|
* locktime
|
||||||
* These checks should always succeed, and they're here
|
* These checks should always succeed, and they're here
|
||||||
* only as an extra check in case of suboptimal node configuration */
|
* 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,
|
/** Return true if given transaction from mapTx has already been evaluated,
|
||||||
* or if the transaction's cached data in mapTx is incorrect. */
|
* 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);
|
bool SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs);
|
||||||
|
@ -1441,7 +1441,7 @@ void CConnman::CalculateNumConnectionsChangedStats()
|
|||||||
statsClient.gauge("peers.torConnections", torNodes, 1.0f);
|
statsClient.gauge("peers.torConnections", torNodes, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnman::InactivityCheck(CNode *pnode)
|
void CConnman::InactivityCheck(CNode *pnode) const
|
||||||
{
|
{
|
||||||
int64_t nTime = GetSystemTimeInSeconds();
|
int64_t nTime = GetSystemTimeInSeconds();
|
||||||
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)
|
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)
|
||||||
|
@ -532,7 +532,7 @@ private:
|
|||||||
void DisconnectNodes();
|
void DisconnectNodes();
|
||||||
void NotifyNumConnectionsChanged();
|
void NotifyNumConnectionsChanged();
|
||||||
void CalculateNumConnectionsChangedStats();
|
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);
|
bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
|
||||||
#ifdef USE_KQUEUE
|
#ifdef USE_KQUEUE
|
||||||
void SocketEventsKqueue(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);
|
void SocketEventsKqueue(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);
|
||||||
|
@ -68,7 +68,7 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, CTxMemPool
|
|||||||
|
|
||||||
NodeContext& EnsureAnyNodeContext(const CoreContext& context)
|
NodeContext& EnsureAnyNodeContext(const CoreContext& context)
|
||||||
{
|
{
|
||||||
auto* node_context = GetContext<NodeContext>(context);
|
auto* const node_context = GetContext<NodeContext>(context);
|
||||||
if (!node_context) {
|
if (!node_context) {
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node context not found");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node context not found");
|
||||||
}
|
}
|
||||||
|
@ -301,8 +301,8 @@ private:
|
|||||||
uint32_t m_first_false_pos = NO_FALSE;
|
uint32_t m_first_false_pos = NO_FALSE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool empty() { return m_stack_size == 0; }
|
bool empty() const { return m_stack_size == 0; }
|
||||||
bool all_true() { return m_first_false_pos == NO_FALSE; }
|
bool all_true() const { return m_first_false_pos == NO_FALSE; }
|
||||||
void push_back(bool f)
|
void push_back(bool f)
|
||||||
{
|
{
|
||||||
if (m_first_false_pos == NO_FALSE && !f) {
|
if (m_first_false_pos == NO_FALSE && !f) {
|
||||||
|
@ -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)
|
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType)
|
||||||
{
|
{
|
||||||
assert(nIn < txTo.vin.size());
|
assert(nIn < txTo.vin.size());
|
||||||
CTxIn& txin = txTo.vin[nIn];
|
const CTxIn& txin = txTo.vin[nIn];
|
||||||
assert(txin.prevout.n < txFrom.vout.size());
|
assert(txin.prevout.n < txFrom.vout.size());
|
||||||
const CTxOut& txout = txFrom.vout[txin.prevout.n];
|
const CTxOut& txout = txFrom.vout[txin.prevout.n];
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ static const unsigned int QUEUE_BATCH_SIZE = 128;
|
|||||||
static const int SCRIPT_CHECK_THREADS = 3;
|
static const int SCRIPT_CHECK_THREADS = 3;
|
||||||
|
|
||||||
struct FakeCheck {
|
struct FakeCheck {
|
||||||
bool operator()()
|
bool operator()() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ struct FailingCheck {
|
|||||||
bool fails;
|
bool fails;
|
||||||
FailingCheck(bool _fails) : fails(_fails){};
|
FailingCheck(bool _fails) : fails(_fails){};
|
||||||
FailingCheck() : fails(true){};
|
FailingCheck() : fails(true){};
|
||||||
bool operator()()
|
bool operator()() const
|
||||||
{
|
{
|
||||||
return !fails;
|
return !fails;
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ struct UniqueCheck {
|
|||||||
struct MemoryCheck {
|
struct MemoryCheck {
|
||||||
static std::atomic<size_t> fake_allocated_memory;
|
static std::atomic<size_t> fake_allocated_memory;
|
||||||
bool b {false};
|
bool b {false};
|
||||||
bool operator()()
|
bool operator()() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ struct FrozenCleanupCheck {
|
|||||||
// Freezing can't be the default initialized behavior given how the queue
|
// Freezing can't be the default initialized behavior given how the queue
|
||||||
// swaps in default initialized Checks.
|
// swaps in default initialized Checks.
|
||||||
bool should_freeze {false};
|
bool should_freeze {false};
|
||||||
bool operator()()
|
bool operator()() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -430,12 +430,12 @@ TestChainSetup::~TestChainSetup()
|
|||||||
SetMockTime(0);
|
SetMockTime(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx)
|
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const
|
||||||
{
|
{
|
||||||
return FromTx(MakeTransactionRef(tx));
|
return FromTx(MakeTransactionRef(tx));
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef& tx)
|
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef& tx) const
|
||||||
{
|
{
|
||||||
return CTxMemPoolEntry(tx, nFee, nTime, nHeight,
|
return CTxMemPoolEntry(tx, nFee, nTime, nHeight,
|
||||||
spendsCoinbase, sigOpCount, lp);
|
spendsCoinbase, sigOpCount, lp);
|
||||||
|
@ -181,8 +181,8 @@ struct TestMemPoolEntryHelper
|
|||||||
nFee(0), nTime(0), nHeight(1),
|
nFee(0), nTime(0), nHeight(1),
|
||||||
spendsCoinbase(false), sigOpCount(1) { }
|
spendsCoinbase(false), sigOpCount(1) { }
|
||||||
|
|
||||||
CTxMemPoolEntry FromTx(const CMutableTransaction& tx);
|
CTxMemPoolEntry FromTx(const CMutableTransaction& tx) const;
|
||||||
CTxMemPoolEntry FromTx(const CTransactionRef& tx);
|
CTxMemPoolEntry FromTx(const CTransactionRef& tx) const;
|
||||||
|
|
||||||
// Change the default value
|
// Change the default value
|
||||||
TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
|
TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
|
||||||
|
@ -717,7 +717,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
|
|||||||
m_view.SetBackend(m_viewmempool);
|
m_view.SetBackend(m_viewmempool);
|
||||||
|
|
||||||
assert(std::addressof(::ChainstateActive().CoinsTip()) == std::addressof(m_active_chainstate.CoinsTip()));
|
assert(std::addressof(::ChainstateActive().CoinsTip()) == std::addressof(m_active_chainstate.CoinsTip()));
|
||||||
CCoinsViewCache& coins_cache = m_active_chainstate.CoinsTip();
|
const CCoinsViewCache& coins_cache = m_active_chainstate.CoinsTip();
|
||||||
// do all inputs exist?
|
// do all inputs exist?
|
||||||
for (const CTxIn& txin : tx.vin) {
|
for (const CTxIn& txin : tx.vin) {
|
||||||
if (!coins_cache.HaveCoinInCache(txin.prevout)) {
|
if (!coins_cache.HaveCoinInCache(txin.prevout)) {
|
||||||
|
@ -592,7 +592,7 @@ void CWallet::AddToSpends(const uint256& wtxid)
|
|||||||
{
|
{
|
||||||
auto it = mapWallet.find(wtxid);
|
auto it = mapWallet.find(wtxid);
|
||||||
assert(it != mapWallet.end());
|
assert(it != mapWallet.end());
|
||||||
CWalletTx& thisTx = it->second;
|
const CWalletTx& thisTx = it->second;
|
||||||
if (thisTx.IsCoinBase()) // Coinbases don't spend anything!
|
if (thisTx.IsCoinBase()) // Coinbases don't spend anything!
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1093,7 +1093,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
|
|||||||
// Can't mark abandoned if confirmed or in mempool
|
// Can't mark abandoned if confirmed or in mempool
|
||||||
auto it = mapWallet.find(hashTx);
|
auto it = mapWallet.find(hashTx);
|
||||||
assert(it != mapWallet.end());
|
assert(it != mapWallet.end());
|
||||||
CWalletTx& origtx = it->second;
|
const CWalletTx& origtx = it->second;
|
||||||
if (origtx.GetDepthInMainChain() != 0 || origtx.InMempool() || origtx.IsLockedByInstantSend()) {
|
if (origtx.GetDepthInMainChain() != 0 || origtx.InMempool() || origtx.IsLockedByInstantSend()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user