diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-12-01 09:32:36 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-12-01 09:30:27 +0100 |
commit | fa6b7adf965e68ec6a46d867966b1d44af98e908 (patch) | |
tree | cbb4ee4aefabce651d0a58ca37a984c963ce9a6e /src/node | |
parent | 9174bcf7da3e15e61dce801ec414a6af01ba44d3 (diff) |
style: Add {} to if-bodies in node/miner
Can be reviewed with --word-diff-regex=. --ignore-all-space
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/miner.cpp | 46 | ||||
-rw-r--r-- | src/node/miner.h | 5 |
2 files changed, 30 insertions, 21 deletions
diff --git a/src/node/miner.cpp b/src/node/miner.cpp index 8778a79f8b..046cc618ce 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -29,14 +29,16 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { int64_t nOldTime = pblock->nTime; - int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime()); - if (nOldTime < nNewTime) + if (nOldTime < nNewTime) { pblock->nTime = nNewTime; + } // Updating time can change work required on testnet: - if (consensusParams.fPowAllowMinDifficultyBlocks) + if (consensusParams.fPowAllowMinDifficultyBlocks) { pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); + } return nNewTime - nOldTime; } @@ -53,7 +55,8 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman) block.hashMerkleRoot = BlockMerkleRoot(block); } -BlockAssembler::Options::Options() { +BlockAssembler::Options::Options() +{ blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE); nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT; } @@ -108,8 +111,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc pblocktemplate.reset(new CBlockTemplate()); - if(!pblocktemplate.get()) + if (!pblocktemplate.get()) { return nullptr; + } CBlock* const pblock = &pblocktemplate->block; // pointer for convenience // Add dummy coinbase tx as first transaction @@ -125,8 +129,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios - if (chainparams.MineBlocksOnDemand()) + if (chainparams.MineBlocksOnDemand()) { pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion); + } pblock->nTime = GetAdjustedTime(); const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); @@ -193,8 +198,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet) // Only test txs not already in the block if (inBlock.count(*iit)) { testSet.erase(iit++); - } - else { + } else { iit++; } } @@ -203,10 +207,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet) bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const { // TODO: switch to weight-based accounting for packages instead of vsize-based accounting. - if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) + if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) { return false; - if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) + } + if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) { return false; + } return true; } @@ -217,10 +223,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const { for (CTxMemPool::txiter it : package) { - if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff)) + if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff)) { return false; - if (!fIncludeWitness && it->GetTx().HasWitness()) + } + if (!fIncludeWitness && it->GetTx().HasWitness()) { return false; + } } return true; } @@ -253,8 +261,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already m_mempool.CalculateDescendants(it, descendants); // Insert all descendants (not yet in block) into the modified set for (CTxMemPool::txiter desc : descendants) { - if (alreadyAdded.count(desc)) + if (alreadyAdded.count(desc)) { continue; + } ++nDescendantsUpdated; modtxiter mit = mapModifiedTx.find(desc); if (mit == mapModifiedTx.end()) { @@ -280,7 +289,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already // guaranteed to fail again, but as a belt-and-suspenders check we put it in // failedTx and avoid re-evaluation, since the re-evaluation would be using // cached size/sigops/fee values that are not actually correct. -bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, CTxMemPool::setEntries &failedTx) +bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx) { assert(it != m_mempool.mapTx.end()); return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it); @@ -307,7 +316,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve // Each time through the loop, we compare the best transaction in // mapModifiedTxs with the next transaction in the mempool to decide what // transaction package to work on next. -void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated) +void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated) { // mapModifiedTx will store sorted packages after they are modified // because some of their txs are already in the block @@ -423,7 +432,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda std::vector<CTxMemPool::txiter> sortedEntries; SortForBlock(ancestors, sortedEntries); - for (size_t i=0; i<sortedEntries.size(); ++i) { + for (size_t i = 0; i < sortedEntries.size(); ++i) { AddToBlock(sortedEntries[i]); // Erase from the modified set, if present mapModifiedTx.erase(sortedEntries[i]); @@ -440,13 +449,12 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned { // Update nExtraNonce static uint256 hashPrevBlock; - if (hashPrevBlock != pblock->hashPrevBlock) - { + if (hashPrevBlock != pblock->hashPrevBlock) { nExtraNonce = 0; hashPrevBlock = pblock->hashPrevBlock; } ++nExtraNonce; - unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2 + unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2 CMutableTransaction txCoinbase(*pblock->vtx[0]); txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)); assert(txCoinbase.vin[0].scriptSig.size() <= 100); diff --git a/src/node/miner.h b/src/node/miner.h index 0e8c02793a..be5e2bbe91 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -80,10 +80,11 @@ struct modifiedentry_iter { // This is sufficient to sort an ancestor package in an order that is valid // to appear in a block. struct CompareTxIterByAncestorCount { - bool operator()(const CTxMemPool::txiter &a, const CTxMemPool::txiter &b) const + bool operator()(const CTxMemPool::txiter& a, const CTxMemPool::txiter& b) const { - if (a->GetCountWithAncestors() != b->GetCountWithAncestors()) + if (a->GetCountWithAncestors() != b->GetCountWithAncestors()) { return a->GetCountWithAncestors() < b->GetCountWithAncestors(); + } return CompareIteratorByHash()(a, b); } }; |