aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-12-12 18:20:36 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-12-12 18:20:36 +0000
commit97ee01ad898b0699c2319a1283313881ef4ba430 (patch)
treed680c26748fc327f3d0e86ddd0ec96a718af4964 /main.cpp
parent82201801336f64ee77851b9eaab9383ee4e442f0 (diff)
downloadbitcoin-97ee01ad898b0699c2319a1283313881ef4ba430.tar.xz
added some DoS limits, removed safe mode
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@199 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/main.cpp b/main.cpp
index 10d482d898..6e7cb3eac8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -571,10 +571,15 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
if ((int64)nLockTime > INT_MAX)
return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet");
- // Rather not work on nonstandard transactions
- if (!IsStandard() || GetSigOpCount() > 2 || ::GetSerializeSize(*this, SER_NETWORK) < 100)
+ // Safety limits
+ unsigned int nSize = ::GetSerializeSize(*this, SER_NETWORK);
+ if (GetSigOpCount() > 2 || nSize < 100)
return error("AcceptToMemoryPool() : nonstandard transaction");
+ // Rather not work on nonstandard transactions
+ if (!IsStandard())
+ return error("AcceptToMemoryPool() : nonstandard transaction type");
+
// Do we already have it?
uint256 hash = GetHash();
CRITICAL_BLOCK(cs_mapTransactions)
@@ -612,14 +617,36 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
}
}
- // Check against previous transactions
- map<uint256, CTxIndex> mapUnused;
- int64 nFees = 0;
- if (fCheckInputs && !ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), pindexBest, nFees, false, false))
+ if (fCheckInputs)
{
- if (pfMissingInputs)
- *pfMissingInputs = true;
- return error("AcceptToMemoryPool() : ConnectInputs failed %s", hash.ToString().substr(0,10).c_str());
+ // Check against previous transactions
+ map<uint256, CTxIndex> mapUnused;
+ int64 nFees = 0;
+ if (!ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), pindexBest, nFees, false, false))
+ {
+ if (pfMissingInputs)
+ *pfMissingInputs = true;
+ return error("AcceptToMemoryPool() : ConnectInputs failed %s", hash.ToString().substr(0,10).c_str());
+ }
+
+ // Don't accept it if it can't get into a block
+ if (nFees < GetMinFee(1000))
+ return error("AcceptToMemoryPool() : not enough fees");
+
+ // Limit free transactions per 10 minutes
+ if (nFees < CENT && GetBoolArg("-limitfreerelay"))
+ {
+ static int64 nNextReset;
+ static int64 nFreeCount;
+ if (GetTime() > nNextReset)
+ {
+ nNextReset = GetTime() + 10 * 60;
+ nFreeCount = 0;
+ }
+ if (nFreeCount > 150000 && !IsFromMe())
+ return error("AcceptToMemoryPool() : free transaction rejected by rate limiter");
+ nFreeCount += nSize;
+ }
}
// Store transaction in memory