Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9181 from EOSIO/rabbitmq-trx-dev
Browse files Browse the repository at this point in the history
amqp_trx_plugin - transaction in, transaction_trace out
  • Loading branch information
heifner authored Jun 22, 2020
2 parents 3e876ca + e3c26d3 commit 80e249c
Show file tree
Hide file tree
Showing 30 changed files with 739 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .cicd/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eo pipefail
. ./.cicd/helpers/general.sh
mkdir -p $BUILD_DIR
CMAKE_EXTRAS="-DCMAKE_BUILD_TYPE='Release' -DENABLE_MULTIVERSION_PROTOCOL_TEST=true -DENABLE_UNITY_BUILD=ON"
CMAKE_EXTRAS="-DCMAKE_BUILD_TYPE='Release' -DENABLE_MULTIVERSION_PROTOCOL_TEST=true -DENABLE_UNITY_BUILD=ON -DAMQP_CONN_STR='amqp://guest:guest@localhost:5672'"
if [[ "$(uname)" == 'Darwin' && $FORCE_LINUX != true ]]; then
# You can't use chained commands in execute
if [[ "$GITHUB_ACTIONS" == 'true' ]]; then
Expand Down Expand Up @@ -59,4 +59,4 @@ else # Linux
COMMANDS="$PRE_COMMANDS && $COMMANDS"
echo "$ docker run $ARGS $(buildkite-intrinsics) $FULL_TAG bash -c \"$COMMANDS\""
eval docker run $ARGS $(buildkite-intrinsics) $FULL_TAG bash -c \"$COMMANDS\"
fi
fi
7 changes: 6 additions & 1 deletion .cicd/platforms/pinned/amazon_linux-2-pinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ RUN yum update -y && \
libtool make bzip2 bzip2-devel openssl-devel gmp-devel libstdc++ libcurl-devel \
libusbx-devel python3 python3-devel python-devel libedit-devel doxygen \
graphviz patch gcc gcc-c++ vim-common jq
# install erlang and rabbitmq
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | bash && \
yum install -y erlang
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | bash && \
yum install -y rabbitmq-server
# build cmake
RUN curl -LO https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz && \
tar -xzf cmake-3.16.2.tar.gz && \
Expand Down Expand Up @@ -50,4 +55,4 @@ RUN echo 'export NVM_DIR="$HOME/.nvm"' > ~/.bashrc && \
# install node 10
RUN bash -c '. ~/.bashrc; nvm install --lts=dubnium' && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/node" /usr/local/bin/node && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/npm" /usr/local/bin/npm
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/npm" /usr/local/bin/npm
7 changes: 6 additions & 1 deletion .cicd/platforms/pinned/centos-7.7-pinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ RUN yum update -y && \
graphviz bzip2-devel openssl-devel gmp-devel ocaml \
python python-devel rh-python36 file libusbx-devel \
libcurl-devel patch vim-common jq
# install erlang and rabbitmq
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | bash && \
yum install -y erlang
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | bash && \
yum install -y rabbitmq-server
# build cmake
RUN curl -LO https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz && \
tar -xzf cmake-3.16.2.tar.gz && \
Expand Down Expand Up @@ -57,4 +62,4 @@ RUN cp ~/.bashrc ~/.bashrc.bak && \
# install node 10
RUN bash -c '. ~/.bashrc; nvm install --lts=dubnium' && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/node" /usr/local/bin/node
RUN yum install -y nodejs
RUN yum install -y nodejs
6 changes: 4 additions & 2 deletions .cicd/platforms/pinned/macos-10.14-pinned.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eo pipefail
VERSION=1
brew update
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl@1.1 jq || :
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl@1.1 jq rabbitmq || :
# install clang from source
git clone --single-branch --branch llvmorg-10.0.0 https://github.com/llvm/llvm-project clang10
mkdir clang10/build
Expand All @@ -23,4 +23,6 @@ sudo SDKROOT="$SDKROOT" ./b2 --with-iostreams --with-date_time --with-filesystem
cd ..
sudo rm -rf boost_1_72_0.tar.bz2 boost_1_72_0
# install nvm for ship_test
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
# add sbin to path from rabbitmq-server
echo "export PATH=$PATH:/usr/local/sbin" >> ~/.bash_profile
6 changes: 4 additions & 2 deletions .cicd/platforms/pinned/macos-10.15-pinned.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eo pipefail
VERSION=1
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
brew update
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl jq || :
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl jq rabbitmq || :
# install clang from source
git clone --single-branch --branch llvmorg-10.0.0 https://github.com/llvm/llvm-project clang10
mkdir clang10/build
Expand All @@ -22,4 +22,6 @@ sudo -E ./b2 --with-iostreams --with-date_time --with-filesystem --with-system -
cd ..
sudo rm -rf boost_1_72_0.tar.bz2 boost_1_72_0
# install nvm for ship_test
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
# add sbin to path from rabbitmq-server
echo "export PATH=$PATH:/usr/local/sbin" >> ~/.bash_profile
4 changes: 2 additions & 2 deletions .cicd/platforms/pinned/ubuntu-16.04-pinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git automake \
libbz2-dev libssl-dev doxygen graphviz libgmp3-dev autotools-dev \
python2.7 python2.7-dev python3 python3-dev autoconf libtool curl zlib1g-dev \
sudo ruby libusb-1.0-0-dev libcurl4-gnutls-dev pkg-config apt-transport-https vim-common jq
sudo ruby libusb-1.0-0-dev libcurl4-gnutls-dev pkg-config apt-transport-https vim-common jq rabbitmq-server
# build cmake
RUN curl -LO https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz && \
tar -xzf cmake-3.16.2.tar.gz && \
Expand Down Expand Up @@ -53,4 +53,4 @@ RUN cp ~/.bashrc ~/.bashrc.bak && \
RUN bash -c '. ~/.bashrc; nvm install --lts=dubnium' && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/node" /usr/local/bin/node
RUN curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
RUN sudo apt-get install -y nodejs
RUN sudo apt-get install -y nodejs
4 changes: 2 additions & 2 deletions .cicd/platforms/pinned/ubuntu-18.04-pinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN apt-get update && \
autotools-dev python2.7 python2.7-dev python3 \
python3-dev python-configparser python-requests python-pip \
autoconf libtool g++ gcc curl zlib1g-dev sudo ruby libusb-1.0-0-dev \
libcurl4-gnutls-dev pkg-config patch vim-common jq
libcurl4-gnutls-dev pkg-config patch vim-common jq rabbitmq-server
# build cmake
RUN curl -LO https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz && \
tar -xzf cmake-3.16.2.tar.gz && \
Expand Down Expand Up @@ -55,4 +55,4 @@ RUN cp ~/.bashrc ~/.bashrc.bak && \
RUN bash -c '. ~/.bashrc; nvm install --lts=dubnium' && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/node" /usr/local/bin/node
RUN curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
RUN sudo apt-get install -y nodejs
RUN sudo apt-get install -y nodejs
7 changes: 6 additions & 1 deletion .cicd/platforms/unpinned/amazon_linux-2-unpinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ RUN yum update -y && \
libtool make bzip2 bzip2-devel openssl-devel gmp-devel libstdc++ libcurl-devel \
libusbx-devel python3 python3-devel python-devel libedit-devel doxygen \
graphviz clang patch llvm-devel llvm-static vim-common jq
# install erlang and rabbitmq
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | bash && \
yum install -y erlang
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | bash && \
yum install -y rabbitmq-server
# build cmake
RUN curl -LO https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz && \
tar -xzf cmake-3.16.2.tar.gz && \
Expand All @@ -30,4 +35,4 @@ RUN echo 'export NVM_DIR="$HOME/.nvm"' > ~/.bashrc && \
# install node 10
RUN bash -c '. ~/.bashrc; nvm install --lts=dubnium' && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/node" /usr/local/bin/node && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/npm" /usr/local/bin/npm
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/npm" /usr/local/bin/npm
7 changes: 6 additions & 1 deletion .cicd/platforms/unpinned/centos-7.7-unpinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ RUN yum update -y && \
graphviz bzip2-devel openssl-devel gmp-devel ocaml \
python python-devel rh-python36 file libusbx-devel \
libcurl-devel patch vim-common jq llvm-toolset-7.0-llvm-devel llvm-toolset-7.0-llvm-static
# install erlang and rabbitmq
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | bash && \
yum install -y erlang
RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | bash && \
yum install -y rabbitmq-server
# build cmake
RUN curl -LO https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz && \
tar -xzf cmake-3.16.2.tar.gz && \
Expand Down Expand Up @@ -38,4 +43,4 @@ RUN cp ~/.bashrc ~/.bashrc.bak && \
# install node 10
RUN bash -c '. ~/.bashrc; nvm install --lts=dubnium' && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/node" /usr/local/bin/node
RUN yum install -y nodejs
RUN yum install -y nodejs
6 changes: 4 additions & 2 deletions .cicd/platforms/unpinned/macos-10.14-unpinned.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
set -eo pipefail
VERSION=1
brew update
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl@1.1 jq boost || :
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl@1.1 jq boost rabbitmq || :
# install nvm for ship_test
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
# add sbin to path from rabbitmq-server
echo "export PATH=$PATH:/usr/local/sbin" >> ~/.bash_profile
6 changes: 4 additions & 2 deletions .cicd/platforms/unpinned/macos-10.15-unpinned.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set -eo pipefail
VERSION=1
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
brew update
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl jq boost || :
brew install git cmake python libtool libusb graphviz automake wget gmp pkgconfig doxygen openssl jq boost rabbitmq || :
# install nvm for ship_test
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
cd ~ && brew install nvm && mkdir -p ~/.nvm && echo "export NVM_DIR=$HOME/.nvm" >> ~/.bash_profile && echo 'source $(brew --prefix nvm)/nvm.sh' >> ~/.bash_profile && cat ~/.bash_profile && source ~/.bash_profile && echo $NVM_DIR && nvm install --lts=dubnium
# add sbin to path from rabbitmq-server
echo "export PATH=$PATH:/usr/local/sbin" >> ~/.bash_profile
4 changes: 2 additions & 2 deletions .cicd/platforms/unpinned/ubuntu-18.04-unpinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apt-get update && \
bzip2 automake libbz2-dev libssl-dev doxygen graphviz libgmp3-dev \
autotools-dev python2.7 python2.7-dev python3 python3-dev \
autoconf libtool curl zlib1g-dev sudo ruby libusb-1.0-0-dev \
libcurl4-gnutls-dev pkg-config patch llvm-7-dev clang-7 vim-common jq
libcurl4-gnutls-dev pkg-config patch llvm-7-dev clang-7 vim-common jq rabbitmq-server
# build cmake
RUN curl -LO https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz && \
tar -xzf cmake-3.16.2.tar.gz && \
Expand Down Expand Up @@ -35,4 +35,4 @@ RUN cp ~/.bashrc ~/.bashrc.bak && \
RUN bash -c '. ~/.bashrc; nvm install --lts=dubnium' && \
ln -s "/root/.nvm/versions/node/$(ls -p /root/.nvm/versions/node | sort -Vr | head -1)bin/node" /usr/local/bin/node
RUN curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
RUN sudo apt-get install -y nodejs
RUN sudo apt-get install -y nodejs
6 changes: 3 additions & 3 deletions .cicd/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ set -eo pipefail
# tests
if [[ $(uname) == 'Darwin' ]]; then # macOS
set +e # defer error handling to end
source ~/.bash_profile && ./"$@"
source ~/.bash_profile && rabbitmq-server -detached && sleep 10 && ./"$@"
EXIT_STATUS=$?
else # Linux
COMMANDS="$MOUNTED_DIR/$@"
COMMANDS="rabbitmq-server -detached && sleep 10 && $MOUNTED_DIR/$@"
. $HELPERS_DIR/file-hash.sh $CICD_DIR/platforms/$PLATFORM_TYPE/$IMAGE_TAG.dockerfile
echo "$ docker run --rm --init -v $(pwd):$MOUNTED_DIR $(buildkite-intrinsics) -e JOBS -e BUILDKITE_API_KEY $FULL_TAG bash -c \"$COMMANDS\""
set +e # defer error handling to end
Expand Down Expand Up @@ -45,4 +45,4 @@ fi
if [[ "$EXIT_STATUS" != 0 ]]; then
echo "Failing due to non-zero exit status from ctest: $EXIT_STATUS"
exit $EXIT_STATUS
fi
fi
2 changes: 2 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ add_subdirectory(db_size_api_plugin)
add_subdirectory(login_plugin)
add_subdirectory(test_control_plugin)
add_subdirectory(test_control_api_plugin)
add_subdirectory(amqp_trx_plugin)
add_subdirectory(amqp_trace_plugin)
add_subdirectory(amqp_witness_plugin)
add_subdirectory(amqp_compressed_proof_plugin)

Expand Down
7 changes: 7 additions & 0 deletions plugins/amqp_trace_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
file(GLOB HEADERS "include/eosio/amqp_trace_plugin/*.hpp")
add_library( amqp_trace_plugin
amqp_trace_plugin.cpp
${HEADERS} )

target_link_libraries( amqp_trace_plugin chain_plugin appbase fc amqpcpp )
target_include_directories( amqp_trace_plugin PUBLIC include )
151 changes: 151 additions & 0 deletions plugins/amqp_trace_plugin/amqp_trace_plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include <eosio/amqp_trace_plugin/amqp_trace_plugin.hpp>
#include <eosio/amqp_trace_plugin/amqp_handler.hpp>
#include <eosio/chain_plugin/chain_plugin.hpp>

#include <eosio/chain/exceptions.hpp>
#include <eosio/chain/transaction.hpp>
#include <eosio/chain/thread_utils.hpp>

#include <boost/signals2/connection.hpp>

namespace {

static appbase::abstract_plugin& amqp_trace_plugin_ = appbase::app().register_plugin<eosio::amqp_trace_plugin>();

} // anonymous

namespace eosio {

using boost::signals2::scoped_connection;

struct amqp_trace_plugin_impl : std::enable_shared_from_this<amqp_trace_plugin_impl> {

std::optional<amqp> amqp_trace;
std::optional<scoped_connection> applied_transaction_connection;

std::string amqp_trace_address;
std::string amqp_trace_exchange;
bool started = false;

public:

// called from any thread
void publish_error( std::string tid, int64_t error_code, std::string error_message ) {
try {
transaction_trace_msg msg{transaction_trace_exception{error_code}};
msg.get<transaction_trace_exception>().error_message = std::move( error_message );
auto buf = fc::raw::pack( msg );
amqp_trace->publish( amqp_trace_exchange, tid, std::move( buf ) );
} FC_LOG_AND_DROP()
}

// called on application thread
void on_applied_transaction(const chain::transaction_trace_ptr& trace, const chain::packed_transaction_ptr& t) {
try {
publish_result( t, trace );
} FC_LOG_AND_DROP()
}

private:

// called from application thread
void publish_result( const chain::packed_transaction_ptr& trx, const chain::transaction_trace_ptr& trace ) {
try {
if( !trace->except ) {
dlog( "chain accepted transaction, bcast ${id}", ("id", trace->id) );
} else {
dlog( "trace except : ${m}", ("m", trace->except->to_string()) );
}
amqp_trace->publish( amqp_trace_exchange, trx->id(), [trace]() {
fc::unsigned_int which = transaction_trace_msg::tag<chain::transaction_trace>::value;
uint32_t payload_size = fc::raw::pack_size( which );
payload_size += fc::raw::pack_size( *trace );
std::vector<char> buf( payload_size );
fc::datastream<char*> ds( buf.data(), payload_size );
fc::raw::pack( ds, which );
fc::raw::pack( ds, *trace );
return buf;
});
} FC_LOG_AND_DROP()
}

};

amqp_trace_plugin::amqp_trace_plugin()
: my(std::make_shared<amqp_trace_plugin_impl>()) {}

amqp_trace_plugin::~amqp_trace_plugin() {}

void amqp_trace_plugin::publish_error( std::string tid, int64_t error_code, std::string error_message ) {
my->publish_error( std::move(tid), error_code, std::move(error_message) );
}

void amqp_trace_plugin::set_program_options(options_description& cli, options_description& cfg) {
auto op = cfg.add_options();
op("amqp-trace-address", bpo::value<std::string>(),
"AMQP address: Format: amqp://USER:PASSWORD@ADDRESS:PORT\n"
"Will publish to 'trace' queue.");
op("amqp-trace-exchange", bpo::value<std::string>()->default_value(""),
"Existing AMQP exchange to send transaction trace messages.");
}

void amqp_trace_plugin::plugin_initialize(const variables_map& options) {
try {
EOS_ASSERT( options.count("amqp-trace-address"), chain::plugin_config_exception, "amqp-trace-address required" );
my->amqp_trace_address = options.at("amqp-trace-address").as<std::string>();
my->amqp_trace_exchange = options.at("amqp-trace-exchange").as<std::string>();
}
FC_LOG_AND_RETHROW()
}

void amqp_trace_plugin::plugin_startup() {
if( !my->started ) {
handle_sighup();
try {
ilog( "Starting amqp_trace_plugin" );
my->started = true;

my->amqp_trace.emplace( my->amqp_trace_address, "trace",
[]( const std::string& err ) {
elog( "amqp error: ${e}", ("e", err) );
app().quit();
} );

auto chain_plug = app().find_plugin<chain_plugin>();
EOS_ASSERT( chain_plug, chain::missing_chain_plugin_exception, "chain_plugin required" );

my->applied_transaction_connection.emplace(
chain_plug->chain().applied_transaction.connect(
[me = my]( std::tuple<const chain::transaction_trace_ptr&, const chain::packed_transaction_ptr&> t ) {
me->on_applied_transaction( std::get<0>( t ), std::get<1>( t ) );
} ) );

} catch( ... ) {
// always want plugin_shutdown even on exception
plugin_shutdown();
throw;
}
}
}

void amqp_trace_plugin::plugin_shutdown() {
if( my->started ) {
try {
dlog( "shutdown.." );

my->applied_transaction_connection.reset();
if( my->amqp_trace ) {
my->amqp_trace->stop();
}

dlog( "exit amqp_trace_plugin" );
}
FC_CAPTURE_AND_RETHROW()
my->started = false;
}
}

void amqp_trace_plugin::handle_sighup() {
}

} // namespace eosio
Loading

0 comments on commit 80e249c

Please sign in to comment.