Skip to content

Commit 011124a

Browse files
committed
Update benchmarking with package statistics
1 parent 42cd8c8 commit 011124a

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/miner.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
179179
// transaction (which in most cases can be a no-op).
180180
fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus());
181181

182-
addPackageTxs();
182+
int nPackagesSelected = 0;
183+
int nDescendantsUpdated = 0;
184+
addPackageTxs(nPackagesSelected, nDescendantsUpdated);
183185

184186
int64_t nTime1 = GetTimeMicros();
185187

@@ -215,7 +217,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
215217
}
216218
int64_t nTime2 = GetTimeMicros();
217219

218-
LogPrint("bench", "CreateNewBlock() packages: %.2fms, validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart));
220+
LogPrint("bench", "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart));
219221

220222
return std::move(pblocktemplate);
221223
}
@@ -289,16 +291,18 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
289291
}
290292
}
291293

292-
void BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded,
294+
int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded,
293295
indexed_modified_transaction_set &mapModifiedTx)
294296
{
297+
int nDescendantsUpdated = 0;
295298
BOOST_FOREACH(const CTxMemPool::txiter it, alreadyAdded) {
296299
CTxMemPool::setEntries descendants;
297300
mempool.CalculateDescendants(it, descendants);
298301
// Insert all descendants (not yet in block) into the modified set
299302
BOOST_FOREACH(CTxMemPool::txiter desc, descendants) {
300303
if (alreadyAdded.count(desc))
301304
continue;
305+
++nDescendantsUpdated;
302306
modtxiter mit = mapModifiedTx.find(desc);
303307
if (mit == mapModifiedTx.end()) {
304308
CTxMemPoolModifiedEntry modEntry(desc);
@@ -311,6 +315,7 @@ void BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alread
311315
}
312316
}
313317
}
318+
return nDescendantsUpdated;
314319
}
315320

316321
// Skip entries in mapTx that are already in a block or are present
@@ -351,7 +356,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, CTxMemP
351356
// Each time through the loop, we compare the best transaction in
352357
// mapModifiedTxs with the next transaction in the mempool to decide what
353358
// transaction package to work on next.
354-
void BlockAssembler::addPackageTxs()
359+
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated)
355360
{
356361
// mapModifiedTx will store sorted packages after they are modified
357362
// because some of their txs are already in the block
@@ -474,8 +479,10 @@ void BlockAssembler::addPackageTxs()
474479
mapModifiedTx.erase(sortedEntries[i]);
475480
}
476481

482+
++nPackagesSelected;
483+
477484
// Update transactions that depend on each of these
478-
UpdatePackagesForAdded(ancestors, mapModifiedTx);
485+
nDescendantsUpdated += UpdatePackagesForAdded(ancestors, mapModifiedTx);
479486
}
480487
}
481488

src/miner.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ class BlockAssembler
180180
void AddToBlock(CTxMemPool::txiter iter);
181181

182182
// Methods for how to add transactions to a block.
183-
/** Add transactions based on feerate including unconfirmed ancestors */
184-
void addPackageTxs();
183+
/** Add transactions based on feerate including unconfirmed ancestors
184+
* Increments nPackagesSelected / nDescendantsUpdated with corresponding
185+
* statistics from the package selection (for logging statistics). */
186+
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated);
185187

186188
// helper functions for addPackageTxs()
187189
/** Remove confirmed (inBlock) entries from given set */
@@ -199,8 +201,9 @@ class BlockAssembler
199201
/** Sort the package in an order that is valid to appear in a block */
200202
void SortForBlock(const CTxMemPool::setEntries& package, CTxMemPool::txiter entry, std::vector<CTxMemPool::txiter>& sortedEntries);
201203
/** Add descendants of given transactions to mapModifiedTx with ancestor
202-
* state updated assuming given transactions are inBlock. */
203-
void UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set &mapModifiedTx);
204+
* state updated assuming given transactions are inBlock. Returns number
205+
* of updated descendants. */
206+
int UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set &mapModifiedTx);
204207
};
205208

206209
/** Modify the extranonce in a block */

0 commit comments

Comments
 (0)