Browse Source

GetMinFee takes a mode parameter (GMF_{BLOCK,RELAY,SEND}) instead of fForRelay

0.8
Luke Dashjr 13 years ago
parent
commit
dbbf1d4a48
  1. 4
      src/main.cpp
  2. 11
      src/main.h
  3. 3
      src/wallet.cpp

4
src/main.cpp

@ -419,7 +419,7 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
} }
// Don't accept it if it can't get into a block // Don't accept it if it can't get into a block
if (nFees < GetMinFee(1000, true, true)) if (nFees < GetMinFee(1000, true, GMF_RELAY))
return error("AcceptToMemoryPool() : not enough fees"); return error("AcceptToMemoryPool() : not enough fees");
// Continuously rate-limit free transactions // Continuously rate-limit free transactions
@ -2757,7 +2757,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
// Transaction fee required depends on block size // Transaction fee required depends on block size
bool fAllowFree = (nBlockSize + nTxSize < 4000 || CTransaction::AllowFree(dPriority)); bool fAllowFree = (nBlockSize + nTxSize < 4000 || CTransaction::AllowFree(dPriority));
int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree); int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree, GMF_BLOCK);
// 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

11
src/main.h

@ -387,6 +387,13 @@ public:
enum GetMinFee_mode
{
GMF_BLOCK,
GMF_RELAY,
GMF_SEND,
};
// //
// The basic transaction that is broadcasted on the network and contained in // The basic transaction that is broadcasted on the network and contained in
// blocks. A transaction can contain multiple inputs and outputs. // blocks. A transaction can contain multiple inputs and outputs.
@ -523,10 +530,10 @@ public:
return dPriority > COIN * 144 / 250; return dPriority > COIN * 144 / 250;
} }
int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, bool fForRelay=false) const int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, enum GetMinFee_mode mode=GMF_BLOCK) const
{ {
// Base fee is either MIN_TX_FEE or MIN_RELAY_TX_FEE // Base fee is either MIN_TX_FEE or MIN_RELAY_TX_FEE
int64 nBaseFee = fForRelay ? MIN_RELAY_TX_FEE : MIN_TX_FEE; int64 nBaseFee = (mode == GMF_RELAY) ? MIN_RELAY_TX_FEE : MIN_TX_FEE;
unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK); unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK);
unsigned int nNewBlockSize = nBlockSize + nBytes; unsigned int nNewBlockSize = nBlockSize + nBytes;

3
src/wallet.cpp

@ -931,6 +931,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
int64 nChange = nValueIn - nValue - nFeeRet; int64 nChange = nValueIn - nValue - nFeeRet;
// if sub-cent change is required, the fee must be raised to at least MIN_TX_FEE // if sub-cent change is required, the fee must be raised to at least MIN_TX_FEE
// or until nChange becomes zero // or until nChange becomes zero
// NOTE: this depends on the exact behaviour of GetMinFee
if (nFeeRet < MIN_TX_FEE && nChange > 0 && nChange < CENT) if (nFeeRet < MIN_TX_FEE && nChange > 0 && nChange < CENT)
{ {
int64 nMoveToFee = min(nChange, MIN_TX_FEE - nFeeRet); int64 nMoveToFee = min(nChange, MIN_TX_FEE - nFeeRet);
@ -984,7 +985,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
// 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 = CTransaction::AllowFree(dPriority); bool fAllowFree = CTransaction::AllowFree(dPriority);
int64 nMinFee = wtxNew.GetMinFee(1, fAllowFree); int64 nMinFee = wtxNew.GetMinFee(1, fAllowFree, GMF_SEND);
if (nFeeRet < max(nPayFee, nMinFee)) if (nFeeRet < max(nPayFee, nMinFee))
{ {
nFeeRet = max(nPayFee, nMinFee); nFeeRet = max(nPayFee, nMinFee);

Loading…
Cancel
Save