Bitcoin ABC  0.26.3
P2P Digital Currency
fees.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2018-2019 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include <policy/fees.h>
8 
9 #include <feerate.h>
10 
11 FeeFilterRounder::FeeFilterRounder(const CFeeRate &minIncrementalFee) {
12  Amount minFeeLimit = std::max(SATOSHI, minIncrementalFee.GetFeePerK() / 2);
13  feeset.insert(Amount::zero());
14  for (double bucketBoundary = minFeeLimit / SATOSHI;
15  bucketBoundary <= double(MAX_FEERATE / SATOSHI);
16  bucketBoundary *= FEE_SPACING) {
17  feeset.insert(int64_t(bucketBoundary) * SATOSHI);
18  }
19 }
20 
21 Amount FeeFilterRounder::round(const Amount currentMinFee) {
22  auto it = feeset.lower_bound(currentMinFee);
23  if ((it != feeset.begin() && insecure_rand.rand32() % 3 != 0) ||
24  it == feeset.end()) {
25  it--;
26  }
27 
28  return *it;
29 }
static constexpr Amount SATOSHI
Definition: amount.h:143
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
uint32_t rand32() noexcept
Generate a random 32-bit integer.
Definition: random.h:247
FastRandomContext insecure_rand
Definition: fees.h:41
std::set< Amount > feeset
Definition: fees.h:40
FeeFilterRounder(const CFeeRate &minIncrementalFee)
Create new FeeFilterRounder.
Definition: fees.cpp:11
Amount round(const Amount currentMinFee)
Quantize a minimum fee for privacy purpose before broadcast.
Definition: fees.cpp:21
static const double FEE_SPACING
Spacing of FeeRate buckets.
Definition: fees.h:26
static const Amount MAX_FEERATE(int64_t(1e7) *SATOSHI)
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32