Skip to content

Commit

Permalink
Merge pull request #677 from luke-jr/minfee_modes
Browse files Browse the repository at this point in the history
API: GetMinFee modes
  • Loading branch information
gavinandresen committed Dec 20, 2011
2 parents 67a5450 + 319bb04 commit bd33c24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
return error("AcceptToMemoryPool() : transaction with out-of-bounds SigOpCount");

// 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");

// Continuously rate-limit free transactions
Expand Down Expand Up @@ -2959,7 +2959,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)

// Transaction fee required depends on block size
bool fAllowFree = (nBlockSize + nTxSize < 4000 || CTransaction::AllowFree(dPriority));
int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree, true);
int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree, GMF_BLOCK);

// Connecting shouldn't fail due to dependency on other memory pool transactions
// because we're already processing them in order of dependency
Expand Down
11 changes: 9 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ class CTxOut



enum GetMinFee_mode
{
GMF_BLOCK,
GMF_RELAY,
GMF_SEND,
};

//
// The basic transaction that is broadcasted on the network and contained in
// blocks. A transaction can contain multiple inputs and outputs.
Expand Down Expand Up @@ -515,10 +522,10 @@ class CTransaction
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
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 nNewBlockSize = nBlockSize + nBytes;
Expand Down
3 changes: 2 additions & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
int64 nChange = nValueIn - nValue - nFeeRet;
// if sub-cent change is required, the fee must be raised to at least MIN_TX_FEE
// or until nChange becomes zero
// NOTE: this depends on the exact behaviour of GetMinFee
if (nFeeRet < MIN_TX_FEE && nChange > 0 && nChange < CENT)
{
int64 nMoveToFee = min(nChange, MIN_TX_FEE - nFeeRet);
Expand Down Expand Up @@ -1055,7 +1056,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
// Check that enough fee is included
int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);
bool fAllowFree = CTransaction::AllowFree(dPriority);
int64 nMinFee = wtxNew.GetMinFee(1, fAllowFree);
int64 nMinFee = wtxNew.GetMinFee(1, fAllowFree, GMF_SEND);
if (nFeeRet < max(nPayFee, nMinFee))
{
nFeeRet = max(nPayFee, nMinFee);
Expand Down

0 comments on commit bd33c24

Please sign in to comment.