Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: trivial 2024 06 05 #6047

Merged
17 commits merged into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7f39b5a
Merge bitcoin/bitcoin#23635: test: Bump shellcheck version to 0.8.0
fanquake Dec 1, 2021
10828f5
Merge bitcoin/bitcoin#23733: fuzz: Move ISO8601 to one place
Dec 11, 2021
5a31be9
Merge bitcoin/bitcoin#23812: test: fix intermittent failures in p2p_t…
Dec 20, 2021
2ec5940
Merge bitcoin/bitcoin#23532: test: add functional test for -startupno…
Jan 3, 2022
ee9b3cd
Merge bitcoin/bitcoin#23979: test: wait for rather than assert presen…
Jan 5, 2022
72b62ed
Merge bitcoin/bitcoin#23834: wallettool: Check that the dumpfile chec…
laanwj Jan 5, 2022
3fa8158
Merge bitcoin/bitcoin#22317: doc: Highlight DNS requests part in tor.md
achow101 Jan 18, 2022
f5116a7
Merge bitcoin-core/gui#549: refactor: use std::chrono for formatDurat…
hebasto Mar 5, 2022
3cabce6
Merge bitcoin/bitcoin#24472: fuzz: execute each file in dir without f…
Mar 17, 2022
fe56d9b
Merge bitcoin/bitcoin#24698: test: -peerblockfilters without -blockfi…
Mar 31, 2022
57e9b56
Merge bitcoin/bitcoin#24145: mempool: Clear vTxHashes when mapTx is c…
laanwj Apr 6, 2022
7e0474a
Merge bitcoin/bitcoin#24632: add `(none)` in -getinfo `Warnings:` if …
laanwj Apr 13, 2022
e9f5b4b
Merge bitcoin/bitcoin#24213: refactor: use Span in random.*
laanwj Apr 21, 2022
3c44399
Merge bitcoin/bitcoin#24856: lint: Converting lint-assertions.sh to l…
laanwj Apr 25, 2022
d50f0b0
Merge bitcoin/bitcoin#24977: rpc: Explain active and internal in list…
fanquake Apr 26, 2022
6269c6f
Merge bitcoin/bitcoin#25053: Guard `#include <config/bitcoin-config.h>`
fanquake May 3, 2022
76279c1
Merge bitcoin/bitcoin#25149: refactor: Add thread safety annotation t…
May 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/lint/04_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ ${CI_RETRY_EXE} pip3 install vulture==2.3
${CI_RETRY_EXE} pip3 install yq
${CI_RETRY_EXE} pip3 install mypy==0.781

SHELLCHECK_VERSION=v0.7.2
SHELLCHECK_VERSION=v0.8.0
curl -sL "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar --xz -xf - --directory /tmp/
export PATH="/tmp/shellcheck-${SHELLCHECK_VERSION}:${PATH}"
2 changes: 1 addition & 1 deletion contrib/guix/guix-clean
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ check_tools cat mkdir make git guix
#
under_dir() {
local path_residue
path_residue="${2##${1}}"
path_residue="${2##"${1}"}"
if [ -z "$path_residue" ] || [ "$path_residue" = "$2" ]; then
return 1
else
Expand Down
2 changes: 2 additions & 0 deletions doc/tor.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ outgoing connections, but more is possible.
-onion=ip:port Set the proxy server to use for Tor onion services. You do not
need to set this if it's the same as -proxy. You can use -onion=0
to explicitly disable access to onion services.
------------------------------------------------------------------
Note: Only the -proxy option sets the proxy for DNS requests;
with -onion they will not route over Tor, so use -proxy if you
have privacy concerns.
------------------------------------------------------------------

-listen When using -proxy, listening is disabled by default. If you want
to manually configure an onion service (see section 3), you'll
Expand Down
2 changes: 1 addition & 1 deletion src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
{
// Generate random temporary filename
uint16_t randv = 0;
GetRandBytes((unsigned char*)&randv, sizeof(randv));
GetRandBytes({(unsigned char*)&randv, sizeof(randv)});
std::string tmpfn = strprintf("%s.%04x", prefix, randv);

// open temp output file, and associate with CAutoFile
Expand Down
47 changes: 27 additions & 20 deletions src/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
: m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
{
LoadBanlist();
DumpBanlist();
}

BanMan::~BanMan()
{
DumpBanlist();
}

void BanMan::LoadBanlist()
{
LOCK(m_cs_banned);

if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist…").translated);

int64_t n_start = GetTimeMillis();
Expand All @@ -29,13 +42,6 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t
m_banned = {};
m_is_dirty = true;
}

DumpBanlist();
}

BanMan::~BanMan()
{
DumpBanlist();
}

void BanMan::DumpBanlist()
Expand Down Expand Up @@ -183,23 +189,24 @@ void BanMan::GetBanned(banmap_t& banmap)

void BanMan::SweepBanned()
{
AssertLockHeld(m_cs_banned);

int64_t now = GetTime();
bool notify_ui = false;
{
LOCK(m_cs_banned);
banmap_t::iterator it = m_banned.begin();
while (it != m_banned.end()) {
CSubNet sub_net = (*it).first;
CBanEntry ban_entry = (*it).second;
if (!sub_net.IsValid() || now > ban_entry.nBanUntil) {
m_banned.erase(it++);
m_is_dirty = true;
notify_ui = true;
LogPrint(BCLog::NET, "Removed banned node address/subnet: %s\n", sub_net.ToString());
} else
++it;
banmap_t::iterator it = m_banned.begin();
while (it != m_banned.end()) {
CSubNet sub_net = (*it).first;
CBanEntry ban_entry = (*it).second;
if (!sub_net.IsValid() || now > ban_entry.nBanUntil) {
m_banned.erase(it++);
m_is_dirty = true;
notify_ui = true;
LogPrint(BCLog::NET, "Removed banned node address/subnet: %s\n", sub_net.ToString());
} else {
++it;
}
}

// update UI
if (notify_ui && m_client_interface) {
m_client_interface->BannedListChanged();
Expand Down
3 changes: 2 additions & 1 deletion src/banman.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ class BanMan
void DumpBanlist();

private:
void LoadBanlist() EXCLUSIVE_LOCKS_REQUIRED(!m_cs_banned);
bool BannedSetIsDirty();
//!set the "dirty" flag for the banlist
void SetBannedSetDirty(bool dirty = true);
//!clean unused entries (if bantime has expired)
void SweepBanned();
void SweepBanned() EXCLUSIVE_LOCKS_REQUIRED(m_cs_banned);

RecursiveMutex m_cs_banned;
banmap_t m_banned GUARDED_BY(m_cs_banned);
Expand Down
4 changes: 3 additions & 1 deletion src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,9 @@ static void ParseGetInfoResult(UniValue& result)
result_string += "\n";
}

result_string += strprintf("%sWarnings:%s %s", YELLOW, RESET, result["warnings"].getValStr());
const std::string warnings{result["warnings"].getValStr()};
result_string += strprintf("%sWarnings:%s %s", YELLOW, RESET, warnings.empty() ? "(none)" : warnings);

result.setStr(result_string);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bls/bls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void CBLSSecretKey::MakeNewKey()
{
unsigned char buf[SerSize];
while (true) {
GetStrongRandBytes(buf, sizeof(buf));
GetStrongRandBytes({buf, sizeof(buf)});
try {
impl = bls::PrivateKey::FromBytes(bls::Bytes(reinterpret_cast<const uint8_t*>(buf), SerSize));
break;
Expand Down
2 changes: 1 addition & 1 deletion src/bls/bls_ies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void CBLSIESMultiRecipientBlobs::InitEncrypt(size_t count)
{
ephemeralSecretKey.MakeNewKey();
ephemeralPubKey = ephemeralSecretKey.GetPublicKey();
GetStrongRandBytes(ivSeed.begin(), ivSeed.size());
GetStrongRandBytes({ivSeed.begin(), ivSeed.size()});

uint256 iv = ivSeed;
ivVector.resize(count);
Expand Down
2 changes: 1 addition & 1 deletion src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const unsigned int CDBWrapper::OBFUSCATE_KEY_NUM_BYTES = 8;
std::vector<unsigned char> CDBWrapper::CreateObfuscateKey() const
{
std::vector<uint8_t> ret(OBFUSCATE_KEY_NUM_BYTES);
GetRandBytes(ret.data(), OBFUSCATE_KEY_NUM_BYTES);
GetRandBytes(ret);
return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool CKey::Check(const unsigned char *vch) {

void CKey::MakeNewKey(bool fCompressedIn) {
do {
GetStrongRandBytes(keydata.data(), keydata.size());
GetStrongRandBytes(keydata);
} while (!Check(keydata.data()));
fValid = true;
fCompressed = fCompressedIn;
Expand Down Expand Up @@ -242,7 +242,7 @@ bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
}
unsigned char rnd[8];
std::string str = "Bitcoin key verification\n";
GetRandBytes(rnd, sizeof(rnd));
GetRandBytes(rnd);
uint256 hash;
CHash256().Write(MakeUCharSpan(str)).Write(rnd).Finalize(hash);
std::vector<unsigned char> vchSig;
Expand Down Expand Up @@ -406,7 +406,7 @@ void ECC_Start() {
{
// Pass in a random blinding seed to the secp256k1 context.
std::vector<unsigned char, secure_allocator<unsigned char>> vseed(32);
GetRandBytes(vseed.data(), 32);
GetRandBytes(vseed);
bool ret = secp256k1_context_randomize(ctx, vseed.data());
assert(ret);
}
Expand Down
4 changes: 2 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer)
CAddress addrMe = CAddress(CService(), nLocalNodeServices);

uint256 mnauthChallenge;
GetRandBytes(mnauthChallenge.begin(), mnauthChallenge.size());
GetRandBytes({mnauthChallenge.begin(), mnauthChallenge.size()});
pnode.SetSentMNAuthChallenge(mnauthChallenge);

int nProtocolVersion = PROTOCOL_VERSION;
Expand Down Expand Up @@ -5220,7 +5220,7 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::mic
if (pingSend) {
uint64_t nonce = 0;
while (nonce == 0) {
GetRandBytes((unsigned char*)&nonce, sizeof(nonce));
GetRandBytes({(unsigned char*)&nonce, sizeof(nonce)});
}
peer.m_ping_queued = false;
peer.m_ping_start = now;
Expand Down
29 changes: 12 additions & 17 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1676,23 +1676,18 @@ QString ConnectionTypeToQString(ConnectionType conn_type)

QString formatDurationStr(std::chrono::seconds dur)
{
const auto secs = count_seconds(dur);
QStringList strList;
int days = secs / 86400;
int hours = (secs % 86400) / 3600;
int mins = (secs % 3600) / 60;
int seconds = secs % 60;

if (days)
strList.append(QObject::tr("%1 d").arg(days));
if (hours)
strList.append(QObject::tr("%1 h").arg(hours));
if (mins)
strList.append(QObject::tr("%1 m").arg(mins));
if (seconds || (!days && !hours && !mins))
strList.append(QObject::tr("%1 s").arg(seconds));

return strList.join(" ");
using days = std::chrono::duration<int, std::ratio<86400>>; // can remove this line after C++20
const auto d{std::chrono::duration_cast<days>(dur)};
const auto h{std::chrono::duration_cast<std::chrono::hours>(dur - d)};
const auto m{std::chrono::duration_cast<std::chrono::minutes>(dur - d - h)};
const auto s{std::chrono::duration_cast<std::chrono::seconds>(dur - d - h - m)};
QStringList str_list;
if (auto d2{d.count()}) str_list.append(QObject::tr("%1 d").arg(d2));
if (auto h2{h.count()}) str_list.append(QObject::tr("%1 h").arg(h2));
if (auto m2{m.count()}) str_list.append(QObject::tr("%1 m").arg(m2));
const auto s2{s.count()};
if (s2 || str_list.empty()) str_list.append(QObject::tr("%1 s").arg(s2));
return str_list.join(" ");
}

QString formatServicesStr(quint64 mask)
Expand Down
7 changes: 4 additions & 3 deletions src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <logging.h> // for LogPrintf()
#include <randomenv.h>
#include <support/allocators/secure.h>
#include <span.h>
#include <sync.h> // for Mutex
#include <util/time.h> // for GetTimeMicros()

Expand Down Expand Up @@ -582,8 +583,8 @@ static void ProcRand(unsigned char* out, int num, RNGLevel level) noexcept
}
}

void GetRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::FAST); }
void GetStrongRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::SLOW); }
void GetRandBytes(Span<unsigned char> bytes) noexcept { ProcRand(bytes.data(), bytes.size(), RNGLevel::FAST); }
void GetStrongRandBytes(Span<unsigned char> bytes) noexcept { ProcRand(bytes.data(), bytes.size(), RNGLevel::SLOW); }
void RandAddPeriodic() noexcept { ProcRand(nullptr, 0, RNGLevel::PERIODIC); }
void RandAddEvent(const uint32_t event_info) noexcept { GetRNGState().AddEvent(event_info); }

Expand All @@ -602,7 +603,7 @@ int GetRandInt(int nMax) noexcept
uint256 GetRandHash() noexcept
{
uint256 hash;
GetRandBytes((unsigned char*)&hash, sizeof(hash));
GetRandBytes(hash);
return hash;
}

Expand Down
4 changes: 2 additions & 2 deletions src/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
*
* Thread-safe.
*/
void GetRandBytes(unsigned char* buf, int num) noexcept;
void GetRandBytes(Span<unsigned char> bytes) noexcept;
/** Generate a uniform random integer in the range [0..range). Precondition: range > 0 */
uint64_t GetRand(uint64_t nMax) noexcept;
/** Generate a uniform random duration in the range [0..max). Precondition: max.count() > 0 */
Expand Down Expand Up @@ -98,7 +98,7 @@ bool GetRandBool(double rate);
*
* Thread-safe.
*/
void GetStrongRandBytes(unsigned char* buf, int num) noexcept;
void GetStrongRandBytes(Span<unsigned char> bytes) noexcept;

/**
* Gather entropy from various expensive sources, and feed them to the PRNG state.
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool GenerateAuthCookie(std::string *cookie_out)
{
const size_t COOKIE_SIZE = 32;
unsigned char rand_pwd[COOKIE_SIZE];
GetRandBytes(rand_pwd, COOKIE_SIZE);
GetRandBytes(rand_pwd);
std::string cookie = COOKIEAUTH_USER + ":" + HexStr(rand_pwd);

/** the umask determines what permissions are used to create this file -
Expand Down
6 changes: 4 additions & 2 deletions src/shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

#include <shutdown.h>

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif

#include <logging.h>
#include <util/tokenpipe.h>

#include <node/ui_interface.h>
#include <warnings.h>

#include <config/bitcoin-config.h>

#include <assert.h>
#include <atomic>
#ifdef WIN32
Expand Down
Loading
Loading