File tree Expand file tree Collapse file tree 4 files changed +16
-22
lines changed Expand file tree Collapse file tree 4 files changed +16
-22
lines changed Original file line number Diff line number Diff line change 7
7
8
8
#include < tinyformat.h>
9
9
10
- CFeeRate::CFeeRate (const CAmount& nFeePaid, size_t nBytes_ )
10
+ CFeeRate::CFeeRate (const CAmount& nFeePaid, uint32_t num_bytes )
11
11
{
12
- assert (nBytes_ <= uint64_t (std::numeric_limits<int64_t >::max ()));
13
- int64_t nSize = int64_t (nBytes_);
12
+ const int64_t nSize{num_bytes};
14
13
15
- if (nSize > 0 )
14
+ if (nSize > 0 ) {
16
15
nSatoshisPerK = nFeePaid * 1000 / nSize;
17
- else
16
+ } else {
18
17
nSatoshisPerK = 0 ;
18
+ }
19
19
}
20
20
21
- CAmount CFeeRate::GetFee (size_t nBytes_ ) const
21
+ CAmount CFeeRate::GetFee (uint32_t num_bytes ) const
22
22
{
23
- assert (nBytes_ <= uint64_t (std::numeric_limits<int64_t >::max ()));
24
- int64_t nSize = int64_t (nBytes_);
23
+ const int64_t nSize{num_bytes};
25
24
26
25
CAmount nFee = nSatoshisPerK * nSize / 1000 ;
27
26
28
27
if (nFee == 0 && nSize != 0 ) {
29
- if (nSatoshisPerK > 0 )
30
- nFee = CAmount (1 );
31
- if (nSatoshisPerK < 0 )
32
- nFee = CAmount (-1 );
28
+ if (nSatoshisPerK > 0 ) nFee = CAmount (1 );
29
+ if (nSatoshisPerK < 0 ) nFee = CAmount (-1 );
33
30
}
34
31
35
32
return nFee;
Original file line number Diff line number Diff line change @@ -39,20 +39,17 @@ class CFeeRate
39
39
// We've previously had bugs creep in from silent double->int conversion...
40
40
static_assert (std::is_integral<I>::value, " CFeeRate should be used without floats" );
41
41
}
42
- /* * Constructor for a fee rate in satoshis per kvB (sat/kvB). The size in bytes must not exceed (2^63 - 1).
42
+ /* * Constructor for a fee rate in satoshis per kvB (sat/kvB).
43
43
*
44
- * Passing an nBytes value of COIN (1e8) returns a fee rate in satoshis per vB (sat/vB),
44
+ * Passing a num_bytes value of COIN (1e8) returns a fee rate in satoshis per vB (sat/vB),
45
45
* e.g. (nFeePaid * 1e8 / 1e3) == (nFeePaid / 1e5),
46
46
* where 1e5 is the ratio to convert from BTC/kvB to sat/vB.
47
- *
48
- * @param[in] nFeePaid CAmount fee rate to construct with
49
- * @param[in] nBytes size_t bytes (units) to construct with
50
47
*/
51
- CFeeRate (const CAmount& nFeePaid, size_t nBytes );
48
+ CFeeRate (const CAmount& nFeePaid, uint32_t num_bytes );
52
49
/* *
53
50
* Return the fee in satoshis for the given size in bytes.
54
51
*/
55
- CAmount GetFee (size_t nBytes ) const ;
52
+ CAmount GetFee (uint32_t num_bytes ) const ;
56
53
/* *
57
54
* Return the fee in satoshis for a size of 1000 bytes
58
55
*/
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(GetFeeTest)
83
83
BOOST_CHECK (CFeeRate (CAmount (26 ), 789 ) == CFeeRate (32 ));
84
84
BOOST_CHECK (CFeeRate (CAmount (27 ), 789 ) == CFeeRate (34 ));
85
85
// Maximum size in bytes, should not crash
86
- CFeeRate (MAX_MONEY, std::numeric_limits<size_t >::max () >> 1 ).GetFeePerK ();
86
+ CFeeRate (MAX_MONEY, std::numeric_limits<uint32_t >::max ()).GetFeePerK ();
87
87
}
88
88
89
89
BOOST_AUTO_TEST_CASE (BinaryOperatorTest)
Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ FUZZ_TARGET(fee_rate)
20
20
const CFeeRate fee_rate{satoshis_per_k};
21
21
22
22
(void )fee_rate.GetFeePerK ();
23
- const size_t bytes = fuzzed_data_provider.ConsumeIntegral <size_t >();
24
- if (!MultiplicationOverflow (static_cast < int64_t >( bytes) , satoshis_per_k) && bytes <= static_cast < uint64_t >(std::numeric_limits< int64_t >:: max () )) {
23
+ const auto bytes = fuzzed_data_provider.ConsumeIntegral <uint32_t >();
24
+ if (!MultiplicationOverflow (int64_t { bytes} , satoshis_per_k)) {
25
25
(void )fee_rate.GetFee (bytes);
26
26
}
27
27
(void )fee_rate.ToString ();
You can’t perform that action at this time.
0 commit comments