Bitcoin ABC  0.22.13
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 zero()
Definition: amount.h:35
std::set< Amount > feeset
Definition: fees.h:37
Definition: amount.h:17
static constexpr Amount SATOSHI
Definition: amount.h:151
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
static const double FEE_SPACING
Spacing of FeeRate buckets.
Definition: fees.h:26
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
FastRandomContext insecure_rand
Definition: fees.h:38
uint32_t rand32() noexcept
Generate a random 32-bit integer.
Definition: random.h:204
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
static const Amount MAX_FEERATE(int64_t(1e7) *SATOSHI)