bitcoin core – GetMinFee() in blockchain.cpp


  "mempoolminfee" : n,       (numeric) Minimum fee rate in BTC/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee
  "minrelaytxfee" : n,       (numeric) Current minimum relay fee for transactions

I am trying to understand how is mempoolminfee calculated. Based on above documentation it should be max of minrelaytxfee and minimum mempool fee. I understand minrelaytxfee is a config option which can be set to anything by user. What is the other fee: ‘minimum mempool fee’?

Looking at the code for getmempoolinfo RPC I found this comment in one header file which explains the function that is used for calculation:

    ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee).GetFeePerK()));

    /** The minimum fee to get into the mempool, which may itself not be enough
      *  for larger-sized transactions.
      *  The incrementalRelayFee policy variable is used to bound the time it
      *  takes the fee rate to go back down all the way to 0. When the feerate
      *  would otherwise be half of this, it is set to 0 instead.

CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const {
    if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
        return CFeeRate(llround(rollingMinimumFeeRate));

    int64_t time = GetTime();
    if (time > lastRollingFeeUpdate + 10) {
        double halflife = ROLLING_FEE_HALFLIFE;
        if (DynamicMemoryUsage() < sizelimit / 4)
            halflife /= 4;
        else if (DynamicMemoryUsage() < sizelimit / 2)
            halflife /= 2;

        rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
        lastRollingFeeUpdate = time;

        if (rollingMinimumFeeRate < (double)incrementalRelayFee.GetFeePerK() / 2) {
            rollingMinimumFeeRate = 0;
            return CFeeRate(0);
    return std::max(CFeeRate(llround(rollingMinimumFeeRate)), incrementalRelayFee);

I still don’t understand what GetMinFee() does. Can someone explain this is in a different way or use some examples?

If I save minrelaytxfee=0.0002 and incrementalrelayfee=0.0003, mempoolminfee is 0.0002 which isn’t max of both.

Source link

Leave a reply