Browse Source

SigOp and orphan-tx constants and counts are always unsigned.

Fixes several sign-comparison warnings.
miguelfreitas
Jeff Garzik 13 years ago committed by Jeff Garzik
parent
commit
7bd9c3a3cf
  1. 22
      src/main.cpp
  2. 8
      src/main.h
  3. 10
      src/script.cpp
  4. 4
      src/script.h
  5. 2
      src/test/DoS_tests.cpp

22
src/main.cpp

@ -195,9 +195,9 @@ void static EraseOrphanTx(uint256 hash)
mapOrphanTransactions.erase(hash); mapOrphanTransactions.erase(hash);
} }
int LimitOrphanTxSize(int nMaxOrphans) unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
{ {
int nEvicted = 0; unsigned int nEvicted = 0;
while (mapOrphanTransactions.size() > nMaxOrphans) while (mapOrphanTransactions.size() > nMaxOrphans)
{ {
// Evict a random orphan: // Evict a random orphan:
@ -328,10 +328,10 @@ bool CTransaction::AreInputsStandard(const MapPrevTx& mapInputs) const
return true; return true;
} }
int unsigned int
CTransaction::GetLegacySigOpCount() const CTransaction::GetLegacySigOpCount() const
{ {
int nSigOps = 0; unsigned int nSigOps = 0;
BOOST_FOREACH(const CTxIn& txin, vin) BOOST_FOREACH(const CTxIn& txin, vin)
{ {
nSigOps += txin.scriptSig.GetSigOpCount(false); nSigOps += txin.scriptSig.GetSigOpCount(false);
@ -1079,12 +1079,12 @@ int64 CTransaction::GetValueIn(const MapPrevTx& inputs) const
} }
int CTransaction::GetP2SHSigOpCount(const MapPrevTx& inputs) const unsigned int CTransaction::GetP2SHSigOpCount(const MapPrevTx& inputs) const
{ {
if (IsCoinBase()) if (IsCoinBase())
return 0; return 0;
int nSigOps = 0; unsigned int nSigOps = 0;
for (unsigned int i = 0; i < vin.size(); i++) for (unsigned int i = 0; i < vin.size(); i++)
{ {
const CTxOut& prevout = GetOutputFor(vin[i], inputs); const CTxOut& prevout = GetOutputFor(vin[i], inputs);
@ -1284,7 +1284,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
map<uint256, CTxIndex> mapQueuedChanges; map<uint256, CTxIndex> mapQueuedChanges;
int64 nFees = 0; int64 nFees = 0;
int nSigOps = 0; unsigned int nSigOps = 0;
BOOST_FOREACH(CTransaction& tx, vtx) BOOST_FOREACH(CTransaction& tx, vtx)
{ {
nSigOps += tx.GetLegacySigOpCount(); nSigOps += tx.GetLegacySigOpCount();
@ -1645,7 +1645,7 @@ bool CBlock::CheckBlock() const
if (!tx.CheckTransaction()) if (!tx.CheckTransaction())
return DoS(tx.nDoS, error("CheckBlock() : CheckTransaction failed")); return DoS(tx.nDoS, error("CheckBlock() : CheckTransaction failed"));
int nSigOps = 0; unsigned int nSigOps = 0;
BOOST_FOREACH(const CTransaction& tx, vtx) BOOST_FOREACH(const CTransaction& tx, vtx)
{ {
nSigOps += tx.GetLegacySigOpCount(); nSigOps += tx.GetLegacySigOpCount();
@ -2583,9 +2583,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
AddOrphanTx(vMsg); AddOrphanTx(vMsg);
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded // DoS prevention: do not allow mapOrphanTransactions to grow unbounded
int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS); unsigned int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS);
if (nEvicted > 0) if (nEvicted > 0)
printf("mapOrphan overflow, removed %d tx\n", nEvicted); printf("mapOrphan overflow, removed %u tx\n", nEvicted);
} }
if (tx.nDoS) pfrom->Misbehaving(tx.nDoS); if (tx.nDoS) pfrom->Misbehaving(tx.nDoS);
} }
@ -3209,7 +3209,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
continue; continue;
// Legacy limits on sigOps: // Legacy limits on sigOps:
int nTxSigOps = tx.GetLegacySigOpCount(); unsigned int nTxSigOps = tx.GetLegacySigOpCount();
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
continue; continue;

8
src/main.h

@ -28,8 +28,8 @@ class CNode;
static const unsigned int MAX_BLOCK_SIZE = 1000000; static const unsigned int MAX_BLOCK_SIZE = 1000000;
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2; static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50; static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
static const int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100; static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
static const int64 MIN_TX_FEE = 50000; static const int64 MIN_TX_FEE = 50000;
static const int64 MIN_RELAY_TX_FEE = 10000; static const int64 MIN_RELAY_TX_FEE = 10000;
static const int64 MAX_MONEY = 21000000 * COIN; static const int64 MAX_MONEY = 21000000 * COIN;
@ -495,7 +495,7 @@ public:
@return number of sigops this transaction's outputs will produce when spent @return number of sigops this transaction's outputs will produce when spent
@see CTransaction::FetchInputs @see CTransaction::FetchInputs
*/ */
int GetLegacySigOpCount() const; unsigned int GetLegacySigOpCount() const;
/** Count ECDSA signature operations in pay-to-script-hash inputs. /** Count ECDSA signature operations in pay-to-script-hash inputs.
@ -503,7 +503,7 @@ public:
@return maximum number of sigops required to validate this transaction's inputs @return maximum number of sigops required to validate this transaction's inputs
@see CTransaction::FetchInputs @see CTransaction::FetchInputs
*/ */
int GetP2SHSigOpCount(const MapPrevTx& mapInputs) const; unsigned int GetP2SHSigOpCount(const MapPrevTx& mapInputs) const;
/** Amount of bitcoins spent by this transaction. /** Amount of bitcoins spent by this transaction.
@return sum of all outputs (note: does not include fees) @return sum of all outputs (note: does not include fees)

10
src/script.cpp

@ -1360,9 +1360,9 @@ bool IsStandard(const CScript& scriptPubKey)
} }
int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore) unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore)
{ {
int nResult = 0; unsigned int nResult = 0;
BOOST_FOREACH(const valtype& pubkey, pubkeys) BOOST_FOREACH(const valtype& pubkey, pubkeys)
{ {
CBitcoinAddress address; CBitcoinAddress address;
@ -1566,9 +1566,9 @@ bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsig
return true; return true;
} }
int CScript::GetSigOpCount(bool fAccurate) const unsigned int CScript::GetSigOpCount(bool fAccurate) const
{ {
int n = 0; unsigned int n = 0;
const_iterator pc = begin(); const_iterator pc = begin();
opcodetype lastOpcode = OP_INVALIDOPCODE; opcodetype lastOpcode = OP_INVALIDOPCODE;
while (pc < end()) while (pc < end())
@ -1590,7 +1590,7 @@ int CScript::GetSigOpCount(bool fAccurate) const
return n; return n;
} }
int CScript::GetSigOpCount(const CScript& scriptSig) const unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
{ {
if (!IsPayToScriptHash()) if (!IsPayToScriptHash())
return GetSigOpCount(true); return GetSigOpCount(true);

4
src/script.h

@ -491,11 +491,11 @@ public:
// CHECKMULTISIGs serialized in scriptSigs are // CHECKMULTISIGs serialized in scriptSigs are
// counted more accurately, assuming they are of the form // counted more accurately, assuming they are of the form
// ... OP_N CHECKMULTISIG ... // ... OP_N CHECKMULTISIG ...
int GetSigOpCount(bool fAccurate) const; unsigned int GetSigOpCount(bool fAccurate) const;
// Accurately count sigOps, including sigOps in // Accurately count sigOps, including sigOps in
// pay-to-script-hash transactions: // pay-to-script-hash transactions:
int GetSigOpCount(const CScript& scriptSig) const; unsigned int GetSigOpCount(const CScript& scriptSig) const;
bool IsPayToScriptHash() const; bool IsPayToScriptHash() const;

2
src/test/DoS_tests.cpp

@ -14,7 +14,7 @@
// Tests this internal-to-main.cpp method: // Tests this internal-to-main.cpp method:
extern void AddOrphanTx(const CDataStream& vMsg); extern void AddOrphanTx(const CDataStream& vMsg);
extern int LimitOrphanTxSize(int nMaxOrphans); extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
extern std::map<uint256, CDataStream*> mapOrphanTransactions; extern std::map<uint256, CDataStream*> mapOrphanTransactions;
extern std::multimap<uint256, CDataStream*> mapOrphanTransactionsByPrev; extern std::multimap<uint256, CDataStream*> mapOrphanTransactionsByPrev;

Loading…
Cancel
Save