require some minimal priority for free transactions to slow down transaction spam

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@185 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
s_nakamoto 2010-11-19 23:37:05 +00:00
parent 683bcb9154
commit f35e21e2e4
3 changed files with 16 additions and 11 deletions

View File

@ -3197,6 +3197,7 @@ void BitcoinMiner()
while (!mapPriority.empty()) while (!mapPriority.empty())
{ {
// Take highest priority transaction off priority queue // Take highest priority transaction off priority queue
double dPriority = (*mapPriority.begin()).first;
CTransaction& tx = *(*mapPriority.begin()).second; CTransaction& tx = *(*mapPriority.begin()).second;
mapPriority.erase(mapPriority.begin()); mapPriority.erase(mapPriority.begin());
@ -3208,8 +3209,9 @@ void BitcoinMiner()
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
continue; continue;
// Transaction fee based on block size // Transaction fee required depends on block size
int64 nMinFee = tx.GetMinFee(nBlockSize); bool fAllowFree = (nBlockSize + nTxSize < 4000 || dPriority > COIN * 144 / 250);
int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree);
// Connecting shouldn't fail due to dependency on other memory pool transactions // Connecting shouldn't fail due to dependency on other memory pool transactions
// because we're already processing them in order of dependency // because we're already processing them in order of dependency

5
main.h
View File

@ -528,13 +528,15 @@ public:
return nValueOut; return nValueOut;
} }
int64 GetMinFee(unsigned int nBlockSize=1) const int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true) const
{ {
// Base fee is 1 cent per kilobyte // Base fee is 1 cent per kilobyte
unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK); unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK);
unsigned int nNewBlockSize = nBlockSize + nBytes; unsigned int nNewBlockSize = nBlockSize + nBytes;
int64 nMinFee = (1 + (int64)nBytes / 1000) * CENT; int64 nMinFee = (1 + (int64)nBytes / 1000) * CENT;
if (fAllowFree)
{
// Transactions under 25K are free as long as block size is under 40K // Transactions under 25K are free as long as block size is under 40K
// (about 11,000bc if made of 50bc inputs) // (about 11,000bc if made of 50bc inputs)
if (nBytes < 25000 && nNewBlockSize < 40000) if (nBytes < 25000 && nNewBlockSize < 40000)
@ -543,6 +545,7 @@ public:
// Transactions under 3K are free as long as block size is under 50K // Transactions under 3K are free as long as block size is under 50K
if (nBytes < 3000 && nNewBlockSize < 50000) if (nBytes < 3000 && nNewBlockSize < 50000)
nMinFee = 0; nMinFee = 0;
}
// To limit dust spam, require a 0.01 fee if any output is less than 0.01 // To limit dust spam, require a 0.01 fee if any output is less than 0.01
if (nMinFee < CENT) if (nMinFee < CENT)

View File

@ -22,7 +22,7 @@ class CDataStream;
class CAutoFile; class CAutoFile;
static const unsigned int MAX_SIZE = 0x02000000; static const unsigned int MAX_SIZE = 0x02000000;
static const int VERSION = 31502; static const int VERSION = 31503;
static const char* pszSubVer = ""; static const char* pszSubVer = "";