Merge pull request #4356 from kittywhiskers/depends

merge bitcoin#18820, #19764, #13686, #17538, #18405: zmq backports, boost depends split
This commit is contained in:
PastaPastaPasta 2021-08-31 15:31:38 -04:00 committed by GitHub
commit bbc8623245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 240 additions and 309 deletions

View File

@ -4,8 +4,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
'''
A script to check that the (Linux) executables produced by Gitian only contain
allowed gcc, glibc and libstdc++ version symbols. This makes sure they are
still compatible with the minimum supported Linux distribution versions.
allowed gcc and glibc version symbols. This makes sure they are still compatible
with the minimum supported Linux distribution versions.
Example usage:
@ -16,30 +16,30 @@ import re
import sys
import os
# Debian 6.0.9 (Squeeze) has:
# Debian 8 (Jessie) EOL: 2020. https://wiki.debian.org/DebianReleases#Production_Releases
#
# - g++ version 4.4.5 (https://packages.debian.org/search?suite=default&section=all&arch=any&searchon=names&keywords=g%2B%2B)
# - libc version 2.11.3 (https://packages.debian.org/search?suite=default&section=all&arch=any&searchon=names&keywords=libc6)
# - libstdc++ version 4.4.5 (https://packages.debian.org/search?suite=default&section=all&arch=any&searchon=names&keywords=libstdc%2B%2B6)
# - g++ version 4.9.2 (https://packages.debian.org/search?suite=jessie&arch=any&searchon=names&keywords=g%2B%2B)
# - libc version 2.19 (https://packages.debian.org/search?suite=jessie&arch=any&searchon=names&keywords=libc6)
#
# Ubuntu 10.04.4 (Lucid Lynx) has:
# Ubuntu 16.04 (Xenial) EOL: 2024. https://wiki.ubuntu.com/Releases
#
# - g++ version 4.4.3 (http://packages.ubuntu.com/search?keywords=g%2B%2B&searchon=names&suite=lucid&section=all)
# - libc version 2.11.1 (http://packages.ubuntu.com/search?keywords=libc6&searchon=names&suite=lucid&section=all)
# - libstdc++ version 4.4.3 (http://packages.ubuntu.com/search?suite=lucid&section=all&arch=any&keywords=libstdc%2B%2B&searchon=names)
# - g++ version 5.3.1 (https://packages.ubuntu.com/search?keywords=g%2B%2B&searchon=names&suite=xenial&section=all)
# - libc version 2.23.0 (https://packages.ubuntu.com/search?keywords=libc6&searchon=names&suite=xenial&section=all)
#
# CentOS 7 EOL: 2024. https://wiki.centos.org/FAQ/General
#
# - g++ version 4.8.5 (http://mirror.centos.org/centos/7/os/x86_64/Packages/)
# - libc version 2.17 (http://mirror.centos.org/centos/7/os/x86_64/Packages/)
#
# Taking the minimum of these as our target.
#
# According to GNU ABI document (http://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) this corresponds to:
# GCC 4.4.0: GCC_4.4.0
# GCC 4.4.2: GLIBCXX_3.4.13, CXXABI_1.3.3
# (glibc) GLIBC_2_11
# According to GNU ABI document (https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) this corresponds to:
# GCC 4.8.5: GCC_4.8.0
# (glibc) GLIBC_2_17
#
MAX_VERSIONS = {
'GCC': (4,4,0),
'CXXABI': (1,3,3),
'GLIBCXX': (3,4,13),
'GLIBC': (2,11),
'GCC': (4,8,0),
'GLIBC': (2,17),
'LIBATOMIC': (1,0)
}
# See here for a description of _IO_stdin_used:

View File

@ -4,6 +4,30 @@
print-%:
@echo $* = $($*)
# When invoking a sub-make, keep only the command line variable definitions
# matching the pattern in the filter function.
#
# e.g. invoking:
# $ make A=1 C=1 print-MAKEOVERRIDES print-MAKEFLAGS
#
# with the following in the Makefile:
# MAKEOVERRIDES := $(filter A=% B=%,$(MAKEOVERRIDES))
#
# will print:
# MAKEOVERRIDES = A=1
# MAKEFLAGS = -- A=1
#
# this is because as the GNU make manual says:
# The command line variable definitions really appear in the variable
# MAKEOVERRIDES, and MAKEFLAGS contains a reference to this variable.
#
# and since the GNU make manual also says:
# variables defined on the command line are passed to the sub-make through
# MAKEFLAGS
#
# this means that sub-makes will be invoked as if:
# $(MAKE) A=1 blah blah
MAKEOVERRIDES := $(filter V=%,$(MAKEOVERRIDES))
SOURCES_PATH ?= $(BASEDIR)/sources
WORK_PATH = $(BASEDIR)/work
BASE_CACHE ?= $(BASEDIR)/built

View File

@ -13,9 +13,18 @@ default_host_OTOOL = $(host_toolchain)otool
default_host_NM = $(host_toolchain)nm
define add_host_tool_func
ifneq ($(filter $(origin $1),undefined default),)
# Do not consider the well-known var $1 if it is undefined or is taking a value
# that is predefined by "make" (e.g. the make variable "CC" has a predefined
# value of "cc")
$(host_os)_$1?=$$(default_host_$1)
$(host_arch)_$(host_os)_$1?=$$($(host_os)_$1)
$(host_arch)_$(host_os)_$(release_type)_$1?=$$($(host_os)_$1)
else
$(host_os)_$1=$(or $($1),$($(host_os)_$1),$(default_host_$1))
$(host_arch)_$(host_os)_$1=$(or $($1),$($(host_arch)_$(host_os)_$1),$$($(host_os)_$1))
$(host_arch)_$(host_os)_$(release_type)_$1=$(or $($1),$($(host_arch)_$(host_os)_$(release_type)_$1),$$($(host_os)_$1))
endif
host_$1=$$($(host_arch)_$(host_os)_$1)
endef

View File

@ -1,40 +1,44 @@
package=boost
$(package)_version=1_70_0
$(package)_download_path=https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/
$(package)_file_name=$(package)_$($(package)_version).tar.bz2
$(package)_sha256_hash=430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778
$(package)_version=1_71_0
$(package)_download_path=https://boostorg.jfrog.io/artifactory/main/release/$(subst _,.,$($(package)_version))/source/
$(package)_file_name=boost_$($(package)_version).tar.bz2
$(package)_sha256_hash=d73a8da01e8bf8c7eda40b4c84915071a8c8a0df4a6734537ddde4a8580524ee
$(package)_dependencies=native_b2
define $(package)_set_vars
$(package)_config_opts_release=variant=release
$(package)_config_opts_debug=variant=debug
$(package)_config_opts=--layout=tagged --build-type=complete --user-config=user-config.jam
$(package)_config_opts+=threading=multi link=static -sNO_BZIP2=1 -sNO_ZLIB=1
$(package)_config_opts_linux=threadapi=pthread runtime-link=shared
$(package)_config_opts_darwin=--toolset=clang-darwin runtime-link=shared
$(package)_config_opts_mingw32=binary-format=pe target-os=windows threadapi=win32 runtime-link=static
$(package)_config_opts_x86_64_mingw32=address-model=64
$(package)_config_opts_i686_mingw32=address-model=32
$(package)_config_opts_i686_linux=address-model=32 architecture=x86
$(package)_config_opts+=threading=multi link=static -sNO_COMPRESSION=1
$(package)_config_opts_linux=target-os=linux threadapi=pthread runtime-link=shared
$(package)_config_opts_darwin=target-os=darwin runtime-link=shared
$(package)_config_opts_mingw32=target-os=windows binary-format=pe threadapi=win32 runtime-link=static
$(package)_config_opts_x86_64=architecture=x86 address-model=64
$(package)_config_opts_i686=architecture=x86 address-model=32
$(package)_config_opts_aarch64=address-model=64
$(package)_config_opts_armv7a=address-model=32
ifneq (,$(findstring clang,$($(package)_cxx)))
$(package)_toolset_$(host_os)=clang
else
$(package)_toolset_$(host_os)=gcc
$(package)_archiver_$(host_os)=$($(package)_ar)
$(package)_toolset_darwin=clang-darwin
endif
$(package)_config_libraries=chrono,filesystem,system,thread,test
$(package)_cxxflags=-std=c++11 -fvisibility=hidden
$(package)_cxxflags_linux=-fPIC
endef
define $(package)_preprocess_cmds
echo "using $($(package)_toolset_$(host_os)) : : $($(package)_cxx) : <cxxflags>\"$($(package)_cxxflags) $($(package)_cppflags)\" <linkflags>\"$($(package)_ldflags)\" <archiver>\"$($(package)_archiver_$(host_os))\" <striper>\"$(host_STRIP)\" <ranlib>\"$(host_RANLIB)\" <rc>\"$(host_WINDRES)\" : ;" > user-config.jam
echo "using $($(package)_toolset_$(host_os)) : : $($(package)_cxx) : <cflags>\"$($(package)_cflags)\" <cxxflags>\"$($(package)_cxxflags)\" <compileflags>\"$($(package)_cppflags)\" <linkflags>\"$($(package)_ldflags)\" <archiver>\"$($(package)_ar)\" <striper>\"$(host_STRIP)\" <ranlib>\"$(host_RANLIB)\" <rc>\"$(host_WINDRES)\" : ;" > user-config.jam
endef
define $(package)_config_cmds
./bootstrap.sh --without-icu --with-libraries=$($(package)_config_libraries)
./bootstrap.sh --without-icu --with-libraries=$($(package)_config_libraries) --with-toolset=$($(package)_toolset_$(host_os)) --with-bjam=b2
endef
define $(package)_build_cmds
./b2 -d2 -j2 -d1 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) stage
b2 -d2 -j2 -d1 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) toolset=$($(package)_toolset_$(host_os)) stage
endef
define $(package)_stage_cmds
./b2 -d0 -j4 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) install
b2 -d0 -j4 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) toolset=$($(package)_toolset_$(host_os)) install
endef

View File

@ -0,0 +1,20 @@
package=native_b2
$(package)_version=$(boost_version)
$(package)_download_path=$(boost_download_path)
$(package)_file_name=$(boost_file_name)
$(package)_sha256_hash=$(boost_sha256_hash)
$(package)_build_subdir=tools/build/src/engine
ifneq (,$(findstring clang,$($(package)_cxx)))
$(package)_toolset_$(host_os)=clang
else
$(package)_toolset_$(host_os)=gcc
endif
define $(package)_build_cmds
CXX="$($(package)_cxx)" CXXFLAGS="$($(package)_cxxflags)" ./build.sh "$($(package)_toolset_$(host_os))"
endef
define $(package)_stage_cmds
mkdir -p "$($(package)_staging_prefix_dir)"/bin/ && \
cp b2 "$($(package)_staging_prefix_dir)"/bin/
endef

View File

@ -14,6 +14,8 @@ upnp_packages=miniupnpc
darwin_native_packages = native_biplist native_ds_store native_mac_alias
$(host_arch)_$(host_os)_native_packages += native_b2
ifneq ($(build_os),darwin)
darwin_native_packages += native_cctools native_cdrkit native_libdmg-hfsplus
endif

View File

@ -3,7 +3,6 @@ $(package)_version=4.2.3
$(package)_download_path=https://github.com/zeromq/libzmq/releases/download/v$($(package)_version)/
$(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=8f1e2b2aade4dbfde98d82366d61baef2f62e812530160d2e6d0a5bb24e40bc0
$(package)_patches=0001-fix-build-with-older-mingw64.patch 0002-disable-pthread_set_name_np.patch
define $(package)_set_vars
$(package)_config_opts=--without-docs --disable-shared --disable-curve --disable-curve-keygen --disable-perf --disable-Werror --disable-drafts
@ -14,8 +13,6 @@ define $(package)_set_vars
endef
define $(package)_preprocess_cmds
patch -p1 < $($(package)_patch_dir)/0001-fix-build-with-older-mingw64.patch && \
patch -p1 < $($(package)_patch_dir)/0002-disable-pthread_set_name_np.patch && \
cp -f $(BASEDIR)/config.guess $(BASEDIR)/config.sub config
endef

View File

@ -1,30 +0,0 @@
From 1a159c128c69a42d90819375c06a39994f3fbfc1 Mon Sep 17 00:00:00 2001
From: Cory Fields <cory-nospam-@coryfields.com>
Date: Tue, 28 Nov 2017 20:33:25 -0500
Subject: [PATCH] fix build with older mingw64
---
src/windows.hpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/windows.hpp b/src/windows.hpp
index 99e889d..e69038e 100644
--- a/src/windows.hpp
+++ b/src/windows.hpp
@@ -55,6 +55,13 @@
#include <winsock2.h>
#include <windows.h>
#include <mswsock.h>
+
+#if defined __MINGW64_VERSION_MAJOR && __MINGW64_VERSION_MAJOR < 4
+// Workaround for mingw-w64 < v4.0 which did not include ws2ipdef.h in iphlpapi.h.
+// Fixed in mingw-w64 by 9bd8fe9148924840d315b4c915dd099955ea89d1.
+#include <ws2def.h>
+#include <ws2ipdef.h>
+#endif
#include <iphlpapi.h>
#if !defined __MINGW32__
--
2.7.4

View File

@ -1,35 +0,0 @@
From 6e6b47d5ab381c3df3b30bb0b0a6cf210dfb1eba Mon Sep 17 00:00:00 2001
From: Cory Fields <cory-nospam-@coryfields.com>
Date: Mon, 5 Mar 2018 14:22:05 -0500
Subject: [PATCH] disable pthread_set_name_np
pthread_set_name_np adds a Glibc requirement on >= 2.12.
---
src/thread.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/thread.cpp b/src/thread.cpp
index 4fc59c3e..c3fdfd46 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -220,7 +220,7 @@ void zmq::thread_t::setThreadName(const char *name_)
*/
if (!name_)
return;
-
+#if 0
#if defined(ZMQ_HAVE_PTHREAD_SETNAME_1)
int rc = pthread_setname_np(name_);
if(rc) return;
@@ -233,6 +233,8 @@ void zmq::thread_t::setThreadName(const char *name_)
#elif defined(ZMQ_HAVE_PTHREAD_SET_NAME)
pthread_set_name_np(descriptor, name_);
#endif
+#endif
+ return;
}
#endif
--
2.11.1

View File

@ -302,10 +302,10 @@ BITCOIN_CORE_H = \
wallet/coinselection.h \
warnings.h \
zmq/zmqabstractnotifier.h \
zmq/zmqconfig.h\
zmq/zmqnotificationinterface.h \
zmq/zmqpublishnotifier.h \
zmq/zmqrpc.h
zmq/zmqrpc.h \
zmq/zmqutil.h
obj/build.h: FORCE
@ -426,7 +426,8 @@ libdash_zmq_a_SOURCES = \
zmq/zmqabstractnotifier.cpp \
zmq/zmqnotificationinterface.cpp \
zmq/zmqpublishnotifier.cpp \
zmq/zmqrpc.cpp
zmq/zmqrpc.cpp \
zmq/zmqutil.cpp
endif

View File

@ -5,6 +5,7 @@
#include <zmq/zmqabstractnotifier.h>
#include <util/system.h>
#include <cassert>
CZMQAbstractNotifier::~CZMQAbstractNotifier()
{

View File

@ -5,20 +5,26 @@
#ifndef BITCOIN_ZMQ_ZMQABSTRACTNOTIFIER_H
#define BITCOIN_ZMQ_ZMQABSTRACTNOTIFIER_H
#include <zmq/zmqconfig.h>
#include <util/memory.h>
#include <memory>
#include <string>
class CBlockIndex;
class CGovernanceObject;
class CGovernanceVote;
class CTransaction;
class CZMQAbstractNotifier;
typedef std::shared_ptr<const CTransaction> CTransactionRef;
namespace llmq {
class CChainLockSig;
class CInstantSendLock;
class CRecoveredSig;
} // namespace llmq
typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)();
using CZMQNotifierFactory = std::unique_ptr<CZMQAbstractNotifier> (*)();
class CZMQAbstractNotifier
{
@ -27,9 +33,9 @@ public:
virtual ~CZMQAbstractNotifier();
template <typename T>
static CZMQAbstractNotifier* Create()
static std::unique_ptr<CZMQAbstractNotifier> Create()
{
return new T();
return MakeUnique<T>();
}
std::string GetType() const { return type; }

View File

@ -1,31 +0,0 @@
// Copyright (c) 2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_ZMQ_ZMQCONFIG_H
#define BITCOIN_ZMQ_ZMQCONFIG_H
#if defined(HAVE_CONFIG_H)
#include <config/dash-config.h>
#endif
#include <stdarg.h>
#include <string>
#if ENABLE_ZMQ
#include <zmq.h>
#endif
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <governance/governance-object.h>
#include <governance/governance-vote.h>
#include <llmq/quorums_chainlocks.h>
#include <llmq/quorums_instantsend.h>
#include <llmq/quorums_signing.h>
void zmqError(const char *str);
#endif // BITCOIN_ZMQ_ZMQCONFIG_H

View File

@ -4,17 +4,15 @@
#include <zmq/zmqnotificationinterface.h>
#include <zmq/zmqpublishnotifier.h>
#include <zmq/zmqutil.h>
#include <zmq.h>
#include <version.h>
#include <validation.h>
#include <streams.h>
#include <util/system.h>
void zmqError(const char *str)
{
LogPrint(BCLog::ZMQ, "zmq: Error: %s, errno=%s\n", str, zmq_strerror(errno));
}
CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(nullptr)
{
}
@ -22,28 +20,20 @@ CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(nullptr)
CZMQNotificationInterface::~CZMQNotificationInterface()
{
Shutdown();
for (std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin(); i!=notifiers.end(); ++i)
{
delete *i;
}
}
std::list<const CZMQAbstractNotifier*> CZMQNotificationInterface::GetActiveNotifiers() const
{
std::list<const CZMQAbstractNotifier*> result;
for (const auto* n : notifiers) {
result.push_back(n);
for (const auto& n : notifiers) {
result.push_back(n.get());
}
return result;
}
CZMQNotificationInterface* CZMQNotificationInterface::Create()
{
CZMQNotificationInterface* notificationInterface = nullptr;
std::map<std::string, CZMQNotifierFactory> factories;
std::list<CZMQAbstractNotifier*> notifiers;
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
factories["pubhashchainlock"] = CZMQAbstractNotifier::Create<CZMQPublishHashChainLockNotifier>;
factories["pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
@ -63,33 +53,32 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create()
factories["pubrawinstantsenddoublespend"] = CZMQAbstractNotifier::Create<CZMQPublishRawInstantSendDoubleSpendNotifier>;
factories["pubrawrecoveredsig"] = CZMQAbstractNotifier::Create<CZMQPublishRawRecoveredSigNotifier>;
std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
for (const auto& entry : factories)
{
std::string arg("-zmq" + entry.first);
if (gArgs.IsArgSet(arg))
{
CZMQNotifierFactory factory = entry.second;
std::string address = gArgs.GetArg(arg, "");
CZMQAbstractNotifier *notifier = factory();
const auto& factory = entry.second;
const std::string address = gArgs.GetArg(arg, "");
std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
notifier->SetType(entry.first);
notifier->SetAddress(address);
notifiers.push_back(notifier);
notifiers.push_back(std::move(notifier));
}
}
if (!notifiers.empty())
{
notificationInterface = new CZMQNotificationInterface();
notificationInterface->notifiers = notifiers;
std::unique_ptr<CZMQNotificationInterface> notificationInterface(new CZMQNotificationInterface());
notificationInterface->notifiers = std::move(notifiers);
if (!notificationInterface->Initialize())
{
delete notificationInterface;
notificationInterface = nullptr;
if (notificationInterface->Initialize()) {
return notificationInterface.release();
}
}
return notificationInterface;
return nullptr;
}
// Called at startup to conditionally set up ZMQ socket(s)
@ -106,25 +95,14 @@ bool CZMQNotificationInterface::Initialize()
return false;
}
std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin();
for (; i!=notifiers.end(); ++i)
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->Initialize(pcontext))
{
LogPrint(BCLog::ZMQ, " Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
}
else
{
LogPrint(BCLog::ZMQ, " Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
break;
}
}
if (i!=notifiers.end())
{
for (auto& notifier : notifiers) {
if (notifier->Initialize(pcontext)) {
LogPrint(BCLog::ZMQ, "zmq: Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
} else {
LogPrint(BCLog::ZMQ, "zmq: Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
return false;
}
}
return true;
}
@ -135,10 +113,8 @@ void CZMQNotificationInterface::Shutdown()
LogPrint(BCLog::ZMQ, "zmq: Shutdown notification interface\n");
if (pcontext)
{
for (std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin(); i!=notifiers.end(); ++i)
{
CZMQAbstractNotifier *notifier = *i;
LogPrint(BCLog::ZMQ, " Shutdown notifier %s at %s\n", notifier->GetType(), notifier->GetAddress());
for (auto& notifier : notifiers) {
LogPrint(BCLog::ZMQ, "zmq: Shutdown notifier %s at %s\n", notifier->GetType(), notifier->GetAddress());
notifier->Shutdown();
}
zmq_ctx_destroy(pcontext);
@ -147,41 +123,37 @@ void CZMQNotificationInterface::Shutdown()
}
}
void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
namespace {
template <typename Function>
void TryForEachAndRemoveFailed(std::list<std::unique_ptr<CZMQAbstractNotifier>>& notifiers, const Function& func)
{
if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
return;
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyBlock(pindexNew))
{
i++;
}
else
{
for (auto i = notifiers.begin(); i != notifiers.end(); ) {
CZMQAbstractNotifier* notifier = i->get();
if (func(notifier)) {
++i;
} else {
notifier->Shutdown();
i = notifiers.erase(i);
}
}
}
}
void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
{
if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
return;
TryForEachAndRemoveFailed(notifiers, [pindexNew](CZMQAbstractNotifier* notifier) {
return notifier->NotifyBlock(pindexNew);
});
}
void CZMQNotificationInterface::NotifyChainLock(const CBlockIndex *pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)
{
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyChainLock(pindex, clsig))
{
i++;
}
else
{
notifier->Shutdown();
i = notifiers.erase(i);
}
}
TryForEachAndRemoveFailed(notifiers, [pindex, &clsig](CZMQAbstractNotifier* notifier) {
return notifier->NotifyChainLock(pindex, clsig);
});
}
void CZMQNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime)
@ -190,19 +162,9 @@ void CZMQNotificationInterface::TransactionAddedToMempool(const CTransactionRef&
// all the same external callback.
const CTransaction& tx = *ptx;
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyTransaction(tx))
{
i++;
}
else
{
notifier->Shutdown();
i = notifiers.erase(i);
}
}
TryForEachAndRemoveFailed(notifiers, [&tx](CZMQAbstractNotifier* notifier) {
return notifier->NotifyTransaction(tx);
});
}
void CZMQNotificationInterface::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted)
@ -223,79 +185,37 @@ void CZMQNotificationInterface::BlockDisconnected(const std::shared_ptr<const CB
void CZMQNotificationInterface::NotifyTransactionLock(const CTransactionRef& tx, const std::shared_ptr<const llmq::CInstantSendLock>& islock)
{
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyTransactionLock(tx, islock))
{
i++;
}
else
{
notifier->Shutdown();
i = notifiers.erase(i);
}
}
TryForEachAndRemoveFailed(notifiers, [&tx, &islock](CZMQAbstractNotifier* notifier) {
return notifier->NotifyTransactionLock(tx, islock);
});
}
void CZMQNotificationInterface::NotifyGovernanceVote(const std::shared_ptr<const CGovernanceVote> &vote)
{
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyGovernanceVote(vote))
{
i++;
}
else
{
notifier->Shutdown();
i = notifiers.erase(i);
}
}
TryForEachAndRemoveFailed(notifiers, [&vote](CZMQAbstractNotifier* notifier) {
return notifier->NotifyGovernanceVote(vote);
});
}
void CZMQNotificationInterface::NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject> &object)
{
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyGovernanceObject(object))
{
i++;
}
else
{
notifier->Shutdown();
i = notifiers.erase(i);
}
}
TryForEachAndRemoveFailed(notifiers, [&object](CZMQAbstractNotifier* notifier) {
return notifier->NotifyGovernanceObject(object);
});
}
void CZMQNotificationInterface::NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx)
{
for (auto it = notifiers.begin(); it != notifiers.end();) {
CZMQAbstractNotifier *notifier = *it;
if (notifier->NotifyInstantSendDoubleSpendAttempt(currentTx, previousTx)) {
++it;
} else {
notifier->Shutdown();
it = notifiers.erase(it);
}
}
TryForEachAndRemoveFailed(notifiers, [&currentTx, &previousTx](CZMQAbstractNotifier* notifier) {
return notifier->NotifyInstantSendDoubleSpendAttempt(currentTx, previousTx);
});
}
void CZMQNotificationInterface::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig)
{
for (auto it = notifiers.begin(); it != notifiers.end();) {
CZMQAbstractNotifier *notifier = *it;
if (notifier->NotifyRecoveredSig(sig)) {
++it;
} else {
notifier->Shutdown();
it = notifiers.erase(it);
}
}
TryForEachAndRemoveFailed(notifiers, [&sig](CZMQAbstractNotifier* notifier) {
return notifier->NotifyRecoveredSig(sig);
});
}
CZMQNotificationInterface* g_zmq_notification_interface = nullptr;

View File

@ -9,6 +9,7 @@
#include <string>
#include <map>
#include <list>
#include <memory>
class CBlockIndex;
class CZMQAbstractNotifier;
@ -42,7 +43,7 @@ private:
CZMQNotificationInterface();
void *pcontext;
std::list<CZMQAbstractNotifier*> notifiers;
std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
};
extern CZMQNotificationInterface* g_zmq_notification_interface;

View File

@ -2,12 +2,30 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <zmq/zmqpublishnotifier.h>
#include <chain.h>
#include <chainparams.h>
#include <rpc/server.h>
#include <streams.h>
#include <zmq/zmqpublishnotifier.h>
#include <validation.h>
#include <util/system.h>
#include <validation.h>
#include <zmq/zmqutil.h>
#include <governance/governance-object.h>
#include <governance/governance-vote.h>
#include <llmq/quorums_chainlocks.h>
#include <llmq/quorums_instantsend.h>
#include <llmq/quorums_signing.h>
#include <zmq.h>
#include <cstdarg>
#include <cstddef>
#include <map>
#include <string>
#include <utility>
static std::multimap<std::string, CZMQAbstractPublishNotifier*> mapPublishNotifiers;
@ -142,7 +160,7 @@ void CZMQAbstractPublishNotifier::Shutdown()
psocket = nullptr;
}
bool CZMQAbstractPublishNotifier::SendMessage(const char *command, const void* data, size_t size)
bool CZMQAbstractPublishNotifier::SendZmqMessage(const char *command, const void* data, size_t size)
{
assert(psocket);
@ -166,7 +184,7 @@ bool CZMQPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
char data[32];
for (unsigned int i = 0; i < 32; i++)
data[31 - i] = hash.begin()[i];
return SendMessage(MSG_HASHBLOCK, data, 32);
return SendZmqMessage(MSG_HASHBLOCK, data, 32);
}
bool CZMQPublishHashChainLockNotifier::NotifyChainLock(const CBlockIndex *pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)
@ -176,7 +194,7 @@ bool CZMQPublishHashChainLockNotifier::NotifyChainLock(const CBlockIndex *pindex
char data[32];
for (unsigned int i = 0; i < 32; i++)
data[31 - i] = hash.begin()[i];
return SendMessage(MSG_HASHCHAINLOCK, data, 32);
return SendZmqMessage(MSG_HASHCHAINLOCK, data, 32);
}
bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
@ -186,7 +204,7 @@ bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &t
char data[32];
for (unsigned int i = 0; i < 32; i++)
data[31 - i] = hash.begin()[i];
return SendMessage(MSG_HASHTX, data, 32);
return SendZmqMessage(MSG_HASHTX, data, 32);
}
bool CZMQPublishHashTransactionLockNotifier::NotifyTransactionLock(const CTransactionRef& transaction, const std::shared_ptr<const llmq::CInstantSendLock>& islock)
@ -196,7 +214,7 @@ bool CZMQPublishHashTransactionLockNotifier::NotifyTransactionLock(const CTransa
char data[32];
for (unsigned int i = 0; i < 32; i++)
data[31 - i] = hash.begin()[i];
return SendMessage(MSG_HASHTXLOCK, data, 32);
return SendZmqMessage(MSG_HASHTXLOCK, data, 32);
}
bool CZMQPublishHashGovernanceVoteNotifier::NotifyGovernanceVote(const std::shared_ptr<const CGovernanceVote>& vote)
@ -206,7 +224,7 @@ bool CZMQPublishHashGovernanceVoteNotifier::NotifyGovernanceVote(const std::shar
char data[32];
for (unsigned int i = 0; i < 32; i++)
data[31 - i] = hash.begin()[i];
return SendMessage(MSG_HASHGVOTE, data, 32);
return SendZmqMessage(MSG_HASHGVOTE, data, 32);
}
bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object)
@ -216,7 +234,7 @@ bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const std::
char data[32];
for (unsigned int i = 0; i < 32; i++)
data[31 - i] = hash.begin()[i];
return SendMessage(MSG_HASHGOBJ, data, 32);
return SendZmqMessage(MSG_HASHGOBJ, data, 32);
}
bool CZMQPublishHashInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx)
@ -228,8 +246,8 @@ bool CZMQPublishHashInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpend
dataCurrentHash[31 - i] = currentHash.begin()[i];
dataPreviousHash[31 - i] = previousHash.begin()[i];
}
return SendMessage(MSG_HASHISCON, dataCurrentHash, 32)
&& SendMessage(MSG_HASHISCON, dataPreviousHash, 32);
return SendZmqMessage(MSG_HASHISCON, dataCurrentHash, 32)
&& SendZmqMessage(MSG_HASHISCON, dataPreviousHash, 32);
}
bool CZMQPublishHashRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig)
@ -238,7 +256,7 @@ bool CZMQPublishHashRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_p
char data[32];
for (unsigned int i = 0; i < 32; i++)
data[31 - i] = sig->msgHash.begin()[i];
return SendMessage(MSG_HASHRECSIG, data, 32);
return SendZmqMessage(MSG_HASHRECSIG, data, 32);
}
bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
@ -259,7 +277,7 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
ss << block;
}
return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawChainLockNotifier::NotifyChainLock(const CBlockIndex *pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)
@ -280,7 +298,7 @@ bool CZMQPublishRawChainLockNotifier::NotifyChainLock(const CBlockIndex *pindex,
ss << block;
}
return SendMessage(MSG_RAWCHAINLOCK, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWCHAINLOCK, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawChainLockSigNotifier::NotifyChainLock(const CBlockIndex *pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)
@ -302,7 +320,7 @@ bool CZMQPublishRawChainLockSigNotifier::NotifyChainLock(const CBlockIndex *pind
ss << *clsig;
}
return SendMessage(MSG_RAWCLSIG, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWCLSIG, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
@ -311,7 +329,7 @@ bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &tr
LogPrint(BCLog::ZMQ, "zmq: Publish rawtx %s\n", hash.GetHex());
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << transaction;
return SendMessage(MSG_RAWTX, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWTX, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawTransactionLockNotifier::NotifyTransactionLock(const CTransactionRef& transaction, const std::shared_ptr<const llmq::CInstantSendLock>& islock)
@ -320,7 +338,7 @@ bool CZMQPublishRawTransactionLockNotifier::NotifyTransactionLock(const CTransac
LogPrint(BCLog::ZMQ, "zmq: Publish rawtxlock %s\n", hash.GetHex());
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << *transaction;
return SendMessage(MSG_RAWTXLOCK, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWTXLOCK, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawTransactionLockSigNotifier::NotifyTransactionLock(const CTransactionRef& transaction, const std::shared_ptr<const llmq::CInstantSendLock>& islock)
@ -330,7 +348,7 @@ bool CZMQPublishRawTransactionLockSigNotifier::NotifyTransactionLock(const CTran
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << *transaction;
ss << *islock;
return SendMessage(MSG_RAWTXLOCKSIG, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWTXLOCKSIG, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawGovernanceVoteNotifier::NotifyGovernanceVote(const std::shared_ptr<const CGovernanceVote>& vote)
@ -339,7 +357,7 @@ bool CZMQPublishRawGovernanceVoteNotifier::NotifyGovernanceVote(const std::share
LogPrint(BCLog::ZMQ, "zmq: Publish rawgovernanceobject: hash = %s, vote = %d\n", nHash.ToString(), vote->ToString());
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << *vote;
return SendMessage(MSG_RAWGVOTE, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWGVOTE, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& govobj)
@ -348,7 +366,7 @@ bool CZMQPublishRawGovernanceObjectNotifier::NotifyGovernanceObject(const std::s
LogPrint(BCLog::ZMQ, "zmq: Publish rawgovernanceobject: hash = %s, type = %d\n", nHash.ToString(), govobj->GetObjectType());
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << *govobj;
return SendMessage(MSG_RAWGOBJ, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWGOBJ, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx)
@ -357,8 +375,8 @@ bool CZMQPublishRawInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpendA
CDataStream ssCurrent(SER_NETWORK, PROTOCOL_VERSION), ssPrevious(SER_NETWORK, PROTOCOL_VERSION);
ssCurrent << *currentTx;
ssPrevious << *previousTx;
return SendMessage(MSG_RAWISCON, &(*ssCurrent.begin()), ssCurrent.size())
&& SendMessage(MSG_RAWISCON, &(*ssPrevious.begin()), ssPrevious.size());
return SendZmqMessage(MSG_RAWISCON, &(*ssCurrent.begin()), ssCurrent.size())
&& SendZmqMessage(MSG_RAWISCON, &(*ssPrevious.begin()), ssPrevious.size());
}
bool CZMQPublishRawRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig)
@ -368,6 +386,6 @@ bool CZMQPublishRawRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_pt
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << *sig;
return SendMessage(MSG_RAWRECSIG, &(*ss.begin()), ss.size());
return SendZmqMessage(MSG_RAWRECSIG, &(*ss.begin()), ss.size());
}

View File

@ -24,7 +24,7 @@ public:
* data
* message sequence number
*/
bool SendMessage(const char *command, const void* data, size_t size);
bool SendZmqMessage(const char *command, const void* data, size_t size);
bool Initialize(void *pcontext) override;
void Shutdown() override;

14
src/zmq/zmqutil.cpp Normal file
View File

@ -0,0 +1,14 @@
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <zmq/zmqutil.h>
#include <logging.h>
#include <zmq.h>
void zmqError(const char* str)
{
LogPrint(BCLog::ZMQ, "zmq: Error: %s, errno=%s\n", str, zmq_strerror(errno));
}

10
src/zmq/zmqutil.h Normal file
View File

@ -0,0 +1,10 @@
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_ZMQ_ZMQUTIL_H
#define BITCOIN_ZMQ_ZMQUTIL_H
void zmqError(const char* str);
#endif // BITCOIN_ZMQ_ZMQUTIL_H