From d73a8920d0960fe5c6498f6c99ad0a0e97eb32dd Mon Sep 17 00:00:00 2001 From: psolstice Date: Sat, 19 Feb 2022 07:30:04 +0300 Subject: [PATCH] Made macOS performance better by removing unnecessary copying of Consensus::Params (#1144) --- src/lelantus.cpp | 4 ++-- src/miner.cpp | 8 ++++---- src/net_processing.cpp | 2 +- src/sigma.cpp | 4 ++-- src/txdb.cpp | 2 +- src/validation.cpp | 2 +- src/wallet/lelantusjoinsplitbuilder.cpp | 2 +- src/wallet/sigmaspendbuilder.cpp | 2 +- src/wallet/wallet.cpp | 4 ++-- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/lelantus.cpp b/src/lelantus.cpp index 926b190109..31f81b093d 100644 --- a/src/lelantus.cpp +++ b/src/lelantus.cpp @@ -900,7 +900,7 @@ bool ConnectBlockLelantus( if (fJustCheck) return true; - auto& params = ::Params().GetConsensus(); + const auto& params = ::Params().GetConsensus(); CHash256 hash; std::vector data(GroupElement::serialize_size); bool updateHash = false; @@ -1472,7 +1472,7 @@ void CLelantusState::GetAnonymitySet( } LelantusCoinGroupInfo &coinGroup = coinGroups[coinGroupID]; - auto params = ::Params().GetConsensus(); + const auto ¶ms = ::Params().GetConsensus(); LOCK(cs_main); int maxHeight = fStartLelantusBlacklist ? (chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1)) : (params.nLelantusFixesStartBlock - 1); diff --git a/src/miner.cpp b/src/miner.cpp index 89c5d57e93..8c5067dcc4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -428,7 +428,7 @@ bool BlockAssembler::TestForBlock(CTxMemPool::txiter iter) // Check transaction against sigma limits if (tx.IsSigmaSpend()) { CAmount spendAmount = sigma::GetSpendAmount(tx); - auto ¶ms = chainparams.GetConsensus(); + const auto ¶ms = chainparams.GetConsensus(); if (tx.vin.size() > params.nMaxSigmaInputPerTransaction || spendAmount > params.nMaxValueSigmaSpendPerTransaction) return false; @@ -444,7 +444,7 @@ bool BlockAssembler::TestForBlock(CTxMemPool::txiter iter) if(tx.IsLelantusJoinSplit()) { CAmount spendAmount = lelantus::GetSpendTransparentAmount(tx); size_t spendNumber = lelantus::GetSpendInputs(tx); - auto ¶ms = chainparams.GetConsensus(); + const auto ¶ms = chainparams.GetConsensus(); if (spendNumber > params.nMaxLelantusInputPerTransaction || spendAmount > params.nMaxValueLelantusSpendPerTransaction) return false; @@ -476,7 +476,7 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter) if(tx.IsLelantusJoinSplit()) { CAmount spendAmount = lelantus::GetSpendTransparentAmount(tx); size_t spendNumber = lelantus::GetSpendInputs(tx); - auto ¶ms = chainparams.GetConsensus(); + const auto ¶ms = chainparams.GetConsensus(); if (spendAmount > params.nMaxValueLelantusSpendPerTransaction) return; @@ -801,7 +801,7 @@ void BlockAssembler::addPriorityTxs() } void BlockAssembler::FillFoundersReward(CMutableTransaction &coinbaseTx, bool fMTP) { - auto ¶ms = chainparams.GetConsensus(); + const auto ¶ms = chainparams.GetConsensus(); CAmount coin = COIN / (fMTP ? params.nMTPRewardReduction : 1); if (nHeight >= params.nSubsidyHalvingFirst && nHeight < params.nSubsidyHalvingFirst + params.nSubsidyHalvingInterval) { diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 5e9f1cfaeb..a8a14a359f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2271,7 +2271,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr txpools.getStemTxPool().size(), txpools.getStemTxPool().DynamicMemoryUsage() / 1000); int64_t nCurrTime = GetTimeMicros(); - auto& consensus = Params().GetConsensus(); + const auto& consensus = Params().GetConsensus(); int64_t nEmbargo = 1000000 * consensus.nDandelionEmbargoMinimum + PoissonNextSend(nCurrTime, consensus.nDandelionEmbargoAvgAdd); pfrom->insertDandelionEmbargo(tx.GetHash(), nEmbargo); diff --git a/src/sigma.cpp b/src/sigma.cpp index 383f95a93e..4212407807 100644 --- a/src/sigma.cpp +++ b/src/sigma.cpp @@ -132,7 +132,7 @@ CAmount GetSpendAmount(const CTransaction& tx) { } bool CheckSigmaBlock(CValidationState &state, const CBlock& block) { - auto& consensus = ::Params().GetConsensus(); + const auto& consensus = ::Params().GetConsensus(); size_t blockSpendsAmount = 0; CAmount blockSpendsValue(0); @@ -1096,7 +1096,7 @@ void CSigmaState::GetAnonymitySet( return; SigmaCoinGroupInfo coinGroup = coinGroups[denomAndId]; - auto params = ::Params().GetConsensus(); + const auto ¶ms = ::Params().GetConsensus(); int maxHeight = fStartSigmaBlacklist ? (chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1)) : (params.nStartSigmaBlacklist - 1); for (CBlockIndex *block = coinGroup.lastBlock; diff --git a/src/txdb.cpp b/src/txdb.cpp index 196c7ef595..ae51fdbed8 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -350,7 +350,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) { bool CBlockTreeDB::LoadBlockIndexGuts(boost::function insertBlockIndex) { - auto consensusParams = Params().GetConsensus(); + const auto &consensusParams = Params().GetConsensus(); std::unique_ptr pcursor(NewIterator()); pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256())); diff --git a/src/validation.cpp b/src/validation.cpp index 8486181a9f..d61fc26377 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -661,7 +661,7 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &state, bool fChe return false; } - auto params = ::Params().GetConsensus(); + const auto ¶ms = ::Params().GetConsensus(); if (tx.IsZerocoinSpend() || tx.IsZerocoinMint()) { if (!isVerifyDB && nHeight >= params.nDisableZerocoinStartBlock) return state.DoS(1, error("Zerocoin is disabled at this point")); diff --git a/src/wallet/lelantusjoinsplitbuilder.cpp b/src/wallet/lelantusjoinsplitbuilder.cpp index 3a0e7696ec..f931ec2037 100644 --- a/src/wallet/lelantusjoinsplitbuilder.cpp +++ b/src/wallet/lelantusjoinsplitbuilder.cpp @@ -184,7 +184,7 @@ CWalletTx LelantusJoinSplitBuilder::Build( spendCoins.clear(); sigmaSpendCoins.clear(); - auto& consensusParams = Params().GetConsensus(); + const auto& consensusParams = Params().GetConsensus(); CAmount changeToMint = 0; std::vector denomChanges; diff --git a/src/wallet/sigmaspendbuilder.cpp b/src/wallet/sigmaspendbuilder.cpp index c86a1cb0f1..cda66d6986 100644 --- a/src/wallet/sigmaspendbuilder.cpp +++ b/src/wallet/sigmaspendbuilder.cpp @@ -136,7 +136,7 @@ CAmount SigmaSpendBuilder::GetInputs(std::vector>& selected.clear(); denomChanges.clear(); - auto& consensusParams = Params().GetConsensus(); + const auto& consensusParams = Params().GetConsensus(); std::list sigmaCoins = pwalletMain->GetAvailableCoins(coinControl); if (!wallet.GetCoinsToSpend(required, selected, denomChanges, sigmaCoins, diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3ce0b3365e..6dee64d9cb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3258,7 +3258,7 @@ bool CWallet::GetCoinsToJoinSplit( { EnsureMintWalletAvailable(); - Consensus::Params consensusParams = Params().GetConsensus(); + const Consensus::Params &consensusParams = Params().GetConsensus(); if (required > consensusParams.nMaxValueLelantusSpendPerTransaction) { throw std::invalid_argument(_("The required amount exceeds spend limit")); @@ -5464,7 +5464,7 @@ std::pair CWallet::EstimateJoinSplitFee( spendCoins.clear(); sigmaSpendCoins.clear(); - auto &consensusParams = Params().GetConsensus(); + const auto &consensusParams = Params().GetConsensus(); CAmount changeToMint = 0; std::vector denomChanges;