2929int64_t UpdateTime (CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
3030{
3131 int64_t nOldTime = pblock->nTime ;
32- int64_t nNewTime = std::max (pindexPrev->GetMedianTimePast ()+ 1 , GetAdjustedTime ());
32+ int64_t nNewTime = std::max (pindexPrev->GetMedianTimePast () + 1 , GetAdjustedTime ());
3333
34- if (nOldTime < nNewTime)
34+ if (nOldTime < nNewTime) {
3535 pblock->nTime = nNewTime;
36+ }
3637
3738 // Updating time can change work required on testnet:
38- if (consensusParams.fPowAllowMinDifficultyBlocks )
39+ if (consensusParams.fPowAllowMinDifficultyBlocks ) {
3940 pblock->nBits = GetNextWorkRequired (pindexPrev, pblock, consensusParams);
41+ }
4042
4143 return nNewTime - nOldTime;
4244}
@@ -53,7 +55,8 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
5355 block.hashMerkleRoot = BlockMerkleRoot (block);
5456}
5557
56- BlockAssembler::Options::Options () {
58+ BlockAssembler::Options::Options ()
59+ {
5760 blockMinFeeRate = CFeeRate (DEFAULT_BLOCK_MIN_TX_FEE);
5861 nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
5962}
@@ -108,8 +111,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
108111
109112 pblocktemplate.reset (new CBlockTemplate ());
110113
111- if (!pblocktemplate.get ())
114+ if (!pblocktemplate.get ()) {
112115 return nullptr ;
116+ }
113117 CBlock* const pblock = &pblocktemplate->block ; // pointer for convenience
114118
115119 // Add dummy coinbase tx as first transaction
@@ -125,8 +129,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
125129 pblock->nVersion = g_versionbitscache.ComputeBlockVersion (pindexPrev, chainparams.GetConsensus ());
126130 // -regtest only: allow overriding block.nVersion with
127131 // -blockversion=N to test forking scenarios
128- if (chainparams.MineBlocksOnDemand ())
132+ if (chainparams.MineBlocksOnDemand ()) {
129133 pblock->nVersion = gArgs .GetIntArg (" -blockversion" , pblock->nVersion );
134+ }
130135
131136 pblock->nTime = GetAdjustedTime ();
132137 const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast ();
@@ -193,8 +198,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
193198 // Only test txs not already in the block
194199 if (inBlock.count (*iit)) {
195200 testSet.erase (iit++);
196- }
197- else {
201+ } else {
198202 iit++;
199203 }
200204 }
@@ -203,10 +207,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
203207bool BlockAssembler::TestPackage (uint64_t packageSize, int64_t packageSigOpsCost) const
204208{
205209 // TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
206- if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight)
210+ if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
207211 return false ;
208- if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST)
212+ }
213+ if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
209214 return false ;
215+ }
210216 return true ;
211217}
212218
@@ -217,10 +223,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
217223bool BlockAssembler::TestPackageTransactions (const CTxMemPool::setEntries& package) const
218224{
219225 for (CTxMemPool::txiter it : package) {
220- if (!IsFinalTx (it->GetTx (), nHeight, nLockTimeCutoff))
226+ if (!IsFinalTx (it->GetTx (), nHeight, nLockTimeCutoff)) {
221227 return false ;
222- if (!fIncludeWitness && it->GetTx ().HasWitness ())
228+ }
229+ if (!fIncludeWitness && it->GetTx ().HasWitness ()) {
223230 return false ;
231+ }
224232 }
225233 return true ;
226234}
@@ -253,8 +261,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
253261 m_mempool.CalculateDescendants (it, descendants);
254262 // Insert all descendants (not yet in block) into the modified set
255263 for (CTxMemPool::txiter desc : descendants) {
256- if (alreadyAdded.count (desc))
264+ if (alreadyAdded.count (desc)) {
257265 continue ;
266+ }
258267 ++nDescendantsUpdated;
259268 modtxiter mit = mapModifiedTx.find (desc);
260269 if (mit == mapModifiedTx.end ()) {
@@ -280,7 +289,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
280289// guaranteed to fail again, but as a belt-and-suspenders check we put it in
281290// failedTx and avoid re-evaluation, since the re-evaluation would be using
282291// cached size/sigops/fee values that are not actually correct.
283- bool BlockAssembler::SkipMapTxEntry (CTxMemPool::txiter it, indexed_modified_transaction_set & mapModifiedTx, CTxMemPool::setEntries & failedTx)
292+ bool BlockAssembler::SkipMapTxEntry (CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx)
284293{
285294 assert (it != m_mempool.mapTx .end ());
286295 return mapModifiedTx.count (it) || inBlock.count (it) || failedTx.count (it);
@@ -307,7 +316,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
307316// Each time through the loop, we compare the best transaction in
308317// mapModifiedTxs with the next transaction in the mempool to decide what
309318// transaction package to work on next.
310- void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
319+ void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
311320{
312321 // mapModifiedTx will store sorted packages after they are modified
313322 // because some of their txs are already in the block
@@ -423,7 +432,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
423432 std::vector<CTxMemPool::txiter> sortedEntries;
424433 SortForBlock (ancestors, sortedEntries);
425434
426- for (size_t i= 0 ; i< sortedEntries.size (); ++i) {
435+ for (size_t i = 0 ; i < sortedEntries.size (); ++i) {
427436 AddToBlock (sortedEntries[i]);
428437 // Erase from the modified set, if present
429438 mapModifiedTx.erase (sortedEntries[i]);
@@ -440,13 +449,12 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
440449{
441450 // Update nExtraNonce
442451 static uint256 hashPrevBlock;
443- if (hashPrevBlock != pblock->hashPrevBlock )
444- {
452+ if (hashPrevBlock != pblock->hashPrevBlock ) {
445453 nExtraNonce = 0 ;
446454 hashPrevBlock = pblock->hashPrevBlock ;
447455 }
448456 ++nExtraNonce;
449- unsigned int nHeight = pindexPrev->nHeight + 1 ; // Height first in coinbase required for block.version=2
457+ unsigned int nHeight = pindexPrev->nHeight + 1 ; // Height first in coinbase required for block.version=2
450458 CMutableTransaction txCoinbase (*pblock->vtx [0 ]);
451459 txCoinbase.vin [0 ].scriptSig = (CScript () << nHeight << CScriptNum (nExtraNonce));
452460 assert (txCoinbase.vin [0 ].scriptSig .size () <= 100 );
0 commit comments