Skip to content

Commit c49d5bc

Browse files
committed
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.
1 parent 16f4a6e commit c49d5bc

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
964964
}
965965
}
966966

967-
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbase);
967+
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbase, nSigOps);
968968
unsigned int nSize = entry.GetTxSize();
969969

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

src/test/test_bitcoin.cpp

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

152152
return CTxMemPoolEntry(txn, nFee, nTime, dPriority, nHeight,
153-
hasNoDependencies, inChainValue, spendsCoinbase);
153+
hasNoDependencies, inChainValue, spendsCoinbase, sigOpCount);
154154
}
155155

156156
void Shutdown(void* parg)

src/test/test_bitcoin.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ struct TestMemPoolEntryHelper
6666
unsigned int nHeight;
6767
bool hadNoDependencies;
6868
bool spendsCoinbase;
69-
69+
unsigned int sigOpCount;
70+
7071
TestMemPoolEntryHelper() :
7172
nFee(0), nTime(0), dPriority(0.0), nHeight(1),
72-
hadNoDependencies(false), spendsCoinbase(false) { }
73-
73+
hadNoDependencies(false), spendsCoinbase(false), sigOpCount(1) { }
74+
7475
CTxMemPoolEntry FromTx(CMutableTransaction &tx, CTxMemPool *pool = NULL);
7576

7677
// Change the default value
@@ -80,5 +81,6 @@ struct TestMemPoolEntryHelper
8081
TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
8182
TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; }
8283
TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
84+
TestMemPoolEntryHelper &SigOps(unsigned int _sigops) { sigOpCount = _sigops; return *this; }
8385
};
8486
#endif

src/txmempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ using namespace std;
2222
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
2323
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
2424
bool poolHasNoInputsOf, CAmount _inChainInputValue,
25-
bool _spendsCoinbase):
25+
bool _spendsCoinbase, unsigned int _sigOps):
2626
tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight),
2727
hadNoDependencies(poolHasNoInputsOf), inChainInputValue(_inChainInputValue),
28-
spendsCoinbase(_spendsCoinbase)
28+
spendsCoinbase(_spendsCoinbase), sigOpCount(_sigOps)
2929
{
3030
nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
3131
nModSize = tx.CalculateModifiedSize(nTxSize);

src/txmempool.h

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

7273
// Information about descendants of this transaction that are in the
7374
// mempool; if we remove this transaction we must remove all of these
@@ -81,7 +82,8 @@ class CTxMemPoolEntry
8182
public:
8283
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
8384
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
84-
bool poolHasNoInputsOf, CAmount _inChainInputValue, bool spendsCoinbase);
85+
bool poolHasNoInputsOf, CAmount _inChainInputValue, bool spendsCoinbase,
86+
unsigned int nSigOps);
8587
CTxMemPoolEntry(const CTxMemPoolEntry& other);
8688

8789
const CTransaction& GetTx() const { return this->tx; }
@@ -95,6 +97,7 @@ class CTxMemPoolEntry
9597
int64_t GetTime() const { return nTime; }
9698
unsigned int GetHeight() const { return entryHeight; }
9799
bool WasClearAtEntry() const { return hadNoDependencies; }
100+
unsigned int GetSigOpCount() const { return sigOpCount; }
98101
size_t DynamicMemoryUsage() const { return nUsageSize; }
99102

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

0 commit comments

Comments
 (0)