Coverage Report

Created: 2025-09-19 18:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/policy/feerate.h
Line
Count
Source
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_POLICY_FEERATE_H
7
#define BITCOIN_POLICY_FEERATE_H
8
9
#include <consensus/amount.h>
10
#include <serialize.h>
11
#include <util/feefrac.h>
12
13
14
#include <cstdint>
15
#include <string>
16
#include <type_traits>
17
18
const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
19
const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
20
21
/* Used to determine type of fee estimation requested */
22
enum class FeeEstimateMode {
23
    UNSET,        //!< Use default settings based on other criteria
24
    ECONOMICAL,   //!< Force estimateSmartFee to use non-conservative estimates
25
    CONSERVATIVE, //!< Force estimateSmartFee to use conservative estimates
26
    BTC_KVB,      //!< Use BTC/kvB fee rate unit
27
    SAT_VB,       //!< Use sat/vB fee rate unit
28
};
29
30
/**
31
 * Fee rate in satoshis per virtualbyte: CAmount / vB
32
 * the feerate is represented internally as FeeFrac
33
 */
34
class CFeeRate
35
{
36
private:
37
    /** Fee rate in sats/vB (satoshis per N virtualbytes) */
38
    FeePerVSize m_feerate;
39
40
public:
41
    /** Fee rate of 0 satoshis per 0 vB */
42
0
    CFeeRate() = default;
43
    template<std::integral I> // Disallow silent float -> int conversion
44
2.46k
    explicit CFeeRate(const I m_feerate_kvb) : m_feerate(FeePerVSize(m_feerate_kvb, 1000)) {}
_ZN8CFeeRateC2ITkSt8integrallEET_
Line
Count
Source
44
615
    explicit CFeeRate(const I m_feerate_kvb) : m_feerate(FeePerVSize(m_feerate_kvb, 1000)) {}
_ZN8CFeeRateC2ITkSt8integraljEET_
Line
Count
Source
44
1.84k
    explicit CFeeRate(const I m_feerate_kvb) : m_feerate(FeePerVSize(m_feerate_kvb, 1000)) {}
Unexecuted instantiation: _ZN8CFeeRateC2ITkSt8integraliEET_
Unexecuted instantiation: _ZN8CFeeRateC2ITkSt8integralxEET_
45
46
    /**
47
     * Construct a fee rate from a fee in satoshis and a vsize in vB.
48
     *
49
     * Passing any virtual_bytes less than or equal to 0 will result in 0 fee rate per 0 size.
50
     */
51
    CFeeRate(const CAmount& nFeePaid, int32_t virtual_bytes);
52
53
    /**
54
     * Return the fee in satoshis for the given vsize in vbytes.
55
     * If the calculated fee would have fractional satoshis, then the
56
     * returned fee will always be rounded up to the nearest satoshi.
57
     */
58
    CAmount GetFee(int32_t virtual_bytes) const;
59
60
    /**
61
     * Return the fee in satoshis for a vsize of 1000 vbytes
62
     */
63
0
    CAmount GetFeePerK() const { return CAmount(m_feerate.EvaluateFeeDown(1000)); }
64
    friend std::weak_ordering operator<=>(const CFeeRate& a, const CFeeRate& b) noexcept
65
0
    {
66
0
        return FeeRateCompare(a.m_feerate, b.m_feerate);
67
0
    }
68
    friend bool operator==(const CFeeRate& a, const CFeeRate& b) noexcept
69
0
    {
70
0
        return FeeRateCompare(a.m_feerate, b.m_feerate) == std::weak_ordering::equivalent;
71
0
    }
72
0
    CFeeRate& operator+=(const CFeeRate& a) {
73
0
        m_feerate = FeePerVSize(GetFeePerK() + a.GetFeePerK(), 1000);
74
0
        return *this;
75
0
    }
76
    std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
77
0
    friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.m_feerate.fee, f.m_feerate.size); }
78
0
    friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.m_feerate.fee, f.m_feerate.size); }
79
80
0
    SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.m_feerate.fee, obj.m_feerate.size); }
Unexecuted instantiation: _ZN8CFeeRate16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_
Unexecuted instantiation: _ZN8CFeeRate16SerializationOpsI10DataStreamKS_15ActionSerializeEEvRT0_RT_T1_
81
};
82
83
#endif // BITCOIN_POLICY_FEERATE_H