From f254f77d75ddd76889eec7401d5685cc48fcbb58 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 9 Feb 2021 07:56:37 +0100 Subject: [PATCH 01/11] Merge #21075: doc: Fix markdown formatting e1604b3d50dca3291a432be59cfd03c0e846e7b2 doc: Replace tabs for spaces (Gunar C. Gessner) 98db48d3490e5863b4d89e03cebeece9bd1f91ae doc: Fix markdown formatting (Gunar Gessner) Pull request description: Lines were being joined making it hard to read. ACKs for top commit: RandyMcMillan: ACK e1604b3d50dca3291a432be59cfd03c0e846e7b2 Tree-SHA512: fd5a7c5e9a1cbbf0fbb13b5c30b87853c84751da7f0fad08151bda07f1933872ab51cad29a0c0a70ced48e60df6d83bff3f84c2f77d00d22723fae9a8c3534fc --- doc/build-unix.md | 18 ++++---- doc/init.md | 18 ++++---- doc/tor.md | 104 +++++++++++++++++++++++----------------------- 3 files changed, 70 insertions(+), 70 deletions(-) diff --git a/doc/build-unix.md b/doc/build-unix.md index e700601daf..21dea362bc 100644 --- a/doc/build-unix.md +++ b/doc/build-unix.md @@ -9,7 +9,7 @@ Note Always use absolute paths to configure and compile Dash Core and the dependencies. For example, when specifying the path of the dependency: - ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX + ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX Here BDB_PREFIX must be an absolute path - it is defined using $(pwd) which ensures the usage of the absolute path. @@ -227,9 +227,9 @@ Boost ----- If you need to build Boost yourself: - sudo su - ./bootstrap.sh - ./bjam install + sudo su + ./bootstrap.sh + ./bjam install Security @@ -240,8 +240,8 @@ This can be disabled with: Hardening Flags: - ./configure --enable-hardening - ./configure --disable-hardening + ./configure --enable-hardening + ./configure --disable-hardening Hardening enables the following features: @@ -256,7 +256,7 @@ Hardening enables the following features: To test that you have built PIE executable, install scanelf, part of paxutils, and use: - scanelf -e ./dashd + scanelf -e ./dashd The output should contain: @@ -273,8 +273,8 @@ Hardening enables the following features: `scanelf -e ./dashd` The output should contain: - STK/REL/PTL - RW- R-- RW- + STK/REL/PTL + RW- R-- RW- The STK RW- means that the stack is readable and writeable but not executable. diff --git a/doc/init.md b/doc/init.md index f5d2891912..2c184d1c6d 100644 --- a/doc/init.md +++ b/doc/init.md @@ -53,11 +53,11 @@ Paths All three configurations assume several paths that might need to be adjusted. -Binary: `/usr/bin/dashd` -Configuration file: `/etc/dashcore/dash.conf` -Data directory: `/var/lib/dashd` -PID file: `/var/run/dashd/dashd.pid` (OpenRC and Upstart) or `/run/dashd/dashd.pid` (systemd) -Lock file: `/var/lock/subsys/dashd` (CentOS) + Binary: /usr/bin/dashd + Configuration file: /etc/dashcore/dash.conf + Data directory: /var/lib/dashd + PID file: /var/run/dashd/dashd.pid (OpenRC and Upstart) or /run/dashd/dashd.pid (systemd) + Lock file: /var/lock/subsys/dashd (CentOS) The PID directory (if applicable) and data directory should both be owned by the dashcore user and group. It is advised for security reasons to make the @@ -83,10 +83,10 @@ OpenRC). ### macOS -Binary: `/usr/local/bin/dashd` -Configuration file: `~/Library/Application Support/DashCore/dash.conf` -Data directory: `~/Library/Application Support/DashCore` -Lock file: `~/Library/Application Support/DashCore/.lock` + Binary: /usr/local/bin/dashd + Configuration file: ~/Library/Application Support/DashCore/dash.conf + Data directory: ~/Library/Application Support/DashCore + Lock file: ~/Library/Application Support/DashCore/.lock Installing Service Configuration ----------------------------------- diff --git a/doc/tor.md b/doc/tor.md index 66bc8e309e..6362941501 100644 --- a/doc/tor.md +++ b/doc/tor.md @@ -24,44 +24,44 @@ information in the debug log about your Tor configuration. The first step is running Dash Core behind a Tor proxy. This will already anonymize all outgoing connections, but more is possible. - -proxy=ip:port Set the proxy server. If SOCKS5 is selected (default), this proxy - server will be used to try to reach .onion addresses as well. - You need to use -noonion or -onion=0 to explicitly disable - outbound access to onion services. + -proxy=ip:port Set the proxy server. If SOCKS5 is selected (default), this proxy + server will be used to try to reach .onion addresses as well. + You need to use -noonion or -onion=0 to explicitly disable + outbound access to onion services. - -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. + -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 - need to enable it explicitly. + -listen When using -proxy, listening is disabled by default. If you want + to manually configure an onion service (see section 3), you'll + need to enable it explicitly. - -connect=X When behind a Tor proxy, you can specify .onion addresses instead - -addnode=X of IP addresses or hostnames in these parameters. It requires - -seednode=X SOCKS5. In Tor mode, such addresses can also be exchanged with - other P2P nodes. + -connect=X When behind a Tor proxy, you can specify .onion addresses instead + -addnode=X of IP addresses or hostnames in these parameters. It requires + -seednode=X SOCKS5. In Tor mode, such addresses can also be exchanged with + other P2P nodes. - -onlynet=onion Make outgoing connections only to .onion addresses. Incoming - connections are not affected by this option. This option can be - specified multiple times to allow multiple network types, e.g. - ipv4, ipv6 or onion. If you use this option with values other - than onion you *cannot* disable onion connections; outgoing onion - connections will be enabled when you use -proxy or -onion. Use - -noonion or -onion=0 if you want to be sure there are no outbound - onion connections over the default proxy or your defined -proxy. + -onlynet=onion Make outgoing connections only to .onion addresses. Incoming + connections are not affected by this option. This option can be + specified multiple times to allow multiple network types, e.g. + ipv4, ipv6 or onion. If you use this option with values other + than onion you *cannot* disable onion connections; outgoing onion + connections will be enabled when you use -proxy or -onion. Use + -noonion or -onion=0 if you want to be sure there are no outbound + onion connections over the default proxy or your defined -proxy. An example how to start the client if the Tor proxy is running on local host on port 9050 and only allows .onion nodes to connect: - ./dashd -onion=127.0.0.1:9050 -onlynet=onion -listen=0 -addnode=ssapp53tmftyjmjb.onion + ./dashd -onion=127.0.0.1:9050 -onlynet=onion -listen=0 -addnode=ssapp53tmftyjmjb.onion In a typical situation, this suffices to run behind a Tor proxy: - ./dashd -proxy=127.0.0.1:9050 + ./dashd -proxy=127.0.0.1:9050 ## 2. Automatically create a Dash Core onion service @@ -162,57 +162,57 @@ reachable from the Tor network. Add these lines to your /etc/tor/torrc (or equiv config file): *Needed for Tor version 0.2.7.0 and older versions of Tor only. For newer versions of Tor see [Section 4](#4-automatically-listen-on-tor).* - HiddenServiceDir /var/lib/tor/dashcore-service/ - HiddenServicePort 9999 127.0.0.1:9996 + HiddenServiceDir /var/lib/tor/dashcore-service/ + HiddenServicePort 9999 127.0.0.1:9996 The directory can be different of course, but virtual port numbers should be equal to your dashd's P2P listen port (9999 by default), and target addresses and ports should be equal to binding address and port for inbound Tor connections (127.0.0.1:9996 by default). - -externalip=X You can tell Dash Core about its publicly reachable addresses using - this option, and this can be an onion address. Given the above - configuration, you can find your onion address in - /var/lib/tor/dashcore-service/hostname. For connections - coming from unroutable addresses (such as 127.0.0.1, where the - Tor proxy typically runs), onion addresses are given - preference for your node to advertise itself with. + -externalip=X You can tell Dash Core about its publicly reachable addresses using + this option, and this can be an onion address. Given the above + configuration, you can find your onion address in + /var/lib/tor/dashcore-service/hostname. For connections + coming from unroutable addresses (such as 127.0.0.1, where the + Tor proxy typically runs), onion addresses are given + preference for your node to advertise itself with. - You can set multiple local addresses with -externalip. The - one that will be rumoured to a particular peer is the most - compatible one and also using heuristics, e.g. the address - with the most incoming connections, etc. + You can set multiple local addresses with -externalip. The + one that will be rumoured to a particular peer is the most + compatible one and also using heuristics, e.g. the address + with the most incoming connections, etc. - -listen You'll need to enable listening for incoming connections, as this - is off by default behind a proxy. + -listen You'll need to enable listening for incoming connections, as this + is off by default behind a proxy. - -discover When -externalip is specified, no attempt is made to discover local - IPv4 or IPv6 addresses. If you want to run a dual stack, reachable - from both Tor and IPv4 (or IPv6), you'll need to either pass your - other addresses using -externalip, or explicitly enable -discover. - Note that both addresses of a dual-stack system may be easily - linkable using traffic analysis. + -discover When -externalip is specified, no attempt is made to discover local + IPv4 or IPv6 addresses. If you want to run a dual stack, reachable + from both Tor and IPv4 (or IPv6), you'll need to either pass your + other addresses using -externalip, or explicitly enable -discover. + Note that both addresses of a dual-stack system may be easily + linkable using traffic analysis. In a typical situation, where you're only reachable via Tor, this should suffice: - ./dashd -proxy=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -listen + ./dashd -proxy=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -listen (obviously, replace the .onion address with your own). It should be noted that you still listen on all devices and another node could establish a clearnet connection, when knowing your address. To mitigate this, additionally bind the address of your Tor proxy: - ./dashd ... -bind=127.0.0.1 + ./dashd ... -bind=127.0.0.1 If you don't care too much about hiding your node, and want to be reachable on IPv4 as well, use `discover` instead: - ./dashd ... -discover + ./dashd ... -discover and open port 9999 on your firewall (or use port mapping, i.e., `-upnp` or `-natpmp`). If you only want to use Tor to reach .onion addresses, but not use it as a proxy for normal IPv4/IPv6 communication, use: - ./dashd -onion=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -discover + ./dashd -onion=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -discover ## 3.1. List of known Dash Core Tor relays From 4abb76845648ff97329b7794a5346e95c2901571 Mon Sep 17 00:00:00 2001 From: fanquake Date: Wed, 10 Feb 2021 09:13:10 +0800 Subject: [PATCH 02/11] Merge #21126: ci: Properly bump to focal for win cross build fa272dfdff711e324baefc9bdbb2bf4b52d99eb0 ci: Properly bump to focal for win cross build (MarcoFalke) Pull request description: Fixes #21122 ACKs for top commit: fanquake: ACK fa272dfdff711e324baefc9bdbb2bf4b52d99eb0 - Looks good to me. I can see the wine version output, `wine-5.0 (Ubuntu 5.0-3ubuntu1)`, in the [log](https://cirrus-ci.com/task/5743559502462976), and `make check` is running. Tree-SHA512: cd37462afc5512e00cef5e9e7fd1bb5c43c600e833b30cdea2c1c443dc7b0e68f5f2cbaf9d7b655892059af0a226478211db1dc97c10fe4dcdfe666a784f3afc --- .cirrus.yml | 2 +- ci/test/00_setup_env_win64.sh | 2 +- ci/test/wrap-wine.sh | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 103fed7409..13a30555b7 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -71,7 +71,7 @@ task: QEMU_USER_CMD: "" # Disable qemu and run the test natively task: - name: 'Win64 [unit tests, no gui tests, no boost::process, no functional tests] [bionic]' + name: 'Win64 [unit tests, no gui tests, no boost::process, no functional tests] [focal]' << : *GLOBAL_TASK_TEMPLATE container: image: ubuntu:focal diff --git a/ci/test/00_setup_env_win64.sh b/ci/test/00_setup_env_win64.sh index 0dcf820100..43f072d2a1 100755 --- a/ci/test/00_setup_env_win64.sh +++ b/ci/test/00_setup_env_win64.sh @@ -8,8 +8,8 @@ export LC_ALL=C.UTF-8 export CONTAINER_NAME=ci_win64 export HOST=x86_64-w64-mingw32 -export PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine-binfmt wine64 file" export DPKG_ADD_ARCH="i386" +export PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine-binfmt wine64 wine32 file" export RUN_FUNCTIONAL_TESTS=false export RUN_SECURITY_TESTS="false" export GOAL="deploy" diff --git a/ci/test/wrap-wine.sh b/ci/test/wrap-wine.sh index 58a8983e6e..5c2eae2dd6 100755 --- a/ci/test/wrap-wine.sh +++ b/ci/test/wrap-wine.sh @@ -6,6 +6,8 @@ export LC_ALL=C.UTF-8 +wine --version + for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/univalue/{no_nul,test_json,unitester,object}}.exe; do # shellcheck disable=SC2044 for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename $b_name)"); do @@ -13,7 +15,7 @@ for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/univalue/{no_nul, echo "Wrap $b ..." mv "$b" "${b}_orig" echo '#!/usr/bin/env bash' > "$b" - echo "wine64 \"${b}_orig\" \"\$@\"" >> "$b" + echo "wine \"${b}_orig\" \"\$@\"" >> "$b" chmod +x "$b" fi done From 88a45d4a9aa74f38f851f414bee4d364cdc432b0 Mon Sep 17 00:00:00 2001 From: fanquake Date: Wed, 10 Feb 2021 19:50:39 +0800 Subject: [PATCH 03/11] Merge #21138: ci: Re-run wine tests once if they fail faa8afe70b4992267176a97262f59413d1a1196b ci: Re-run wine tests once if they fail (MarcoFalke) Pull request description: Works around the intermittent wine issue: https://github.com/bitcoin/bitcoin/issues/21122#issuecomment-776517563 ACKs for top commit: fanquake: ACK faa8afe70b4992267176a97262f59413d1a1196b - thanks for following up with this. Tree-SHA512: cb377a8e62c7fcf38fb5bdd6203af82c6c302c86f7fc219cb756eb7b6d3d4fe4ebf30a36ebba739199ff7814b26256a3701cf38dc5e681b18c2f249cdf6d852e --- ci/test/wrap-wine.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ci/test/wrap-wine.sh b/ci/test/wrap-wine.sh index 5c2eae2dd6..82964897e1 100755 --- a/ci/test/wrap-wine.sh +++ b/ci/test/wrap-wine.sh @@ -6,8 +6,6 @@ export LC_ALL=C.UTF-8 -wine --version - for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/univalue/{no_nul,test_json,unitester,object}}.exe; do # shellcheck disable=SC2044 for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename $b_name)"); do @@ -15,7 +13,7 @@ for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/univalue/{no_nul, echo "Wrap $b ..." mv "$b" "${b}_orig" echo '#!/usr/bin/env bash' > "$b" - echo "wine \"${b}_orig\" \"\$@\"" >> "$b" + echo "( wine \"${b}_orig\" \"\$@\" ) || ( sleep 1 && wine \"${b}_orig\" \"\$@\" )" >> "$b" chmod +x "$b" fi done From 318c7263d0395c6b590b67231960457d23a732e7 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 12 Feb 2021 10:56:51 +0100 Subject: [PATCH 04/11] Merge #19522: build: fix building libconsensus with reduced exports for Darwin targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit de4238f92f4c067f099663f68d9772105de81d75 build: consolidate reduced export checks (fanquake) 012bdec1b7df01906566a6526e56f27d57d1653b build: add building libconsensus to end-of-configure output (fanquake) 8f360e349e365870b40a6873917c81de714ae41a build: remove ax_gcc_func_attribute macro (fanquake) f054a089ecfbdc4732e6f705a10e93189074f41c build: remove AX_GCC_FUNC_ATTRIBUTE test for dllimport (fanquake) 7cd0a696643a824ab6f6911278f116f01c5af662 build: test for __declspec(dllexport) in configure (fanquake) 1624e17b5430dfe808bb3b1b79dfa53bf45aa053 build: remove duplicate visibility attribute detection (fanquake) Pull request description: Darwin targets do not have a `protected` visibility function attribute, see [LLVM explanation](https://github.com/llvm/llvm-project/blob/8e9a505139fbef7d2e6e9d0adfe1efc87326f9ef/clang/lib/Basic/Targets/OSTargets.h#L131). This means that the `AX_GCC_FUNC_ATTRIBUTE` check for `visibility` fails: ```bash configure:24513: checking for __attribute__((visibility)) configure:24537: g++ -std=c++11 -o conftest -g -O2 -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -Wl,-headerpad_max_install_names conftest.cpp >&5 conftest.cpp:35:56: warning: target does not support 'protected' visibility; using 'default' [-Wunsupported-visibility] int foo_pro( void ) __attribute__((visibility("protected"))); ^ 1 warning generated. configure:24537: $? = 0 configure:24550: result: no ``` This leads to `EXPORT_SYMBOL` being [defined to nothing](https://github.com/bitcoin/bitcoin/blob/f4de89edfa8be4501534fec0c662c650a4ce7ef2/src/script/bitcoinconsensus.h#L29), as `HAVE_FUNC_ATTRIBUTE_VISIBILITY` is not defined, and when building with reduced exports, you end up with a libbitcoinconsensus.dylib that doesn't export any `_bitcoinconsensus_*` symbols. ```bash โžœ git:(master) nm -C src/.libs/libbitcoinconsensus.dylib | rg _bitcoinconsensus_ โžœ git:(master) ``` We do have a [second check](https://github.com/bitcoin/bitcoin/blob/f4de89edfa8be4501534fec0c662c650a4ce7ef2/configure.ac#L882) for the `visibility` attribute, which works for Darwin as it's only testing for default visibility, however the result of this check isn't used at all. It was added in #4725, along with the `--enable-reduce-exports` option, however when libbitcoinconsensus was added in #5235, it used the results of the added `AX_GCC_FUNC_ATTRIBUTE` calls. This PR removes our usage of the AX_GCC_FUNC_ATTRIBUTE macro entirely, in favour of our own checks in configure. This meant adding a check for `dllexport`, which I've tested as working with both [GCC](https://gcc.gnu.org/onlinedocs/gcc/Microsoft-Windows-Function-Attributes.html) and [Clang](https://releases.llvm.org/10.0.0/tools/clang/docs/AttributeReference.html#dllexport) when building for Windows. I haven't added an equivalent check for `dllimport`, as we weren't actually using the result of that check, we're just testing that `MSC_VER` was defined before using. With these changes building a libbitcoinconsensus with reduced exports, when targeting Darwin, works as expected: ```bash ./autogen.sh ./configure --disable-tests --disable-bench --with-utils=no --with-daemon=no --with-gui=no --disable-wallet --with-libs=yes --enable-reduce-exports make -j8 ... nm -C src/.libs/libbitcoinconsensus.dylib | rg _bitcoinconsensus_ 000000000000a340 T _bitcoinconsensus_verify_script 00000000000097e0 T _bitcoinconsensus_verify_script_with_amount 000000000000a3c0 T _bitcoinconsensus_version ``` ```python >>> import ctypes >>> consensus = ctypes.CDLL("src/.libs/libbitcoinconsensus.dylib") >>> print(consensus.bitcoinconsensus_version()) 1 >>> exit() ``` TODO: Modify a CI job to compile with --enable-reduce-exports and check for symbols in shared lib? ACKs for top commit: laanwj: Code review ACK de4238f92f4c067f099663f68d9772105de81d75 Tree-SHA512: d148f3c55d14dac6e9e5b718cc65bb557bcf6f663218d24bc9044b86281bd5dd3d931ebea79c336a58e8ed50d683218c0a9e75494f2267b91097665043e252ae --- build-aux/m4/ax_gcc_func_attribute.m4 | 223 -------------------------- configure.ac | 37 +++-- src/script/bitcoinconsensus.h | 12 +- 3 files changed, 26 insertions(+), 246 deletions(-) delete mode 100644 build-aux/m4/ax_gcc_func_attribute.m4 diff --git a/build-aux/m4/ax_gcc_func_attribute.m4 b/build-aux/m4/ax_gcc_func_attribute.m4 deleted file mode 100644 index c788ca9bd4..0000000000 --- a/build-aux/m4/ax_gcc_func_attribute.m4 +++ /dev/null @@ -1,223 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE) -# -# DESCRIPTION -# -# This macro checks if the compiler supports one of GCC's function -# attributes; many other compilers also provide function attributes with -# the same syntax. Compiler warnings are used to detect supported -# attributes as unsupported ones are ignored by default so quieting -# warnings when using this macro will yield false positives. -# -# The ATTRIBUTE parameter holds the name of the attribute to be checked. -# -# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_. -# -# The macro caches its result in the ax_cv_have_func_attribute_ -# variable. -# -# The macro currently supports the following function attributes: -# -# alias -# aligned -# alloc_size -# always_inline -# artificial -# cold -# const -# constructor -# constructor_priority for constructor attribute with priority -# deprecated -# destructor -# dllexport -# dllimport -# error -# externally_visible -# flatten -# format -# format_arg -# gnu_inline -# hot -# ifunc -# leaf -# malloc -# noclone -# noinline -# nonnull -# noreturn -# nothrow -# optimize -# pure -# unused -# used -# visibility -# warning -# warn_unused_result -# weak -# weakref -# -# Unsuppored function attributes will be tested with a prototype returning -# an int and not accepting any arguments and the result of the check might -# be wrong or meaningless so use with care. -# -# LICENSE -# -# Copyright (c) 2013 Gabriele Svelto -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 3 - -AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ - AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) - - AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ - AC_LINK_IFELSE([AC_LANG_PROGRAM([ - m4_case([$1], - [alias], [ - int foo( void ) { return 0; } - int bar( void ) __attribute__(($1("foo"))); - ], - [aligned], [ - int foo( void ) __attribute__(($1(32))); - ], - [alloc_size], [ - void *foo(int a) __attribute__(($1(1))); - ], - [always_inline], [ - inline __attribute__(($1)) int foo( void ) { return 0; } - ], - [artificial], [ - inline __attribute__(($1)) int foo( void ) { return 0; } - ], - [cold], [ - int foo( void ) __attribute__(($1)); - ], - [const], [ - int foo( void ) __attribute__(($1)); - ], - [constructor_priority], [ - int foo( void ) __attribute__((__constructor__(65535/2))); - ], - [constructor], [ - int foo( void ) __attribute__(($1)); - ], - [deprecated], [ - int foo( void ) __attribute__(($1(""))); - ], - [destructor], [ - int foo( void ) __attribute__(($1)); - ], - [dllexport], [ - __attribute__(($1)) int foo( void ) { return 0; } - ], - [dllimport], [ - int foo( void ) __attribute__(($1)); - ], - [error], [ - int foo( void ) __attribute__(($1(""))); - ], - [externally_visible], [ - int foo( void ) __attribute__(($1)); - ], - [flatten], [ - int foo( void ) __attribute__(($1)); - ], - [format], [ - int foo(const char *p, ...) __attribute__(($1(printf, 1, 2))); - ], - [format_arg], [ - char *foo(const char *p) __attribute__(($1(1))); - ], - [gnu_inline], [ - inline __attribute__(($1)) int foo( void ) { return 0; } - ], - [hot], [ - int foo( void ) __attribute__(($1)); - ], - [ifunc], [ - int my_foo( void ) { return 0; } - static int (*resolve_foo(void))(void) { return my_foo; } - int foo( void ) __attribute__(($1("resolve_foo"))); - ], - [leaf], [ - __attribute__(($1)) int foo( void ) { return 0; } - ], - [malloc], [ - void *foo( void ) __attribute__(($1)); - ], - [noclone], [ - int foo( void ) __attribute__(($1)); - ], - [noinline], [ - __attribute__(($1)) int foo( void ) { return 0; } - ], - [nonnull], [ - int foo(char *p) __attribute__(($1(1))); - ], - [noreturn], [ - void foo( void ) __attribute__(($1)); - ], - [nothrow], [ - int foo( void ) __attribute__(($1)); - ], - [optimize], [ - __attribute__(($1(3))) int foo( void ) { return 0; } - ], - [pure], [ - int foo( void ) __attribute__(($1)); - ], - [unused], [ - int foo( void ) __attribute__(($1)); - ], - [used], [ - int foo( void ) __attribute__(($1)); - ], - [visibility], [ - int foo_def( void ) __attribute__(($1("default"))); - int foo_hid( void ) __attribute__(($1("hidden"))); - int foo_int( void ) __attribute__(($1("internal"))); - int foo_pro( void ) __attribute__(($1("protected"))); - ], - [warning], [ - int foo( void ) __attribute__(($1(""))); - ], - [warn_unused_result], [ - int foo( void ) __attribute__(($1)); - ], - [weak], [ - int foo( void ) __attribute__(($1)); - ], - [weakref], [ - static int foo( void ) { return 0; } - static int bar( void ) __attribute__(($1("foo"))); - ], - [ - m4_warn([syntax], [Unsupported attribute $1, the test may fail]) - int foo( void ) __attribute__(($1)); - ] - )], []) - ], - dnl GCC doesn't exit with an error if an unknown attribute is - dnl provided but only outputs a warning, so accept the attribute - dnl only if no warning were issued. - [AS_IF([test -s conftest.err], - [AS_VAR_SET([ac_var], [no])], - [AS_VAR_SET([ac_var], [yes])])], - [AS_VAR_SET([ac_var], [no])]) - ]) - - AS_IF([test yes = AS_VAR_GET([ac_var])], - [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1, - [Define to 1 if the system has the `$1' function attribute])], []) - - AS_VAR_POPDEF([ac_var]) -]) diff --git a/configure.ac b/configure.ac index e86fc71d9a..989cbbcfe9 100644 --- a/configure.ac +++ b/configure.ac @@ -913,10 +913,6 @@ if test x$ac_cv_sys_large_files != x && CPPFLAGS="$CPPFLAGS -D_LARGE_FILES=$ac_cv_sys_large_files" fi -AX_GCC_FUNC_ATTRIBUTE([visibility]) -AX_GCC_FUNC_ATTRIBUTE([dllexport]) -AX_GCC_FUNC_ATTRIBUTE([dllimport]) - AC_SEARCH_LIBS([clock_gettime],[rt]) if test "x$enable_gprof" = xyes; then @@ -1078,13 +1074,13 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ [ AC_MSG_RESULT(no)] ) -AC_MSG_CHECKING([for visibility attribute]) -AC_LINK_IFELSE([AC_LANG_SOURCE([ - int foo_def( void ) __attribute__((visibility("default"))); +AC_MSG_CHECKING([for default visibility attribute]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + int foo(void) __attribute__((visibility("default"))); int main(){} ])], [ - AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.]) + AC_DEFINE(HAVE_DEFAULT_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.]) AC_MSG_RESULT(yes) ], [ @@ -1095,6 +1091,18 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ ] ) +AC_MSG_CHECKING([for dllexport attribute]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + __declspec(dllexport) int foo(void); + int main(){} + ])], + [ + AC_DEFINE(HAVE_DLLEXPORT_ATTRIBUTE,1,[Define if the dllexport attribute is supported.]) + AC_MSG_RESULT(yes) + ], + [AC_MSG_RESULT(no)] +) + if test "x$use_thread_local" = xyes || test "x$use_thread_local" = xauto; then TEMP_LDFLAGS="$LDFLAGS" LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS" @@ -1269,12 +1277,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ [ AC_MSG_RESULT(no); HAVE_STRONG_GETAUXVAL=0 ] ) -dnl Check for reduced exports -if test x$use_reduce_exports = xyes; then - AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"], - [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])]) -fi - AC_MSG_CHECKING([for std::system]) AC_LINK_IFELSE( [ AC_LANG_PROGRAM( @@ -1486,9 +1488,11 @@ fi BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB" fi +dnl Check for reduced exports if test x$use_reduce_exports = xyes; then - CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS" - AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"],, [[$LDFLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[CXXFLAGS="$CXXFLAGS -fvisibility=hidden"], + [AC_MSG_ERROR([Cannot set hidden symbol visibility. Use --disable-reduce-exports.])],[[$CXXFLAG_WERROR]]) + AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]],[RELDFLAGS="-Wl,--exclude-libs,ALL"],,[[$LDFLAG_WERROR]]) fi if test x$use_tests = xyes; then @@ -1951,6 +1955,7 @@ echo echo "Options used to compile and link:" echo " boost process = $with_boost_process" echo " multiprocess = $build_multiprocess" +echo " with libs = $build_bitcoin_libs" echo " with wallet = $enable_wallet" echo " with gui / qt = $bitcoin_enable_qt" if test "x$enable_wallet" != "xno"; then diff --git a/src/script/bitcoinconsensus.h b/src/script/bitcoinconsensus.h index 63958ac377..5fa4ac3a52 100644 --- a/src/script/bitcoinconsensus.h +++ b/src/script/bitcoinconsensus.h @@ -11,14 +11,12 @@ #if defined(BUILD_BITCOIN_INTERNAL) && defined(HAVE_CONFIG_H) #include #if defined(_WIN32) - #if defined(DLL_EXPORT) - #if defined(HAVE_FUNC_ATTRIBUTE_DLLEXPORT) - #define EXPORT_SYMBOL __declspec(dllexport) - #else - #define EXPORT_SYMBOL - #endif + #if defined(HAVE_DLLEXPORT_ATTRIBUTE) + #define EXPORT_SYMBOL __declspec(dllexport) + #else + #define EXPORT_SYMBOL #endif - #elif defined(HAVE_FUNC_ATTRIBUTE_VISIBILITY) + #elif defined(HAVE_DEFAULT_VISIBILITY_ATTRIBUTE) #define EXPORT_SYMBOL __attribute__ ((visibility ("default"))) #endif #elif defined(MSC_VER) && !defined(STATIC_LIBBITCOINCONSENSUS) From 6bcc86ad3b848036ae26183b9b0c3380bf2c1ace Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 19 Feb 2021 11:28:36 +0100 Subject: [PATCH 05/11] Merge #21221: [tools] Allow argument/parameter bin packing in clang-format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 876ac3f6b62087fb5c22b0a477751895915d47b8 [tools] Allow argument/parameter bin packing in clang-format (John Newbery) Pull request description: clang-format documentation for BinPackArguments: If `false`, a function callโ€™s arguments will either be all on the same line or will have one line each. ``` true: void f() { f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); } false: void f() { f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); } ``` https://clang.llvm.org/docs/ClangFormatStyleOptions.html#configurable-format-style-options There's no reason to forbid this format. Having multiple arguments or parameters per line can be just as readable as having one per line (and is certainly more readable than having extremely long lines). ACKs for top commit: laanwj: ACK 876ac3f6b62087fb5c22b0a477751895915d47b8 MarcoFalke: review ACK 876ac3f6b62087fb5c22b0a477751895915d47b8 vasild: ACK 876ac3f6b62087fb5c22b0a477751895915d47b8 Tree-SHA512: 7c401b4551b458c83dd70883860788b4a60e08a5399171fef27a2f5fdc6b933f6454fe0d396c32d826e3ab537791329da3275ae9b5e9ad36630a6dc2c167e88f --- src/.clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.clang-format b/src/.clang-format index 73515a234b..8b717d1190 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -14,7 +14,7 @@ AllowShortLoopsOnASingleLine: false AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: true BinPackArguments: true -BinPackParameters: false +BinPackParameters: true BreakBeforeBinaryOperators: None BreakBeforeBraces: Custom BraceWrapping: From a3702534e56c126af8e53bf44eac9be9afb8417f Mon Sep 17 00:00:00 2001 From: fanquake Date: Fri, 5 Mar 2021 09:30:17 +0800 Subject: [PATCH 06/11] Merge #21354: build, doc: Drop no longer required packages from macOS cross-compiling dependencies f7f3829a68df173c54ab11ecfe162b840afb64e8 build, doc: Drop libbz2-dev from macOS cross-compiling dependencies (Hennadii Stepanov) d8239362e283107657a5a6577890fdb198a1d334 build, doc: Drop libcap-dev from macOS cross-compiling dependencies (Hennadii Stepanov) Pull request description: The `libcap-dev` and `libbz2-dev` packages are no longer required when cross-compiling for macOS. ACKs for top commit: fanquake: ACK f7f3829a68df173c54ab11ecfe162b840afb64e8 Tree-SHA512: 820cdc2724f3346c0942d4d4115fc7206f7bf02889d9fa6cbdbd1d9e3afa03a067c1c3fa64dff596aefdc74898178b7c7d64027a6501486e3b606f4760de04ae --- ci/test/00_setup_env_mac.sh | 2 +- contrib/containers/ci/Dockerfile | 2 -- depends/README.md | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ci/test/00_setup_env_mac.sh b/ci/test/00_setup_env_mac.sh index 3c90b09581..fb9322eb09 100755 --- a/ci/test/00_setup_env_mac.sh +++ b/ci/test/00_setup_env_mac.sh @@ -8,7 +8,7 @@ export LC_ALL=C.UTF-8 export CONTAINER_NAME=ci_macos_cross export HOST=x86_64-apple-darwin -export PACKAGES="cmake libcap-dev libz-dev libbz2-dev libtinfo5 python3-setuptools" +export PACKAGES="cmake libz-dev libtinfo5 python3-setuptools" export XCODE_VERSION=12.2 export XCODE_BUILD_ID=12B45b export RUN_UNIT_TESTS=false diff --git a/contrib/containers/ci/Dockerfile b/contrib/containers/ci/Dockerfile index 38dd7456bc..7f8cc4d44a 100644 --- a/contrib/containers/ci/Dockerfile +++ b/contrib/containers/ci/Dockerfile @@ -104,9 +104,7 @@ RUN apt-get update && apt-get install $APT_ARGS \ g++-arm-linux-gnueabihf \ g++-mingw-w64-x86-64 \ jq \ - libcap-dev \ libz-dev \ - libbz2-dev \ libncurses5 \ nsis \ python3-zmq \ diff --git a/depends/README.md b/depends/README.md index b8dc83bc96..404e66fc23 100644 --- a/depends/README.md +++ b/depends/README.md @@ -47,7 +47,7 @@ The paths are automatically configured and no other options are needed unless ta #### For macOS cross compilation - sudo apt-get install curl bsdmainutils cmake libcap-dev libz-dev libbz2-dev python3-setuptools libtinfo5 xorriso + sudo apt-get install curl bsdmainutils cmake libz-dev python3-setuptools libtinfo5 xorriso Note: You must obtain the macOS SDK before proceeding with a cross-compile. Under the depends directory, create a subdirectory named `SDKs`. From e866b431605b372aa7de5bd788f909a03f746beb Mon Sep 17 00:00:00 2001 From: fanquake Date: Wed, 31 Mar 2021 13:08:12 +0800 Subject: [PATCH 07/11] Merge #21542: ci: Bump macOS VM image to the latest version b8e76479cea448d4e00f698fe39ab3e0228ab22d ci: Bump macOS VM image to the latest version (Hennadii Stepanov) Pull request description: On Cirrus CI bump macOS VM from Catalina to Big Sur. ACKs for top commit: fanquake: ACK b8e76479cea448d4e00f698fe39ab3e0228ab22d - I'm always going to question bumping things for the sake of it/when there's no reasoning given. In this case, moving from building on macOS 10.x to 11.x shouldn't really lose us any coverage, and may turn up potential macOS quirks a bit earlier. Tree-SHA512: ab2daee194683ab0553328020fd2fcb918160f466cd380c542e1a9b44f5bea3664fb40b032f1b611ee0107b0efbe278230e067316e2373c3cb0470b205dd2f9d --- .cirrus.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 13a30555b7..99d6aa070c 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -157,13 +157,13 @@ task: FILE_ENV: "./ci/test/00_setup_env_mac.sh" task: - name: 'macOS 10.15 native [gui] [no depends]' + name: 'macOS 11 native [gui] [no depends]' macos_brew_addon_script: - brew install boost libevent berkeley-db4 qt miniupnpc ccache zeromq qrencode sqlite libtool automake pkg-config gnu-getopt << : *GLOBAL_TASK_TEMPLATE macos_instance: # Use latest image, but hardcode version to avoid silent upgrades (and breaks) - image: catalina-xcode-12.1 # https://cirrus-ci.org/guide/macOS + image: big-sur-xcode-12.4 # https://cirrus-ci.org/guide/macOS env: DANGER_RUN_CI_ON_HOST: "true" CI_USE_APT_INSTALL: "no" From 085120d9f91530e9dd95b0d5884e430699ff1801 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 17 Feb 2021 09:36:27 +0100 Subject: [PATCH 08/11] Merge #20993: test: store subversion (user agent) as string in msg_version de85af5cce727981383ac0fe81f635451b331f23 test: store subversion (user agent) as string in msg_version (Sebastian Falbesoner) Pull request description: It seems more natural to treat the "subversion" field (=user agent string, see [BIP 14](https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki#Proposal)) of a node as pure string rather than a bytestring within the test framework. This is also suggested with the naming prefix in `msg_version.strSubVer`: one probably wouldn't expect a field starting with "str" to be a bytestring that needs further decoding to be useful. This PR moves the encoding/decoding parts to the serialization/deserialization routines so that the user doesn't have to bother with that anymore. Note that currently, in the master branch the `msg_version.strSubVer` is never read (only in `msg_version.__repr__`); However, one issue that is solved by this PR came up while testing #19509 (not merged yet): A decoding script for binary message capture files takes use of the functional test framework convert it into JSON format. Bytestrings will be convered to hexstrings, while pure strings will (surprise surprise) end up without modification in the file. So without this patch, we get: ``` $ jq . out.json | grep -m5 strSubVer "strSubVer": "2f5361746f7368693a32312e39392e302f" "strSubVer": "2f5361746f7368693a302e32302e312f" "strSubVer": "2f5361746f7368693a32312e39392e302f" "strSubVer": "2f5361746f7368693a302e32302e312f" "strSubVer": "2f5361746f7368693a32312e39392e302f" ``` After this patch: ``` $ jq . out2.json | grep -m5 strSubVer "strSubVer": "/Satoshi:21.99.0/" "strSubVer": "/Satoshi:0.20.1/" "strSubVer": "/Satoshi:21.99.0/" "strSubVer": "/Satoshi:0.20.1/" "strSubVer": "/Satoshi:21.99.0/" ``` ACKs for top commit: jnewbery: utACK de85af5cce727981383ac0fe81f635451b331f23 Tree-SHA512: ff23642705c858e8387a625537dfec82e6b8a15da6d99b8d12152560e52d243ba17431b602b26f60996d897e00e3f37dcf8dc8a303ffb1d544df29a5937080f9 --- test/functional/p2p_quorum_data.py | 2 +- test/functional/test_framework/messages.py | 8 ++++---- test/functional/test_framework/p2p.py | 8 ++++---- test/functional/test_framework/test_node.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/functional/p2p_quorum_data.py b/test/functional/p2p_quorum_data.py index d14ce4874d..7257007f8a 100755 --- a/test/functional/p2p_quorum_data.py +++ b/test/functional/p2p_quorum_data.py @@ -78,7 +78,7 @@ def get_p2p_id(node, uacomment=None): for p2p in node.p2ps: if uacomment is not None and p2p.uacomment != uacomment: continue - if p["subver"] == p2p.strSubVer.decode(): + if p["subver"] == p2p.strSubVer: return p["id"] return None wait_until_helper(lambda: get_id() is not None, timeout=10) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 17164eb55a..d4a8eca3c2 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -33,7 +33,7 @@ import dash_hash MIN_VERSION_SUPPORTED = 60001 MY_VERSION = 70231 # NO_LEGACY_ISLOCK_PROTO_VERSION -MY_SUBVERSION = b"/python-p2p-tester:0.0.3%s/" +MY_SUBVERSION = "/python-p2p-tester:0.0.3%s/" MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37) MAX_LOCATOR_SZ = 101 @@ -1521,7 +1521,7 @@ class msg_version: self.addrTo = CAddress() self.addrFrom = CAddress() self.nNonce = random.getrandbits(64) - self.strSubVer = MY_SUBVERSION % b"" + self.strSubVer = MY_SUBVERSION % "" self.nStartingHeight = -1 self.nRelay = MY_RELAY @@ -1535,7 +1535,7 @@ class msg_version: self.addrFrom = CAddress() self.addrFrom.deserialize(f, with_time=False) self.nNonce = struct.unpack(" Date: Sat, 6 Apr 2024 23:50:45 +0700 Subject: [PATCH 09/11] fix: adjust functional tests due to dash's support of thread name after v0.12 --- test/functional/test_framework/test_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index d092e33304..355a2d2ae8 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -116,7 +116,7 @@ class TestNode(): "--gen-suppressions=all", "--exit-on-first-error=yes", "--error-exitcode=1", "--quiet"] + self.args - if self.version_is_at_least(190000): + if self.version_is_at_least(120100): self.args.append("-logthreadnames") self.cli = TestNodeCLI(bitcoin_cli, self.datadir) From 4774e1e8f62f172aa92b8f99b2d4db31beb00ce3 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 18 Feb 2021 14:20:42 +0100 Subject: [PATCH 10/11] Merge #19809: log: Prefix log messages with function name and source code location if -logsourcelocations is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit b4511e2e2ed1a6077ae6826a9ee6b7a311293d08 log: Prefix log messages with function name if -logsourcelocations is set (practicalswift) Pull request description: Prefix log messages with function name if `-logfunctionnames` is set. Yes, exactly like `-logthreadnames` but for function names instead of thread names :) This is a small developer ergonomics improvement: I've found this to be a cheap/simple way to correlate log output and originating function. For me it beats the ordinary cycle of 1.) try to figure out a regexp matching the static part of the dynamic log message, 2.) `git grep -E 'Using .* MiB out of .* requested for signature cache'`, 3.) `mcedit filename.cpp` (`openemacs filename.cpp` works too!) and 4.) search for log message and scroll up to find the function name :) Without any logging parameters: ``` $ src/bitcoind -regtest 2020-08-25T03:29:04Z Using RdRand as an additional entropy source 2020-08-25T03:29:04Z Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements 2020-08-25T03:29:04Z Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements 2020-08-25T03:29:04Z Loaded best chain: hashBestChain=0fff88f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22ff height=0 date=2011-02-02T23:16:42Z progress=1.000000 2020-08-25T03:29:04Z block tree size = 1 2020-08-25T03:29:04Z nBestHeight = 0 2020-08-25T03:29:04Z Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast 2020-08-25T03:29:04Z 0 addresses found from DNS seeds ``` With `-logthreadnames` and `-logfunctionnames`: ``` $ src/bitcoind -regtest -logthreadnames -logfunctionnames 2020-08-25T03:29:04Z [init] [ReportHardwareRand] Using RdRand as an additional entropy source 2020-08-25T03:29:04Z [init] [InitSignatureCache] Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements 2020-08-25T03:29:04Z [init] [InitScriptExecutionCache] Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements 2020-08-25T03:29:04Z [init] [LoadChainTip] Loaded best chain: hashBestChain=0fff88f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22ff height=0 date=2011-02-02T23:16:42Z progress=1.000000 2020-08-25T03:29:04Z [init] [AppInitMain] block tree size = 1 2020-08-25T03:29:04Z [init] [AppInitMain] nBestHeight = 0 2020-08-25T03:29:04Z [loadblk] [LoadMempool] Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast 2020-08-25T03:29:04Z [dnsseed] [ThreadDNSAddressSeed] 0 addresses found from DNS seeds ``` ACKs for top commit: laanwj: Code review ACK b4511e2e2ed1a6077ae6826a9ee6b7a311293d08 MarcoFalke: review ACK b4511e2e2ed1a6077ae6826a9ee6b7a311293d08 ๐ŸŒƒ Tree-SHA512: d100f5364630c323f31d275259864c597f7725e462d5f4bdedcc7033ea616d7fc0d16ef1b2af557e692f4deea73c6773ccfc681589e7bf6ba970b9ec169040c7 --- src/batchedlogger.cpp | 9 ++- src/batchedlogger.h | 6 +- src/init.cpp | 3 + src/llmq/commitment.cpp | 63 +++++++++------------ src/llmq/dkgsession.cpp | 50 ++++++++-------- src/logging.cpp | 7 ++- src/logging.h | 10 +++- src/test/fuzz/string.cpp | 1 + src/test/util/setup_common.cpp | 1 + src/test/util_tests.cpp | 13 +++++ src/util/string.h | 8 +++ test/functional/test_framework/test_node.py | 2 + 12 files changed, 104 insertions(+), 69 deletions(-) diff --git a/src/batchedlogger.cpp b/src/batchedlogger.cpp index 8af506fb06..a4204e86f4 100644 --- a/src/batchedlogger.cpp +++ b/src/batchedlogger.cpp @@ -4,8 +4,11 @@ #include -CBatchedLogger::CBatchedLogger(BCLog::LogFlags _category, const std::string& _header) : - accept(LogAcceptCategory(_category)), header(_header) +CBatchedLogger::CBatchedLogger(BCLog::LogFlags _category, const std::string& logging_function, const std::string& source_file, int source_line) : + accept(LogAcceptCategory(_category)), + m_logging_function(logging_function), + m_source_file(source_file), + m_source_line(source_line) { } @@ -19,6 +22,6 @@ void CBatchedLogger::Flush() if (!accept || msg.empty()) { return; } - LogInstance().LogPrintStr(strprintf("%s:\n%s", header, msg)); + LogInstance().LogPrintStr(msg, m_logging_function, m_source_file, m_source_line); msg.clear(); } diff --git a/src/batchedlogger.h b/src/batchedlogger.h index 031e55ad39..c24ca84fe5 100644 --- a/src/batchedlogger.h +++ b/src/batchedlogger.h @@ -11,10 +11,12 @@ class CBatchedLogger { private: bool accept; - std::string header; + std::string m_logging_function;; + std::string m_source_file; + const int m_source_line; std::string msg; public: - CBatchedLogger(BCLog::LogFlags _category, const std::string& _header); + CBatchedLogger(BCLog::LogFlags _category, const std::string& logging_function, const std::string& m_source_file, int m_source_line); virtual ~CBatchedLogger(); template diff --git a/src/init.cpp b/src/init.cpp index 64ee07832e..856c3e5075 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -719,6 +719,7 @@ void SetupServerArgs(NodeContext& node) argsman.AddArg("-debugexclude=", strprintf("Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except the specified category. This option can be specified multiple times to exclude multiple categories."), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-disablegovernance", strprintf("Disable governance validation (0-1, default: %u)", 0), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); + argsman.AddArg("-logsourcelocations", strprintf("Prepend debug output with name of the originating source location (source file, line number and function name) (default: %u)", DEFAULT_LOGSOURCELOCATIONS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); #ifdef HAVE_THREAD_LOCAL argsman.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); @@ -1084,6 +1085,8 @@ void InitLogging(const ArgsManager& args) #ifdef HAVE_THREAD_LOCAL LogInstance().m_log_threadnames = args.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES); #endif + LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS); + fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS); std::string version_string = FormatFullVersion(); diff --git a/src/llmq/commitment.cpp b/src/llmq/commitment.cpp index b6a8f82951..258fe8e479 100644 --- a/src/llmq/commitment.cpp +++ b/src/llmq/commitment.cpp @@ -27,18 +27,11 @@ CFinalCommitment::CFinalCommitment(const Consensus::LLMQParams& params, const ui { } -template -void LogPrintfFinalCommitment(Types... out) { - if (LogAcceptCategory(BCLog::LLMQ)) { - LogInstance().LogPrintStr(strprintf("CFinalCommitment::%s -- %s", __func__, tinyformat::format(out...))); - } -} - bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_null pQuorumBaseBlockIndex, bool checkSigs) const { const auto& llmq_params_opt = Params().GetLLMQ(llmqType); if (!llmq_params_opt.has_value()) { - LogPrintfFinalCommitment("q[%s] invalid llmqType=%d\n", quorumHash.ToString(), ToUnderlying(llmqType)); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- q[%s] invalid llmqType=%d\n", quorumHash.ToString(), ToUnderlying(llmqType)); return false; } const auto& llmq_params = llmq_params_opt.value(); @@ -46,17 +39,17 @@ bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_nullGetBlockHash() != quorumHash) { - LogPrintfFinalCommitment("q[%s] invalid quorumHash\n", quorumHash.ToString()); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- q[%s] invalid quorumHash\n", quorumHash.ToString()); return false; } if ((pQuorumBaseBlockIndex->nHeight % llmq_params.dkgInterval) != quorumIndex) { - LogPrintfFinalCommitment("q[%s] invalid quorumIndex=%d\n", quorumHash.ToString(), quorumIndex); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- q[%s] invalid quorumIndex=%d\n", quorumHash.ToString(), quorumIndex); return false; } @@ -65,27 +58,27 @@ bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_nullproTxHash.ToString().substr(0, 4) << " | "; } - LogPrintfFinalCommitment("CFinalCommitment::%s members[%s] quorumPublicKey[%s] commitmentHash[%s]\n", + LogPrint(BCLog::LLMQ, "CFinalCommitment::%s members[%s] quorumPublicKey[%s] commitmentHash[%s]\n", __func__, ss3.str(), quorumPublicKey.ToString(), commitmentHash.ToString()); } std::vector memberPubKeys; @@ -130,17 +123,17 @@ bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_null(tx); if (!opt_qcTx) { - LogPrintfFinalCommitment("h[%d] GetTxPayload failed\n", pindexPrev->nHeight); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- h[%d] GetTxPayload LLMQCommitment failed\n", pindexPrev->nHeight); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-payload"); } auto& qcTx = *opt_qcTx; const auto& llmq_params_opt = Params().GetLLMQ(qcTx.commitment.llmqType); if (!llmq_params_opt.has_value()) { - LogPrintfFinalCommitment("h[%d] GetLLMQ failed for llmqType[%d]\n", pindexPrev->nHeight, ToUnderlying(qcTx.commitment.llmqType)); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- h[%d] GetLLMQ failed for llmqType[%d]\n", pindexPrev->nHeight, ToUnderlying(qcTx.commitment.llmqType)); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-commitment-type"); } @@ -193,17 +186,17 @@ bool CheckLLMQCommitment(CDeterministicMNManager& dmnman, const CTransaction& tx for (const auto i: irange::range(llmq_params_opt->size)) { ss << "v[" << i << "]=" << qcTx.commitment.validMembers[i]; } - LogPrintfFinalCommitment("%s llmqType[%d] validMembers[%s] signers[]\n", __func__, + LogPrint(BCLog::LLMQ, "CFinalCommitment -- %s llmqType[%d] validMembers[%s] signers[]\n", __func__, int(qcTx.commitment.llmqType), ss.str()); } if (qcTx.nVersion == 0 || qcTx.nVersion > CFinalCommitmentTxPayload::CURRENT_VERSION) { - LogPrintfFinalCommitment("h[%d] invalid qcTx.nVersion[%d]\n", pindexPrev->nHeight, qcTx.nVersion); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- h[%d] invalid qcTx.nVersion[%d]\n", pindexPrev->nHeight, qcTx.nVersion); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-version"); } if (qcTx.nHeight != uint32_t(pindexPrev->nHeight + 1)) { - LogPrintfFinalCommitment("h[%d] invalid qcTx.nHeight[%d]\n", pindexPrev->nHeight, qcTx.nHeight); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- h[%d] invalid qcTx.nHeight[%d]\n", pindexPrev->nHeight, qcTx.nHeight); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-height"); } @@ -220,18 +213,18 @@ bool CheckLLMQCommitment(CDeterministicMNManager& dmnman, const CTransaction& tx if (qcTx.commitment.IsNull()) { if (!qcTx.commitment.VerifyNull()) { - LogPrintfFinalCommitment("h[%d] invalid qcTx.commitment[%s] VerifyNull failed\n", pindexPrev->nHeight, qcTx.commitment.quorumHash.ToString()); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- h[%d] invalid qcTx.commitment[%s] VerifyNull failed\n", pindexPrev->nHeight, qcTx.commitment.quorumHash.ToString()); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-invalid-null"); } return true; } if (!qcTx.commitment.Verify(dmnman, pQuorumBaseBlockIndex, false)) { - LogPrintfFinalCommitment("h[%d] invalid qcTx.commitment[%s] Verify failed\n", pindexPrev->nHeight, qcTx.commitment.quorumHash.ToString()); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- h[%d] invalid qcTx.commitment[%s] Verify failed\n", pindexPrev->nHeight, qcTx.commitment.quorumHash.ToString()); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-invalid"); } - LogPrintfFinalCommitment("h[%d] CheckLLMQCommitment VALID\n", pindexPrev->nHeight); + LogPrint(BCLog::LLMQ, "CFinalCommitment -- h[%d] CheckLLMQCommitment VALID\n", pindexPrev->nHeight); return true; } diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index 8b4345940c..2aa46c2e4e 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -35,10 +35,10 @@ namespace llmq class CDKGLogger : public CBatchedLogger { public: - CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func) : - CDKGLogger(_quorumDkg.params.name, _quorumDkg.quorumIndex, _quorumDkg.m_quorum_base_block_index->GetBlockHash(), _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember(), _func){}; - CDKGLogger(std::string_view _llmqTypeName, int _quorumIndex, const uint256& _quorumHash, int _height, bool _areWeMember, std::string_view _func) : - CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, quorumIndex=%d, height=%d, member=%d, func=%s)", _llmqTypeName, _quorumIndex, _height, _areWeMember, _func)){}; + CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func, int source_line) : + CDKGLogger(_quorumDkg.params.name, _quorumDkg.quorumIndex, _quorumDkg.m_quorum_base_block_index->GetBlockHash(), _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember(), _func, source_line){}; + CDKGLogger(std::string_view _llmqTypeName, int _quorumIndex, const uint256& _quorumHash, int _height, bool _areWeMember, std::string_view _func, int source_line) : + CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, qIndex=%d, h=%d, member=%d)", _llmqTypeName, _quorumIndex, _height, _areWeMember), __FILE__, source_line){}; }; static std::array, ToUnderlying(DKGError::type::_COUNT)> simDkgErrorMap{}; @@ -100,7 +100,7 @@ bool CDKGSession::Init(gsl::not_null _pQuorumBaseBlockIndex, } } - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); if (LogAcceptCategory(BCLog::LLMQ) && IsQuorumRotationEnabled(params, m_quorum_base_block_index)) { int cycleQuorumBaseHeight = m_quorum_base_block_index->nHeight - quorumIndex; @@ -140,7 +140,7 @@ bool CDKGSession::Init(gsl::not_null _pQuorumBaseBlockIndex, void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); if (!AreWeMember()) { return; @@ -161,7 +161,7 @@ void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages) void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); assert(AreWeMember()); @@ -214,7 +214,7 @@ void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages) // only performs cheap verifications, but not the signature of the message. this is checked with batched verification bool CDKGSession::PreVerifyMessage(const CDKGContribution& qc, bool& retBan) const { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -262,7 +262,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc, bool& retBan) { LOCK(cs_pending); - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -357,7 +357,7 @@ void CDKGSession::VerifyPendingContributions() { AssertLockHeld(cs_pending); - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); cxxtimer::Timer t1(true); @@ -418,7 +418,7 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages) VerifyPendingContributions(); } - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); // we check all members if they sent us their contributions // we consider members as bad if they missed to send anything or if they sent multiple @@ -454,7 +454,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions() const return; } - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); std::unordered_map protoMap; connman.ForEachNode([&](const CNode* pnode) { @@ -489,7 +489,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions() const void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); assert(AreWeMember()); @@ -532,7 +532,7 @@ void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages) // only performs cheap verifications, but not the signature of the message. this is checked with batched verification bool CDKGSession::PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -574,7 +574,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const void CDKGSession::ReceiveMessage(const CDKGComplaint& qc, bool& retBan) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -641,7 +641,7 @@ void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages) return; } - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); std::set justifyFor; @@ -678,7 +678,7 @@ void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages) void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const std::set& forMembers) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); assert(AreWeMember()); @@ -727,7 +727,7 @@ void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const // only performs cheap verifications, but not the signature of the message. this is checked with batched verification bool CDKGSession::PreVerifyMessage(const CDKGJustification& qj, bool& retBan) const { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -785,7 +785,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGJustification& qj, bool& retBan) co void CDKGSession::ReceiveMessage(const CDKGJustification& qj, bool& retBan) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -883,7 +883,7 @@ void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages) return; } - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); std::vector badMembers; badMembers.reserve(members.size()); @@ -924,7 +924,7 @@ void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages) void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); assert(AreWeMember()); @@ -1039,7 +1039,7 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages) // only performs cheap verifications, but not the signature of the message. this is checked with batched verification bool CDKGSession::PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retBan) const { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -1100,7 +1100,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retB void CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc, bool& retBan) { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); retBan = false; @@ -1183,7 +1183,7 @@ std::vector CDKGSession::FinalizeCommitments() return {}; } - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); using Key = std::vector; std::map> commitmentsMap; @@ -1309,7 +1309,7 @@ void CDKGSession::MarkBadMember(size_t idx) void CDKGSession::RelayInvToParticipants(const CInv& inv) const { - CDKGLogger logger(*this, __func__); + CDKGLogger logger(*this, __func__, __LINE__); std::stringstream ss; for (const auto& r : relayMembers) { ss << r.ToString().substr(0, 4) << " | "; diff --git a/src/logging.cpp b/src/logging.cpp index 0409fa7fa1..3f70d0c22a 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -269,11 +270,15 @@ namespace BCLog { } } // namespace BCLog -void BCLog::Logger::LogPrintStr(const std::string& str) +void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, const int source_line) { StdLockGuard scoped_lock(m_cs); std::string str_prefixed = LogEscapeMessage(str); + if (m_log_sourcelocations && m_started_new_line) { + str_prefixed.insert(0, "[" + RemovePrefix(source_file, "./") + ":" + ToString(source_line) + "] [" + logging_function + "] "); + } + if (m_log_threadnames && m_started_new_line) { // 16 chars total, "dash-" is 5 of them and another 1 is a NUL terminator str_prefixed.insert(0, "[" + strprintf("%10s", util::ThreadGetInternalName()) + "] "); diff --git a/src/logging.h b/src/logging.h index e5b446926f..6cf696f3d0 100644 --- a/src/logging.h +++ b/src/logging.h @@ -22,6 +22,7 @@ static const bool DEFAULT_LOGTIMEMICROS = false; static const bool DEFAULT_LOGIPS = false; static const bool DEFAULT_LOGTIMESTAMPS = true; static const bool DEFAULT_LOGTHREADNAMES = false; +static const bool DEFAULT_LOGSOURCELOCATIONS = false; extern const char * const DEFAULT_DEBUGLOGFILE; extern bool fLogThreadNames; @@ -117,12 +118,13 @@ namespace BCLog { bool m_log_timestamps = DEFAULT_LOGTIMESTAMPS; bool m_log_time_micros = DEFAULT_LOGTIMEMICROS; bool m_log_threadnames = DEFAULT_LOGTHREADNAMES; + bool m_log_sourcelocations = DEFAULT_LOGSOURCELOCATIONS; fs::path m_file_path; std::atomic m_reopen_file{false}; /** Send a string to the log output */ - void LogPrintStr(const std::string& str); + void LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, const int source_line); /** Returns whether logs will be written to any output */ bool Enabled() const @@ -203,7 +205,7 @@ std::string SafeStringFormat(const std::string& fmt, const Args&... args) // peer can fill up a user's disk with debug.log entries. template -static inline void LogPrintf(const char* fmt, const Args&... args) +static inline void LogPrintf_(const std::string& logging_function, const std::string& source_file, const int source_line, const char* fmt, const Args&... args) { if (LogInstance().Enabled()) { std::string log_msg; @@ -213,10 +215,12 @@ static inline void LogPrintf(const char* fmt, const Args&... args) /* Original format string will have newline so don't add one here */ log_msg = "Error \"" + std::string(fmterr.what()) + "\" while formatting log message: " + fmt; } - LogInstance().LogPrintStr(log_msg); + LogInstance().LogPrintStr(log_msg, logging_function, source_file, source_line); } } +#define LogPrintf(...) LogPrintf_(__func__, __FILE__, __LINE__, __VA_ARGS__) + // Use a macro instead of a function for conditional logging to prevent // evaluating arguments when logging for the category is not enabled. #define LogPrint(category, ...) \ diff --git a/src/test/fuzz/string.cpp b/src/test/fuzz/string.cpp index 6c618c51f0..4710f7b996 100644 --- a/src/test/fuzz/string.cpp +++ b/src/test/fuzz/string.cpp @@ -161,6 +161,7 @@ FUZZ_TARGET(string) (void)ParseNonRFCJSONValue(random_string_1); } catch (const std::runtime_error&) { } + (void)RemovePrefix(random_string_1, random_string_2); (void)ResolveErrMsg(random_string_1, random_string_2); try { (void)RPCConvertNamedValues(random_string_1, random_string_vector); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index d40b0ecb7a..edb981e729 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -142,6 +142,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve { "dummy", "-printtoconsole=0", + "-logsourcelocations", "-logtimemicros", "-logthreadnames", "-debug", diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index d5eafe2824..ee5774e981 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -2635,4 +2635,17 @@ BOOST_AUTO_TEST_CASE(message_hash) BOOST_CHECK_NE(message_hash1, signature_hash); } +BOOST_AUTO_TEST_CASE(remove_prefix) +{ + BOOST_CHECK_EQUAL(RemovePrefix("./util/system.h", "./"), "util/system.h"); + BOOST_CHECK_EQUAL(RemovePrefix("foo", "foo"), ""); + BOOST_CHECK_EQUAL(RemovePrefix("foo", "fo"), "o"); + BOOST_CHECK_EQUAL(RemovePrefix("foo", "f"), "oo"); + BOOST_CHECK_EQUAL(RemovePrefix("foo", ""), "foo"); + BOOST_CHECK_EQUAL(RemovePrefix("fo", "foo"), "fo"); + BOOST_CHECK_EQUAL(RemovePrefix("f", "foo"), "f"); + BOOST_CHECK_EQUAL(RemovePrefix("", "foo"), ""); + BOOST_CHECK_EQUAL(RemovePrefix("", ""), ""); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/util/string.h b/src/util/string.h index 5ff21fbbd6..72fea9fae8 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -39,6 +39,14 @@ void ReplaceAll(std::string& in_out, const std::string& search, const std::strin return str.substr(front, end - front + 1); } +[[nodiscard]] inline std::string RemovePrefix(const std::string& str, const std::string& prefix) +{ + if (str.substr(0, prefix.size()) == prefix) { + return str.substr(prefix.size()); + } + return str; +} + /** * Join a list of items * diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 355a2d2ae8..441cba00f1 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -118,6 +118,8 @@ class TestNode(): if self.version_is_at_least(120100): self.args.append("-logthreadnames") + if self.version_is_at_least(21000000): + self.args.append("-logsourcelocations") self.cli = TestNodeCLI(bitcoin_cli, self.datadir) self.use_cli = use_cli From 005a6b104a2289a512175a7cd6915c59f21a71a6 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 10 Apr 2024 17:32:55 +0700 Subject: [PATCH 11/11] fix: format string in llmq/commitment - mismatched arguments --- src/llmq/commitment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llmq/commitment.cpp b/src/llmq/commitment.cpp index 258fe8e479..19c03c2eb7 100644 --- a/src/llmq/commitment.cpp +++ b/src/llmq/commitment.cpp @@ -39,7 +39,7 @@ bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_null