Skip to content

Commit d7413ff

Browse files
Merge #6047: backport: trivial 2024 06 05
76279c1 Merge bitcoin#25149: refactor: Add thread safety annotation to `BanMan::SweepBanned()` (MacroFake) 6269c6f Merge bitcoin#25053: Guard `#include <config/bitcoin-config.h>` (fanquake) d50f0b0 Merge bitcoin#24977: rpc: Explain active and internal in listdescriptors (fanquake) 3c44399 Merge bitcoin#24856: lint: Converting lint-assertions.sh to lint-assertions.py (laanwj) e9f5b4b Merge bitcoin#24213: refactor: use Span in random.* (laanwj) 7e0474a Merge bitcoin#24632: add `(none)` in -getinfo `Warnings:` if no warning returned (laanwj) 57e9b56 Merge bitcoin#24145: mempool: Clear vTxHashes when mapTx is cleared (laanwj) fe56d9b Merge bitcoin#24698: test: -peerblockfilters without -blockfilterindex raises an error (MarcoFalke) 3cabce6 Merge bitcoin#24472: fuzz: execute each file in dir without fuzz engine (MarcoFalke) f5116a7 Merge bitcoin-core/gui#549: refactor: use std::chrono for formatDurationStr() helper (Hennadii Stepanov) 3fa8158 Merge bitcoin#22317: doc: Highlight DNS requests part in tor.md (Andrew Chow) 72b62ed Merge bitcoin#23834: wallettool: Check that the dumpfile checksum is the correct size (laanwj) ee9b3cd Merge bitcoin#23979: test: wait for rather than assert presence of file in startupnotify test (MarcoFalke) 2ec5940 Merge bitcoin#23532: test: add functional test for -startupnotify (MarcoFalke) 5a31be9 Merge bitcoin#23812: test: fix intermittent failures in p2p_timeouts.py (MarcoFalke) 10828f5 Merge bitcoin#23733: fuzz: Move ISO8601 to one place (MarcoFalke) 7f39b5a Merge bitcoin#23635: test: Bump shellcheck version to 0.8.0 (fanquake) Pull request description: ## Issue being fixed or feature implemented Trivial batch of backports ## What was done? trivial backports ## How Has This Been Tested? Unit tests ran; waiting on CI ## Breaking Changes ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Top commit has no ACKs. Tree-SHA512: a3f97003e6441468951b827b2c3ea607740e5b9d36b96c2f93e45e7fb4088ecf4d0a2b7038de050ca0e7d61379c364969f4a8caff98ec1cc69016f4114e64c6a
2 parents d441cda + 76279c1 commit d7413ff

37 files changed

+268
-118
lines changed

ci/lint/04_install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ ${CI_RETRY_EXE} pip3 install vulture==2.3
1717
${CI_RETRY_EXE} pip3 install yq
1818
${CI_RETRY_EXE} pip3 install mypy==0.781
1919

20-
SHELLCHECK_VERSION=v0.7.2
20+
SHELLCHECK_VERSION=v0.8.0
2121
curl -sL "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar --xz -xf - --directory /tmp/
2222
export PATH="/tmp/shellcheck-${SHELLCHECK_VERSION}:${PATH}"

contrib/guix/guix-clean

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ check_tools cat mkdir make git guix
3434
#
3535
under_dir() {
3636
local path_residue
37-
path_residue="${2##${1}}"
37+
path_residue="${2##"${1}"}"
3838
if [ -z "$path_residue" ] || [ "$path_residue" = "$2" ]; then
3939
return 1
4040
else

doc/tor.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ outgoing connections, but more is possible.
3535
-onion=ip:port Set the proxy server to use for Tor onion services. You do not
3636
need to set this if it's the same as -proxy. You can use -onion=0
3737
to explicitly disable access to onion services.
38+
------------------------------------------------------------------
3839
Note: Only the -proxy option sets the proxy for DNS requests;
3940
with -onion they will not route over Tor, so use -proxy if you
4041
have privacy concerns.
42+
------------------------------------------------------------------
4143

4244
-listen When using -proxy, listening is disabled by default. If you want
4345
to manually configure an onion service (see section 3), you'll

src/addrdb.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
4242
{
4343
// Generate random temporary filename
4444
uint16_t randv = 0;
45-
GetRandBytes((unsigned char*)&randv, sizeof(randv));
45+
GetRandBytes({(unsigned char*)&randv, sizeof(randv)});
4646
std::string tmpfn = strprintf("%s.%04x", prefix, randv);
4747

4848
// open temp output file, and associate with CAutoFile

src/banman.cpp

+27-20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
1717
: m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
1818
{
19+
LoadBanlist();
20+
DumpBanlist();
21+
}
22+
23+
BanMan::~BanMan()
24+
{
25+
DumpBanlist();
26+
}
27+
28+
void BanMan::LoadBanlist()
29+
{
30+
LOCK(m_cs_banned);
31+
1932
if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist…").translated);
2033

2134
int64_t n_start = GetTimeMillis();
@@ -29,13 +42,6 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t
2942
m_banned = {};
3043
m_is_dirty = true;
3144
}
32-
33-
DumpBanlist();
34-
}
35-
36-
BanMan::~BanMan()
37-
{
38-
DumpBanlist();
3945
}
4046

4147
void BanMan::DumpBanlist()
@@ -183,23 +189,24 @@ void BanMan::GetBanned(banmap_t& banmap)
183189

184190
void BanMan::SweepBanned()
185191
{
192+
AssertLockHeld(m_cs_banned);
193+
186194
int64_t now = GetTime();
187195
bool notify_ui = false;
188-
{
189-
LOCK(m_cs_banned);
190-
banmap_t::iterator it = m_banned.begin();
191-
while (it != m_banned.end()) {
192-
CSubNet sub_net = (*it).first;
193-
CBanEntry ban_entry = (*it).second;
194-
if (!sub_net.IsValid() || now > ban_entry.nBanUntil) {
195-
m_banned.erase(it++);
196-
m_is_dirty = true;
197-
notify_ui = true;
198-
LogPrint(BCLog::NET, "Removed banned node address/subnet: %s\n", sub_net.ToString());
199-
} else
200-
++it;
196+
banmap_t::iterator it = m_banned.begin();
197+
while (it != m_banned.end()) {
198+
CSubNet sub_net = (*it).first;
199+
CBanEntry ban_entry = (*it).second;
200+
if (!sub_net.IsValid() || now > ban_entry.nBanUntil) {
201+
m_banned.erase(it++);
202+
m_is_dirty = true;
203+
notify_ui = true;
204+
LogPrint(BCLog::NET, "Removed banned node address/subnet: %s\n", sub_net.ToString());
205+
} else {
206+
++it;
201207
}
202208
}
209+
203210
// update UI
204211
if (notify_ui && m_client_interface) {
205212
m_client_interface->BannedListChanged();

src/banman.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ class BanMan
8181
void DumpBanlist();
8282

8383
private:
84+
void LoadBanlist() EXCLUSIVE_LOCKS_REQUIRED(!m_cs_banned);
8485
bool BannedSetIsDirty();
8586
//!set the "dirty" flag for the banlist
8687
void SetBannedSetDirty(bool dirty = true);
8788
//!clean unused entries (if bantime has expired)
88-
void SweepBanned();
89+
void SweepBanned() EXCLUSIVE_LOCKS_REQUIRED(m_cs_banned);
8990

9091
RecursiveMutex m_cs_banned;
9192
banmap_t m_banned GUARDED_BY(m_cs_banned);

src/bitcoin-cli.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,9 @@ static void ParseGetInfoResult(UniValue& result)
10481048
result_string += "\n";
10491049
}
10501050

1051-
result_string += strprintf("%sWarnings:%s %s", YELLOW, RESET, result["warnings"].getValStr());
1051+
const std::string warnings{result["warnings"].getValStr()};
1052+
result_string += strprintf("%sWarnings:%s %s", YELLOW, RESET, warnings.empty() ? "(none)" : warnings);
1053+
10521054
result.setStr(result_string);
10531055
}
10541056

src/bls/bls.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void CBLSSecretKey::MakeNewKey()
6363
{
6464
unsigned char buf[SerSize];
6565
while (true) {
66-
GetStrongRandBytes(buf, sizeof(buf));
66+
GetStrongRandBytes({buf, sizeof(buf)});
6767
try {
6868
impl = bls::PrivateKey::FromBytes(bls::Bytes(reinterpret_cast<const uint8_t*>(buf), SerSize));
6969
break;

src/bls/bls_ies.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void CBLSIESMultiRecipientBlobs::InitEncrypt(size_t count)
9797
{
9898
ephemeralSecretKey.MakeNewKey();
9999
ephemeralPubKey = ephemeralSecretKey.GetPublicKey();
100-
GetStrongRandBytes(ivSeed.begin(), ivSeed.size());
100+
GetStrongRandBytes({ivSeed.begin(), ivSeed.size()});
101101

102102
uint256 iv = ivSeed;
103103
ivVector.resize(count);

src/dbwrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const unsigned int CDBWrapper::OBFUSCATE_KEY_NUM_BYTES = 8;
224224
std::vector<unsigned char> CDBWrapper::CreateObfuscateKey() const
225225
{
226226
std::vector<uint8_t> ret(OBFUSCATE_KEY_NUM_BYTES);
227-
GetRandBytes(ret.data(), OBFUSCATE_KEY_NUM_BYTES);
227+
GetRandBytes(ret);
228228
return ret;
229229
}
230230

src/key.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ bool CKey::Check(const unsigned char *vch) {
157157

158158
void CKey::MakeNewKey(bool fCompressedIn) {
159159
do {
160-
GetStrongRandBytes(keydata.data(), keydata.size());
160+
GetStrongRandBytes(keydata);
161161
} while (!Check(keydata.data()));
162162
fValid = true;
163163
fCompressed = fCompressedIn;
@@ -242,7 +242,7 @@ bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
242242
}
243243
unsigned char rnd[8];
244244
std::string str = "Bitcoin key verification\n";
245-
GetRandBytes(rnd, sizeof(rnd));
245+
GetRandBytes(rnd);
246246
uint256 hash;
247247
CHash256().Write(MakeUCharSpan(str)).Write(rnd).Finalize(hash);
248248
std::vector<unsigned char> vchSig;
@@ -406,7 +406,7 @@ void ECC_Start() {
406406
{
407407
// Pass in a random blinding seed to the secp256k1 context.
408408
std::vector<unsigned char, secure_allocator<unsigned char>> vseed(32);
409-
GetRandBytes(vseed.data(), 32);
409+
GetRandBytes(vseed);
410410
bool ret = secp256k1_context_randomize(ctx, vseed.data());
411411
assert(ret);
412412
}

src/net_processing.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer)
12471247
CAddress addrMe = CAddress(CService(), nLocalNodeServices);
12481248

12491249
uint256 mnauthChallenge;
1250-
GetRandBytes(mnauthChallenge.begin(), mnauthChallenge.size());
1250+
GetRandBytes({mnauthChallenge.begin(), mnauthChallenge.size()});
12511251
pnode.SetSentMNAuthChallenge(mnauthChallenge);
12521252

12531253
int nProtocolVersion = PROTOCOL_VERSION;
@@ -5220,7 +5220,7 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::mic
52205220
if (pingSend) {
52215221
uint64_t nonce = 0;
52225222
while (nonce == 0) {
5223-
GetRandBytes((unsigned char*)&nonce, sizeof(nonce));
5223+
GetRandBytes({(unsigned char*)&nonce, sizeof(nonce)});
52245224
}
52255225
peer.m_ping_queued = false;
52265226
peer.m_ping_start = now;

src/qt/guiutil.cpp

+12-17
Original file line numberDiff line numberDiff line change
@@ -1676,23 +1676,18 @@ QString ConnectionTypeToQString(ConnectionType conn_type)
16761676

16771677
QString formatDurationStr(std::chrono::seconds dur)
16781678
{
1679-
const auto secs = count_seconds(dur);
1680-
QStringList strList;
1681-
int days = secs / 86400;
1682-
int hours = (secs % 86400) / 3600;
1683-
int mins = (secs % 3600) / 60;
1684-
int seconds = secs % 60;
1685-
1686-
if (days)
1687-
strList.append(QObject::tr("%1 d").arg(days));
1688-
if (hours)
1689-
strList.append(QObject::tr("%1 h").arg(hours));
1690-
if (mins)
1691-
strList.append(QObject::tr("%1 m").arg(mins));
1692-
if (seconds || (!days && !hours && !mins))
1693-
strList.append(QObject::tr("%1 s").arg(seconds));
1694-
1695-
return strList.join(" ");
1679+
using days = std::chrono::duration<int, std::ratio<86400>>; // can remove this line after C++20
1680+
const auto d{std::chrono::duration_cast<days>(dur)};
1681+
const auto h{std::chrono::duration_cast<std::chrono::hours>(dur - d)};
1682+
const auto m{std::chrono::duration_cast<std::chrono::minutes>(dur - d - h)};
1683+
const auto s{std::chrono::duration_cast<std::chrono::seconds>(dur - d - h - m)};
1684+
QStringList str_list;
1685+
if (auto d2{d.count()}) str_list.append(QObject::tr("%1 d").arg(d2));
1686+
if (auto h2{h.count()}) str_list.append(QObject::tr("%1 h").arg(h2));
1687+
if (auto m2{m.count()}) str_list.append(QObject::tr("%1 m").arg(m2));
1688+
const auto s2{s.count()};
1689+
if (s2 || str_list.empty()) str_list.append(QObject::tr("%1 s").arg(s2));
1690+
return str_list.join(" ");
16961691
}
16971692

16981693
QString formatServicesStr(quint64 mask)

src/random.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <logging.h> // for LogPrintf()
1818
#include <randomenv.h>
1919
#include <support/allocators/secure.h>
20+
#include <span.h>
2021
#include <sync.h> // for Mutex
2122
#include <util/time.h> // for GetTimeMicros()
2223

@@ -582,8 +583,8 @@ static void ProcRand(unsigned char* out, int num, RNGLevel level) noexcept
582583
}
583584
}
584585

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

@@ -602,7 +603,7 @@ int GetRandInt(int nMax) noexcept
602603
uint256 GetRandHash() noexcept
603604
{
604605
uint256 hash;
605-
GetRandBytes((unsigned char*)&hash, sizeof(hash));
606+
GetRandBytes(hash);
606607
return hash;
607608
}
608609

src/random.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
*
7070
* Thread-safe.
7171
*/
72-
void GetRandBytes(unsigned char* buf, int num) noexcept;
72+
void GetRandBytes(Span<unsigned char> bytes) noexcept;
7373
/** Generate a uniform random integer in the range [0..range). Precondition: range > 0 */
7474
uint64_t GetRand(uint64_t nMax) noexcept;
7575
/** Generate a uniform random duration in the range [0..max). Precondition: max.count() > 0 */
@@ -98,7 +98,7 @@ bool GetRandBool(double rate);
9898
*
9999
* Thread-safe.
100100
*/
101-
void GetStrongRandBytes(unsigned char* buf, int num) noexcept;
101+
void GetStrongRandBytes(Span<unsigned char> bytes) noexcept;
102102

103103
/**
104104
* Gather entropy from various expensive sources, and feed them to the PRNG state.

src/rpc/request.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool GenerateAuthCookie(std::string *cookie_out)
7777
{
7878
const size_t COOKIE_SIZE = 32;
7979
unsigned char rand_pwd[COOKIE_SIZE];
80-
GetRandBytes(rand_pwd, COOKIE_SIZE);
80+
GetRandBytes(rand_pwd);
8181
std::string cookie = COOKIEAUTH_USER + ":" + HexStr(rand_pwd);
8282

8383
/** the umask determines what permissions are used to create this file -

src/shutdown.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55

66
#include <shutdown.h>
77

8+
#if defined(HAVE_CONFIG_H)
9+
#include <config/bitcoin-config.h>
10+
#endif
11+
812
#include <logging.h>
913
#include <util/tokenpipe.h>
1014

1115
#include <node/ui_interface.h>
1216
#include <warnings.h>
1317

14-
#include <config/bitcoin-config.h>
15-
1618
#include <assert.h>
1719
#include <atomic>
1820
#ifdef WIN32

0 commit comments

Comments
 (0)