Merge pull request #5816 from PastaPastaPasta/develop-trivial-2024-01-10

backport: trivial 2024 01 10
This commit is contained in:
PastaPastaPasta 2024-01-13 19:32:54 -06:00 committed by GitHub
commit dfc978adcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 297 additions and 127 deletions

View File

@ -13,7 +13,7 @@ AC_CONFIG_HEADERS([src/config/bitcoin-config.h])
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux/m4]) AC_CONFIG_MACRO_DIR([build-aux/m4])
m4_ifndef([PKG_PROG_PKG_CONFIG], [AC_MSG_ERROR([PKG_PROG_PKG_CONFIG macro not found. Please install pkg-config and re-run autogen.sh])]) m4_ifndef([PKG_PROG_PKG_CONFIG], [m4_fatal([PKG_PROG_PKG_CONFIG macro not found. Please install pkg-config and re-run autogen.sh])])
PKG_PROG_PKG_CONFIG PKG_PROG_PKG_CONFIG
if test "x$PKG_CONFIG" = x; then if test "x$PKG_CONFIG" = x; then
AC_MSG_ERROR([pkg-config not found]) AC_MSG_ERROR([pkg-config not found])
@ -1478,6 +1478,26 @@ if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench
fi fi
fi fi
if test x$use_libevent = xyes; then
TEMP_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $EVENT_CFLAGS"
AC_MSG_CHECKING([if evhttp_connection_get_peer expects const char**])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <cstdint>
#include <event2/http.h>
]], [[
evhttp_connection *conn = (evhttp_connection *)1;
const char *host;
uint16_t port;
evhttp_connection_get_peer(conn, &host, &port);
]])],
[ AC_MSG_RESULT([yes]); AC_DEFINE([HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR], [1], [Define this symbol if evhttp_connection_get_peer expects const char**]) ],
[ AC_MSG_RESULT([no]) ]
)
CXXFLAGS="$TEMP_CXXFLAGS"
fi
dnl QR Code encoding library check dnl QR Code encoding library check
if test "x$use_qr" != xno; then if test "x$use_qr" != xno; then
@ -1787,6 +1807,7 @@ AC_SUBST(HAVE_MM_PREFETCH)
AC_SUBST(HAVE_STRONG_GETAUXVAL) AC_SUBST(HAVE_STRONG_GETAUXVAL)
AC_SUBST(HAVE_GMTIME_R) AC_SUBST(HAVE_GMTIME_R)
AC_SUBST(ANDROID_ARCH) AC_SUBST(ANDROID_ARCH)
AC_SUBST(HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini]) AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh]) AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])]) AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])

View File

@ -1,12 +1,13 @@
package=zeromq package=zeromq
$(package)_version=4.3.1 $(package)_version=4.3.4
$(package)_download_path=https://github.com/zeromq/libzmq/releases/download/v$($(package)_version)/ $(package)_download_path=https://github.com/zeromq/libzmq/releases/download/v$($(package)_version)/
$(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=bcbabe1e2c7d0eec4ed612e10b94b112dd5f06fcefa994a0c79a45d835cd21eb $(package)_sha256_hash=c593001a89f5a85dd2ddf564805deb860e02471171b3f204944857336295c3e5
$(package)_patches=remove_libstd_link.patch $(package)_patches=remove_libstd_link.patch netbsd_kevent_void.patch
define $(package)_set_vars define $(package)_set_vars
$(package)_config_opts=--without-docs --disable-shared --disable-curve --disable-curve-keygen --disable-perf $(package)_config_opts = --without-docs --disable-shared --disable-valgrind
$(package)_config_opts += --disable-perf --disable-curve-keygen --disable-curve --disable-libbsd
$(package)_config_opts += --without-libsodium --without-libgssapi_krb5 --without-pgm --without-norm --without-vmci $(package)_config_opts += --without-libsodium --without-libgssapi_krb5 --without-pgm --without-norm --without-vmci
$(package)_config_opts += --disable-libunwind --disable-radix-tree --without-gcov --disable-dependency-tracking $(package)_config_opts += --disable-libunwind --disable-radix-tree --without-gcov --disable-dependency-tracking
$(package)_config_opts += --disable-Werror --disable-drafts --enable-option-checking $(package)_config_opts += --disable-Werror --disable-drafts --enable-option-checking
@ -20,10 +21,12 @@ endef
define $(package)_preprocess_cmds define $(package)_preprocess_cmds
patch -p1 < $($(package)_patch_dir)/remove_libstd_link.patch && \ patch -p1 < $($(package)_patch_dir)/remove_libstd_link.patch && \
patch -p1 < $($(package)_patch_dir)/netbsd_kevent_void.patch && \
cp -f $(BASEDIR)/config.guess $(BASEDIR)/config.sub config cp -f $(BASEDIR)/config.guess $(BASEDIR)/config.sub config
endef endef
define $(package)_config_cmds define $(package)_config_cmds
./autogen.sh && \
$($(package)_autoconf) $($(package)_autoconf)
endef endef

View File

@ -0,0 +1,57 @@
commit 129137d5182967dbfcfec66bad843df2a992a78f
Author: fanquake <fanquake@gmail.com>
Date: Mon Jan 3 20:13:33 2022 +0800
problem: kevent udata is now void* on NetBSD Current (10)
solution: check for the intptr_t variant in configure.
diff --git a/configure.ac b/configure.ac
index 1a571291..402f8b86 100644
--- a/configure.ac
+++ b/configure.ac
@@ -307,6 +307,27 @@ case "${host_os}" in
if test "x$libzmq_netbsd_has_atomic" = "xno"; then
AC_DEFINE(ZMQ_FORCE_MUTEXES, 1, [Force to use mutexes])
fi
+ # NetBSD Current (to become 10) has changed the type of udata in it's
+ # kevent struct from intptr_t to void * to align with darwin and other
+ # BSDs, see upstream commit:
+ # https://github.com/NetBSD/src/commit/e5ead823eb916b56589d2c6c560dbcfe4a2d0afc
+ AC_MSG_CHECKING([whether kevent udata type is intptr_t])
+ AC_LANG_PUSH([C++])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM(
+ [[#include <sys/types.h>
+ #include <sys/event.h>
+ #include <sys/time.h>]],
+ [[struct kevent ev;
+ intptr_t udata;
+ EV_SET(&ev, 0, 0, EV_ADD, 0, 0, udata);
+ return 0;]])],
+ [libzmq_netbsd_kevent_udata_intptr_t=yes],
+ [libzmq_netbsd_kevent_udata_intptr_t=no])
+ AC_LANG_POP([C++])
+ AC_MSG_RESULT([$libzmq_netbsd_kevent_udata_intptr_t])
+ if test "x$libzmq_netbsd_kevent_udata_intptr_t" = "xyes"; then
+ AC_DEFINE(ZMQ_NETBSD_KEVENT_UDATA_INTPTR_T, 1, [kevent udata type is intptr_t])
+ fi
;;
*openbsd*|*bitrig*)
# Define on OpenBSD to enable all library features
diff --git a/src/kqueue.cpp b/src/kqueue.cpp
index 53d82ac4..a6a7a7f2 100644
--- a/src/kqueue.cpp
+++ b/src/kqueue.cpp
@@ -46,9 +46,9 @@
#include "i_poll_events.hpp"
#include "likely.hpp"
-// NetBSD defines (struct kevent).udata as intptr_t, everyone else
-// as void *.
-#if defined ZMQ_HAVE_NETBSD
+// NetBSD up to version 9 defines (struct kevent).udata as intptr_t,
+// everyone else as void *.
+#if defined ZMQ_HAVE_NETBSD && defined(ZMQ_NETBSD_KEVENT_UDATA_INTPTR_T)
#define kevent_udata_t intptr_t
#else
#define kevent_udata_t void *

View File

@ -123,6 +123,7 @@ Only supports JSON as output format.
Returns transactions in the TX mempool. Returns transactions in the TX mempool.
Only supports JSON as output format. Only supports JSON as output format.
Refer to the `getrawmempool` RPC help for details.
Risks Risks
------------- -------------

View File

@ -24,22 +24,19 @@ template<unsigned int BITS>
class base_uint class base_uint
{ {
protected: protected:
static_assert(BITS / 32 > 0 && BITS % 32 == 0, "Template parameter BITS must be a positive multiple of 32.");
static constexpr int WIDTH = BITS / 32; static constexpr int WIDTH = BITS / 32;
uint32_t pn[WIDTH]; uint32_t pn[WIDTH];
public: public:
base_uint() base_uint()
{ {
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
for (int i = 0; i < WIDTH; i++) for (int i = 0; i < WIDTH; i++)
pn[i] = 0; pn[i] = 0;
} }
base_uint(const base_uint& b) base_uint(const base_uint& b)
{ {
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
for (int i = 0; i < WIDTH; i++) for (int i = 0; i < WIDTH; i++)
pn[i] = b.pn[i]; pn[i] = b.pn[i];
} }
@ -53,8 +50,6 @@ public:
base_uint(uint64_t b) base_uint(uint64_t b)
{ {
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
pn[0] = (unsigned int)b; pn[0] = (unsigned int)b;
pn[1] = (unsigned int)(b >> 32); pn[1] = (unsigned int)(b >> 32);
for (int i = 2; i < WIDTH; i++) for (int i = 2; i < WIDTH; i++)

View File

@ -7,6 +7,7 @@
#include <netaddress.h> #include <netaddress.h>
#include <node/ui_interface.h> #include <node/ui_interface.h>
#include <sync.h>
#include <util/system.h> #include <util/system.h>
#include <util/time.h> #include <util/time.h>
#include <util/translation.h> #include <util/translation.h>
@ -39,18 +40,23 @@ BanMan::~BanMan()
void BanMan::DumpBanlist() void BanMan::DumpBanlist()
{ {
SweepBanned(); // clean unused entries (if bantime has expired) static Mutex dump_mutex;
LOCK(dump_mutex);
if (!BannedSetIsDirty()) return;
int64_t n_start = GetTimeMillis();
banmap_t banmap; banmap_t banmap;
GetBanned(banmap); {
if (m_ban_db.Write(banmap)) { LOCK(m_cs_banned);
SweepBanned();
if (!BannedSetIsDirty()) return;
banmap = m_banned;
SetBannedSetDirty(false); SetBannedSetDirty(false);
} }
int64_t n_start = GetTimeMillis();
if (!m_ban_db.Write(banmap)) {
SetBannedSetDirty(true);
}
LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(), LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
GetTimeMillis() - n_start); GetTimeMillis() - n_start);
} }

View File

@ -35,7 +35,10 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
{ {
return true; return true;
} }
void swap(PrevectorJob& x){p.swap(x.p);}; void swap(PrevectorJob& x) noexcept
{
p.swap(x.p);
};
}; };
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE}; CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};

View File

@ -70,7 +70,7 @@ public:
); );
} }
void swap(CHDChain& first, CHDChain& second) // nothrow void swap(CHDChain& first, CHDChain& second) noexcept
{ {
// enable ADL (not necessary in our case, but good practice) // enable ADL (not necessary in our case, but good practice)
using std::swap; using std::swap;

View File

@ -2,6 +2,10 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <httpserver.h> #include <httpserver.h>
#include <chainparamsbase.h> #include <chainparamsbase.h>
@ -597,7 +601,13 @@ CService HTTPRequest::GetPeer() const
// evhttp retains ownership over returned address string // evhttp retains ownership over returned address string
const char* address = ""; const char* address = "";
uint16_t port = 0; uint16_t port = 0;
#ifdef HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
evhttp_connection_get_peer(con, &address, &port);
#else
evhttp_connection_get_peer(con, (char**)&address, &port); evhttp_connection_get_peer(con, (char**)&address, &port);
#endif // HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
peer = LookupNumeric(address, port); peer = LookupNumeric(address, port);
} }
return peer; return peer;

View File

@ -2209,7 +2209,7 @@ void CConnman::SetTryNewOutboundPeer(bool flag)
// Return the number of peers we have over our outbound connection limit // Return the number of peers we have over our outbound connection limit
// Exclude peers that are marked for disconnect, or are going to be // Exclude peers that are marked for disconnect, or are going to be
// disconnected soon (eg one-shots and feelers) // disconnected soon (eg ADDR_FETCH and FEELER)
// Also exclude peers that haven't finished initial connection handshake yet // Also exclude peers that haven't finished initial connection handshake yet
// (so that we don't decide we're over our desired connection limit, and then // (so that we don't decide we're over our desired connection limit, and then
// evict some peer that has finished the handshake) // evict some peer that has finished the handshake)

View File

@ -161,10 +161,19 @@ enum class ConnectionType {
MANUAL, MANUAL,
/** /**
* Feeler connections are short lived connections used to increase the * Feeler connections are short-lived connections made to check that a node
* number of connectable addresses in our AddrMan. Approximately every * is alive. They can be useful for:
* FEELER_INTERVAL, we attempt to connect to a random address from the new * - test-before-evict: if one of the peers is considered for eviction from
* table. If successful, we add it to the tried table. * our AddrMan because another peer is mapped to the same slot in the tried table,
* evict only if this longer-known peer is offline.
* - move node addresses from New to Tried table, so that we have more
* connectable addresses in our AddrMan.
* Note that in the literature ("Eclipse Attacks on Bitcoins Peer-to-Peer Network")
* only the latter feature is referred to as "feeler connections",
* although in our codebase feeler connections encompass test-before-evict as well.
* We make these connections approximately every FEELER_INTERVAL:
* first we resolve previously found collisions if they exist (test-before-evict),
* otherwise connect to a node from the new table.
*/ */
FEELER, FEELER,

View File

@ -475,7 +475,8 @@ public:
return *item_ptr(size() - 1); return *item_ptr(size() - 1);
} }
void swap(prevector<N, T, Size, Diff>& other) { void swap(prevector<N, T, Size, Diff>& other) noexcept
{
std::swap(_union, other._union); std::swap(_union, other._union);
std::swap(_size, other._size); std::swap(_size, other._size);
} }

View File

@ -11,6 +11,8 @@
#include <cassert> #include <cassert>
static constexpr auto MAX_DIGITS_BTC = 16;
BitcoinUnits::BitcoinUnits(QObject *parent): BitcoinUnits::BitcoinUnits(QObject *parent):
QAbstractListModel(parent), QAbstractListModel(parent),
unitlist(availableUnits()) unitlist(availableUnits())
@ -129,7 +131,9 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
qint64 n_abs = (n > 0 ? n : -n); qint64 n_abs = (n > 0 ? n : -n);
qint64 quotient = n_abs / coin; qint64 quotient = n_abs / coin;
QString quotient_str = QString::number(quotient); QString quotient_str = QString::number(quotient);
if (justify) quotient_str = quotient_str.rightJustified(16 - num_decimals, ' '); if (justify) {
quotient_str = quotient_str.rightJustified(MAX_DIGITS_BTC - num_decimals, ' ');
}
// Use SI-style thin space separators as these are locale independent and can't be // Use SI-style thin space separators as these are locale independent and can't be
// confused with the decimal marker. // confused with the decimal marker.

View File

@ -14,8 +14,9 @@
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QVariant> #include <QVariant>
#ifdef USE_DBUS #ifdef USE_DBUS
#include <stdint.h> #include <QDBusMetaType>
#include <QtDBus> #include <QtDBus>
#include <stdint.h>
#endif #endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <qt/macnotificationhandler.h> #include <qt/macnotificationhandler.h>
@ -73,8 +74,6 @@ public:
FreedesktopImage() {} FreedesktopImage() {}
explicit FreedesktopImage(const QImage &img); explicit FreedesktopImage(const QImage &img);
static int metaType();
// Image to variant that can be marshalled over DBus // Image to variant that can be marshalled over DBus
static QVariant toVariant(const QImage &img); static QVariant toVariant(const QImage &img);
@ -136,15 +135,10 @@ const QDBusArgument &operator>>(const QDBusArgument &a, FreedesktopImage &i)
return a; return a;
} }
int FreedesktopImage::metaType()
{
return qDBusRegisterMetaType<FreedesktopImage>();
}
QVariant FreedesktopImage::toVariant(const QImage &img) QVariant FreedesktopImage::toVariant(const QImage &img)
{ {
FreedesktopImage fimg(img); FreedesktopImage fimg(img);
return QVariant(FreedesktopImage::metaType(), &fimg); return QVariant(qDBusRegisterMetaType<FreedesktopImage>(), &fimg);
} }
void Notificator::notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout) void Notificator::notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout)

View File

@ -557,9 +557,8 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break; case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break;
case Qt::Key_PageUp: /* pass paging keys to messages widget */ case Qt::Key_PageUp: /* pass paging keys to messages widget */
case Qt::Key_PageDown: case Qt::Key_PageDown:
if(obj == ui->lineEdit) if (obj == ui->lineEdit) {
{ QApplication::sendEvent(ui->messagesWidget, keyevt);
QApplication::postEvent(ui->messagesWidget, new QKeyEvent(*keyevt));
return true; return true;
} }
break; break;
@ -567,7 +566,7 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
case Qt::Key_Enter: case Qt::Key_Enter:
// forward these events to lineEdit // forward these events to lineEdit
if (obj == autoCompleter->popup()) { if (obj == autoCompleter->popup()) {
QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt)); QApplication::sendEvent(ui->lineEdit, keyevt);
autoCompleter->popup()->hide(); autoCompleter->popup()->hide();
return true; return true;
} }
@ -581,7 +580,7 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
((mod & Qt::ShiftModifier) && key == Qt::Key_Insert))) ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
{ {
ui->lineEdit->setFocus(); ui->lineEdit->setFocus();
QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt)); QApplication::sendEvent(ui->lineEdit, keyevt);
return true; return true;
} }
} }

View File

@ -27,7 +27,7 @@ struct FakeCheck {
{ {
return true; return true;
} }
void swap(FakeCheck& x){}; void swap(FakeCheck& x) noexcept {};
}; };
struct FakeCheckCheckCompletion { struct FakeCheckCheckCompletion {
@ -37,7 +37,7 @@ struct FakeCheckCheckCompletion {
n_calls.fetch_add(1, std::memory_order_relaxed); n_calls.fetch_add(1, std::memory_order_relaxed);
return true; return true;
} }
void swap(FakeCheckCheckCompletion& x){}; void swap(FakeCheckCheckCompletion& x) noexcept {};
}; };
struct FailingCheck { struct FailingCheck {
@ -48,7 +48,7 @@ struct FailingCheck {
{ {
return !fails; return !fails;
} }
void swap(FailingCheck& x) void swap(FailingCheck& x) noexcept
{ {
std::swap(fails, x.fails); std::swap(fails, x.fails);
}; };
@ -66,7 +66,10 @@ struct UniqueCheck {
results.insert(check_id); results.insert(check_id);
return true; return true;
} }
void swap(UniqueCheck& x) { std::swap(x.check_id, check_id); }; void swap(UniqueCheck& x) noexcept
{
std::swap(x.check_id, check_id);
};
}; };
@ -94,7 +97,10 @@ struct MemoryCheck {
{ {
fake_allocated_memory.fetch_sub(b, std::memory_order_relaxed); fake_allocated_memory.fetch_sub(b, std::memory_order_relaxed);
}; };
void swap(MemoryCheck& x) { std::swap(b, x.b); }; void swap(MemoryCheck& x) noexcept
{
std::swap(b, x.b);
};
}; };
struct FrozenCleanupCheck { struct FrozenCleanupCheck {
@ -118,7 +124,10 @@ struct FrozenCleanupCheck {
cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;}); cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;});
} }
} }
void swap(FrozenCleanupCheck& x){std::swap(should_freeze, x.should_freeze);}; void swap(FrozenCleanupCheck& x) noexcept
{
std::swap(should_freeze, x.should_freeze);
};
}; };
// Static Allocations // Static Allocations

View File

@ -4,7 +4,6 @@
// Unit tests for denial-of-service detection/prevention code // Unit tests for denial-of-service detection/prevention code
#include <arith_uint256.h>
#include <banman.h> #include <banman.h>
#include <chainparams.h> #include <chainparams.h>
#include <llmq/context.h> #include <llmq/context.h>
@ -373,7 +372,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
// ecdsa_signature_parse_der_lax are executed during this test. // ecdsa_signature_parse_der_lax are executed during this test.
// Specifically branches that run only when an ECDSA // Specifically branches that run only when an ECDSA
// signature's R and S values have leading zeros. // signature's R and S values have leading zeros.
g_insecure_rand_ctx = FastRandomContext(ArithToUint256(arith_uint256(33))); g_insecure_rand_ctx = FastRandomContext{uint256{33}};
CKey key; CKey key;
MakeNewKeyWithFastRandomContext(key); MakeNewKeyWithFastRandomContext(key);

View File

@ -26,7 +26,7 @@ struct DumbCheck {
return result; return result;
} }
void swap(DumbCheck& x) void swap(DumbCheck& x) noexcept
{ {
} }
}; };

View File

@ -161,7 +161,7 @@ public:
pre_vector.shrink_to_fit(); pre_vector.shrink_to_fit();
} }
void swap() void swap() noexcept
{ {
real_vector.swap(real_vector_alt); real_vector.swap(real_vector_alt);
pre_vector.swap(pre_vector_alt); pre_vector.swap(pre_vector_alt);

View File

@ -2,7 +2,6 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <arith_uint256.h>
#include <consensus/merkle.h> #include <consensus/merkle.h>
#include <merkleblock.h> #include <merkleblock.h>
#include <serialize.h> #include <serialize.h>
@ -107,13 +106,13 @@ BOOST_AUTO_TEST_CASE(pmt_test1)
BOOST_AUTO_TEST_CASE(pmt_malleability) BOOST_AUTO_TEST_CASE(pmt_malleability)
{ {
std::vector<uint256> vTxid = { std::vector<uint256> vTxid{
ArithToUint256(1), ArithToUint256(2), uint256{1}, uint256{2},
ArithToUint256(3), ArithToUint256(4), uint256{3}, uint256{4},
ArithToUint256(5), ArithToUint256(6), uint256{5}, uint256{6},
ArithToUint256(7), ArithToUint256(8), uint256{7}, uint256{8},
ArithToUint256(9), ArithToUint256(10), uint256{9}, uint256{10},
ArithToUint256(9), ArithToUint256(10), uint256{9}, uint256{10},
}; };
std::vector<bool> vMatch = {false, false, false, false, false, false, false, false, false, true, true, false}; std::vector<bool> vMatch = {false, false, false, false, false, false, false, false, false, true, true, false};

View File

@ -165,7 +165,8 @@ public:
test(); test();
} }
void swap() { void swap() noexcept
{
real_vector.swap(real_vector_alt); real_vector.swap(real_vector_alt);
pre_vector.swap(pre_vector_alt); pre_vector.swap(pre_vector_alt);
test(); test();

View File

@ -11,6 +11,7 @@
#include <netaddress.h> #include <netaddress.h>
#include <node/ui_interface.h> #include <node/ui_interface.h>
#include <sync.h> #include <sync.h>
#include <tinyformat.h>
#include <util/system.h> #include <util/system.h>
#include <util/translation.h> #include <util/translation.h>
#include <warnings.h> #include <warnings.h>
@ -98,11 +99,12 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
} }
if (LogAcceptCategory(BCLog::NET)) { if (LogAcceptCategory(BCLog::NET)) {
std::string log_message{"time data samples: "};
for (const int64_t n : vSorted) { for (const int64_t n : vSorted) {
LogPrint(BCLog::NET, "%+d ", n); /* Continued */ log_message += strprintf("%+d ", n);
} }
LogPrint(BCLog::NET, "| "); /* Continued */ log_message += strprintf("| median offset = %+d (%+d minutes)", nTimeOffset, nTimeOffset / 60);
LogPrint(BCLog::NET, "nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset / 60); LogPrint(BCLog::NET, "%s\n", log_message);
} }
} }
} }

View File

@ -93,8 +93,7 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
jump = DecodeJump(pos, endpos); jump = DecodeJump(pos, endpos);
if (jump == INVALID) break; // Jump offset straddles EOF if (jump == INVALID) break; // Jump offset straddles EOF
if (bits == 0) break; // No input bits left if (bits == 0) break; // No input bits left
if (pos + jump < pos) break; // overflow if (int64_t{jump} >= int64_t{endpos - pos}) break; // Jumping past EOF
if (pos + jump >= endpos) break; // Jumping past EOF
if (ip[ip.size() - bits]) { if (ip[ip.size() - bits]) {
pos += jump; pos += jump;
} }
@ -156,8 +155,7 @@ bool SanityCheckASMap(const std::vector<bool>& asmap, int bits)
} else if (opcode == Instruction::JUMP) { } else if (opcode == Instruction::JUMP) {
uint32_t jump = DecodeJump(pos, endpos); uint32_t jump = DecodeJump(pos, endpos);
if (jump == INVALID) return false; // Jump offset straddles EOF if (jump == INVALID) return false; // Jump offset straddles EOF
if (pos + jump < pos) return false; // overflow if (int64_t{jump} > int64_t{endpos - pos}) return false; // Jump out of range
if (pos + jump > endpos) return false; // Jump out of range
if (bits == 0) return false; // Consuming bits past the end of the input if (bits == 0) return false; // Consuming bits past the end of the input
--bits; --bits;
uint32_t jump_offset = pos - begin + jump; uint32_t jump_offset = pos - begin + jump;

View File

@ -289,7 +289,8 @@ public:
bool operator()(); bool operator()();
void swap(CScriptCheck &check) { void swap(CScriptCheck& check) noexcept
{
std::swap(ptxTo, check.ptxTo); std::swap(ptxTo, check.ptxTo);
std::swap(m_tx_out, check.m_tx_out); std::swap(m_tx_out, check.m_tx_out);
std::swap(nIn, check.nIn); std::swap(nIn, check.nIn);

View File

@ -1240,9 +1240,8 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRe
// Handle transactions that were removed from the mempool because they // Handle transactions that were removed from the mempool because they
// conflict with transactions in a newly connected block. // conflict with transactions in a newly connected block.
if (reason == MemPoolRemovalReason::CONFLICT) { if (reason == MemPoolRemovalReason::CONFLICT) {
// Call SyncNotifications, so external -walletnotify notifications will // Trigger external -walletnotify notifications for these transactions.
// be triggered for these transactions. Set Status::UNCONFIRMED instead // Set Status::UNCONFIRMED instead of Status::CONFLICTED for a few reasons:
// of Status::CONFLICTED for a few reasons:
// //
// 1. The transactionRemovedFromMempool callback does not currently // 1. The transactionRemovedFromMempool callback does not currently
// provide the conflicting block's hash and height, and for backwards // provide the conflicting block's hash and height, and for backwards

View File

@ -308,6 +308,10 @@ class RESTTest (BitcoinTestFramework):
# Check that there are our submitted transactions in the TX memory pool # Check that there are our submitted transactions in the TX memory pool
json_obj = self.test_rest_request("/mempool/contents") json_obj = self.test_rest_request("/mempool/contents")
raw_mempool_verbose = self.nodes[0].getrawmempool(verbose=True)
assert_equal(json_obj, raw_mempool_verbose)
for i, tx in enumerate(txs): for i, tx in enumerate(txs):
assert tx in json_obj assert tx in json_obj
assert_equal(json_obj[tx]['spentby'], txs[i + 1:i + 2]) assert_equal(json_obj[tx]['spentby'], txs[i + 1:i + 2])

23
test/lint/lint-submodule.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env python3
#
# Copyright (c) 2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
This script checks for git modules
"""
import subprocess
import sys
def main():
submodules_list = subprocess.check_output(['git', 'submodule', 'status', '--recursive'],
universal_newlines = True, encoding = 'utf8').rstrip('\n')
if submodules_list:
print("These submodules were found, delete them:\n", submodules_list)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -1,20 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (c) 2020 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# This script checks for git modules
export LC_ALL=C
EXIT_CODE=0
CMD=$(git submodule status --recursive)
if test -n "$CMD";
then
echo These submodules were found, delete them:
echo "$CMD"
EXIT_CODE=1
fi
exit $EXIT_CODE

87
test/lint/lint-tests.py Executable file
View File

@ -0,0 +1,87 @@
#!/usr/bin/env python3
#
# Copyright (c) 2018-2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
Check the test suite naming conventions
"""
import re
import subprocess
import sys
def grep_boost_fixture_test_suite():
command = [
"git",
"grep",
"-E",
r"^BOOST_FIXTURE_TEST_SUITE\(",
"--",
"src/test/**.cpp",
"src/wallet/test/**.cpp",
]
return subprocess.check_output(command, universal_newlines=True, encoding="utf8")
def check_matching_test_names(test_suite_list):
not_matching = [
x
for x in test_suite_list
if re.search(r"/(.*?)\.cpp:BOOST_FIXTURE_TEST_SUITE\(\1, .*\)", x) is None
]
if len(not_matching) > 0:
not_matching = "\n".join(not_matching)
error_msg = (
"The test suite in file src/test/foo_tests.cpp should be named\n"
'"foo_tests". Please make sure the following test suites follow\n'
"that convention:\n\n"
f"{not_matching}\n"
)
print(error_msg)
return 1
return 0
def get_duplicates(input_list):
"""
From https://stackoverflow.com/a/9835819
"""
seen = set()
dupes = set()
for x in input_list:
if x in seen:
dupes.add(x)
else:
seen.add(x)
return dupes
def check_unique_test_names(test_suite_list):
output = [re.search(r"\((.*?),", x) for x in test_suite_list]
output = [x.group(1) for x in output if x is not None]
output = get_duplicates(output)
output = sorted(list(output))
if len(output) > 0:
output = "\n".join(output)
error_msg = (
"Test suite names must be unique. The following test suite names\n"
f"appear to be used more than once:\n\n{output}"
)
print(error_msg)
return 1
return 0
def main():
test_suite_list = grep_boost_fixture_test_suite().splitlines()
exit_code = check_matching_test_names(test_suite_list)
exit_code |= check_unique_test_names(test_suite_list)
sys.exit(exit_code)
if __name__ == "__main__":
main()

View File

@ -1,35 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (c) 2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Check the test suite naming conventions
export LC_ALL=C
EXIT_CODE=0
NAMING_INCONSISTENCIES=$(git grep -E '^BOOST_FIXTURE_TEST_SUITE\(' -- \
"src/test/**.cpp" "src/wallet/test/**.cpp" | \
grep -vE '/(.*?)\.cpp:BOOST_FIXTURE_TEST_SUITE\(\1, .*\)$')
if [[ ${NAMING_INCONSISTENCIES} != "" ]]; then
echo "The test suite in file src/test/foo_tests.cpp should be named"
echo "\"foo_tests\". Please make sure the following test suites follow"
echo "that convention:"
echo
echo "${NAMING_INCONSISTENCIES}"
EXIT_CODE=1
fi
TEST_SUITE_NAME_COLLISSIONS=$(git grep -E '^BOOST_FIXTURE_TEST_SUITE\(' -- \
"src/test/**.cpp" "src/wallet/test/**.cpp" | cut -f2 -d'(' | cut -f1 -d, | \
sort | uniq -d)
if [[ ${TEST_SUITE_NAME_COLLISSIONS} != "" ]]; then
echo "Test suite names must be unique. The following test suite names"
echo "appear to be used more than once:"
echo
echo "${TEST_SUITE_NAME_COLLISSIONS}"
EXIT_CODE=1
fi
exit ${EXIT_CODE}