Store the total sig op count of a tx.

Store sum of legacy and P2SH sig op counts.  This is calculated in AcceptToMemory pool and storing it saves redoing the expensive calculation in block template creation.

(cherry picked from commit c49d5bc9e6c97c47c0bd78604b2c393a7e4af097)
This commit is contained in:
Alex Morcos 2015-10-26 11:08:46 -04:00 committed by Jack Grigg
parent af34647572
commit dde99ca891
6 changed files with 16 additions and 9 deletions

View File

@ -94,7 +94,7 @@ TEST(Mempool, PriorityStatsDoNotCrash) {
unsigned int nHeight = 92045;
double dPriority = view.GetPriority(tx, nHeight);
CTxMemPoolEntry entry(tx, nFees, nTime, dPriority, nHeight, true, false, SPROUT_BRANCH_ID);
CTxMemPoolEntry entry(tx, nFees, nTime, dPriority, nHeight, true, false, 0, SPROUT_BRANCH_ID);
// Check it does not crash (ie. the death test fails)
EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(testPool.addUnchecked(tx.GetHash(), entry), ""), "");

View File

@ -1886,7 +1886,7 @@ bool AcceptToMemoryPool(
// For v1-v4 transactions, we don't yet know if the transaction commits
// to consensusBranchId, but if the entry gets added to the mempool, then
// it has passed ContextualCheckInputs and therefore this is correct.
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), fSpendsCoinbase, consensusBranchId);
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), fSpendsCoinbase, nSigOps, consensusBranchId);
unsigned int nSize = entry.GetTxSize();
// Before zcashd 4.2.0, we had a condition here to always accept a tx if it contained

View File

@ -208,9 +208,11 @@ TestChain100Setup::~TestChain100Setup()
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(CMutableTransaction &tx, CTxMemPool *pool) {
return CTxMemPoolEntry(tx, nFee, nTime, dPriority, nHeight,
pool ? pool->HasNoInputsOf(tx) : hadNoDependencies,
spendsCoinbase, nBranchId);
CTransaction txn(tx);
bool hasNoDependencies = pool ? pool->HasNoInputsOf(tx) : hadNoDependencies;
return CTxMemPoolEntry(txn, nFee, nTime, dPriority, nHeight,
hasNoDependencies, spendsCoinbase, sigOpCount, nBranchId);
}
void Shutdown(void* parg)

View File

@ -75,11 +75,12 @@ struct TestMemPoolEntryHelper
unsigned int nHeight;
bool hadNoDependencies;
bool spendsCoinbase;
unsigned int sigOpCount;
uint32_t nBranchId;
TestMemPoolEntryHelper() :
nFee(0), nTime(0), dPriority(0.0), nHeight(1),
hadNoDependencies(false), spendsCoinbase(false),
hadNoDependencies(false), spendsCoinbase(false), sigOpCount(1),
nBranchId(SPROUT_BRANCH_ID) { }
CTxMemPoolEntry FromTx(CMutableTransaction &tx, CTxMemPool *pool = NULL);
@ -91,6 +92,7 @@ struct TestMemPoolEntryHelper
TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; }
TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
TestMemPoolEntryHelper &SigOps(unsigned int _sigops) { sigOpCount = _sigops; return *this; }
TestMemPoolEntryHelper &BranchId(uint32_t _branchId) { nBranchId = _branchId; return *this; }
};

View File

@ -31,10 +31,10 @@ CTxMemPoolEntry::CTxMemPoolEntry():
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
int64_t _nTime, double _dPriority,
unsigned int _nHeight, bool poolHasNoInputsOf,
bool _spendsCoinbase, uint32_t _nBranchId):
bool _spendsCoinbase, unsigned int _sigOps, uint32_t _nBranchId):
tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority), nHeight(_nHeight),
hadNoDependencies(poolHasNoInputsOf),
spendsCoinbase(_spendsCoinbase), nBranchId(_nBranchId)
spendsCoinbase(_spendsCoinbase), sigOpCount(_sigOps), nBranchId(_nBranchId)
{
nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
nModSize = tx.CalculateModifiedSize(nTxSize);

View File

@ -56,12 +56,14 @@ private:
unsigned int nHeight; //!< Chain height when entering the mempool
bool hadNoDependencies; //!< Not dependent on any other txs when it entered the mempool
bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
unsigned int sigOpCount; //!< Legacy sig ops plus P2SH sig op count
uint32_t nBranchId; //!< Branch ID this transaction is known to commit to, cached for efficiency
public:
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
int64_t _nTime, double _dPriority, unsigned int _nHeight,
bool poolHasNoInputsOf, bool spendsCoinbase, uint32_t nBranchId);
bool poolHasNoInputsOf, bool spendsCoinbase,
unsigned int nSigOps, uint32_t nBranchId);
CTxMemPoolEntry();
CTxMemPoolEntry(const CTxMemPoolEntry& other);
@ -73,6 +75,7 @@ public:
int64_t GetTime() const { return nTime; }
unsigned int GetHeight() const { return nHeight; }
bool WasClearAtEntry() const { return hadNoDependencies; }
unsigned int GetSigOpCount() const { return sigOpCount; }
size_t DynamicMemoryUsage() const { return nUsageSize; }
bool GetSpendsCoinbase() const { return spendsCoinbase; }