Skip to content

Commit

Permalink
Merge pull request namecoin#163 from phelixnmc/limit_txSize
Browse files Browse the repository at this point in the history
Limit tx size to 20kb
  • Loading branch information
phelixbtc committed Aug 27, 2014
2 parents b3ba912 + a21041b commit aefb681
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ CTransaction::AcceptToMemoryPool (DatabaseSet& dbset, bool fCheckInputs,
if (GetSigOpCount() > nSize / 34 || nSize < 100)
return error("AcceptToMemoryPool() : nonstandard transaction");

// Extremely large transactions with lots of inputs can cost the network
// almost as much to process as they cost the sender in fees, because
// computing signature hashes is O(ninputs*txsize). Limiting transactions
// to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks.
if (nSize >= MAX_STANDARD_TX_SIZE)
return error("AcceptToMemoryPool() : transaction too large");

// Rather not work on nonstandard transactions (unless -testnet)
if (!fTestNet && !IsStandard())
return error("AcceptToMemoryPool() : nonstandard transaction type");
Expand Down
6 changes: 6 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ class CHooks;

class CAuxPow;

/** The maximum allowed size for a serialized block, in bytes (network rule) */
static const unsigned int MAX_BLOCK_SIZE = 1000000;
/** The maximum size for a serialized block that we mine, in bytes */
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
/** The maximum size for transactions we're willing to relay/mine */
static const unsigned int MAX_STANDARD_TX_SIZE = 20000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;

static const int64 COIN = 100000000;
static const int64 CENT = 1000000;
static const int64 MIN_TX_FEE = 500000;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW

// Limit size
unsigned int nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK);
if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
if (nBytes >= MAX_STANDARD_TX_SIZE)
return false;
dPriority /= nBytes;

Expand Down

0 comments on commit aefb681

Please sign in to comment.