Skip to content

Commit

Permalink
Merge pull request dashpay#5821 from PastaPastaPasta/develop-trivial-…
Browse files Browse the repository at this point in the history
…2024-01-13

backport: trivial 2024 01 13
  • Loading branch information
PastaPastaPasta authored Jan 15, 2024
2 parents dfc978a + 2ce8f77 commit d0a6284
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 53 deletions.
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ fi
dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers],[[CXXFLAGS="$CXXFLAGS -fno-extended-identifiers"]],,[[$CXXFLAG_WERROR]])

enable_arm_crc=no
enable_arm_shani=no
enable_sse42=no
enable_sse41=no
enable_avx2=no
Expand Down
2 changes: 1 addition & 1 deletion contrib/verify-commits/trusted-git-root
Original file line number Diff line number Diff line change
@@ -1 +1 @@
82bcf405f6db1d55b684a1f63a4aabad376cdad7
577bd51a4b8de066466a445192c1c653872657e2
2 changes: 0 additions & 2 deletions contrib/verify-commits/trusted-keys
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
71A3B16735405025D447E8F274810B012346C9A6
133EAC179436F14A5CF1B794860FEB804E669320
32EE5C4C3FA15CCADB46ABE529D4BCB6416F53EC
B8B3F1C0E58C15DB6A81D30C3648A882F4316B9B
CA03882CB1FC067B5D3ACFE4D300116E1C875A3D
E777299FC265DD04793070EB944D35F9AC3DB76A
D1DBF2C4B96F2DEBF4C16654410108112E7EA81F
4 changes: 2 additions & 2 deletions doc/build-netbsd.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NetBSD build guide
NetBSD Build Guide
======================
(updated for NetBSD 8.0)
**Updated for NetBSD [8.0](https://www.netbsd.org/releases/formal-8/NetBSD-8.0.html)**

This guide describes how to build dashd and command-line utilities on NetBSD.

Expand Down
15 changes: 3 additions & 12 deletions src/prevector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
class prevector {
static_assert(std::is_trivially_copyable_v<T>);

public:
typedef Size size_type;
typedef Diff difference_type;
Expand Down Expand Up @@ -428,15 +430,7 @@ class prevector {
// representation (with capacity N and size <= N).
iterator p = first;
char* endp = (char*)&(*end());
if (!std::is_trivially_destructible<T>::value) {
while (p != last) {
(*p).~T();
_size--;
++p;
}
} else {
_size -= last - p;
}
_size -= last - p;
memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
return first;
}
Expand Down Expand Up @@ -482,9 +476,6 @@ class prevector {
}

~prevector() {
if (!std::is_trivially_destructible<T>::value) {
clear();
}
if (!is_direct()) {
free(_union.indirect_contents.indirect);
_union.indirect_contents.indirect = nullptr;
Expand Down
6 changes: 2 additions & 4 deletions src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue()
if (m_are_callbacks_running) return;
if (m_callbacks_pending.empty()) return;
}
m_pscheduler->schedule(std::bind(&SingleThreadedSchedulerClient::ProcessQueue, this), std::chrono::system_clock::now());
m_scheduler.schedule([this] { this->ProcessQueue(); }, std::chrono::system_clock::now());
}

void SingleThreadedSchedulerClient::ProcessQueue()
Expand Down Expand Up @@ -177,8 +177,6 @@ void SingleThreadedSchedulerClient::ProcessQueue()

void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void()> func)
{
assert(m_pscheduler);

{
LOCK(m_callbacks_mutex);
m_callbacks_pending.emplace_back(std::move(func));
Expand All @@ -188,7 +186,7 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void()> func

void SingleThreadedSchedulerClient::EmptyQueue()
{
assert(!m_pscheduler->AreThreadsServicingQueue());
assert(!m_scheduler.AreThreadsServicingQueue());
bool should_continue = true;
while (should_continue) {
ProcessQueue();
Expand Down
13 changes: 9 additions & 4 deletions src/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
#ifndef BITCOIN_SCHEDULER_H
#define BITCOIN_SCHEDULER_H

#include <attributes.h>
#include <sync.h>
#include <threadsafety.h>

#include <chrono>
#include <condition_variable>
#include <cstddef>
#include <functional>
#include <list>
#include <map>
#include <thread>

#include <sync.h>
#include <utility>

/**
* Simple class for background tasks that should be run
Expand Down Expand Up @@ -117,7 +122,7 @@ class CScheduler
class SingleThreadedSchedulerClient
{
private:
CScheduler* m_pscheduler;
CScheduler& m_scheduler;

Mutex m_callbacks_mutex;
std::list<std::function<void()>> m_callbacks_pending GUARDED_BY(m_callbacks_mutex);
Expand All @@ -127,7 +132,7 @@ class SingleThreadedSchedulerClient
void ProcessQueue();

public:
explicit SingleThreadedSchedulerClient(CScheduler* pschedulerIn) : m_pscheduler(pschedulerIn) {}
explicit SingleThreadedSchedulerClient(CScheduler& scheduler LIFETIMEBOUND) : m_scheduler{scheduler} {}

/**
* Add a callback to be executed. Callbacks are executed serially
Expand Down
6 changes: 3 additions & 3 deletions src/test/scheduler_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ BOOST_AUTO_TEST_CASE(singlethreadedscheduler_ordered)
CScheduler scheduler;

// each queue should be well ordered with respect to itself but not other queues
SingleThreadedSchedulerClient queue1(&scheduler);
SingleThreadedSchedulerClient queue2(&scheduler);
SingleThreadedSchedulerClient queue1(scheduler);
SingleThreadedSchedulerClient queue2(scheduler);

// create more threads than queues
// if the queues only permit execution of one task at once then
// the extra threads should effectively be doing nothing
// if they don't we'll get out of order behaviour
std::vector<std::thread> threads;
for (int i = 0; i < 5; ++i) {
threads.emplace_back(std::bind(&CScheduler::serviceQueue, &scheduler));
threads.emplace_back([&] { scheduler.serviceQueue(); });
}

// these are not atomic, if SinglethreadedSchedulerClient prevents
Expand Down
4 changes: 2 additions & 2 deletions src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct MainSignalsInstance {
// our own queue here :(
SingleThreadedSchedulerClient m_schedulerClient;

explicit MainSignalsInstance(CScheduler *pscheduler) : m_schedulerClient(pscheduler) {}
explicit MainSignalsInstance(CScheduler& scheduler LIFETIMEBOUND) : m_schedulerClient(scheduler) {}

void Register(std::shared_ptr<CValidationInterface> callbacks)
{
Expand Down Expand Up @@ -97,7 +97,7 @@ static CMainSignals g_signals;
void CMainSignals::RegisterBackgroundSignalScheduler(CScheduler& scheduler)
{
assert(!m_internals);
m_internals.reset(new MainSignalsInstance(&scheduler));
m_internals = std::make_unique<MainSignalsInstance>(scheduler);
}

void CMainSignals::UnregisterBackgroundSignalScheduler()
Expand Down
13 changes: 8 additions & 5 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,8 +1939,10 @@ int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& r
*/
CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate)
{
int64_t nNow = GetTime();
int64_t start_time = GetTimeMillis();
using Clock = std::chrono::steady_clock;
constexpr auto LOG_INTERVAL{60s};
auto current_time{Clock::now()};
auto start_time{Clock::now()};

assert(reserver.isReserved());

Expand All @@ -1967,8 +1969,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
if (block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
ShowProgress(strprintf("%s " + _("Rescanning...").translated, GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
}
if (GetTime() >= nNow + 60) {
nNow = GetTime();
if (Clock::now() >= current_time + LOG_INTERVAL) {
current_time = Clock::now();
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", block_height, progress_current);
}

Expand Down Expand Up @@ -2035,7 +2037,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", block_height, progress_current);
result.status = ScanResult::USER_ABORT;
} else {
WalletLogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - start_time);
auto duration_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_time);
WalletLogPrintf("Rescan completed in %15dms\n", duration_milliseconds.count());
}
return result;
}
Expand Down
3 changes: 3 additions & 0 deletions test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ def run_test(self):
# the size of the memory pool should be greater than 3x ~100 bytes
assert_greater_than(json_obj['bytes'], 300)

mempool_info = self.nodes[0].getmempoolinfo()
assert_equal(json_obj, mempool_info)

# Check that there are our submitted transactions in the TX memory pool
json_obj = self.test_rest_request("/mempool/contents")
raw_mempool_verbose = self.nodes[0].getrawmempool(verbose=True)
Expand Down
15 changes: 5 additions & 10 deletions test/functional/p2p_unrequested_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,11 @@ def run_test(self):
test_node.send_message(msg_block(block_291))

# At this point we've sent an obviously-bogus block, wait for full processing
# without assuming whether we will be disconnected or not
try:
# Only wait a short while so the test doesn't take forever if we do get
# disconnected
test_node.sync_with_ping(timeout=1)
except AssertionError:
test_node.wait_for_disconnect()

self.nodes[0].disconnect_p2ps()
test_node = self.nodes[0].add_p2p_connection(P2PInterface())
# and assume disconnection
test_node.wait_for_disconnect()

self.nodes[0].disconnect_p2ps()
test_node = self.nodes[0].add_p2p_connection(P2PInterface())

# We should have failed reorg and switched back to 290 (but have block 291)
assert_equal(self.nodes[0].getblockcount(), 290)
Expand Down
6 changes: 3 additions & 3 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,7 @@ class msg_getcfilters:
__slots__ = ("filter_type", "start_height", "stop_hash")
msgtype = b"getcfilters"

def __init__(self, filter_type, start_height, stop_hash):
def __init__(self, filter_type=None, start_height=None, stop_hash=None):
self.filter_type = filter_type
self.start_height = start_height
self.stop_hash = stop_hash
Expand Down Expand Up @@ -2421,7 +2421,7 @@ class msg_getcfheaders:
__slots__ = ("filter_type", "start_height", "stop_hash")
msgtype = b"getcfheaders"

def __init__(self, filter_type, start_height, stop_hash):
def __init__(self, filter_type=None, start_height=None, stop_hash=None):
self.filter_type = filter_type
self.start_height = start_height
self.stop_hash = stop_hash
Expand Down Expand Up @@ -2474,7 +2474,7 @@ class msg_getcfcheckpt:
__slots__ = ("filter_type", "stop_hash")
msgtype = b"getcfcheckpt"

def __init__(self, filter_type, stop_hash):
def __init__(self, filter_type=None, stop_hash=None):
self.filter_type = filter_type
self.stop_hash = stop_hash

Expand Down
6 changes: 6 additions & 0 deletions test/functional/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
msg_getaddr,
msg_getblocks,
msg_getblocktxn,
msg_getcfcheckpt,
msg_getcfheaders,
msg_getcfilters,
msg_getdata,
msg_getheaders,
msg_getheaders2,
Expand Down Expand Up @@ -93,6 +96,9 @@
b"getaddr": msg_getaddr,
b"getblocks": msg_getblocks,
b"getblocktxn": msg_getblocktxn,
b"getcfcheckpt": msg_getcfcheckpt,
b"getcfheaders": msg_getcfheaders,
b"getcfilters": msg_getcfilters,
b"getdata": msg_getdata,
b"getheaders": msg_getheaders,
b"getheaders2": msg_getheaders2,
Expand Down
10 changes: 5 additions & 5 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import unittest

# Formatting. Default colors to empty strings.
BOLD, GREEN, RED, GREY = ("", ""), ("", ""), ("", ""), ("", "")
DEFAULT, BOLD, GREEN, RED = ("", ""), ("", ""), ("", ""), ("", "")
try:
# Make sure python thinks it can write unicode to its stdout
"\u2713".encode("utf_8").decode(sys.stdout.encoding)
Expand Down Expand Up @@ -59,10 +59,10 @@
kernel32.SetConsoleMode(stderr, stderr_mode.value | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
# primitive formatting on supported
# terminal via ANSI escape sequences:
DEFAULT = ('\033[0m', '\033[0m')
BOLD = ('\033[0m', '\033[1m')
GREEN = ('\033[0m', '\033[0;32m')
RED = ('\033[0m', '\033[0;31m')
GREY = ('\033[0m', '\033[1;30m')

TEST_EXIT_PASSED = 0
TEST_EXIT_SKIPPED = 77
Expand Down Expand Up @@ -321,11 +321,11 @@ def main():

args, unknown_args = parser.parse_known_args()
if not args.ansi:
global BOLD, GREEN, RED, GREY
global DEFAULT, BOLD, GREEN, RED
DEFAULT = ("", "")
BOLD = ("", "")
GREEN = ("", "")
RED = ("", "")
GREY = ("", "")

# args to be passed on always start with two dashes; tests are the remaining unknown args
tests = [arg for arg in unknown_args if arg[:2] != "--"]
Expand Down Expand Up @@ -692,7 +692,7 @@ def __repr__(self):
color = RED
glyph = CROSS
elif self.status == "Skipped":
color = GREY
color = DEFAULT
glyph = CIRCLE

return color[1] + "%s | %s%s | %s s\n" % (self.name.ljust(self.padding), glyph, self.status.ljust(7), self.time) + color[0]
Expand Down

0 comments on commit d0a6284

Please sign in to comment.