From ffb69ab4eb2392f1a323912632894c009e11d3ec Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 20 Jan 2016 11:30:47 -0800 Subject: [PATCH 01/12] Add OpenBSD to build config. --- install.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 610d3393..d13ff4fa 100755 --- a/install.sh +++ b/install.sh @@ -61,11 +61,13 @@ set -e #------------------------------------------------------------------------------ SEQUENTIAL=1 OS=`uname -s` -if [[ $TRAVIS == true ]]; then +if [[ $PARALLEL ]]; then + echo "Using shell-defined PARALLEL value." +elif [[ $TRAVIS == true ]]; then PARALLEL=$SEQUENTIAL elif [[ $OS == Linux ]]; then PARALLEL=`nproc` -elif [[ $OS == Darwin ]]; then +elif [[ ($OS == Darwin) || ($OS == OpenBSD) ]]; then PARALLEL=`sysctl -n hw.ncpu` else echo "Unsupported system: $OS" @@ -81,14 +83,20 @@ if [[ $OS == Darwin ]]; then export CC="clang" export CXX="clang++" LIBC="libc++" - + # Always initialize prefix on OSX so default is useful. PREFIX="/usr/local" +elif [[ $OS == OpenBSD ]]; then + make() { gmake "$@"; } + export CC="egcc" + export CXX="eg++" + LIBC="libestdc++" else LIBC="libstdc++" fi echo "Make with cc: $CC" echo "Make with cxx: $CXX" +echo "Make with stdlib: $LIBC" # Define compiler specific settings. #------------------------------------------------------------------------------ @@ -357,7 +365,7 @@ initialize_boost_icu() initialize_icu_packages() { - if [[ $OS == Darwin && !($BUILD_ICU) ]]; then + if [[ ($OS == Darwin) && !($BUILD_ICU) ]]; then # Update PKG_CONFIG_PATH for ICU package installations on OSX. # OSX provides libicucore.dylib with no pkgconfig and doesn't support # renaming or important features, so we can't use that. From 06867348ba41c2a4cd6ce3de822c39daee3358e3 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 21 Jan 2016 01:09:57 -0800 Subject: [PATCH 02/12] Fix comment typo. --- src/subscribe_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subscribe_manager.cpp b/src/subscribe_manager.cpp index 5b5bd393..c866fb74 100644 --- a/src/subscribe_manager.cpp +++ b/src/subscribe_manager.cpp @@ -237,7 +237,7 @@ void subscribe_manager::post_updates(const payment_address& address, BITCOIN_ASSERT(height <= max_uint32); const auto height32 = static_cast(height); - // [ addr,version ] (1 byte) + // [ addr.version ] (1 byte) // [ addr.hash ] (20 bytes) // [ height ] (4 bytes) // [ block_hash ] (32 bytes) From 9ab125be812776cd490b63151c6d7f737ed79a40 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 22 Jan 2016 00:15:29 -0800 Subject: [PATCH 03/12] Implement subscription limit and expiration config settings. --- src/dispatch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dispatch.cpp b/src/dispatch.cpp index 14fca4a5..d0659516 100644 --- a/src/dispatch.cpp +++ b/src/dispatch.cpp @@ -268,7 +268,8 @@ static console_result run(const settings_type& config, std::ostream& output, } // By the current design this must be kept in scope until end of run. - subscribe_manager subscriber(full_node); + subscribe_manager subscriber(full_node, config.server.subscription_limit, + config.server.subscription_expiration_minutes); request_worker worker; if (config.server.queries_enabled) From 6d189c4af83bf839aeb7f01de8d73f9fa7dbbe53 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 22 Jan 2016 18:56:04 -0800 Subject: [PATCH 04/12] Subscribe to new blocks and new mempool txs. --- include/bitcoin/server/server_node.hpp | 11 +++--- src/server_node.cpp | 55 +++++++++++++++++++------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/include/bitcoin/server/server_node.hpp b/include/bitcoin/server/server_node.hpp index 090d8e78..3fc8472f 100644 --- a/include/bitcoin/server/server_node.hpp +++ b/include/bitcoin/server/server_node.hpp @@ -69,13 +69,12 @@ class BCS_API server_node const incoming_message& request, queue_send_callback queue_send); protected: - // Result of store operation in transaction pool. - virtual void new_unconfirm_valid_tx(const std::error_code& ec, - const index_list& unconfirmed, const transaction_type& tx); + bool handle_tx(const std::error_code& ec, const index_list& unconfirmed, + const transaction_type& tx); - virtual void broadcast_new_blocks(const std::error_code& ec, - uint32_t fork_point, const chain::blockchain::block_list& new_blocks, - const chain::blockchain::block_list& replaced_blocks); + bool handle_reorg(const std::error_code& ec, uint64_t fork_point, + const chain::blockchain::block_list& new_blocks, + const chain::blockchain::block_list&); private: typedef std::vector block_notify_list; diff --git a/src/server_node.cpp b/src/server_node.cpp index f4617778..1a1333a7 100644 --- a/src/server_node.cpp +++ b/src/server_node.cpp @@ -36,6 +36,8 @@ using namespace bc::chain; using namespace bc::node; using std::placeholders::_1; using std::placeholders::_2; +using std::placeholders::_3; +using std::placeholders::_4; const settings_type server_node::defaults { @@ -112,6 +114,16 @@ server_node::server_node(const settings_type& config) bool server_node::start(const settings_type& config) { return full_node::start(config); + + // Subscribe to reorganizations. + blockchain_.subscribe_reorganize( + std::bind(&server_node::handle_reorg, + this, _1, _2, _3, _4)); + + // Subscribe to mempool acceptances. + tx_pool_.subscribe_transaction( + std::bind(&server_node::handle_tx, + this, _1, _2, _3)); } void server_node::subscribe_blocks(block_notify_callback notify_block) @@ -124,38 +136,51 @@ void server_node::subscribe_transactions(transaction_notify_callback notify_tx) tx_subscriptions_.push_back(notify_tx); } -void server_node::new_unconfirm_valid_tx(const std::error_code& ec, +bool server_node::handle_tx(const std::error_code& ec, const index_list& unconfirmed, const transaction_type& tx) { - full_node::new_unconfirm_valid_tx(ec, unconfirmed, tx); - if (ec == bc::error::service_stopped) - return; + return false; + + if (ec) + { + log_error(LOG_SERVICE) + << "Failure handling tx: " << ec.message(); + return false; + } // Fire server protocol tx subscription notifications. for (const auto notify: tx_subscriptions_) notify(tx); + + return true; } -void server_node::broadcast_new_blocks(const std::error_code& ec, - uint32_t fork_point, const blockchain::block_list& new_blocks, - const blockchain::block_list& replaced_blocks) +bool server_node::handle_reorg(const std::error_code& ec, uint64_t fork_point, + const blockchain::block_list& new_blocks, const blockchain::block_list&) { - broadcast_new_blocks(ec, fork_point, new_blocks, replaced_blocks); - if (ec == bc::error::service_stopped) - return; + return false; if (fork_point < minimum_start_height_) - return; + return false; + + if (ec) + { + log_error(LOG_SERVICE) + << "Failure handling reorg: " << ec.message(); + return false; + } + + BITCOIN_ASSERT(fork_point < max_size_t - new_blocks.size()); + auto height = static_cast(fork_point); // Fire server protocol block subscription notifications. for (auto new_block: new_blocks) - { - const size_t height = ++fork_point; for (const auto notify: block_sunscriptions_) - notify(height, *new_block); - } + notify(++height, *new_block); + + return true; } void server_node::fullnode_fetch_history(server_node& node, From 8435c71159ca939fbe8f7126fed37dd7cad72c2d Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 22 Jan 2016 18:56:41 -0800 Subject: [PATCH 05/12] Eliminate redundant address/stealth notification messages. --- include/bitcoin/server/subscribe_manager.hpp | 14 ++- src/subscribe_manager.cpp | 109 +++++++++++-------- 2 files changed, 76 insertions(+), 47 deletions(-) diff --git a/include/bitcoin/server/subscribe_manager.hpp b/include/bitcoin/server/subscribe_manager.hpp index 6df638d0..044f6aff 100644 --- a/include/bitcoin/server/subscribe_manager.hpp +++ b/include/bitcoin/server/subscribe_manager.hpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -74,11 +75,16 @@ class BCS_API subscribe_manager queue_send_callback queue_send); void do_submit(size_t height, const hash_digest& block_hash, const transaction_type& tx); - void post_updates(const payment_address& address, - size_t height, const hash_digest& block_hash, - const transaction_type& tx); - void post_stealth_updates(const binary_type& prefix, size_t height, + + void post(const std::vector& addresses, size_t height, + const hash_digest& block_hash, const transaction_type& tx); + void post(const std::vector& prefixes, size_t height, const hash_digest& block_hash, const transaction_type& tx); + void post(const payment_address& address, size_t height, + const hash_digest& block_hash, const transaction_type& tx); + void post(const binary_type& prefix, size_t height, + const hash_digest& block_hash, const transaction_type& tx); + void sweep_expired(); sequencer strand_; diff --git a/src/subscribe_manager.cpp b/src/subscribe_manager.cpp index c866fb74..d6e827e1 100644 --- a/src/subscribe_manager.cpp +++ b/src/subscribe_manager.cpp @@ -19,7 +19,9 @@ */ #include +#include #include +#include #include #include @@ -40,7 +42,7 @@ static void register_with_node(subscribe_manager& manager, server_node& node) const auto receive_tx = [&manager](const transaction_type& tx) { - constexpr size_t height = 0; + static constexpr size_t height = 0; manager.submit(height, null_hash, tx); }; @@ -194,45 +196,60 @@ void subscribe_manager::submit( this, height, block_hash, tx); } +// TODO: move to collection utility. +template +std::vector& unique(std::vector& items) +{ + std::sort(items.begin(), items.end()); + items.erase(std::unique(items.begin(), items.end()), items.end()); + return items; +} + void subscribe_manager::do_submit(size_t height, const hash_digest& block_hash, const transaction_type& tx) { + payment_address address; + std::vector prefixes; + std::vector addresses; + for (const auto& input: tx.inputs) - { - payment_address address; if (extract(address, input.script)) - { - post_updates(address, height, block_hash, tx); - continue; - } - } + addresses.push_back(address); for (const auto& output: tx.outputs) - { - payment_address address; if (extract(address, output.script)) - { - post_updates(address, height, block_hash, tx); - continue; - } + addresses.push_back(address); + post(unique(addresses), height, block_hash, tx); + + // TODO: augment script::type with test for a corresponding spend output. + for (const auto& output: tx.outputs) if (output.script.type() == payment_type::stealth_info) - { - binary_type prefix = calculate_stealth_prefix(output.script); - post_stealth_updates(prefix, height, block_hash, tx); - continue; - } - } + prefixes.push_back(calculate_stealth_prefix(output.script)); + + post(unique(prefixes), height, block_hash, tx); - // Periodicially sweep old expired entries. - // Use the block 10 minute window as a periodic trigger. - if (height) + // Periodicially sweep old expired entries (10 minute average). + if (height > 0) sweep_expired(); } -void subscribe_manager::post_updates(const payment_address& address, - size_t height, const hash_digest& block_hash, - const transaction_type& tx) +void subscribe_manager::post(const std::vector& addresses, + size_t height, const hash_digest& block_hash, const transaction_type& tx) +{ + for (const auto& address: addresses) + post(addresses, height, block_hash, tx); +} + +void subscribe_manager::post(const std::vector& prefixes, + size_t height, const hash_digest& block_hash, const transaction_type& tx) +{ + for (const auto& prefix: prefixes) + post(prefix, height, block_hash, tx); +} + +void subscribe_manager::post(const payment_address& address, size_t height, + const hash_digest& block_hash, const transaction_type& tx) { BITCOIN_ASSERT(height <= max_uint32); const auto height32 = static_cast(height); @@ -242,40 +259,43 @@ void subscribe_manager::post_updates(const payment_address& address, // [ height ] (4 bytes) // [ block_hash ] (32 bytes) // [ tx ] - constexpr size_t info_size = 1 + short_hash_size + 4 + hash_size; + static constexpr size_t info_size = sizeof(uint8_t) + short_hash_size + + sizeof(uint32_t) + hash_size; + + // TODO: defer this serialization until it's needed. + const auto hash = address.hash(); data_chunk data(info_size + satoshi_raw_size(tx)); auto serial = make_serializer(data.begin()); serial.write_byte(address.version()); - serial.write_short_hash(address.hash()); + serial.write_short_hash(hash); serial.write_4_bytes(height32); serial.write_hash(block_hash); BITCOIN_ASSERT(serial.iterator() == data.begin() + info_size); - - // Now write the tx part. DEBUG_ONLY(auto rawtx_end_it =) satoshi_save(tx, serial.iterator()); BITCOIN_ASSERT(rawtx_end_it == data.end()); // Send the result to everyone interested. for (const auto& subscription: subscriptions_) { - // Only interested in address subscriptions. if (subscription.type != subscribe_type::address) continue; - binary_type match(subscription.prefix.size(), address.hash()); + binary_type match(subscription.prefix.size(), hash); if (match != subscription.prefix) continue; - outgoing_message update(subscription.client_origin, "address.update", - data); + log_info(LOG_SERVICE) + << "Subscribed address: " << address.encoded() << " found in tx [" + << encode_hash(hash_transaction(tx)) << "]"; + const auto& origin = subscription.client_origin; + outgoing_message update(origin, "address.update", data); subscription.queue_send(update); } } -void subscribe_manager::post_stealth_updates(const binary_type& prefix, - size_t height, const hash_digest& block_hash, - const transaction_type& tx) +void subscribe_manager::post(const binary_type& prefix, size_t height, + const hash_digest& block_hash, const transaction_type& tx) { BITCOIN_ASSERT(height <= max_uint32); const auto height32 = static_cast(height); @@ -284,16 +304,16 @@ void subscribe_manager::post_stealth_updates(const binary_type& prefix, // [ height ] (4 bytes) // [ block_hash ] (32 bytes) // [ tx ] - constexpr size_t info_size = - sizeof(uint32_t) + sizeof(uint32_t) + hash_size; + static constexpr size_t info_size = sizeof(uint32_t) + sizeof(uint32_t) + + hash_size; + + // TODO: defer this serialization until it's needed. data_chunk data(info_size + satoshi_raw_size(tx)); auto serial = make_serializer(data.begin()); serial.write_data(prefix.blocks()); serial.write_4_bytes(height32); serial.write_hash(block_hash); BITCOIN_ASSERT(serial.iterator() == data.begin() + info_size); - - // Now write the tx part. DEBUG_ONLY(auto rawtx_end_it =) satoshi_save(tx, serial.iterator()); BITCOIN_ASSERT(rawtx_end_it == data.end()); @@ -307,9 +327,12 @@ void subscribe_manager::post_stealth_updates(const binary_type& prefix, if (match != subscription.prefix) continue; - outgoing_message update(subscription.client_origin, - "address.stealth_update", data); + log_info(LOG_SERVICE) + << "Subscribed stealth prefix found in tx [" + << encode_hash(hash_transaction(tx)) << "]"; + const auto& origin = subscription.client_origin; + outgoing_message update(origin, "address.stealth_update", data); subscription.queue_send(update); } } From 8d978b92673ee25010f4d182f69c78280894241a Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 22 Jan 2016 22:47:54 -0800 Subject: [PATCH 06/12] Implement settings: log_requests, heartbeat_interval_, polling_interval_. --- src/dispatch.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dispatch.cpp b/src/dispatch.cpp index d0659516..23e030b5 100644 --- a/src/dispatch.cpp +++ b/src/dispatch.cpp @@ -271,7 +271,10 @@ static console_result run(const settings_type& config, std::ostream& output, subscribe_manager subscriber(full_node, config.server.subscription_limit, config.server.subscription_expiration_minutes); - request_worker worker; + request_worker worker(config.server.log_requests, + config.server.heartbeat_interval_seconds, + config.server.polling_interval_milliseconds); + if (config.server.queries_enabled) { if (!worker.start(config)) From 1a526b67f0037516210300aa4352a41cdee5d502 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 22 Jan 2016 23:53:05 -0800 Subject: [PATCH 07/12] Parameter rename. --- include/bitcoin/server/subscribe_manager.hpp | 2 +- src/subscribe_manager.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/bitcoin/server/subscribe_manager.hpp b/include/bitcoin/server/subscribe_manager.hpp index 044f6aff..0f247876 100644 --- a/include/bitcoin/server/subscribe_manager.hpp +++ b/include/bitcoin/server/subscribe_manager.hpp @@ -42,7 +42,7 @@ enum class subscribe_type class BCS_API subscribe_manager { public: - subscribe_manager(server_node& node, + subscribe_manager(server_node& server, uint32_t maximum_subscriptions=100000000, uint32_t subscription_expiration_minutes=10); diff --git a/src/subscribe_manager.cpp b/src/subscribe_manager.cpp index d6e827e1..bb5aa81b 100644 --- a/src/subscribe_manager.cpp +++ b/src/subscribe_manager.cpp @@ -31,7 +31,7 @@ namespace server { namespace posix_time = boost::posix_time; using posix_time::second_clock; -static void register_with_node(subscribe_manager& manager, server_node& node) +static void register_with_node(subscribe_manager& manager, server_node& server) { const auto receive_block = [&manager](size_t height, const block_type& block) { @@ -46,18 +46,18 @@ static void register_with_node(subscribe_manager& manager, server_node& node) manager.submit(height, null_hash, tx); }; - node.subscribe_blocks(receive_block); - node.subscribe_transactions(receive_tx); + server.subscribe_blocks(receive_block); + server.subscribe_transactions(receive_tx); } -subscribe_manager::subscribe_manager(server_node& node, +subscribe_manager::subscribe_manager(server_node& server, uint32_t maximum_subscriptions, uint32_t subscription_expiration_minutes) - : strand_(node.pool()), + : strand_(server.pool()), subscription_limit_(maximum_subscriptions), subscription_expiration_minutes_(subscription_expiration_minutes) { // subscribe to blocks and txs -> submit - register_with_node(*this, node); + register_with_node(*this, server); } static subscribe_type convert_subscribe_type(uint8_t type_byte) From e267ced6a2c9eaf04f6e57423dd731ce42a975d2 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 22 Jan 2016 23:53:17 -0800 Subject: [PATCH 08/12] Fix unintended code bypass. --- src/server_node.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server_node.cpp b/src/server_node.cpp index 1a1333a7..ab978493 100644 --- a/src/server_node.cpp +++ b/src/server_node.cpp @@ -113,7 +113,8 @@ server_node::server_node(const settings_type& config) bool server_node::start(const settings_type& config) { - return full_node::start(config); + if (!full_node::start(config)) + return false; // Subscribe to reorganizations. blockchain_.subscribe_reorganize( @@ -124,6 +125,8 @@ bool server_node::start(const settings_type& config) tx_pool_.subscribe_transaction( std::bind(&server_node::handle_tx, this, _1, _2, _3)); + + return true; } void server_node::subscribe_blocks(block_notify_callback notify_block) From 6bd19aff4e8d7e659e8a415bb6289bca1b05ad40 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 23 Jan 2016 00:07:20 -0800 Subject: [PATCH 09/12] Fix typeo that results in an infinite recursion. --- src/subscribe_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subscribe_manager.cpp b/src/subscribe_manager.cpp index bb5aa81b..79573e94 100644 --- a/src/subscribe_manager.cpp +++ b/src/subscribe_manager.cpp @@ -238,7 +238,7 @@ void subscribe_manager::post(const std::vector& addresses, size_t height, const hash_digest& block_hash, const transaction_type& tx) { for (const auto& address: addresses) - post(addresses, height, block_hash, tx); + post(address, height, block_hash, tx); } void subscribe_manager::post(const std::vector& prefixes, From b4b04f1173759e71ad331faa83f6eb0d005a83ff Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 23 Jan 2016 00:17:17 -0800 Subject: [PATCH 10/12] Bypass subscription code if no subscribers. --- src/subscribe_manager.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/subscribe_manager.cpp b/src/subscribe_manager.cpp index 79573e94..48680bbf 100644 --- a/src/subscribe_manager.cpp +++ b/src/subscribe_manager.cpp @@ -144,7 +144,8 @@ void subscribe_manager::renew(const incoming_message& request, queue_send_callback queue_send) { strand_.randomly_queue( - &subscribe_manager::do_renew, this, request, queue_send); + &subscribe_manager::do_renew, + this, request, queue_send); } void subscribe_manager::do_renew(const incoming_message& request, queue_send_callback queue_send) @@ -187,10 +188,12 @@ void subscribe_manager::do_renew(const incoming_message& request, queue_send(response); } -void subscribe_manager::submit( - size_t height, const hash_digest& block_hash, +void subscribe_manager::submit(size_t height, const hash_digest& block_hash, const transaction_type& tx) { + if (subscriptions_.empty()) + return; + strand_.queue( &subscribe_manager::do_submit, this, height, block_hash, tx); @@ -344,15 +347,13 @@ void subscribe_manager::sweep_expired() // Delete entries that have expired. for (auto it = subscriptions_.begin(); it != subscriptions_.end();) { - const auto& subscription = *it; - // Already expired? If so, then erase. - if (subscription.expiry_time < now) + if (it->expiry_time < now) { log_debug(LOG_SUBSCRIBER) - << "Deleting expired subscription: " - << subscription.prefix << " from " - << encode_base16(subscription.client_origin); + << "Deleting expired subscription: " << it->prefix << " from " + << encode_base16(it->client_origin); + it = subscriptions_.erase(it); continue; } From 6c7b550790f40117aff3e379a2a6d29267075116 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 23 Jan 2016 00:38:00 -0800 Subject: [PATCH 11/12] Style. --- src/subscribe_manager.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/subscribe_manager.cpp b/src/subscribe_manager.cpp index 48680bbf..03aa3341 100644 --- a/src/subscribe_manager.cpp +++ b/src/subscribe_manager.cpp @@ -83,10 +83,7 @@ bool deserialize_address(AddressPrefix& address, subscribe_type& type, return false; } - if (deserial.iterator() != data.end()) - return false; - - return true; + return deserial.iterator() == data.end(); } void subscribe_manager::subscribe(const incoming_message& request, From 0d9e8eb7609a4a2c44731a24a1fd8b77fa2a0646 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 23 Jan 2016 02:27:34 -0800 Subject: [PATCH 12/12] Eliminate redundant subscription logging and move it to debug. --- src/subscribe_manager.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/subscribe_manager.cpp b/src/subscribe_manager.cpp index 03aa3341..ef4699bf 100644 --- a/src/subscribe_manager.cpp +++ b/src/subscribe_manager.cpp @@ -273,6 +273,7 @@ void subscribe_manager::post(const payment_address& address, size_t height, BITCOIN_ASSERT(serial.iterator() == data.begin() + info_size); DEBUG_ONLY(auto rawtx_end_it =) satoshi_save(tx, serial.iterator()); BITCOIN_ASSERT(rawtx_end_it == data.end()); + auto matched = false; // Send the result to everyone interested. for (const auto& subscription: subscriptions_) @@ -284,14 +285,16 @@ void subscribe_manager::post(const payment_address& address, size_t height, if (match != subscription.prefix) continue; - log_info(LOG_SERVICE) - << "Subscribed address: " << address.encoded() << " found in tx [" - << encode_hash(hash_transaction(tx)) << "]"; - + matched = true; const auto& origin = subscription.client_origin; outgoing_message update(origin, "address.update", data); subscription.queue_send(update); } + + if (matched) + log_debug(LOG_SERVICE) + << "Subscribed address: " << address.encoded() << " found in tx [" + << encode_hash(hash_transaction(tx)) << "]"; } void subscribe_manager::post(const binary_type& prefix, size_t height, @@ -316,6 +319,7 @@ void subscribe_manager::post(const binary_type& prefix, size_t height, BITCOIN_ASSERT(serial.iterator() == data.begin() + info_size); DEBUG_ONLY(auto rawtx_end_it =) satoshi_save(tx, serial.iterator()); BITCOIN_ASSERT(rawtx_end_it == data.end()); + auto matched = false; // Send the result to everyone interested. for (const auto& subscription: subscriptions_) @@ -327,14 +331,16 @@ void subscribe_manager::post(const binary_type& prefix, size_t height, if (match != subscription.prefix) continue; - log_info(LOG_SERVICE) - << "Subscribed stealth prefix found in tx [" - << encode_hash(hash_transaction(tx)) << "]"; - + matched = true; const auto& origin = subscription.client_origin; outgoing_message update(origin, "address.stealth_update", data); subscription.queue_send(update); } + + if (matched) + log_debug(LOG_SERVICE) + << "Subscribed stealth prefix found in tx [" + << encode_hash(hash_transaction(tx)) << "]"; } void subscribe_manager::sweep_expired()