Skip to content

Commit

Permalink
Merge branch 'bitcoin' into auxpow
Browse files Browse the repository at this point in the history
  • Loading branch information
domob1812 committed Nov 27, 2023
2 parents 88a6751 + 5f9fd11 commit c52ba9b
Show file tree
Hide file tree
Showing 84 changed files with 693 additions and 352 deletions.
53 changes: 52 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ jobs:
# ancestors from the rev-list output as described in:
# https://git-scm.com/docs/git-rev-list
echo "TEST_BASE=$(git rev-list -n$((${{ env.MAX_COUNT }} + 1)) --reverse HEAD ^$(git rev-list -n1 --merges HEAD)^@ | head -1)" >> "$GITHUB_ENV"
- run: sudo apt install clang ccache build-essential libtool autotools-dev automake pkg-config bsdmainutils python3-zmq libevent-dev libboost-dev libsqlite3-dev libdb++-dev systemtap-sdt-dev libminiupnpc-dev libnatpmp-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools qtwayland5 libqrencode-dev -y
- run: |
sudo apt-get update
sudo apt-get install clang ccache build-essential libtool autotools-dev automake pkg-config bsdmainutils python3-zmq libevent-dev libboost-dev libsqlite3-dev libdb++-dev systemtap-sdt-dev libminiupnpc-dev libnatpmp-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools qtwayland5 libqrencode-dev -y
- name: Compile and run tests
run: |
# Run tests on commits after the last merge commit and before the PR head commit
Expand Down Expand Up @@ -136,6 +138,55 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Fix Visual Studio installation
# Avoid toolset ambiguity that MSVC can't handle.
run: |
Set-Location "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
$InstallPath = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
$componentsToRemove= @(
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ARM.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ARM"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ARM64.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ARM64"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ATL.ARM.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ATL.ARM"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ATL.ARM64.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ATL.ARM64"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ATL.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.ATL"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.MFC.ARM.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.MFC.ARM"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.MFC.ARM64.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.MFC.ARM64"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.MFC.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.MFC"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.x86.x64.Spectre"
"Microsoft.VisualStudio.Component.VC.14.37.17.7.x86.x64"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ARM"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ARM.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ARM64"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ARM64.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL.ARM"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL.ARM.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL.ARM64"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL.ARM64.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.MFC"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.MFC.ARM"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.MFC.ARM.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.MFC.ARM64"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.MFC.ARM64.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.MFC.Spectre"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.x86.x64"
"Microsoft.VisualStudio.Component.VC.14.38.17.8.x86.x64.Spectre"
)
[string]$workloadArgs = $componentsToRemove | ForEach-Object {" --remove " + $_}
$Arguments = ('/c', "vs_installer.exe", 'modify', '--installPath', "`"$InstallPath`"",$workloadArgs, '--quiet', '--norestart', '--nocache')
# should be run twice
$process = Start-Process -FilePath cmd.exe -ArgumentList $Arguments -Wait -PassThru -WindowStyle Hidden
$process = Start-Process -FilePath cmd.exe -ArgumentList $Arguments -Wait -PassThru -WindowStyle Hidden
- name: Configure Developer Command Prompt for Microsoft Visual C++
# Using microsoft/setup-msbuild is not enough.
uses: ilammy/msvc-dev-cmd@v1
Expand Down
9 changes: 0 additions & 9 deletions ci/lint/06_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ else
fi
export COMMIT_RANGE

# This only checks that the trees are pure subtrees, it is not doing a full
# check with -r to not have to fetch all the remotes.
test/lint/git-subtree-check.sh src/crypto/ctaes
test/lint/git-subtree-check.sh src/secp256k1
test/lint/git-subtree-check.sh src/minisketch
test/lint/git-subtree-check.sh src/leveldb
test/lint/git-subtree-check.sh src/crc32c
RUST_BACKTRACE=1 "${LINT_RUNNER_PATH}/test_runner"
test/lint/check-doc.py
test/lint/all-lint.py

if [ "$CIRRUS_REPO_FULL_NAME" = "bitcoin/bitcoin" ] && [ "$CIRRUS_PR" = "" ] ; then
# Sanity check only the last few commits to get notified of missing sigs,
Expand Down
1 change: 1 addition & 0 deletions ci/lint_imagefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ENV LC_ALL=C.UTF-8
COPY ./.python-version /.python-version
COPY ./ci/lint/container-entrypoint.sh /entrypoint.sh
COPY ./ci/lint/04_install.sh /install.sh
COPY ./test/lint/test_runner /test/lint/test_runner

RUN /install.sh && \
echo 'alias lint="./ci/lint/06_script.sh"' >> ~/.bashrc && \
Expand Down
1 change: 0 additions & 1 deletion ci/test/00_setup_env_i686_multiprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export GOAL="install"
export BITCOIN_CONFIG="--enable-debug CC='clang -m32' CXX='clang++ -m32' \
LDFLAGS='--rtlib=compiler-rt -lgcc_s' CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE'"
export TEST_RUNNER_ENV="BITCOIND=bitcoin-node"
export NO_WERROR=1 # Temporary workaround to avoid -Wdeprecated-declarations from KJ
2 changes: 1 addition & 1 deletion ci/test/00_setup_env_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export SDK_URL=${SDK_URL:-https://bitcoincore.org/depends-sources/sdks}
export CONTAINER_NAME=ci_macos_cross
export CI_IMAGE_NAME_TAG="docker.io/ubuntu:22.04"
export HOST=x86_64-apple-darwin
export PACKAGES="cmake libz-dev python3-setuptools zip"
export PACKAGES="cmake libz-dev zip"
export XCODE_VERSION=12.2
export XCODE_BUILD_ID=12B45b
export RUN_UNIT_TESTS=false
Expand Down
8 changes: 1 addition & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
CXXFLAGS="$TEMP_CXXFLAGS"

# ARM
AX_CHECK_COMPILE_FLAG([-march=armv8-a+crc], [ARM_CRC_CXXFLAGS="-march=armv8-a+crc"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-march=armv8-a+crc+crypto], [ARM_CRC_CXXFLAGS="-march=armv8-a+crc+crypto"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-march=armv8-a+crypto], [ARM_SHANI_CXXFLAGS="-march=armv8-a+crypto"], [], [$CXXFLAG_WERROR])

TEMP_CXXFLAGS="$CXXFLAGS"
Expand Down Expand Up @@ -986,12 +986,6 @@ if test "$use_hardening" != "no"; then
AX_CHECK_LINK_FLAG([-Wl,-z,now], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"], [], [$LDFLAG_WERROR])
AX_CHECK_LINK_FLAG([-Wl,-z,separate-code], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,separate-code"], [], [$LDFLAG_WERROR])
AX_CHECK_LINK_FLAG([-fPIE -pie], [PIE_FLAGS="-fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], [$CXXFLAG_WERROR])

case $host in
*mingw*)
AC_CHECK_LIB([ssp], [main], [], [AC_MSG_ERROR([libssp missing])])
;;
esac
fi

dnl These flags are specific to ld64, and may cause issues with other linkers.
Expand Down
8 changes: 2 additions & 6 deletions contrib/guix/manifest.scm
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,8 @@ inspecting signatures in Mach-O binaries.")
`(append ,flags
;; https://gcc.gnu.org/install/configure.html
(list "--enable-threads=posix",
building-on)))
((#:make-flags flags)
;; Uses the SSP functions from glibc instead of from libssp.so.
;; Our 'symbol-check' script will complain if we link against libssp.so,
;; and thus will ensure that this works properly.
`(cons "gcc_cv_libc_provides_ssp=yes" ,flags))))))
"--enable-default-ssp=yes",
building-on)))))))

(define-public linux-base-gcc
(package
Expand Down
2 changes: 1 addition & 1 deletion depends/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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 libz-dev python3-setuptools zip
sudo apt-get install curl bsdmainutils cmake libz-dev zip

Note: You must obtain the macOS SDK before proceeding with a cross-compile.
Under the depends directory, create a subdirectory named `SDKs`.
Expand Down
4 changes: 2 additions & 2 deletions depends/packages/native_libmultiprocess.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package=native_libmultiprocess
$(package)_version=61d5a0e661f20a4928fbf868ec9c3c6f17883cc7
$(package)_version=414542f81e0997354b45b8ade13ca144a3e35ff1
$(package)_download_path=https://github.com/chaincodelabs/libmultiprocess/archive
$(package)_file_name=$($(package)_version).tar.gz
$(package)_sha256_hash=5cfda224cc2ce913f2493f843317e0fca3184f6d7c1434c9754b2e7dca440ab5
$(package)_sha256_hash=8542dbaf8c4fce8fd7af6929f5dc9b34dffa51c43e9ee360e93ee0f34b180bc2
$(package)_dependencies=native_capnp

define $(package)_config_cmds
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ FUZZ_WALLET_SRC = \

if USE_SQLITE
FUZZ_WALLET_SRC += \
wallet/test/fuzz/notifications.cpp
wallet/test/fuzz/notifications.cpp \
wallet/test/fuzz/scriptpubkeyman.cpp
endif # USE_SQLITE

BITCOIN_TEST_SUITE += \
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.test_fuzz.include
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TEST_FUZZ_H = \
test/fuzz/fuzz.h \
test/fuzz/FuzzedDataProvider.h \
test/fuzz/util.h \
test/fuzz/util/descriptor.h \
test/fuzz/util/mempool.h \
test/fuzz/util/net.h

Expand All @@ -19,6 +20,7 @@ libtest_fuzz_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libtest_fuzz_a_SOURCES = \
test/fuzz/fuzz.cpp \
test/fuzz/util.cpp \
test/fuzz/util/descriptor.cpp \
test/fuzz/util/mempool.cpp \
test/fuzz/util/net.cpp \
$(TEST_FUZZ_H)
2 changes: 1 addition & 1 deletion src/bench/disconnected_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ReorgTxns {
static BlockTxns CreateRandomTransactions(size_t num_txns)
{
// Ensure every transaction has a different txid by having each one spend the previous one.
static uint256 prevout_hash{uint256::ZERO};
static Txid prevout_hash{};

BlockTxns txns;
txns.reserve(num_txns);
Expand Down
2 changes: 1 addition & 1 deletion src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void DuplicateInputs(benchmark::Bench& bench)

uint64_t n_inputs = (((MAX_BLOCK_SERIALIZED_SIZE / WITNESS_SCALE_FACTOR) - (CTransaction(coinbaseTx).GetTotalSize() + CTransaction(naughtyTx).GetTotalSize())) / 41) - 100;
for (uint64_t x = 0; x < (n_inputs - 1); ++x) {
naughtyTx.vin.emplace_back(GetRandHash(), 0, CScript(), 0);
naughtyTx.vin.emplace_back(Txid::FromUint256(GetRandHash()), 0, CScript(), 0);
}
naughtyTx.vin.emplace_back(naughtyTx.vin.back());

Expand Down
2 changes: 1 addition & 1 deletion src/bench/load_external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench)
bench.run([&] {
// "rb" is "binary, O_RDONLY", positioned to the start of the file.
// The file will be closed by LoadExternalBlockFile().
CAutoFile file{fsbridge::fopen(blkfile, "rb"), CLIENT_VERSION};
AutoFile file{fsbridge::fopen(blkfile, "rb")};
testing_setup->m_node.chainman->LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
});
fs::remove(blkfile);
Expand Down
2 changes: 1 addition & 1 deletion src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_ra
for (size_t ancestor = 0; ancestor < n_ancestors && !available_coins.empty(); ++ancestor){
size_t idx = det_rand.randrange(available_coins.size());
Available coin = available_coins[idx];
uint256 hash = coin.ref->GetHash();
Txid hash = coin.ref->GetHash();
// biased towards taking min_ancestors parents, but maybe more
size_t n_to_take = det_rand.randrange(2) == 0 ?
min_ancestors :
Expand Down
3 changes: 1 addition & 2 deletions src/bench/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ static void PoolAllocator_StdUnorderedMapWithPoolResource(benchmark::Bench& benc
std::hash<uint64_t>,
std::equal_to<uint64_t>,
PoolAllocator<std::pair<const uint64_t, uint64_t>,
sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*),
alignof(void*)>>;
sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*)>>;

// make sure the resource supports large enough pools to hold the node. We do this by adding the size of a few pointers to it.
auto pool_resource = Map::allocator_type::ResourceType();
Expand Down
2 changes: 1 addition & 1 deletion src/bench/streams_findbyte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
static void FindByte(benchmark::Bench& bench)
{
// Setup
CAutoFile file{fsbridge::fopen("streams_tmp", "w+b"), 0};
AutoFile file{fsbridge::fopen("streams_tmp", "w+b")};
const size_t file_size = 200;
uint8_t data[file_size] = {0};
data[file_size-1] = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
}

// append to transaction input list
CTxIn txin(txid, vout, CScript(), nSequenceIn);
CTxIn txin(Txid::FromUint256(txid), vout, CScript(), nSequenceIn);
tx.vin.push_back(txin);
}

Expand Down Expand Up @@ -629,7 +629,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
if (nOut < 0)
throw std::runtime_error("vout cannot be negative");

COutPoint out(txid, nOut);
COutPoint out(Txid::FromUint256(txid), nOut);
std::vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));
CScript scriptPubKey(pkData.begin(), pkData.end());

Expand Down
4 changes: 2 additions & 2 deletions src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coi

void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
bool fCoinbase = tx.IsCoinBase();
const uint256& txid = tx.GetHash();
const Txid& txid = tx.GetHash();
for (size_t i = 0; i < tx.vout.size(); ++i) {
bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
// Coinbase transactions can always be overwritten, in order to correctly
Expand Down Expand Up @@ -341,7 +341,7 @@ void CCoinsViewCache::SanityCheck() const
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut());
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;

const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
{
COutPoint iter(txid, 0);
while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
Expand Down
5 changes: 2 additions & 3 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ using CCoinsMap = std::unordered_map<COutPoint,
SaltedOutpointHasher,
std::equal_to<COutPoint>,
PoolAllocator<std::pair<const COutPoint, CCoinsCacheEntry>,
sizeof(std::pair<const COutPoint, CCoinsCacheEntry>) + sizeof(void*) * 4,
alignof(void*)>>;
sizeof(std::pair<const COutPoint, CCoinsCacheEntry>) + sizeof(void*) * 4>>;

using CCoinsMapMemoryResource = CCoinsMap::allocator_type::ResourceType;

Expand Down Expand Up @@ -364,7 +363,7 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight, bool
//! This function can be quite expensive because in the event of a transaction
//! which is not found in the cache, it can cause up to MAX_OUTPUTS_PER_BLOCK
//! lookups to database, so it should be used with care.
const Coin& AccessByTxid(const CCoinsViewCache& cache, const uint256& txid);
const Coin& AccessByTxid(const CCoinsViewCache& cache, const Txid& txid);

/**
* This is a minimally invasive approach to shutdown on LevelDB read errors from the
Expand Down
4 changes: 2 additions & 2 deletions src/common/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
// for finding tx when they appear in a block
if (vData.empty()) // zero-size = "match-all" filter
return true;
const uint256& hash = tx.GetHash();
if (contains(hash))
const Txid& hash = tx.GetHash();
if (contains(hash.ToUint256()))
fFound = true;

for (unsigned int i = 0; i < tx.vout.size(); i++)
Expand Down
2 changes: 1 addition & 1 deletion src/index/txindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
return false;
}

CAutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
AutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
if (file.IsNull()) {
return error("%s: OpenBlockFile failed", __func__);
}
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/coinstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void ApplyCoinHash(std::nullptr_t, const COutPoint& outpoint, const Coin&
//! construction could cause a previously invalid (and potentially malicious)
//! UTXO snapshot to be considered valid.
template <typename T>
static void ApplyHash(T& hash_obj, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
static void ApplyHash(T& hash_obj, const Txid& hash, const std::map<uint32_t, Coin>& outputs)
{
for (auto it = outputs.begin(); it != outputs.end(); ++it) {
COutPoint outpoint = COutPoint(hash, it->first);
Expand Down Expand Up @@ -118,7 +118,7 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
assert(pcursor);

uint256 prevkey;
Txid prevkey;
std::map<uint32_t, Coin> outputs;
while (pcursor->Valid()) {
if (interruption_point) interruption_point();
Expand Down
22 changes: 22 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,17 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
continue;
}

// Do not make automatic outbound connections to addnode peers, to
// not use our limited outbound slots for them and to ensure
// addnode connections benefit from their intended protections.
if (AddedNodesContain(addr)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "Not making automatic %s%s connection to %s peer selected for manual (addnode) connection%s\n",
preferred_net.has_value() ? "network-specific " : "",
ConnectionTypeAsString(conn_type), GetNetworkName(addr.GetNetwork()),
fLogIPs ? strprintf(": %s", addr.ToStringAddrPort()) : "");
continue;
}

addrConnect = addr;
break;
}
Expand Down Expand Up @@ -3454,6 +3465,17 @@ bool CConnman::RemoveAddedNode(const std::string& strNode)
return false;
}

bool CConnman::AddedNodesContain(const CAddress& addr) const
{
AssertLockNotHeld(m_added_nodes_mutex);
const std::string addr_str{addr.ToStringAddr()};
const std::string addr_port_str{addr.ToStringAddrPort()};
LOCK(m_added_nodes_mutex);
return (m_added_node_params.size() < 24 // bound the query to a reasonable limit
&& std::any_of(m_added_node_params.cbegin(), m_added_node_params.cend(),
[&](const auto& p) { return p.m_added_node == addr_str || p.m_added_node == addr_port_str; }));
}

size_t CConnman::GetNodeCount(ConnectionDirection flags) const
{
LOCK(m_nodes_mutex);
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ class CConnman

bool AddNode(const AddedNodeParams& add) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
bool RemoveAddedNode(const std::string& node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
bool AddedNodesContain(const CAddress& addr) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
std::vector<AddedNodeInfo> GetAddedNodeInfo(bool include_connected) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);

/**
Expand Down
Loading

0 comments on commit c52ba9b

Please sign in to comment.