Browse Source

Update benchmarking with package statistics

0.15
Suhas Daftuar 8 years ago
parent
commit
011124a2b2
  1. 17
      src/miner.cpp
  2. 11
      src/miner.h

17
src/miner.cpp

@ -179,7 +179,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
// transaction (which in most cases can be a no-op). // transaction (which in most cases can be a no-op).
fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus()); fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus());
addPackageTxs(); int nPackagesSelected = 0;
int nDescendantsUpdated = 0;
addPackageTxs(nPackagesSelected, nDescendantsUpdated);
int64_t nTime1 = GetTimeMicros(); int64_t nTime1 = GetTimeMicros();
@ -215,7 +217,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
} }
int64_t nTime2 = GetTimeMicros(); int64_t nTime2 = GetTimeMicros();
LogPrint("bench", "CreateNewBlock() packages: %.2fms, validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart)); 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));
return std::move(pblocktemplate); return std::move(pblocktemplate);
} }
@ -289,9 +291,10 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
} }
} }
void BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded,
indexed_modified_transaction_set &mapModifiedTx) indexed_modified_transaction_set &mapModifiedTx)
{ {
int nDescendantsUpdated = 0;
BOOST_FOREACH(const CTxMemPool::txiter it, alreadyAdded) { BOOST_FOREACH(const CTxMemPool::txiter it, alreadyAdded) {
CTxMemPool::setEntries descendants; CTxMemPool::setEntries descendants;
mempool.CalculateDescendants(it, descendants); mempool.CalculateDescendants(it, descendants);
@ -299,6 +302,7 @@ void BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alread
BOOST_FOREACH(CTxMemPool::txiter desc, descendants) { BOOST_FOREACH(CTxMemPool::txiter desc, descendants) {
if (alreadyAdded.count(desc)) if (alreadyAdded.count(desc))
continue; continue;
++nDescendantsUpdated;
modtxiter mit = mapModifiedTx.find(desc); modtxiter mit = mapModifiedTx.find(desc);
if (mit == mapModifiedTx.end()) { if (mit == mapModifiedTx.end()) {
CTxMemPoolModifiedEntry modEntry(desc); CTxMemPoolModifiedEntry modEntry(desc);
@ -311,6 +315,7 @@ void BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alread
} }
} }
} }
return nDescendantsUpdated;
} }
// Skip entries in mapTx that are already in a block or are present // 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
// Each time through the loop, we compare the best transaction in // Each time through the loop, we compare the best transaction in
// mapModifiedTxs with the next transaction in the mempool to decide what // mapModifiedTxs with the next transaction in the mempool to decide what
// transaction package to work on next. // transaction package to work on next.
void BlockAssembler::addPackageTxs() void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated)
{ {
// mapModifiedTx will store sorted packages after they are modified // mapModifiedTx will store sorted packages after they are modified
// because some of their txs are already in the block // because some of their txs are already in the block
@ -474,8 +479,10 @@ void BlockAssembler::addPackageTxs()
mapModifiedTx.erase(sortedEntries[i]); mapModifiedTx.erase(sortedEntries[i]);
} }
++nPackagesSelected;
// Update transactions that depend on each of these // Update transactions that depend on each of these
UpdatePackagesForAdded(ancestors, mapModifiedTx); nDescendantsUpdated += UpdatePackagesForAdded(ancestors, mapModifiedTx);
} }
} }

11
src/miner.h

@ -180,8 +180,10 @@ private:
void AddToBlock(CTxMemPool::txiter iter); void AddToBlock(CTxMemPool::txiter iter);
// Methods for how to add transactions to a block. // Methods for how to add transactions to a block.
/** Add transactions based on feerate including unconfirmed ancestors */ /** Add transactions based on feerate including unconfirmed ancestors
void addPackageTxs(); * Increments nPackagesSelected / nDescendantsUpdated with corresponding
* statistics from the package selection (for logging statistics). */
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated);
// helper functions for addPackageTxs() // helper functions for addPackageTxs()
/** Remove confirmed (inBlock) entries from given set */ /** Remove confirmed (inBlock) entries from given set */
@ -199,8 +201,9 @@ private:
/** Sort the package in an order that is valid to appear in a block */ /** Sort the package in an order that is valid to appear in a block */
void SortForBlock(const CTxMemPool::setEntries& package, CTxMemPool::txiter entry, std::vector<CTxMemPool::txiter>& sortedEntries); void SortForBlock(const CTxMemPool::setEntries& package, CTxMemPool::txiter entry, std::vector<CTxMemPool::txiter>& sortedEntries);
/** Add descendants of given transactions to mapModifiedTx with ancestor /** Add descendants of given transactions to mapModifiedTx with ancestor
* state updated assuming given transactions are inBlock. */ * state updated assuming given transactions are inBlock. Returns number
void UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set &mapModifiedTx); * of updated descendants. */
int UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set &mapModifiedTx);
}; };
/** Modify the extranonce in a block */ /** Modify the extranonce in a block */

Loading…
Cancel
Save