mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Merge #20584: Declare de facto const reference variables/member functions as const
31b136e580
Don't declare de facto const reference variables as non-const (practicalswift)1c65c075ee
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: ACK31b136e580
jonatack: ACK31b136e580
theStack: ACK31b136e580
❄️ Tree-SHA512: f58f8f00744219426874379e9f3e9331132b9b48e954d24f3a85cbb858fdcc98009ed42ef7e7b4619ae8af9fc240a6d8bfc1c438db2e97b0ecd722a80dcfeffe
This commit is contained in:
commit
f13e03cda2
17 changed files with 27 additions and 27 deletions
|
@ -617,7 +617,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);
|
||||
|
|
|
@ -174,7 +174,7 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::vector<LogCategory> BCLog::Logger::LogCategoriesList()
|
||||
std::vector<LogCategory> BCLog::Logger::LogCategoriesList() const
|
||||
{
|
||||
std::vector<LogCategory> ret;
|
||||
for (const CLogCategoryDesc& category_desc : LogCategories) {
|
||||
|
|
|
@ -135,9 +135,9 @@ namespace BCLog {
|
|||
|
||||
bool WillLogCategory(LogFlags category) const;
|
||||
/** Returns a vector of the log categories */
|
||||
std::vector<LogCategory> LogCategoriesList();
|
||||
std::vector<LogCategory> LogCategoriesList() const;
|
||||
/** Returns a string with the log categories */
|
||||
std::string LogCategoriesString()
|
||||
std::string LogCategoriesString() const
|
||||
{
|
||||
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
|
||||
};
|
||||
|
|
|
@ -213,7 +213,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
|
|||
// - transaction finality (locktime)
|
||||
// - premature witness (in case segwit transactions are added to mempool before
|
||||
// segwit activation)
|
||||
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))
|
||||
|
|
|
@ -185,7 +185,7 @@ private:
|
|||
* locktime, premature-witness, serialized size (if necessary)
|
||||
* 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);
|
||||
|
|
|
@ -1206,7 +1206,7 @@ void CConnman::NotifyNumConnectionsChanged()
|
|||
}
|
||||
}
|
||||
|
||||
void CConnman::InactivityCheck(CNode *pnode)
|
||||
void CConnman::InactivityCheck(CNode *pnode) const
|
||||
{
|
||||
int64_t nTime = GetSystemTimeInSeconds();
|
||||
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)
|
||||
|
|
|
@ -420,7 +420,7 @@ private:
|
|||
void AcceptConnection(const ListenSocket& hListenSocket);
|
||||
void DisconnectNodes();
|
||||
void NotifyNumConnectionsChanged();
|
||||
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);
|
||||
void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
|
||||
void SocketHandler();
|
||||
|
|
|
@ -66,7 +66,7 @@ NodeContext& EnsureNodeContext(const util::Ref& context)
|
|||
|
||||
CTxMemPool& EnsureMemPool(const util::Ref& context)
|
||||
{
|
||||
NodeContext& node = EnsureNodeContext(context);
|
||||
const NodeContext& node = EnsureNodeContext(context);
|
||||
if (!node.mempool) {
|
||||
throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found");
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ CTxMemPool& EnsureMemPool(const util::Ref& context)
|
|||
|
||||
ChainstateManager& EnsureChainman(const util::Ref& context)
|
||||
{
|
||||
NodeContext& node = EnsureNodeContext(context);
|
||||
const NodeContext& node = EnsureNodeContext(context);
|
||||
if (!node.chainman) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
|
||||
}
|
||||
|
|
|
@ -305,8 +305,8 @@ private:
|
|||
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) {
|
||||
|
|
|
@ -388,7 +388,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];
|
||||
|
||||
|
|
|
@ -26,7 +26,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;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ struct FailingCheck {
|
|||
bool fails;
|
||||
FailingCheck(bool _fails) : fails(_fails){};
|
||||
FailingCheck() : fails(true){};
|
||||
bool operator()()
|
||||
bool operator()() const
|
||||
{
|
||||
return !fails;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ struct UniqueCheck {
|
|||
struct MemoryCheck {
|
||||
static std::atomic<size_t> fake_allocated_memory;
|
||||
bool b {false};
|
||||
bool operator()()
|
||||
bool operator()() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -107,7 +107,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;
|
||||
}
|
||||
|
|
|
@ -239,12 +239,12 @@ TestChain100Setup::~TestChain100Setup()
|
|||
gArgs.ForceSetArg("-segwitheight", "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, sigOpCost, lp);
|
||||
|
|
|
@ -145,8 +145,8 @@ struct TestMemPoolEntryHelper
|
|||
nFee(0), nTime(0), nHeight(1),
|
||||
spendsCoinbase(false), sigOpCost(4) { }
|
||||
|
||||
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; }
|
||||
|
|
|
@ -637,7 +637,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
|
|||
LockPoints lp;
|
||||
m_view.SetBackend(m_viewmempool);
|
||||
|
||||
CCoinsViewCache& coins_cache = ::ChainstateActive().CoinsTip();
|
||||
const CCoinsViewCache& coins_cache = ::ChainstateActive().CoinsTip();
|
||||
// do all inputs exist?
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
if (!coins_cache.HaveCoinInCache(txin.prevout)) {
|
||||
|
|
|
@ -256,7 +256,7 @@ Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransacti
|
|||
errors.push_back(Untranslated("Invalid or non-wallet transaction id"));
|
||||
return Result::MISC_ERROR;
|
||||
}
|
||||
CWalletTx& oldWtx = it->second;
|
||||
const CWalletTx& oldWtx = it->second;
|
||||
|
||||
// make sure the transaction still has no descendants and hasn't been mined in the meantime
|
||||
Result result = PreconditionChecks(wallet, oldWtx, errors);
|
||||
|
|
|
@ -570,7 +570,7 @@ void CWallet::AddToSpends(const uint256& wtxid)
|
|||
{
|
||||
auto it = mapWallet.find(wtxid);
|
||||
assert(it != mapWallet.end());
|
||||
CWalletTx& thisTx = it->second;
|
||||
const CWalletTx& thisTx = it->second;
|
||||
if (thisTx.IsCoinBase()) // Coinbases don't spend anything!
|
||||
return;
|
||||
|
||||
|
@ -1054,7 +1054,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
|
|||
// Can't mark abandoned if confirmed or in mempool
|
||||
auto it = mapWallet.find(hashTx);
|
||||
assert(it != mapWallet.end());
|
||||
CWalletTx& origtx = it->second;
|
||||
const CWalletTx& origtx = it->second;
|
||||
if (origtx.GetDepthInMainChain() != 0 || origtx.InMempool()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2709,7 +2709,7 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uin
|
|||
return locktime;
|
||||
}
|
||||
|
||||
OutputType CWallet::TransactionChangeType(const Optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend)
|
||||
OutputType CWallet::TransactionChangeType(const Optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const
|
||||
{
|
||||
// If -changetype is specified, always use that change type.
|
||||
if (change_type) {
|
||||
|
|
|
@ -930,7 +930,7 @@ public:
|
|||
Balance GetBalance(int min_depth = 0, bool avoid_reuse = true) const;
|
||||
CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
|
||||
|
||||
OutputType TransactionChangeType(const Optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend);
|
||||
OutputType TransactionChangeType(const Optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;
|
||||
|
||||
/**
|
||||
* Insert additional inputs into the transaction by
|
||||
|
|
Loading…
Add table
Reference in a new issue