Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
fees.cpp
Go to the documentation of this file.
1
// Copyright (c) 2020-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <
common/messages.h
>
6
#include <
consensus/amount.h
>
7
#include <
policy/fees/block_policy_estimator.h
>
8
#include <
test/fuzz/FuzzedDataProvider.h
>
9
#include <
test/fuzz/fuzz.h
>
10
#include <
test/fuzz/util.h
>
11
#include <
util/fees.h
>
12
13
#include <cstdint>
14
#include <string>
15
#include <vector>
16
17
using
common::StringForFeeReason
;
18
19
FUZZ_TARGET
(fees)
20
{
21
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
22
const
CFeeRate
minimal_incremental_fee{
ConsumeMoney
(fuzzed_data_provider)};
23
FastRandomContext
rng
{
/*fDeterministic=*/
true
};
24
FeeFilterRounder
fee_filter_rounder{minimal_incremental_fee,
rng
};
25
LIMITED_WHILE
(fuzzed_data_provider.
ConsumeBool
(), 10000) {
26
const
CAmount
current_minimum_fee =
ConsumeMoney
(fuzzed_data_provider);
27
const
CAmount
rounded_fee = fee_filter_rounder.
round
(current_minimum_fee);
28
assert
(
MoneyRange
(rounded_fee));
29
}
30
const
FeeReason
fee_reason = fuzzed_data_provider.
PickValueInArray
({
FeeReason::FEE_RATE_ESTIMATOR
,
FeeReason::MEMPOOL_MIN
,
FeeReason::USER_SPECIFIED
,
FeeReason::FALLBACK
,
FeeReason::REQUIRED
});
31
(void)
StringForFeeReason
(fee_reason);
32
const
BlockPolicyEstimateReason
block_policy_fee_reason = fuzzed_data_provider.
PickValueInArray
({
BlockPolicyEstimateReason::NONE
,
BlockPolicyEstimateReason::HALF_ESTIMATE
,
BlockPolicyEstimateReason::FULL_ESTIMATE
,
BlockPolicyEstimateReason::DOUBLE_ESTIMATE
,
BlockPolicyEstimateReason::CONSERVATIVE
});
33
(void)
StringForBlockPolicyEstimateReason
(block_policy_fee_reason);
34
const
FeeRateEstimatorType
feerate_estimator_type = fuzzed_data_provider.
PickValueInArray
({
FeeRateEstimatorType::AUTO
,
FeeRateEstimatorType::BLOCK_POLICY
,
FeeRateEstimatorType::MEMPOOL_POLICY
});
35
(void)
FeeRateEstimatorTypeToString
(feerate_estimator_type);
36
(void)
FeeRateEstimatorTypeFromString
(fuzzed_data_provider.
ConsumeRandomLengthString
());
37
}
FuzzedDataProvider.h
amount.h
MoneyRange
bool MoneyRange(const CAmount &nValue)
Definition
amount.h:27
CAmount
int64_t CAmount
Amount in satoshis (Can be negative).
Definition
amount.h:12
block_policy_estimator.h
BlockPolicyEstimateReason
BlockPolicyEstimateReason
Definition
block_policy_estimator.h:58
BlockPolicyEstimateReason::CONSERVATIVE
@ CONSERVATIVE
Definition
block_policy_estimator.h:63
BlockPolicyEstimateReason::FULL_ESTIMATE
@ FULL_ESTIMATE
Definition
block_policy_estimator.h:61
BlockPolicyEstimateReason::NONE
@ NONE
Definition
block_policy_estimator.h:59
BlockPolicyEstimateReason::HALF_ESTIMATE
@ HALF_ESTIMATE
Definition
block_policy_estimator.h:60
BlockPolicyEstimateReason::DOUBLE_ESTIMATE
@ DOUBLE_ESTIMATE
Definition
block_policy_estimator.h:62
CFeeRate
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition
feerate.h:32
FastRandomContext
Fast randomness source.
Definition
random.h:386
FeeFilterRounder
Definition
block_policy_estimator.h:322
FeeFilterRounder::round
CAmount round(CAmount currentMinFee) EXCLUSIVE_LOCKS_REQUIRED(!m_insecure_rand_mutex)
Quantize a minimum fee for privacy purpose before broadcast.
Definition
block_policy_estimator.cpp:1138
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeRandomLengthString
std::string ConsumeRandomLengthString(size_t max_length)
Definition
FuzzedDataProvider.h:153
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::PickValueInArray
T PickValueInArray(const T(&array)[size])
Definition
FuzzedDataProvider.h:304
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
LIMITED_WHILE
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition
fuzz.h:22
messages.h
common::StringForFeeReason
std::string StringForFeeReason(FeeReason reason)
Definition
messages.cpp:27
StringForBlockPolicyEstimateReason
std::string StringForBlockPolicyEstimateReason(BlockPolicyEstimateReason reason)
Definition
block_policy_estimator.cpp:52
rng
FastRandomContext rng
Definition
dbwrapper.cpp:413
StringForFeeReason
std::string StringForFeeReason(FeeReason reason)
Definition
messages.cpp:27
ConsumeMoney
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
Definition
util.cpp:29
util.h
FeeRateEstimatorTypeToString
std::string_view FeeRateEstimatorTypeToString(FeeRateEstimatorType feerate_estimator_type)
Definition
fees.cpp:13
FeeRateEstimatorTypeFromString
std::optional< FeeRateEstimatorType > FeeRateEstimatorTypeFromString(std::string_view feerate_estimator_type)
Definition
fees.cpp:27
fees.h
FeeRateEstimatorType
FeeRateEstimatorType
Identifier for fee rate estimator.
Definition
fees.h:37
FeeRateEstimatorType::BLOCK_POLICY
@ BLOCK_POLICY
Definition
fees.h:39
FeeRateEstimatorType::MEMPOOL_POLICY
@ MEMPOOL_POLICY
Definition
fees.h:40
FeeRateEstimatorType::AUTO
@ AUTO
Definition
fees.h:38
FeeReason
FeeReason
Definition
fees.h:25
FeeReason::USER_SPECIFIED
@ USER_SPECIFIED
Definition
fees.h:28
FeeReason::FEE_RATE_ESTIMATOR
@ FEE_RATE_ESTIMATOR
Definition
fees.h:26
FeeReason::REQUIRED
@ REQUIRED
Definition
fees.h:30
FeeReason::FALLBACK
@ FALLBACK
Definition
fees.h:29
FeeReason::MEMPOOL_MIN
@ MEMPOOL_MIN
Definition
fees.h:27
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.18.0