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,15 +129,12 @@ 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 ();
132- const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast ();
133-
134- nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
135- ? nMedianTimePast
136- : pblock->GetBlockTime ();
137+ m_lock_time_cutoff = pindexPrev->GetMedianTimePast ();
137138
138139 // Decide whether to include witness transactions
139140 // This is only needed in case the witness softfork activation is reverted
@@ -193,8 +194,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
193194 // Only test txs not already in the block
194195 if (inBlock.count (*iit)) {
195196 testSet.erase (iit++);
196- }
197- else {
197+ } else {
198198 iit++;
199199 }
200200 }
@@ -203,10 +203,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
203203bool BlockAssembler::TestPackage (uint64_t packageSize, int64_t packageSigOpsCost) const
204204{
205205 // TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
206- if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight)
206+ if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
207207 return false ;
208- if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST)
208+ }
209+ if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
209210 return false ;
211+ }
210212 return true ;
211213}
212214
@@ -217,10 +219,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
217219bool BlockAssembler::TestPackageTransactions (const CTxMemPool::setEntries& package) const
218220{
219221 for (CTxMemPool::txiter it : package) {
220- if (!IsFinalTx (it->GetTx (), nHeight, nLockTimeCutoff))
222+ if (!IsFinalTx (it->GetTx (), nHeight, m_lock_time_cutoff)) {
221223 return false ;
222- if (!fIncludeWitness && it->GetTx ().HasWitness ())
224+ }
225+ if (!fIncludeWitness && it->GetTx ().HasWitness ()) {
223226 return false ;
227+ }
224228 }
225229 return true ;
226230}
@@ -253,8 +257,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
253257 m_mempool.CalculateDescendants (it, descendants);
254258 // Insert all descendants (not yet in block) into the modified set
255259 for (CTxMemPool::txiter desc : descendants) {
256- if (alreadyAdded.count (desc))
260+ if (alreadyAdded.count (desc)) {
257261 continue ;
262+ }
258263 ++nDescendantsUpdated;
259264 modtxiter mit = mapModifiedTx.find (desc);
260265 if (mit == mapModifiedTx.end ()) {
@@ -280,7 +285,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
280285// guaranteed to fail again, but as a belt-and-suspenders check we put it in
281286// failedTx and avoid re-evaluation, since the re-evaluation would be using
282287// 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)
288+ bool BlockAssembler::SkipMapTxEntry (CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx)
284289{
285290 assert (it != m_mempool.mapTx .end ());
286291 return mapModifiedTx.count (it) || inBlock.count (it) || failedTx.count (it);
@@ -307,7 +312,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
307312// Each time through the loop, we compare the best transaction in
308313// mapModifiedTxs with the next transaction in the mempool to decide what
309314// transaction package to work on next.
310- void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
315+ void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
311316{
312317 // mapModifiedTx will store sorted packages after they are modified
313318 // because some of their txs are already in the block
@@ -423,7 +428,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
423428 std::vector<CTxMemPool::txiter> sortedEntries;
424429 SortForBlock (ancestors, sortedEntries);
425430
426- for (size_t i= 0 ; i< sortedEntries.size (); ++i) {
431+ for (size_t i = 0 ; i < sortedEntries.size (); ++i) {
427432 AddToBlock (sortedEntries[i]);
428433 // Erase from the modified set, if present
429434 mapModifiedTx.erase (sortedEntries[i]);
@@ -440,13 +445,12 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
440445{
441446 // Update nExtraNonce
442447 static uint256 hashPrevBlock;
443- if (hashPrevBlock != pblock->hashPrevBlock )
444- {
448+ if (hashPrevBlock != pblock->hashPrevBlock ) {
445449 nExtraNonce = 0 ;
446450 hashPrevBlock = pblock->hashPrevBlock ;
447451 }
448452 ++nExtraNonce;
449- unsigned int nHeight = pindexPrev->nHeight + 1 ; // Height first in coinbase required for block.version=2
453+ unsigned int nHeight = pindexPrev->nHeight + 1 ; // Height first in coinbase required for block.version=2
450454 CMutableTransaction txCoinbase (*pblock->vtx [0 ]);
451455 txCoinbase.vin [0 ].scriptSig = (CScript () << nHeight << CScriptNum (nExtraNonce));
452456 assert (txCoinbase.vin [0 ].scriptSig .size () <= 100 );
0 commit comments