Skip to content

Commit e5a72fe

Browse files
committed
Store the total sig op count of a tx
coming from btc@c49d5bc9e6c97c47c0bd78604b2c393a7e4af097
1 parent 544e619 commit e5a72fe

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

src/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
961961
// itself can contain sigops MAX_TX_SIGOPS is less than
962962
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
963963
// merely non-standard transaction.
964+
unsigned int nSigOps = 0;
964965
if (!hasZcSpendInputs) {
965-
unsigned int nSigOps = GetLegacySigOpCount(tx);
966+
nSigOps = GetLegacySigOpCount(tx);
966967
unsigned int nMaxSigOps = MAX_TX_SIGOPS_CURRENT;
967968
nSigOps += GetP2SHSigOpCount(tx, view);
968969
if(nSigOps > nMaxSigOps)
@@ -989,7 +990,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
989990
}
990991
}
991992

992-
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainHeight, pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbaseOrCoinstake);
993+
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainHeight, pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbaseOrCoinstake, nSigOps);
993994
unsigned int nSize = entry.GetTxSize();
994995

995996
// Don't accept it if it can't get into a block
@@ -1226,7 +1227,7 @@ bool AcceptableInputs(CTxMemPool& pool, CValidationState& state, const CTransact
12261227
break;
12271228
}
12281229
}
1229-
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainHeight, mempool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbaseOrCoinstake);
1230+
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainHeight, mempool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbaseOrCoinstake, nSigOps);
12301231
unsigned int nSize = entry.GetTxSize();
12311232

12321233
// Don't accept it if it can't get into a block

src/test/test_pivx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(CMutableTransaction &tx, CTxMemPo
7777
CAmount inChainValue = hasNoDependencies ? txn.GetValueOut() : 0;
7878

7979
return CTxMemPoolEntry(txn, nFee, nTime, dPriority, nHeight,
80-
hasNoDependencies, inChainValue, spendsCoinbaseOrCoinstake);
80+
hasNoDependencies, inChainValue, spendsCoinbaseOrCoinstake, sigOpCount);
8181
}
8282

8383
[[noreturn]] void Shutdown(void* parg)

src/test/test_pivx.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ struct TestMemPoolEntryHelper
6464
unsigned int nHeight;
6565
bool hadNoDependencies;
6666
bool spendsCoinbaseOrCoinstake;
67+
unsigned int sigOpCount;
6768

6869
TestMemPoolEntryHelper() :
6970
nFee(0), nTime(0), dPriority(0.0), nHeight(1),
70-
hadNoDependencies(false), spendsCoinbaseOrCoinstake(false) { }
71+
hadNoDependencies(false), spendsCoinbaseOrCoinstake(false), sigOpCount(1) { }
7172

7273
CTxMemPoolEntry FromTx(CMutableTransaction &tx, CTxMemPool *pool = NULL);
7374

@@ -78,6 +79,7 @@ struct TestMemPoolEntryHelper
7879
TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
7980
TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; }
8081
TestMemPoolEntryHelper &SpendsCoinbaseOrCoinstake(bool _flag) { spendsCoinbaseOrCoinstake = _flag; return *this; }
82+
TestMemPoolEntryHelper &SigOps(unsigned int _sigops) { sigOpCount = _sigops; return *this; }
8183
};
8284

8385
#endif

src/txmempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
2424
int64_t _nTime, double _entryPriority,
2525
unsigned int _entryHeight, bool poolHasNoInputsOf, CAmount _inChainInputValue,
26-
bool _spendsCoinbaseOrCoinstake) :
27-
tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight), hadNoDependencies(poolHasNoInputsOf), inChainInputValue(_inChainInputValue), spendsCoinbaseOrCoinstake(_spendsCoinbaseOrCoinstake)
26+
bool _spendsCoinbaseOrCoinstake, unsigned int _sigOps) :
27+
tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight), hadNoDependencies(poolHasNoInputsOf), inChainInputValue(_inChainInputValue), spendsCoinbaseOrCoinstake(_spendsCoinbaseOrCoinstake), sigOpCount(_sigOps)
2828
{
2929
nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
3030
nModSize = tx.CalculateModifiedSize(nTxSize);

src/txmempool.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class CTxMemPoolEntry
7272
bool hadNoDependencies; //! Not dependent on any other txs when it entered the mempool
7373
CAmount inChainInputValue; //! Sum of all txin values that are already in blockchain
7474
bool spendsCoinbaseOrCoinstake; //! keep track of transactions that spend a coinbase or a coinstake
75+
unsigned int sigOpCount; //! Legacy sig ops plus P2SH sig op count
7576

7677
// Information about descendants of this transaction that are in the
7778
// mempool; if we remove this transaction we must remove all of these
@@ -85,7 +86,8 @@ class CTxMemPoolEntry
8586
public:
8687
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
8788
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
88-
bool poolHasNoInputsOf, CAmount _inChainInputValue, bool _spendsCoinbaseOrCoinstake);
89+
bool poolHasNoInputsOf, CAmount _inChainInputValue, bool _spendsCoinbaseOrCoinstake,
90+
unsigned int nSigOps);
8991
CTxMemPoolEntry(const CTxMemPoolEntry& other);
9092

9193
const CTransaction& GetTx() const { return this->tx; }
@@ -100,6 +102,7 @@ class CTxMemPoolEntry
100102
unsigned int GetHeight() const { return entryHeight; }
101103
bool HasZerocoins() const { return hasZerocoins; }
102104
bool WasClearAtEntry() const { return hadNoDependencies; }
105+
unsigned int GetSigOpCount() const { return sigOpCount; }
103106
size_t DynamicMemoryUsage() const { return nUsageSize; }
104107

105108
// Adjusts the descendant state, if this entry is not dirty.

0 commit comments

Comments
 (0)