Refactor fee rules to make them actually readable.
This (nearly) doesn't change fee rules at all: * To make it into the fee transaction area, the dPriority comparison changed from < to <= * We now just ignore transactions > MAX_BLOCK_SIZE/4 instead of doing some calculations to require increasingly large fees as size increases.
This commit is contained in:
parent
d1020b780a
commit
87cce04c17
3 changed files with 15 additions and 29 deletions
35
src/main.cpp
35
src/main.cpp
|
@ -634,31 +634,24 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 GetMinFee(const CTransaction& tx, unsigned int nBlockSize, bool fAllowFree, enum GetMinFee_mode mode)
|
int64 GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode)
|
||||||
{
|
{
|
||||||
// Base fee is either nMinTxFee or nMinRelayTxFee
|
// Base fee is either nMinTxFee or nMinRelayTxFee
|
||||||
int64 nBaseFee = (mode == GMF_RELAY) ? tx.nMinRelayTxFee : tx.nMinTxFee;
|
int64 nBaseFee = (mode == GMF_RELAY) ? tx.nMinRelayTxFee : tx.nMinTxFee;
|
||||||
|
|
||||||
unsigned int nBytes = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
unsigned int nBytes = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
unsigned int nNewBlockSize = nBlockSize + nBytes;
|
|
||||||
int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee;
|
int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee;
|
||||||
|
|
||||||
if (fAllowFree)
|
if (fAllowFree)
|
||||||
{
|
{
|
||||||
if (nBlockSize == 1)
|
// There is a free transaction area in blocks created by most miners,
|
||||||
{
|
// * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000
|
||||||
// Transactions under 10K are free
|
// to be considered to fall into this category
|
||||||
// (about 4500 BTC if made of 50 BTC inputs)
|
// * If we are creating a transaction we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 17000
|
||||||
if (nBytes < 10000)
|
// (= 10000) to be considered safe and assume they can likely make it into this section
|
||||||
|
if (nBytes < (mode == GMF_SEND ? (DEFAULT_BLOCK_PRIORITY_SIZE - 17000) : (DEFAULT_BLOCK_PRIORITY_SIZE - 1000)))
|
||||||
nMinFee = 0;
|
nMinFee = 0;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Free transaction area
|
|
||||||
if (nNewBlockSize < 27000)
|
|
||||||
nMinFee = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// To limit dust spam, require base fee if any output is less than 0.01
|
// To limit dust spam, require base fee if any output is less than 0.01
|
||||||
if (nMinFee < nBaseFee)
|
if (nMinFee < nBaseFee)
|
||||||
|
@ -668,14 +661,6 @@ int64 GetMinFee(const CTransaction& tx, unsigned int nBlockSize, bool fAllowFree
|
||||||
nMinFee = nBaseFee;
|
nMinFee = nBaseFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raise the price as the block approaches full
|
|
||||||
if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2)
|
|
||||||
{
|
|
||||||
if (nNewBlockSize >= MAX_BLOCK_SIZE_GEN)
|
|
||||||
return MAX_MONEY;
|
|
||||||
nMinFee *= MAX_BLOCK_SIZE_GEN / (MAX_BLOCK_SIZE_GEN - nNewBlockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!MoneyRange(nMinFee))
|
if (!MoneyRange(nMinFee))
|
||||||
nMinFee = MAX_MONEY;
|
nMinFee = MAX_MONEY;
|
||||||
return nMinFee;
|
return nMinFee;
|
||||||
|
@ -799,7 +784,7 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fCheckIn
|
||||||
unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
|
||||||
// Don't accept it if it can't get into a block
|
// Don't accept it if it can't get into a block
|
||||||
int64 txMinFee = GetMinFee(tx, 1000, true, GMF_RELAY);
|
int64 txMinFee = GetMinFee(tx, true, GMF_RELAY);
|
||||||
if (fLimitFree && nFees < txMinFee)
|
if (fLimitFree && nFees < txMinFee)
|
||||||
return error("CTxMemPool::accept() : not enough fees %s, %"PRI64d" < %"PRI64d,
|
return error("CTxMemPool::accept() : not enough fees %s, %"PRI64d" < %"PRI64d,
|
||||||
hash.ToString().c_str(),
|
hash.ToString().c_str(),
|
||||||
|
@ -4187,7 +4172,7 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
|
||||||
|
|
||||||
// How much of the block should be dedicated to high-priority transactions,
|
// How much of the block should be dedicated to high-priority transactions,
|
||||||
// included regardless of the fees they pay
|
// included regardless of the fees they pay
|
||||||
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", 27000);
|
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
|
||||||
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
|
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
|
||||||
|
|
||||||
// Minimum block size you want to create; block will be filled with free transactions
|
// Minimum block size you want to create; block will be filled with free transactions
|
||||||
|
@ -4315,7 +4300,7 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
|
||||||
// Prioritize by fee once past the priority size or we run out of high-priority
|
// Prioritize by fee once past the priority size or we run out of high-priority
|
||||||
// transactions:
|
// transactions:
|
||||||
if (!fSortedByFee &&
|
if (!fSortedByFee &&
|
||||||
((nBlockSize + nTxSize >= nBlockPrioritySize) || (dPriority < COIN * 144 / 250)))
|
((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority)))
|
||||||
{
|
{
|
||||||
fSortedByFee = true;
|
fSortedByFee = true;
|
||||||
comparer = TxPriorityCompare(fSortedByFee);
|
comparer = TxPriorityCompare(fSortedByFee);
|
||||||
|
|
|
@ -52,6 +52,8 @@ static const int COINBASE_MATURITY = 100;
|
||||||
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
|
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
|
||||||
/** Maximum number of script-checking threads allowed */
|
/** Maximum number of script-checking threads allowed */
|
||||||
static const int MAX_SCRIPTCHECK_THREADS = 16;
|
static const int MAX_SCRIPTCHECK_THREADS = 16;
|
||||||
|
/** Default amount of block size reserved for high-priority transactions (in bytes) */
|
||||||
|
static const int DEFAULT_BLOCK_PRIORITY_SIZE = 27000;
|
||||||
#ifdef USE_UPNP
|
#ifdef USE_UPNP
|
||||||
static const int fHaveUPnP = true;
|
static const int fHaveUPnP = true;
|
||||||
#else
|
#else
|
||||||
|
@ -262,12 +264,11 @@ struct CDiskTxPos : public CDiskBlockPos
|
||||||
|
|
||||||
enum GetMinFee_mode
|
enum GetMinFee_mode
|
||||||
{
|
{
|
||||||
GMF_BLOCK,
|
|
||||||
GMF_RELAY,
|
GMF_RELAY,
|
||||||
GMF_SEND,
|
GMF_SEND,
|
||||||
};
|
};
|
||||||
|
|
||||||
int64 GetMinFee(const CTransaction& tx, unsigned int nBlockSize = 1, bool fAllowFree = true, enum GetMinFee_mode mode = GMF_BLOCK);
|
int64 GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check transaction inputs, and make sure any
|
// Check transaction inputs, and make sure any
|
||||||
|
|
|
@ -1301,7 +1301,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
|
||||||
// Check that enough fee is included
|
// Check that enough fee is included
|
||||||
int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);
|
int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);
|
||||||
bool fAllowFree = AllowFree(dPriority);
|
bool fAllowFree = AllowFree(dPriority);
|
||||||
int64 nMinFee = GetMinFee(wtxNew, 1, fAllowFree, GMF_SEND);
|
int64 nMinFee = GetMinFee(wtxNew, fAllowFree, GMF_SEND);
|
||||||
if (nFeeRet < max(nPayFee, nMinFee))
|
if (nFeeRet < max(nPayFee, nMinFee))
|
||||||
{
|
{
|
||||||
nFeeRet = max(nPayFee, nMinFee);
|
nFeeRet = max(nPayFee, nMinFee);
|
||||||
|
|
Loading…
Reference in a new issue