29
29
int64_t UpdateTime (CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
30
30
{
31
31
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 ());
33
33
34
- if (nOldTime < nNewTime)
34
+ if (nOldTime < nNewTime) {
35
35
pblock->nTime = nNewTime;
36
+ }
36
37
37
38
// Updating time can change work required on testnet:
38
- if (consensusParams.fPowAllowMinDifficultyBlocks )
39
+ if (consensusParams.fPowAllowMinDifficultyBlocks ) {
39
40
pblock->nBits = GetNextWorkRequired (pindexPrev, pblock, consensusParams);
41
+ }
40
42
41
43
return nNewTime - nOldTime;
42
44
}
@@ -53,7 +55,8 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
53
55
block.hashMerkleRoot = BlockMerkleRoot (block);
54
56
}
55
57
56
- BlockAssembler::Options::Options () {
58
+ BlockAssembler::Options::Options ()
59
+ {
57
60
blockMinFeeRate = CFeeRate (DEFAULT_BLOCK_MIN_TX_FEE);
58
61
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
59
62
}
@@ -108,8 +111,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
108
111
109
112
pblocktemplate.reset (new CBlockTemplate ());
110
113
111
- if (!pblocktemplate.get ())
114
+ if (!pblocktemplate.get ()) {
112
115
return nullptr ;
116
+ }
113
117
CBlock* const pblock = &pblocktemplate->block ; // pointer for convenience
114
118
115
119
// Add dummy coinbase tx as first transaction
@@ -125,8 +129,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
125
129
pblock->nVersion = g_versionbitscache.ComputeBlockVersion (pindexPrev, chainparams.GetConsensus ());
126
130
// -regtest only: allow overriding block.nVersion with
127
131
// -blockversion=N to test forking scenarios
128
- if (chainparams.MineBlocksOnDemand ())
132
+ if (chainparams.MineBlocksOnDemand ()) {
129
133
pblock->nVersion = gArgs .GetIntArg (" -blockversion" , pblock->nVersion );
134
+ }
130
135
131
136
pblock->nTime = GetAdjustedTime ();
132
137
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast ();
@@ -193,8 +198,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
193
198
// Only test txs not already in the block
194
199
if (inBlock.count (*iit)) {
195
200
testSet.erase (iit++);
196
- }
197
- else {
201
+ } else {
198
202
iit++;
199
203
}
200
204
}
@@ -203,10 +207,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
203
207
bool BlockAssembler::TestPackage (uint64_t packageSize, int64_t packageSigOpsCost) const
204
208
{
205
209
// 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) {
207
211
return false ;
208
- if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST)
212
+ }
213
+ if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
209
214
return false ;
215
+ }
210
216
return true ;
211
217
}
212
218
@@ -217,10 +223,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
217
223
bool BlockAssembler::TestPackageTransactions (const CTxMemPool::setEntries& package) const
218
224
{
219
225
for (CTxMemPool::txiter it : package) {
220
- if (!IsFinalTx (it->GetTx (), nHeight, nLockTimeCutoff))
226
+ if (!IsFinalTx (it->GetTx (), nHeight, nLockTimeCutoff)) {
221
227
return false ;
222
- if (!fIncludeWitness && it->GetTx ().HasWitness ())
228
+ }
229
+ if (!fIncludeWitness && it->GetTx ().HasWitness ()) {
223
230
return false ;
231
+ }
224
232
}
225
233
return true ;
226
234
}
@@ -253,8 +261,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
253
261
m_mempool.CalculateDescendants (it, descendants);
254
262
// Insert all descendants (not yet in block) into the modified set
255
263
for (CTxMemPool::txiter desc : descendants) {
256
- if (alreadyAdded.count (desc))
264
+ if (alreadyAdded.count (desc)) {
257
265
continue ;
266
+ }
258
267
++nDescendantsUpdated;
259
268
modtxiter mit = mapModifiedTx.find (desc);
260
269
if (mit == mapModifiedTx.end ()) {
@@ -280,7 +289,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
280
289
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
281
290
// failedTx and avoid re-evaluation, since the re-evaluation would be using
282
291
// 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)
284
293
{
285
294
assert (it != m_mempool.mapTx .end ());
286
295
return mapModifiedTx.count (it) || inBlock.count (it) || failedTx.count (it);
@@ -307,7 +316,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
307
316
// Each time through the loop, we compare the best transaction in
308
317
// mapModifiedTxs with the next transaction in the mempool to decide what
309
318
// transaction package to work on next.
310
- void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
319
+ void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
311
320
{
312
321
// mapModifiedTx will store sorted packages after they are modified
313
322
// because some of their txs are already in the block
@@ -423,7 +432,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
423
432
std::vector<CTxMemPool::txiter> sortedEntries;
424
433
SortForBlock (ancestors, sortedEntries);
425
434
426
- for (size_t i= 0 ; i< sortedEntries.size (); ++i) {
435
+ for (size_t i = 0 ; i < sortedEntries.size (); ++i) {
427
436
AddToBlock (sortedEntries[i]);
428
437
// Erase from the modified set, if present
429
438
mapModifiedTx.erase (sortedEntries[i]);
@@ -440,13 +449,12 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
440
449
{
441
450
// Update nExtraNonce
442
451
static uint256 hashPrevBlock;
443
- if (hashPrevBlock != pblock->hashPrevBlock )
444
- {
452
+ if (hashPrevBlock != pblock->hashPrevBlock ) {
445
453
nExtraNonce = 0 ;
446
454
hashPrevBlock = pblock->hashPrevBlock ;
447
455
}
448
456
++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
450
458
CMutableTransaction txCoinbase (*pblock->vtx [0 ]);
451
459
txCoinbase.vin [0 ].scriptSig = (CScript () << nHeight << CScriptNum (nExtraNonce));
452
460
assert (txCoinbase.vin [0 ].scriptSig .size () <= 100 );
0 commit comments