Skip to content

Conversation

willcl-ark
Copy link
Member

@willcl-ark willcl-ark commented May 23, 2023

Fixes #27586

Disable boost multi index safe mode by default when configuring with
--enable-debug.

This option can cause transactions to take a long time to be accepted
into the mempool under certain conditions; iterator destruction takes
O(n) time vs O(1) as they are stored in a singly linked list. See
27586 and the boost docs for more information.

Re-enable it on the CI builds which previously had it enabled.

Re-enable it on the msan fuzz task so that we have fuzz tasks testing
with it enabled and disabled in this repo.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 23, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK fanquake
Concept ACK MarcoFalke, hebasto

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27737 (ci: compile Clang and compiler-rt in msan jobs by fanquake)
  • #25797 (build: Add CMake-based build system by hebasto)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@hebasto
Copy link
Member

hebasto commented May 23, 2023

Somewhat related: #27353.

@willcl-ark
Copy link
Member Author

The approach taken here was influenced by discussion in #24709 (comment)

I've been unable to instigate the congested behaviour on two nodes overnight, one with default mempool and one with 500MB mempool, but hopefully will manage to do so shortly and will reply here if so.

In any case, it seems overkill to enable these safe mode checks in debug builds (which are often tested on mainnet), and a more sensible approach to limit to CI tasks where performance is less critical.

@fanquake
Copy link
Member

fanquake commented May 23, 2023

Concept NACK - I don't think adding configure flags for specific Boost defines is a good approach. Will follow up in the other threads.

@willcl-ark
Copy link
Member Author

Concept NACK - I don't think adding configure flags for specific Boost defines is a good approach. Will follow up in the other threads.

OK. Looking forward to your thoughts, as I don't know how the same effect could be achieved in any neater or more maintainable way.

One alternative could be to manually append to the CI CPP flags, if that's all we wanted.

@maflcko
Copy link
Member

maflcko commented May 23, 2023

One alternative could be to manually append to the CI CPP flags, if that's all we wanted.

Or just a configure setting to append CPP flags to the existing ones, instead of replacing the default ones?

Concept ACK

@fanquake
Copy link
Member

Or just a configure setting to append CPP flags to the existing ones,

There's no need for a new setting. Just use CPPFLAGS="-DWHATEVER". This has worked since #24391.

@willcl-ark willcl-ark force-pushed the disable-boost-MI-safe-mode branch from dc606c3 to 26ec68a Compare May 23, 2023 09:02
configure.ac Outdated
@@ -1491,7 +1491,7 @@ if test "$use_boost" = "yes"; then
AX_CHECK_PREPROC_FLAG([-DBOOST_NO_CXX98_FUNCTION_BASE], [BOOST_CPPFLAGS="$BOOST_CPPFLAGS -DBOOST_NO_CXX98_FUNCTION_BASE"], [], [$CXXFLAG_WERROR],
[AC_LANG_PROGRAM([[#include <boost/config.hpp>]])])

if test "$enable_debug" = "yes" || test "$enable_fuzz" = "yes"; then
if test "$enable_fuzz" = "yes"; then
BOOST_CPPFLAGS="$BOOST_CPPFLAGS -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be moved to the debug fuzz task to avoid only fuzzing a debug version of boost in all fuzz configs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that. If anything it makes more sense to me to fuzz the non debug version...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally both are fuzzed :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

Do you think it's best to add to 00_setup_env_native_fuzz.sh ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I meant 00_setup_env_native_fuzz_debug.sh, but I see that this is maintained elsewhere. Maybe it can be added to just fuzz_msan, or just no fuzz task at all in this repo?

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but the description needs to be adjusted?

configure.ac Outdated
@@ -1491,7 +1491,7 @@ if test "$use_boost" = "yes"; then
AX_CHECK_PREPROC_FLAG([-DBOOST_NO_CXX98_FUNCTION_BASE], [BOOST_CPPFLAGS="$BOOST_CPPFLAGS -DBOOST_NO_CXX98_FUNCTION_BASE"], [], [$CXXFLAG_WERROR],
[AC_LANG_PROGRAM([[#include <boost/config.hpp>]])])

if test "$enable_debug" = "yes" || test "$enable_fuzz" = "yes"; then
if test "$enable_fuzz" = "yes"; then
BOOST_CPPFLAGS="$BOOST_CPPFLAGS -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally both are fuzzed :)

@willcl-ark willcl-ark force-pushed the disable-boost-MI-safe-mode branch from 26ec68a to 19db479 Compare May 23, 2023 11:50
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can squash to avoid touching the same line twice?

Disable boost multi index safe mode by default when configuring with
--enable-debug.

This option can cause transactions to take a long time to be accepted
into the mempool under certain conditions; iterator destruction takes
O(n) time vs O(1) as they are stored in a singly linked list. See
27586 for more information.

Re-enable it on the CI builds which previously had it enabled.

Re-enable it on the msan fuzz target so that we have fuzz tasks testing
with it enabeld and disabled in this repo.
@willcl-ark
Copy link
Member Author

can squash to avoid touching the same line twice?

Now squashed :)

@willcl-ark willcl-ark force-pushed the disable-boost-MI-safe-mode branch from 19db479 to 59c8944 Compare May 23, 2023 12:45
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 59c8944

UPD. See #27724 (comment)

@@ -17,7 +17,7 @@ export PACKAGES="clang-16 llvm-16 libclang-rt-16-dev cmake"
# BDB generates false-positives and will be removed in future
export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'"
export GOAL="install"
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'"
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could split the long line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do if I touch again :)

I did think about it at the time, but some CI tasks seem to be split on ~100 chars, and some just have long lines. So I just left this one as "long" (and made it longer).

@hebasto
Copy link
Member

hebasto commented May 23, 2023

Retracting my ACK, as FILE_ENV="./ci/test/00_setup_env_native_fuzz_with_msan.sh" ./ci/test_run_all.sh fails locally for me.

@maflcko
Copy link
Member

maflcko commented May 23, 2023

Retracting my ACK, as FILE_ENV="./ci/test/00_setup_env_native_fuzz_with_msan.sh" ./ci/test_run_all.sh fails locally for me.

Seems unrelated, as this is failing on master. I agree it should be fixed, but I don't see why something unrelated should be holding back this pull.

@willcl-ark
Copy link
Member Author

Perhaps I can drop the fuzz CPPFLAGS (introduced in this pull) for now, so that nothing is broken after this commit?

diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh
index dd694f818c..35a0de8034 100755
--- a/ci/test/00_setup_env_native_fuzz_with_msan.sh
+++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh
@@ -17,7 +17,7 @@ export PACKAGES="clang-16 llvm-16 libclang-rt-16-dev cmake"
 # BDB generates false-positives and will be removed in future
 export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'"
 export GOAL="install"
-export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'"
+export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'"
 export USE_MEMORY_SANITIZER="true"
 export RUN_UNIT_TESTS="false"
 export RUN_FUNCTIONAL_TESTS="false"

FWIW I do see the same (I guess) locally. At least I see failure during configure:

configure: exit 1
+ false

@maflcko
Copy link
Member

maflcko commented May 23, 2023

... so that nothing is broken after this commit?

Again, this is unrelated, because the issue happens in master. See also https://cirrus-ci.com/task/4517884630663168?logs=ci#L4910

@fanquake
Copy link
Member

Again, this is unrelated, because the issue happens in master. See also https://cirrus-ci.com/task/4517884630663168?logs=ci#L4910

Should be fixed in #27737.

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 59c8944

@fanquake fanquake merged commit fb4f047 into bitcoin:master May 29, 2023
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request May 29, 2023
Disable boost multi index safe mode by default when configuring with
--enable-debug.

This option can cause transactions to take a long time to be accepted
into the mempool under certain conditions; iterator destruction takes
O(n) time vs O(1) as they are stored in a singly linked list. See
27586 for more information.

Re-enable it on the CI builds which previously had it enabled.

Re-enable it on the msan fuzz target so that we have fuzz tasks testing
with it enabeld and disabled in this repo.

Github-Pull: bitcoin#27724
Rebased-From: 59c8944
@fanquake
Copy link
Member

Backported to 25.x in #27775.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 29, 2023
@willcl-ark willcl-ark deleted the disable-boost-MI-safe-mode branch May 30, 2023 07:18
fanquake added a commit that referenced this pull request Jun 2, 2023
9dc5848 build: disable boost multi index safe mode (willcl-ark)

Pull request description:

  Backports #27724 to `25.x`.

ACKs for top commit:
  stickies-v:
    ACK 9dc5848

Tree-SHA512: 5f156424bbd86caac6ace933b807cd62a21067bcfa7f572d6efeff2622ba0b15401038a3b06fe00d84cf62b5d9b8a9e101650d145683a21fa890c18a9c2bd4b6
hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 10, 2023
This change encompasses:
- bitcoin#24558
- bitcoin#27724
hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 11, 2023
This change encompasses:
- bitcoin#24558
- bitcoin#27724
hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 11, 2023
This change encompasses:
- bitcoin#24558
- bitcoin#27724
hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 12, 2023
This change encompasses:
- bitcoin#24558
- bitcoin#27724
@bitcoin bitcoin locked and limited conversation to collaborators May 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CPU DoS on mainnet in debug mode
5 participants