diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh index 15f27b9e6a7de..fb32fa92f8b4e 100755 --- a/ci/test/04_install.sh +++ b/ci/test/04_install.sh @@ -33,6 +33,11 @@ export P_CI_DIR="$PWD" if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then echo "Creating $DOCKER_NAME_TAG container to run in" + LOCAL_UID=$(id -u) + LOCAL_GID=$(id -g) + + # the name isn't important, so long as we use the same UID + LOCAL_USER=nonroot ${CI_RETRY_EXE} docker pull "$DOCKER_NAME_TAG" # shellcheck disable=SC2086 @@ -45,7 +50,16 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then --env-file /tmp/env \ --name $CONTAINER_NAME \ $DOCKER_NAME_TAG) - export DOCKER_CI_CMD_PREFIX="docker exec $DOCKER_ID" + + # Create a non-root user inside the container which matches the local user. + # + # This prevents the root user in the container modifying the local file system permissions + # on the mounted directories + docker exec "$DOCKER_ID" useradd -u "$LOCAL_UID" -o -m "$LOCAL_USER" + docker exec "$DOCKER_ID" groupmod -o -g "$LOCAL_GID" "$LOCAL_USER" + docker exec "$DOCKER_ID" chown -R "$LOCAL_USER":"$LOCAL_USER" "${BASE_ROOT_DIR}" + export DOCKER_CI_CMD_PREFIX_ROOT="docker exec -u 0 $DOCKER_ID" + export DOCKER_CI_CMD_PREFIX="docker exec -u $LOCAL_UID $DOCKER_ID" else echo "Running on host system without docker wrapper" fi @@ -53,18 +67,22 @@ fi CI_EXEC () { $DOCKER_CI_CMD_PREFIX bash -c "export PATH=$BASE_SCRATCH_DIR/bins/:\$PATH && cd \"$P_CI_DIR\" && $*" } +CI_EXEC_ROOT () { + $DOCKER_CI_CMD_PREFIX_ROOT bash -c "export PATH=$BASE_SCRATCH_DIR/bins/:\$PATH && cd \"$P_CI_DIR\" && $*" +} export -f CI_EXEC +export -f CI_EXEC_ROOT if [ -n "$DPKG_ADD_ARCH" ]; then - CI_EXEC dpkg --add-architecture "$DPKG_ADD_ARCH" + CI_EXEC_ROOT dpkg --add-architecture "$DPKG_ADD_ARCH" fi if [[ $DOCKER_NAME_TAG == *centos* ]]; then - CI_EXEC yum -y install epel-release - CI_EXEC yum -y install "$DOCKER_PACKAGES" "$PACKAGES" + CI_EXEC_ROOT yum -y install epel-release + CI_EXEC_ROOT yum -y install "$DOCKER_PACKAGES" "$PACKAGES" elif [ "$CI_USE_APT_INSTALL" != "no" ]; then - ${CI_RETRY_EXE} CI_EXEC apt-get update - ${CI_RETRY_EXE} CI_EXEC apt-get install --no-install-recommends --no-upgrade -y "$PACKAGES" "$DOCKER_PACKAGES" + ${CI_RETRY_EXE} CI_EXEC_ROOT apt-get update + ${CI_RETRY_EXE} CI_EXEC_ROOT apt-get install --no-install-recommends --no-upgrade -y "$PACKAGES" "$DOCKER_PACKAGES" if [ -n "$PIP_PACKAGES" ]; then # shellcheck disable=SC2086 ${CI_RETRY_EXE} pip3 install --user $PIP_PACKAGES diff --git a/ci/test/05_before_script.sh b/ci/test/05_before_script.sh index dd8ef0917daef..fa847fb0802b4 100755 --- a/ci/test/05_before_script.sh +++ b/ci/test/05_before_script.sh @@ -11,6 +11,7 @@ if [ "$CI_OS_NAME" == "macos" ]; then echo > "${HOME}/Library/Application Support/DashCore" else CI_EXEC echo \> \$HOME/.dashcore + CI_EXEC_ROOT echo \> \$HOME/.dashcore fi CI_EXEC mkdir -p "${DEPENDS_DIR}/SDKs" "${DEPENDS_DIR}/sdk-sources" diff --git a/configure.ac b/configure.ac index e6816f33cccbd..d1751ad55c7f6 100644 --- a/configure.ac +++ b/configure.ac @@ -1925,10 +1925,6 @@ AC_SUBST(HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR) AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini]) AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh]) AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])]) -AC_CONFIG_LINKS([contrib/devtools/security-check.py:contrib/devtools/security-check.py]) -AC_CONFIG_LINKS([contrib/devtools/test-security-check.py:contrib/devtools/test-security-check.py]) -AC_CONFIG_LINKS([contrib/devtools/symbol-check.py:contrib/devtools/symbol-check.py]) -AC_CONFIG_LINKS([contrib/devtools/test-symbol-check.py:contrib/devtools/test-symbol-check.py]) AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py]) AC_CONFIG_LINKS([src/.bear-tidy-config:src/.bear-tidy-config]) AC_CONFIG_LINKS([src/.clang-tidy:src/.clang-tidy]) diff --git a/contrib/devtools/test-security-check.py b/contrib/devtools/test-security-check.py index d3ebb344d7d5c..5d9dc169045a8 100755 --- a/contrib/devtools/test-security-check.py +++ b/contrib/devtools/test-security-check.py @@ -41,7 +41,7 @@ def env_flags() -> List[str]: def call_security_check(cc, source, executable, options): subprocess.run([*cc,source,'-o',executable] + env_flags() + options, check=True) - p = subprocess.run(['./contrib/devtools/security-check.py',executable], stdout=subprocess.PIPE, universal_newlines=True) + p = subprocess.run([os.path.join(os.path.dirname(__file__), 'security-check.py'), executable], stdout=subprocess.PIPE, universal_newlines=True) return (p.returncode, p.stdout.rstrip()) def get_arch(cc, source, executable): diff --git a/contrib/devtools/test-symbol-check.py b/contrib/devtools/test-symbol-check.py index 7b972ee753971..44482bc2f1ad2 100755 --- a/contrib/devtools/test-symbol-check.py +++ b/contrib/devtools/test-symbol-check.py @@ -23,7 +23,7 @@ def call_symbol_check(cc: List[str], source, executable, options): env_flags += filter(None, os.environ.get(var, '').split(' ')) subprocess.run([*cc,source,'-o',executable] + env_flags + options, check=True) - p = subprocess.run(['./contrib/devtools/symbol-check.py',executable], stdout=subprocess.PIPE, universal_newlines=True) + p = subprocess.run([os.path.join(os.path.dirname(__file__), 'symbol-check.py'), executable], stdout=subprocess.PIPE, universal_newlines=True) os.remove(source) os.remove(executable) return (p.returncode, p.stdout.rstrip()) diff --git a/doc/JSON-RPC-interface.md b/doc/JSON-RPC-interface.md index 30cd65538080e..9fb0e7be297ea 100644 --- a/doc/JSON-RPC-interface.md +++ b/doc/JSON-RPC-interface.md @@ -128,7 +128,7 @@ RPC interface will be abused. Instead, expose it only on the host system's localhost, for example: `-p 127.0.0.1:8332:8332` -- **Secure authentication:** By default, Dash Core generates unique +- **Secure authentication:** By default, when no `rpcpassword` is specified, Dash Core generates unique login credentials each time it restarts and puts them into a file readable only by the user that started Dash Core, allowing any of that user's RPC clients with read access to the file to login diff --git a/doc/tracing.md b/doc/tracing.md index bd354b8637b1c..0734f1a496a17 100644 --- a/doc/tracing.md +++ b/doc/tracing.md @@ -76,7 +76,7 @@ the passed message. #### Tracepoint `net:outbound_message` -Is called when a message is send to a peer over the P2P network. Passes +Is called when a message is sent to a peer over the P2P network. Passes information about our peer, the connection and the message as arguments. Arguments passed: @@ -116,7 +116,7 @@ added to and removed (spent) from the cache when we connect a new block. (`chainstate.CoinsTip()`). For example, the RPCs `generateblock` and `getblocktemplate` call `TestBlockValidity()`, which applies the UTXO set changes to a temporary cache. Similarly, mempool consistency checks, which are -frequent on regtest, also apply the the UTXO set changes to a temporary cache. +frequent on regtest, also apply the UTXO set changes to a temporary cache. Changes to the _main_ UTXO cache and to temporary caches trigger the tracepoints. We can't tell if a temporary cache or the _main_ cache was changed. @@ -253,8 +253,8 @@ TRACE6(net, inbound_message, ### Guidelines and best practices -#### Clear motivation and use-case -Tracepoints need a clear motivation and use-case. The motivation should +#### Clear motivation and use case +Tracepoints need a clear motivation and use case. The motivation should outweigh the impact on, for example, code readability. There is no point in adding tracepoints that don't end up being used. diff --git a/src/Makefile.am b/src/Makefile.am index 55856f41a0d98..23ecb98e47860 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -336,7 +336,6 @@ BITCOIN_CORE_H = \ support/lockedpool.h \ sync.h \ timestampindex.h \ - threadinterrupt.h \ threadsafety.h \ timedata.h \ torcontrol.h \ @@ -381,6 +380,7 @@ BITCOIN_CORE_H = \ util/system.h \ util/time.h \ util/thread.h \ + util/threadinterrupt.h \ util/threadnames.h \ util/tokenpipe.h \ util/trace.h \ @@ -840,7 +840,6 @@ libbitcoin_util_a_SOURCES = \ stacktraces.cpp \ support/cleanse.cpp \ sync.cpp \ - threadinterrupt.cpp \ util/asmap.cpp \ util/bip32.cpp \ util/bytevectorhash.cpp \ @@ -864,6 +863,7 @@ libbitcoin_util_a_SOURCES = \ util/serfloat.cpp \ util/string.cpp \ util/thread.cpp \ + util/threadinterrupt.cpp \ util/threadnames.cpp \ util/tokenpipe.cpp \ util/wpipe.cpp \ diff --git a/src/chain.h b/src/chain.h index 7e31bf830be4f..f7fe7584936bf 100644 --- a/src/chain.h +++ b/src/chain.h @@ -196,10 +196,6 @@ class CBlockIndex //! (memory only) Maximum nTime in the chain up to and including this block. unsigned int nTimeMax{0}; - CBlockIndex() - { - } - explicit CBlockIndex(const CBlockHeader& block) : nVersion{block.nVersion}, hashMerkleRoot{block.hashMerkleRoot}, @@ -333,6 +329,24 @@ class CBlockIndex //! Efficiently find an ancestor of this block. CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; + + CBlockIndex() = default; + ~CBlockIndex() = default; + +protected: + //! CBlockIndex should not allow public copy construction because equality + //! comparison via pointer is very common throughout the codebase, making + //! use of copy a footgun. Also, use of copies do not have the benefit + //! of simplifying lifetime considerations due to attributes like pprev and + //! pskip, which are at risk of becoming dangling pointers in a copied + //! instance. + //! + //! We declare these protected instead of simply deleting them so that + //! CDiskBlockIndex can reuse copy construction. + CBlockIndex(const CBlockIndex&) = default; + CBlockIndex& operator=(const CBlockIndex&) = delete; + CBlockIndex(CBlockIndex&&) = delete; + CBlockIndex& operator=(CBlockIndex&&) = delete; }; arith_uint256 GetBlockProof(const CBlockIndex& block); diff --git a/src/i2p.cpp b/src/i2p.cpp index 3bc687e0dfde3..43e14e945cdd7 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/src/i2p.h b/src/i2p.h index 8bac0bae609af..c620a5442181e 100644 --- a/src/i2p.h +++ b/src/i2p.h @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/src/index/base.h b/src/index/base.h index 9441c13b09e21..8c4fc98b68b23 100644 --- a/src/index/base.h +++ b/src/index/base.h @@ -6,7 +6,7 @@ #define BITCOIN_INDEX_BASE_H #include -#include +#include #include #include diff --git a/src/llmq/instantsend.h b/src/llmq/instantsend.h index 132787f2b4c24..6d20380872156 100644 --- a/src/llmq/instantsend.h +++ b/src/llmq/instantsend.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/llmq/quorums.h b/src/llmq/quorums.h index 596d0eefec71b..915b42aebf390 100644 --- a/src/llmq/quorums.h +++ b/src/llmq/quorums.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/llmq/signing.h b/src/llmq/signing.h index 1b7891c7dba0e..bb01087b60822 100644 --- a/src/llmq/signing.h +++ b/src/llmq/signing.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/llmq/signing_shares.h b/src/llmq/signing_shares.h index 51e4a142d0f51..58eac7e23a357 100644 --- a/src/llmq/signing_shares.h +++ b/src/llmq/signing_shares.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/mapport.cpp b/src/mapport.cpp index eb4e0934d4a6c..85d65e39c5c55 100644 --- a/src/mapport.cpp +++ b/src/mapport.cpp @@ -13,9 +13,9 @@ #include #include #include -#include #include #include +#include #ifdef USE_NATPMP #include diff --git a/src/net.cpp b/src/net.cpp index 2f6376868a59b..659841ee5dbde 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/src/net.h b/src/net.h index 95cf7b6d42134..2dfc9d32b08ac 100644 --- a/src/net.h +++ b/src/net.h @@ -28,12 +28,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 130141210bdd9..f3062ce00740e 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -6,8 +6,8 @@ #ifndef BITCOIN_PRIMITIVES_TRANSACTION_H #define BITCOIN_PRIMITIVES_TRANSACTION_H +#include #include -#include #include