Merge branch 'limitfree' of /Users/gavin/src/integration_btc
This commit is contained in:
commit
2abd56f428
1 changed files with 20 additions and 10 deletions
30
main.cpp
30
main.cpp
|
@ -742,19 +742,29 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
|
||||||
if (nFees < GetMinFee(1000))
|
if (nFees < GetMinFee(1000))
|
||||||
return error("AcceptToMemoryPool() : not enough fees");
|
return error("AcceptToMemoryPool() : not enough fees");
|
||||||
|
|
||||||
// Limit free transactions per 10 minutes
|
// Continuously rate-limit free transactions
|
||||||
if (nFees < CENT && GetBoolArg("-limitfreerelay"))
|
// This mitigates 'penny-flooding' -- sending thousands of free transactions just to
|
||||||
|
// be annoying or make other's transactions take longer to confirm.
|
||||||
|
if (nFees < CENT)
|
||||||
{
|
{
|
||||||
static int64 nNextReset;
|
static CCriticalSection cs;
|
||||||
static int64 nFreeCount;
|
static double dFreeCount;
|
||||||
if (GetTime() > nNextReset)
|
static int64 nLastTime;
|
||||||
|
int64 nNow = GetTime();
|
||||||
|
|
||||||
|
CRITICAL_BLOCK(cs)
|
||||||
{
|
{
|
||||||
nNextReset = GetTime() + 10 * 60;
|
// Use an exponentially decaying ~10-minute window:
|
||||||
nFreeCount = 0;
|
dFreeCount *= pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime));
|
||||||
}
|
nLastTime = nNow;
|
||||||
if (nFreeCount > 150000 && !IsFromMe())
|
// -limitfreerelay unit is thousand-bytes-per-minute
|
||||||
|
// At default rate it would take over a month to fill 1GB
|
||||||
|
if (dFreeCount > GetArg("-limitfreerelay", 15)*10*1000 && !IsFromMe())
|
||||||
return error("AcceptToMemoryPool() : free transaction rejected by rate limiter");
|
return error("AcceptToMemoryPool() : free transaction rejected by rate limiter");
|
||||||
nFreeCount += nSize;
|
if (fDebug)
|
||||||
|
printf("Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
|
||||||
|
dFreeCount += nSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue