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,15 +129,12 @@ 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
- 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 ();
137
138
138
139
// Decide whether to include witness transactions
139
140
// This is only needed in case the witness softfork activation is reverted
@@ -193,8 +194,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
193
194
// Only test txs not already in the block
194
195
if (inBlock.count (*iit)) {
195
196
testSet.erase (iit++);
196
- }
197
- else {
197
+ } else {
198
198
iit++;
199
199
}
200
200
}
@@ -203,10 +203,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
203
203
bool BlockAssembler::TestPackage (uint64_t packageSize, int64_t packageSigOpsCost) const
204
204
{
205
205
// 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) {
207
207
return false ;
208
- if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST)
208
+ }
209
+ if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
209
210
return false ;
211
+ }
210
212
return true ;
211
213
}
212
214
@@ -217,10 +219,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
217
219
bool BlockAssembler::TestPackageTransactions (const CTxMemPool::setEntries& package) const
218
220
{
219
221
for (CTxMemPool::txiter it : package) {
220
- if (!IsFinalTx (it->GetTx (), nHeight, nLockTimeCutoff))
222
+ if (!IsFinalTx (it->GetTx (), nHeight, m_lock_time_cutoff)) {
221
223
return false ;
222
- if (!fIncludeWitness && it->GetTx ().HasWitness ())
224
+ }
225
+ if (!fIncludeWitness && it->GetTx ().HasWitness ()) {
223
226
return false ;
227
+ }
224
228
}
225
229
return true ;
226
230
}
@@ -253,8 +257,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
253
257
m_mempool.CalculateDescendants (it, descendants);
254
258
// Insert all descendants (not yet in block) into the modified set
255
259
for (CTxMemPool::txiter desc : descendants) {
256
- if (alreadyAdded.count (desc))
260
+ if (alreadyAdded.count (desc)) {
257
261
continue ;
262
+ }
258
263
++nDescendantsUpdated;
259
264
modtxiter mit = mapModifiedTx.find (desc);
260
265
if (mit == mapModifiedTx.end ()) {
@@ -280,7 +285,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
280
285
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
281
286
// failedTx and avoid re-evaluation, since the re-evaluation would be using
282
287
// 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)
284
289
{
285
290
assert (it != m_mempool.mapTx .end ());
286
291
return mapModifiedTx.count (it) || inBlock.count (it) || failedTx.count (it);
@@ -307,7 +312,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
307
312
// Each time through the loop, we compare the best transaction in
308
313
// mapModifiedTxs with the next transaction in the mempool to decide what
309
314
// transaction package to work on next.
310
- void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
315
+ void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
311
316
{
312
317
// mapModifiedTx will store sorted packages after they are modified
313
318
// because some of their txs are already in the block
@@ -423,7 +428,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
423
428
std::vector<CTxMemPool::txiter> sortedEntries;
424
429
SortForBlock (ancestors, sortedEntries);
425
430
426
- for (size_t i= 0 ; i< sortedEntries.size (); ++i) {
431
+ for (size_t i = 0 ; i < sortedEntries.size (); ++i) {
427
432
AddToBlock (sortedEntries[i]);
428
433
// Erase from the modified set, if present
429
434
mapModifiedTx.erase (sortedEntries[i]);
@@ -440,13 +445,12 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
440
445
{
441
446
// Update nExtraNonce
442
447
static uint256 hashPrevBlock;
443
- if (hashPrevBlock != pblock->hashPrevBlock )
444
- {
448
+ if (hashPrevBlock != pblock->hashPrevBlock ) {
445
449
nExtraNonce = 0 ;
446
450
hashPrevBlock = pblock->hashPrevBlock ;
447
451
}
448
452
++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
450
454
CMutableTransaction txCoinbase (*pblock->vtx [0 ]);
451
455
txCoinbase.vin [0 ].scriptSig = (CScript () << nHeight << CScriptNum (nExtraNonce));
452
456
assert (txCoinbase.vin [0 ].scriptSig .size () <= 100 );
0 commit comments