Skip to content

Commit

Permalink
Update files
Browse files Browse the repository at this point in the history
  • Loading branch information
janus committed Jul 5, 2024
1 parent 8043a13 commit 27c33db
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 74 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ crypto_libBGL_crypto_base_la_SOURCES = \
crypto/chacha20poly1305.h \
crypto/chacha20poly1305.cpp \
crypto/common.h \
crypto/hex_base.cpp \
crypto/hex_base.h \
crypto/hkdf_sha256_32.cpp \
crypto/hkdf_sha256_32.h \
crypto/hmac_sha256.cpp \
Expand Down
17 changes: 15 additions & 2 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
unsigned int curFarBucket = maxbucketindex;
unsigned int bestFarBucket = maxbucketindex;

// We'll always group buckets into sets that meet sufficientTxVal --
// this ensures that we're using consistent groups between different
// confirmation targets.
double partialNum = 0;

bool foundAnswer = false;
unsigned int bins = unconfTxs.size();
bool newBucketRange = true;
Expand All @@ -275,6 +280,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
}
curFarBucket = bucket;
nConf += confAvg[periodTarget - 1][bucket];
partialNum += txCtAvg[bucket];
totalNum += txCtAvg[bucket];
failNum += failAvg[periodTarget - 1][bucket];
for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++)
Expand All @@ -284,7 +290,14 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
// we can test for success
// (Only count the confirmed data points, so that each confirmation count
// will be looking at the same amount of data and same bucket breaks)
if (totalNum >= sufficientTxVal / (1 - decay)) {

if (partialNum < sufficientTxVal / (1 - decay)) {
// the buckets we've added in this round aren't sufficient
// so keep adding
continue;
} else {
partialNum = 0; // reset for the next range we'll add

double curPct = nConf / (totalNum + failNum + extraNum);

// Check to see if we are no longer getting confirmed at the success rate
Expand Down Expand Up @@ -1086,4 +1099,4 @@ CAmount FeeFilterRounder::round(CAmount currentMinFee)
--it;
}
return static_cast<CAmount>(*it);
}
}
3 changes: 2 additions & 1 deletion src/policy/fees.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static constexpr bool DEFAULT_ACCEPT_STALE_FEE_ESTIMATES{false};
class AutoFile;
class TxConfirmStats;
struct RemovedMempoolTransactionInfo;
struct NewMempoolTransactionInfo;

/* Identifier for each of the 3 different TxConfirmStats which will track
* history over different time horizons. */
Expand Down Expand Up @@ -341,4 +342,4 @@ class FeeFilterRounder
FastRandomContext& insecure_rand GUARDED_BY(m_insecure_rand_mutex);
};

#endif // BGL_POLICY_FEES_H
#endif // BGL_POLICY_FEES_H
2 changes: 1 addition & 1 deletion src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <primitives/transaction.h>

#include <consensus/amount.h>
#include <crypto/hex_base.h>
#include <hash.h>
#include <script/script.h>
#include <serialize.h>
#include <tinyformat.h>
#include <uint256.h>
#include <util/strencodings.h>
#include <util/transaction_identifier.h>

#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void CScheduler::schedule(CScheduler::Function f, std::chrono::steady_clock::tim

void CScheduler::MockForward(std::chrono::seconds delta_seconds)
{
assert(delta_seconds.count() > 0 && delta_seconds < std::chrono::hours{1});
assert(delta_seconds > 0s && delta_seconds <= 1h);

{
LOCK(newTaskMutex);
Expand Down
2 changes: 1 addition & 1 deletion src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <script/script.h>

#include <crypto/common.h>
#include <crypto/hex_base.h>
#include <hash.h>
#include <uint256.h>
#include <util/hash_type.h>
#include <util/strencodings.h>

#include <string>

Expand Down
63 changes: 4 additions & 59 deletions src/util/strencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <span.h>
#include <util/strencodings.h>

#include <crypto/hex_base.h>
#include <span.h>

#include <array>
#include <cassert>
#include <cstring>
Expand Down Expand Up @@ -36,29 +38,6 @@ std::string SanitizeString(std::string_view str, int rule)
return result;
}

const signed char p_util_hexdigit[256] =
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };

signed char HexDigit(char c)
{
return p_util_hexdigit[(unsigned char)c];
}

bool IsHex(std::string_view str)
{
for (char c : str) {
Expand Down Expand Up @@ -466,40 +445,6 @@ std::string Capitalize(std::string str)
return str;
}

namespace {

using ByteAsHex = std::array<char, 2>;

constexpr std::array<ByteAsHex, 256> CreateByteToHexMap()
{
constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

std::array<ByteAsHex, 256> byte_to_hex{};
for (size_t i = 0; i < byte_to_hex.size(); ++i) {
byte_to_hex[i][0] = hexmap[i >> 4];
byte_to_hex[i][1] = hexmap[i & 15];
}
return byte_to_hex;
}

} // namespace

std::string HexStr(const Span<const uint8_t> s)
{
std::string rv(s.size() * 2, '\0');
static constexpr auto byte_to_hex = CreateByteToHexMap();
static_assert(sizeof(byte_to_hex) == 512);

char* it = rv.data();
for (uint8_t v : s) {
std::memcpy(it, byte_to_hex[v].data(), 2);
it += 2;
}

assert(it == rv.data() + rv.size());
return rv;
}

std::optional<uint64_t> ParseByteUnits(std::string_view str, ByteUnit default_multiplier)
{
if (str.empty()) {
Expand Down Expand Up @@ -543,4 +488,4 @@ std::optional<uint64_t> ParseByteUnits(std::string_view str, ByteUnit default_mu
return std::nullopt;
}
return *parsed_num * unit_amount;
}
}
10 changes: 1 addition & 9 deletions src/util/strencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef BGL_UTIL_STRENCODINGS_H
#define BGL_UTIL_STRENCODINGS_H

#include <crypto/hex_base.h> // IWYU pragma: export
#include <span.h>
#include <util/string.h>

Expand Down Expand Up @@ -66,7 +67,6 @@ std::vector<Byte> ParseHex(std::string_view hex_str)
{
return TryParseHex<Byte>(hex_str).value_or(std::vector<Byte>{});
}
signed char HexDigit(char c);
/* Returns true if each character in str is a hex character, and has an even
* number of hex digits.*/
bool IsHex(std::string_view str);
Expand Down Expand Up @@ -231,13 +231,6 @@ std::optional<T> ToIntegral(std::string_view str)
*/
[[nodiscard]] bool ParseUInt64(std::string_view str, uint64_t *out);

/**
* Convert a span of bytes to a lower-case hexadecimal string.
*/
std::string HexStr(const Span<const uint8_t> s);
inline std::string HexStr(const Span<const char> s) { return HexStr(MakeUCharSpan(s)); }
inline std::string HexStr(const Span<const std::byte> s) { return HexStr(MakeUCharSpan(s)); }

/**
* Format a paragraph of text to a fixed width, adding spaces for
* indentation to any added line.
Expand All @@ -260,7 +253,6 @@ bool TimingResistantEqual(const T& a, const T& b)
}

/** Parse number as fixed point according to JSON number syntax.
* See https://json.org/number.gif
* @returns true on success, false on error.
* @note The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger.
*/
Expand Down

0 comments on commit 27c33db

Please sign in to comment.