Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: DannyHamilton on May 16, 2013, 10:49:39 PM



Title: Bitcoin-Qt fee calculation. Explain this code for me?
Post by: DannyHamilton on May 16, 2013, 10:49:39 PM
Ok, I just did a pull from git, I'm looking at:
Code:
bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason)
and I'm a bit confused.

I'm sure I must be overlooking something simple, but I just can't seem to see it.  Would someone here mind pointing out what I'm missing?

It is my understanding that the "fee per kilobyte" is only supposed to be enforced by the client when the total size of the transaction exceeds 10 kilobytes, is this right?

Code:
                int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);
                bool fAllowFree = CTransaction::AllowFree(dPriority);
                int64 nMinFee = wtxNew.GetMinFee(1, fAllowFree, GMF_SEND);
                if (nFeeRet < max(nPayFee, nMinFee))
                {
                    nFeeRet = max(nPayFee, nMinFee);
                    continue;
                }

This code doesn't seem to have any sort of "if (int64)nBytes > 10240)" conditional?

It seems to set nPayFee to
Code:
nTransactionFee * (1 + (int64)nBytes / 1000)
regardless of the size of the transaction.

Then it sets:
Code:
nFeeRet = max(nPayFee, nMinFee);
which would seem to indicate that at a minimum the fee will always be nPayFee regardless of the size of the transaction.

Can someone please point out to me where in the code it tests for (int64)nBytes > 10240 ??


Title: Re: Bitcoin-Qt fee calculation. Explain this code for me?
Post by: gmaxwell on May 16, 2013, 11:41:16 PM
It is my understanding that the "fee per kilobyte" is only supposed to be enforced by the client when the total size of the transaction exceeds 10 kilobytes, is this right?
The minimum anti-DOS fee per kb is only enforced for transactions which don't qualify as free (too small output, too large data, too low priority), but a _user configured_ fee per kilobyte applies to all transactions.


Title: Re: Bitcoin-Qt fee calculation. Explain this code for me?
Post by: DannyHamilton on May 16, 2013, 11:55:17 PM
It is my understanding that the "fee per kilobyte" is only supposed to be enforced by the client when the total size of the transaction exceeds 10 kilobytes, is this right?
The minimum anti-DOS fee per kb is only enforced for transactions which don't qualify as free (too small output, too large data, too low priority), but a _user configured_ fee per kilobyte applies to all transactions.

Ah, ok.

So I have to look at GetMinFee to see the anti-DOS fee per kb.  Thanks. I'll check on it and open a new topic if I'm still confused.