Skip to content

Commit bb2bfca

Browse files
committed
fixup Implement block size/sigop cost rules, limits, and GBT support: use int64_t for sigopcost everywhere
1 parent cfb0a83 commit bb2bfca

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/consensus/consensus.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
#ifndef BITCOIN_CONSENSUS_CONSENSUS_H
77
#define BITCOIN_CONSENSUS_CONSENSUS_H
88

9+
#include <stdint.h>
10+
911
/** The maximum allowed size for a serialized block, in bytes (only for buffer size limits) */
1012
static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = 4000000;
1113
/** The maximum allowed cost for a block, see BIP 141 (network rule) */
1214
static const unsigned int MAX_BLOCK_COST = 4000000;
1315
/** The maximum allowed size for a block excluding witness data, in bytes (network rule) */
1416
static const unsigned int MAX_BLOCK_BASE_SIZE = 1000000;
1517
/** The maximum allowed number of signature check operations in a block (network rule) */
16-
static const unsigned int MAX_BLOCK_SIGOPS_COST = 80000;
18+
static const int64_t MAX_BLOCK_SIGOPS_COST = 80000;
1719
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
1820
static const int COINBASE_MATURITY = 100;
1921

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
11681168
if (fRequireStandard && !AreInputsStandard(tx, view))
11691169
return state.Invalid(false, REJECT_NONSTANDARD, "bad-txns-nonstandard-inputs");
11701170

1171-
unsigned int nSigOpsCost = GetTransactionSigOpCost(tx, view, STANDARD_SCRIPT_VERIFY_FLAGS);
1171+
int64_t nSigOpsCost = GetTransactionSigOpCost(tx, view, STANDARD_SCRIPT_VERIFY_FLAGS);
11721172

11731173
CAmount nValueOut = tx.GetValueOut();
11741174
CAmount nFees = nValueIn-nValueOut;
@@ -2369,7 +2369,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
23692369
std::vector<int> prevheights;
23702370
CAmount nFees = 0;
23712371
int nInputs = 0;
2372-
unsigned int nSigOpsCost = 0;
2372+
int64_t nSigOpsCost = 0;
23732373
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
23742374
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
23752375
vPos.reserve(block.vtx.size());

src/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
121121
bool fPrintPriority = GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
122122
uint64_t nBlockCost = 4000;
123123
uint64_t nBlockTx = 0;
124-
unsigned int nBlockSigOpsCost = 400;
124+
int64_t nBlockSigOpsCost = 400;
125125
int lastFewTxs = 0;
126126
CAmount nFees = 0;
127127

@@ -231,7 +231,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
231231
if (!IsFinalTx(tx, nHeight, nLockTimeCutoff))
232232
continue;
233233

234-
unsigned int nTxSigOpsCost = iter->GetSigOpCost();
234+
int64_t nTxSigOpsCost = iter->GetSigOpCost();
235235
if (nBlockSigOpsCost + nTxSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
236236
if (nBlockSigOpsCost > MAX_BLOCK_SIGOPS_COST - 8) {
237237
break;

src/txmempool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace std;
2323
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
2424
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
2525
bool poolHasNoInputsOf, CAmount _inChainInputValue,
26-
bool _spendsCoinbase, unsigned int _sigOpsCost, LockPoints lp):
26+
bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp):
2727
tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight),
2828
hadNoDependencies(poolHasNoInputsOf), inChainInputValue(_inChainInputValue),
2929
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
@@ -655,7 +655,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
655655
bool fDependsWait = false;
656656
setEntries setParentCheck;
657657
int64_t parentSizes = 0;
658-
unsigned int parentSigOpCost = 0;
658+
int64_t parentSigOpCost = 0;
659659
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
660660
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
661661
indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
@@ -687,7 +687,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
687687
uint64_t nCountCheck = setAncestors.size() + 1;
688688
uint64_t nSizeCheck = it->GetTxSize();
689689
CAmount nFeesCheck = it->GetModifiedFee();
690-
unsigned int nSigOpCheck = it->GetSigOpCost();
690+
int64_t nSigOpCheck = it->GetSigOpCost();
691691

692692
BOOST_FOREACH(txiter ancestorIt, setAncestors) {
693693
nSizeCheck += ancestorIt->GetTxSize();

src/txmempool.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CTxMemPoolEntry
8484
bool hadNoDependencies; //!< Not dependent on any other txs when it entered the mempool
8585
CAmount inChainInputValue; //!< Sum of all txin values that are already in blockchain
8686
bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
87-
unsigned int sigOpCost; //!< Total sigop cost
87+
int64_t sigOpCost; //!< Total sigop cost
8888
int64_t feeDelta; //!< Used for determining the priority of the transaction for mining in a block
8989
LockPoints lockPoints; //!< Track the height and time at which tx was final
9090

@@ -101,13 +101,13 @@ class CTxMemPoolEntry
101101
uint64_t nCountWithAncestors;
102102
uint64_t nSizeWithAncestors;
103103
CAmount nModFeesWithAncestors;
104-
unsigned int nSigOpCostWithAncestors;
104+
int64_t nSigOpCostWithAncestors;
105105

106106
public:
107107
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
108108
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
109109
bool poolHasNoInputsOf, CAmount _inChainInputValue, bool spendsCoinbase,
110-
unsigned int nSigOpsCost, LockPoints lp);
110+
int64_t nSigOpsCost, LockPoints lp);
111111
CTxMemPoolEntry(const CTxMemPoolEntry& other);
112112

113113
const CTransaction& GetTx() const { return this->tx; }
@@ -121,7 +121,7 @@ class CTxMemPoolEntry
121121
int64_t GetTime() const { return nTime; }
122122
unsigned int GetHeight() const { return entryHeight; }
123123
bool WasClearAtEntry() const { return hadNoDependencies; }
124-
unsigned int GetSigOpCost() const { return sigOpCost; }
124+
int64_t GetSigOpCost() const { return sigOpCost; }
125125
int64_t GetModifiedFee() const { return nFee + feeDelta; }
126126
size_t DynamicMemoryUsage() const { return nUsageSize; }
127127
const LockPoints& GetLockPoints() const { return lockPoints; }
@@ -145,7 +145,7 @@ class CTxMemPoolEntry
145145
uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
146146
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
147147
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
148-
unsigned int GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; }
148+
int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; }
149149
};
150150

151151
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.

0 commit comments

Comments
 (0)