Skip to content

Commit

Permalink
Merge branch 'bitcoin' into particl_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tecnovert committed Apr 16, 2024
2 parents 3bf5684 + 07720b1 commit f146d61
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 168 deletions.
7 changes: 3 additions & 4 deletions ci/test/00_setup_env_native_fuzz_with_valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

export LC_ALL=C.UTF-8

export CI_IMAGE_NAME_TAG="docker.io/debian:bookworm"
export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04"
export CONTAINER_NAME=ci_native_fuzz_valgrind
export PACKAGES="clang llvm libclang-rt-dev libevent-dev libboost-dev libsqlite3-dev valgrind"
export PACKAGES="clang-16 llvm-16 libclang-rt-16-dev libevent-dev libboost-dev libsqlite3-dev valgrind"
export NO_DEPENDS=1
export RUN_UNIT_TESTS=false
export RUN_FUNCTIONAL_TESTS=false
export RUN_FUZZ_TESTS=true
export FUZZ_TESTS_CONFIG="--valgrind"
export GOAL="install"
# Temporarily pin dwarf 4, until using Valgrind 3.20 or later
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang CXX=clang++ CFLAGS=-gdwarf-4 CXXFLAGS=-gdwarf-4"
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang-16 CXX=clang++-16"
export CCACHE_MAXSIZE=200M
9 changes: 4 additions & 5 deletions ci/test/00_setup_env_native_valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

export LC_ALL=C.UTF-8

export CI_IMAGE_NAME_TAG="docker.io/debian:bookworm"
export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04"
export CONTAINER_NAME=ci_native_valgrind
export PACKAGES="valgrind clang llvm libclang-rt-dev python3-zmq libevent-dev libboost-dev libdb5.3++-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev libsqlite3-dev"
export PACKAGES="valgrind clang-16 llvm-16 libclang-rt-16-dev python3-zmq libevent-dev libboost-dev libdb5.3++-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev libsqlite3-dev"
export USE_VALGRIND=1
export NO_DEPENDS=1
export TEST_RUNNER_EXTRA="--exclude feature_init,rpc_bind,feature_bind_extra" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
export TEST_RUNNER_EXTRA="--exclude rpc_bind,feature_bind_extra" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
export GOAL="install"
# Temporarily pin dwarf 4, until using Valgrind 3.20 or later
export BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --with-gui=no CC=clang CXX=clang++ CFLAGS=-gdwarf-4 CXXFLAGS=-gdwarf-4" # TODO enable GUI
export BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --with-gui=no CC=clang-16 CXX=clang++-16" # TODO enable GUI
4 changes: 2 additions & 2 deletions ci/test/00_setup_env_s390x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export LC_ALL=C.UTF-8
export HOST=s390x-linux-gnu
export PACKAGES="python3-zmq"
export CONTAINER_NAME=ci_s390x
export CI_IMAGE_NAME_TAG="docker.io/s390x/debian:bookworm"
export TEST_RUNNER_EXTRA="--exclude feature_init,rpc_bind,feature_bind_extra" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
export CI_IMAGE_NAME_TAG="docker.io/s390x/ubuntu:24.04"
export TEST_RUNNER_EXTRA="--exclude rpc_bind,feature_bind_extra" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
export RUN_FUNCTIONAL_TESTS=true
export GOAL="install"
export BITCOIN_CONFIG="--enable-reduce-exports"
17 changes: 0 additions & 17 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -983,22 +983,6 @@ AC_CHECK_DECLS([setsid])

AC_CHECK_DECLS([pipe2])

AC_MSG_CHECKING([for __builtin_clzl])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
(void) __builtin_clzl(0);
]])],
[ AC_MSG_RESULT([yes]); have_clzl=yes; AC_DEFINE([HAVE_BUILTIN_CLZL], [1], [Define this symbol if you have __builtin_clzl])],
[ AC_MSG_RESULT([no]); have_clzl=no;]
)

AC_MSG_CHECKING([for __builtin_clzll])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
(void) __builtin_clzll(0);
]])],
[ AC_MSG_RESULT([yes]); have_clzll=yes; AC_DEFINE([HAVE_BUILTIN_CLZLL], [1], [Define this symbol if you have __builtin_clzll])],
[ AC_MSG_RESULT([no]); have_clzll=no;]
)

dnl Check for malloc_info (for memory statistics information in getmemoryinfo)
AC_MSG_CHECKING([for getmemoryinfo])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
Expand Down Expand Up @@ -1827,7 +1811,6 @@ AM_CONDITIONAL([ENABLE_USBDEVICE], [test "$enable_usbdevice" = "yes"])

dnl for minisketch
AM_CONDITIONAL([ENABLE_CLMUL], [test "$enable_clmul" = "yes"])
AM_CONDITIONAL([HAVE_CLZ], [test "$have_clzl$have_clzll" = "yesyes"])

AC_DEFINE([CLIENT_VERSION_MAJOR], [_CLIENT_VERSION_MAJOR], [Major version])
AC_DEFINE([CLIENT_VERSION_MINOR], [_CLIENT_VERSION_MINOR], [Minor version])
Expand Down
4 changes: 2 additions & 2 deletions contrib/valgrind.supp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#
# Note that suppressions may depend on OS and/or library versions.
# Tested on:
# * aarch64 (Debian Bookworm system libs, clang, without gui)
# * x86_64 (Debian Bookworm system libs, clang, without gui)
# * aarch64 (Ubuntu Noble system libs, clang, without gui)
# * x86_64 (Ubuntu Noble system libs, clang, without gui)
{
Suppress libdb warning - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=662917
Memcheck:Cond
Expand Down
4 changes: 0 additions & 4 deletions src/Makefile.minisketch.include
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ LIBMINISKETCH_CPPFLAGS += -DHAVE_CLMUL
MINISKETCH_LIBS += $(LIBMINISKETCH_CLMUL)
endif

if HAVE_CLZ
LIBMINISKETCH_CPPFLAGS += -DHAVE_CLZ
endif

EXTRA_LIBRARIES += $(MINISKETCH_LIBS)

minisketch_libminisketch_clmul_a_SOURCES = $(MINISKETCH_FIELD_CLMUL_SOURCES_INT) $(MINISKETCH_FIELD_CLMUL_HEADERS_INT)
Expand Down
8 changes: 2 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,16 +691,12 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-torcontrol=<ip>:<port>", strprintf("Tor control host and port to use if onion listening enabled (default: %s). If no port is specified, the default port of %i will be used.", DEFAULT_TOR_CONTROL, DEFAULT_TOR_CONTROL_PORT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-torpassword=<pass>", "Tor control port password (default: empty)", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::CONNECTION);
#ifdef USE_UPNP
#if USE_UPNP
argsman.AddArg("-upnp", "Use UPnP to map the listening port (default: 1 when listening and no -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#else
argsman.AddArg("-upnp", strprintf("Use UPnP to map the listening port (default: %u)", 0), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#endif
argsman.AddArg("-upnp", strprintf("Use UPnP to map the listening port (default: %u)", DEFAULT_UPNP), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#else
hidden_args.emplace_back("-upnp");
#endif
#ifdef USE_NATPMP
argsman.AddArg("-natpmp", strprintf("Use NAT-PMP to map the listening port (default: %s)", DEFAULT_NATPMP ? "1 when listening and no -proxy" : "0"), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-natpmp", strprintf("Use NAT-PMP to map the listening port (default: %u)", DEFAULT_NATPMP), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#else
hidden_args.emplace_back("-natpmp");
#endif // USE_NATPMP
Expand Down
57 changes: 30 additions & 27 deletions src/minisketch/.cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ env_matrix_snippet: &ENV_MATRIX_VALGRIND
TESTRUNS: 1
BUILD:

env_matrix_snippet: &ENV_MATRIX_SAN
- env:
ENABLE_FIELDS: 28
- env:
BUILD: distcheck
- env:
CXXFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
BENCH: no

env_matrix_snippet: &ENV_MATRIX_SAN_VALGRIND
- env:
ENABLE_FIELDS: "11,64,37"
Expand All @@ -72,9 +61,9 @@ task:
<< : *ENV_MATRIX_SAN_VALGRIND
matrix:
- env:
CC: gcc
CXX: g++
- env:
CC: clang
CXX: clang++ -gdwarf-4
<< : *MERGE_BASE
test_script:
- ./ci/cirrus.sh
Expand All @@ -92,30 +81,45 @@ task:
<< : *ENV_MATRIX_VALGRIND
matrix:
- env:
CC: i686-linux-gnu-gcc
CXX: i686-linux-gnu-g++
- env:
CC: clang --target=i686-pc-linux-gnu -isystem /usr/i686-linux-gnu/include
CXX: clang++ --target=i686-linux-gnu -gdwarf-4
CXXFLAGS: -g -O2 -isystem /usr/i686-linux-gnu/include -isystem /usr/i686-linux-gnu/include/c++/10/i686-linux-gnu
test_script:
- ./ci/cirrus.sh
<< : *CAT_LOGS

task:
name: "x86_64: macOS Catalina"
name: "arm64: macOS Monterey"
macos_instance:
image: catalina-base
image: ghcr.io/cirruslabs/macos-monterey-base:latest
env:
# Cirrus gives us a fixed number of 12 virtual CPUs.
MAKEFLAGS: -j13
matrix:
<< : *ENV_MATRIX_SAN
# Cirrus gives us a fixed number of 4 virtual CPUs.
MAKEFLAGS: -j5
matrix:
- env:
CC: gcc-9
CXX: g++-11
# Homebrew's gcc for arm64 has no libubsan.
matrix:
- env:
ENABLE_FIELDS: 28
- env:
BUILD: distcheck
- env:
CC: clang
CXX: clang++
matrix:
- env:
ENABLE_FIELDS: 28
- env:
BUILD: distcheck
- env:
CXXFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
BENCH: no
brew_script:
- brew update
- brew install automake libtool gcc@9
- brew install automake libtool gcc@11
<< : *MERGE_BASE
test_script:
- ./ci/cirrus.sh
Expand All @@ -128,13 +132,11 @@ task:
cpu: 4
memory: 2G
env:
EXEC_CMD: qemu-s390x -L /usr/s390x-linux-gnu
EXEC_CMD: qemu-s390x
HOST: s390x-linux-gnu
BUILD:
<< : *MERGE_BASE
test_script:
# https://sourceware.org/bugzilla/show_bug.cgi?id=27008
- rm /etc/ld.so.cache
- ./ci/cirrus.sh
<< : *CAT_LOGS

Expand All @@ -146,6 +148,7 @@ task:
memory: 2G
env:
EXEC_CMD: wine
EXEC_EXT: .exe
HOST: x86_64-w64-mingw32
BUILD:
<< : *MERGE_BASE
Expand Down
8 changes: 4 additions & 4 deletions src/minisketch/ci/cirrus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export LC_ALL=C

env >> test_env.log

$CC -v || true
$CXX -v || true
valgrind --version || true

./autogen.sh
Expand All @@ -32,10 +32,10 @@ then
fi

if [ -n "$EXEC_CMD" ]; then
$EXEC_CMD ./test $TESTRUNS
$EXEC_CMD ./test-verify $TESTRUNS
$EXEC_CMD "./test$EXEC_EXT" $TESTRUNS
$EXEC_CMD "./test-verify$EXEC_EXT" $TESTRUNS
fi

if [ "$BENCH" = "yes" ]; then
$EXEC_CMD ./bench
$EXEC_CMD "./bench$EXEC_EXT"
fi
6 changes: 3 additions & 3 deletions src/minisketch/ci/linux-debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ RUN apt-get update
RUN apt-get install --no-install-recommends --no-upgrade -y \
git ca-certificates \
make automake libtool pkg-config dpkg-dev valgrind qemu-user \
gcc g++ clang libc6-dbg \
gcc g++ clang libclang-rt-dev libc6-dbg \
gcc-i686-linux-gnu g++-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 \
g++-s390x-linux-gnu gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
wine g++-mingw-w64-x86-64
g++-s390x-linux-gnu libstdc++6:s390x gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
wine wine64 g++-mingw-w64-x86-64

# Run a dummy command in wine to make it set up configuration
RUN wine true || true
6 changes: 0 additions & 6 deletions src/minisketch/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ esac
AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[CXXFLAGS="$CXXFLAGS -fvisibility=hidden"],[],[$CXXFLAG_WERROR])

## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
## unknown options if any other warning is produced. Test the -Wfoo case, and
## set the -Wno-foo case if it works.
AX_CHECK_COMPILE_FLAG([-Wshift-count-overflow],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-shift-count-overflow"],,[[$CXXFLAG_WERROR]])

if test "x$use_ccache" != "xno"; then
AC_MSG_CHECKING(if ccache should be used)
if test x$CCACHE = x; then
Expand All @@ -119,7 +114,6 @@ if test "x$use_ccache" != "xno"; then
fi
else
use_ccache=yes
CC="$ac_cv_path_CCACHE $CC"
CXX="$ac_cv_path_CCACHE $CXX"
fi
AC_MSG_RESULT($use_ccache)
Expand Down
34 changes: 27 additions & 7 deletions src/minisketch/src/int_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
#ifndef _MINISKETCH_INT_UTILS_H_
#define _MINISKETCH_INT_UTILS_H_

#include <stdint.h>
#include <stdlib.h>

#include <limits>
#include <algorithm>
#include <type_traits>

#ifdef _MSC_VER
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
# include <bit>
#elif defined(_MSC_VER)
# include <intrin.h>
#endif

Expand Down Expand Up @@ -54,11 +57,10 @@ class BitWriter {
int offset = 0;
unsigned char* out;

public:
BitWriter(unsigned char* output) : out(output) {}

template<int BITS, typename I>
inline void Write(I val) {
inline void WriteInner(I val) {
// We right shift by up to 8 bits below. Verify that's well defined for the type I.
static_assert(std::numeric_limits<I>::digits > 8, "BitWriter::WriteInner needs I > 8 bits");
int bits = BITS;
if (bits + offset >= 8) {
state |= ((val & ((I(1) << (8 - offset)) - 1)) << offset);
Expand All @@ -77,6 +79,19 @@ class BitWriter {
offset += bits;
}


public:
BitWriter(unsigned char* output) : out(output) {}

template<int BITS, typename I>
inline void Write(I val) {
// If I is smaller than an unsigned int, invoke WriteInner with argument converted to unsigned.
using compute_type = typename std::conditional<
(std::numeric_limits<I>::digits < std::numeric_limits<unsigned>::digits),
unsigned, I>::type;
return WriteInner<BITS, compute_type>(val);
}

inline void Flush() {
if (offset) {
*(out++) = state;
Expand Down Expand Up @@ -129,7 +144,11 @@ constexpr inline I Mask() { return ((I((I(-1)) << (std::numeric_limits<I>::digit
/** Compute the smallest power of two that is larger than val. */
template<typename I>
static inline int CountBits(I val, int max) {
#ifdef _MSC_VER
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
// c++20 impl
(void)max;
return std::bit_width(val);
#elif defined(_MSC_VER)
(void)max;
unsigned long index;
unsigned char ret;
Expand Down Expand Up @@ -175,6 +194,7 @@ class BitsInt {
}

static constexpr inline bool IsZero(I a) { return a == 0; }
static constexpr inline bool IsOne(I a) { return a == 1; }
static constexpr inline I Mask(I val) { return val & MASK; }
static constexpr inline I Shift(I val, int bits) { return ((val << bits) & MASK); }
static constexpr inline I UnsafeShift(I val, int bits) { return (val << bits); }
Expand Down Expand Up @@ -233,7 +253,7 @@ template<typename I, int N, typename L, typename F> inline constexpr I GFMul(con
template<typename I, typename F, int BITS, uint32_t MOD>
inline I InvExtGCD(I x)
{
if (F::IsZero(x)) return x;
if (F::IsZero(x) || F::IsOne(x)) return x;
I t(0), newt(1);
I r(MOD), newr = x;
int rlen = BITS + 1, newrlen = F::Bits(newr, BITS);
Expand Down
7 changes: 5 additions & 2 deletions src/rpc/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <univalue.h>
#include <util/any.h>
#include <util/check.h>
#include <util/time.h>

#include <stdint.h>
#ifdef HAVE_MALLOC_INFO
Expand Down Expand Up @@ -63,9 +64,11 @@ static RPCHelpMan setmocktime()

bool isOffset = request.params.size() > 1 ? GetBool(request.params[1]) : false;
const int64_t time{request.params[0].getInt<int64_t>()};
if (time < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
constexpr int64_t max_time{Ticks<std::chrono::seconds>(std::chrono::nanoseconds::max())};
if (time < 0 || time > max_time) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime must be in the range [0, %s], not %s.", max_time, time));
}

if (isOffset) {
SetMockTimeOffset(time);
} else {
Expand Down
Loading

0 comments on commit f146d61

Please sign in to comment.