0

Referring to the function CAmount CFeeRate::GetFee(size_t nBytes_) in feerate.cpp:

If I pass in say 2000 as the nBytes argument, what will this function return as the fee nFee? I don't understand how nSatoshisPerK is defined. Also, curious as to why this is used instead of letting miners determine this fee through selective mining.

CAmount CFeeRate::GetFee(size_t nBytes_) const
{
    assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
    int64_t nSize = int64_t(nBytes_);

    CAmount nFee = nSatoshisPerK * nSize / 1000;

    if (nFee == 0 && nSize != 0) {
        if (nSatoshisPerK > 0)
            nFee = CAmount(1);
        if (nSatoshisPerK < 0)
            nFee = CAmount(-1);
    }

    return nFee;
}
1

If I pass in say 2000 as the nBytes argument, what will this function return as the fee nFee?

It depends on the fee rate that the CFeeRate object represents. The fee rate is denoted in Bitcoin per Kilobyte. So you pass in the number of bytes into GetFee and and calculates the amount in Bitcoin for the fee to be paid for something of size nBytes_.

If, for example, your CFeeRate object represents 0.00020000 Bitcoin per Kilobyte (or 20 satoshis per byte), giving 2000 as nBytes means that your fee will be 2000 * 0.0002 / 1000 = 0.0004 BTC.

I don't understand how nSatoshisPerK is defined.

It is defined at the creation of the object. Whatever created the object specifies the fee rate to use.

Also, curious as to why this is used instead of letting miners determine this fee through selective mining.

This is just an implementation detail, not an actual network thing that specifies the fee rate for everyone to use. CFeeRate is internal to Bitcoin Core and is simply just how fee rates are representing in internal logic. The fee rates themselves are constructed by the fee estimator which calculates fees based upon mined transactions.

  • Ok so this definition CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) in feerate.h looks like the one being used in validation.cpp here: CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);, which would set nSatoshisPerK to DEFAULT_MIN_RELAY_TX_FEE. Is that what you're saying? Also, it seems that this is enforced in validation.cpp I thought these validations were run on all incoming blocks. – JBaczuk Jul 3 '18 at 19:45
  • 1
    There are multiple fee rates used for different purposes. One of them is the minimum relay fee (which is what you are looking at) which is the minimum fee that a transaction must pay in order for it to be accepted to the node's mempool and relayed. Yes. that particular fee rate in validation.cpp sets nSatoshisPerK for that fee rate object to the DEFAULT_MIN_RELAY_TX_FEE. – Andrew Chow Jul 3 '18 at 19:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.