From 64424b9979db12c74ae2226f901e2763d0d2a9a5 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 26 Jan 2026 21:04:53 -0500 Subject: [PATCH 1/4] Replace invalid use of std::function<...>{} with noop handler. --- .../bitcoin/network/channels/channel_rpc.hpp | 10 +------- .../network/impl/channels/channel_rpc.ipp | 18 -------------- .../network/impl/protocols/protocol_rpc.ipp | 24 +++++++++++++++++++ .../network/protocols/protocol_rpc.hpp | 17 +++++++++---- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/include/bitcoin/network/channels/channel_rpc.hpp b/include/bitcoin/network/channels/channel_rpc.hpp index 7ae4af9a0..246b12dd5 100644 --- a/include/bitcoin/network/channels/channel_rpc.hpp +++ b/include/bitcoin/network/channels/channel_rpc.hpp @@ -58,12 +58,7 @@ class channel_rpc { } - /// Senders, rpc version and identity added to responses (requires strand). - inline void send_code(const code& ec) NOEXCEPT; - inline void send_error(rpc::result_t&& error) NOEXCEPT; - inline void send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT; - - /// Senders with completion handlers (requires strand). + /// Senders (requires strand). inline void send_code(const code& ec, result_handler&& handler) NOEXCEPT; inline void send_error(rpc::result_t&& error, result_handler&& handler) NOEXCEPT; @@ -104,9 +99,6 @@ class channel_rpc const rpc::response_cptr& response, const result_handler& handler) NOEXCEPT; - /// Default noop completion handler. - virtual inline void complete(const code&) NOEXCEPT {}; - private: // These are protected by strand. rpc::version version_; diff --git a/include/bitcoin/network/impl/channels/channel_rpc.ipp b/include/bitcoin/network/impl/channels/channel_rpc.ipp index ada016289..d1c9af514 100644 --- a/include/bitcoin/network/impl/channels/channel_rpc.ipp +++ b/include/bitcoin/network/impl/channels/channel_rpc.ipp @@ -132,24 +132,6 @@ inline http::flat_buffer& CLASS::request_buffer() NOEXCEPT // Send. // ---------------------------------------------------------------------------- -TEMPLATE -void CLASS::send_code(const code& ec) NOEXCEPT -{ - send_code(ec, std::bind(&CLASS::complete, _1)); -} - -TEMPLATE -void CLASS::send_error(rpc::result_t&& error) NOEXCEPT -{ - send_error(std::move(error), std::bind(&CLASS::complete, _1)); -} - -TEMPLATE -void CLASS::send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT -{ - send_result(std::move(result), size_hint, std::bind(&CLASS::complete, _1)); -} - TEMPLATE void CLASS::send_code(const code& ec, result_handler&& handler) NOEXCEPT { diff --git a/include/bitcoin/network/impl/protocols/protocol_rpc.ipp b/include/bitcoin/network/impl/protocols/protocol_rpc.ipp index e01750f33..05a028987 100644 --- a/include/bitcoin/network/impl/protocols/protocol_rpc.ipp +++ b/include/bitcoin/network/impl/protocols/protocol_rpc.ipp @@ -25,6 +25,30 @@ namespace libbitcoin { namespace network { +TEMPLATE +inline void CLASS::send_code(const code& ec) NOEXCEPT +{ + using namespace std::placeholders; + send_code(ec,std::bind(&CLASS::complete, + shared_from_base(), _1)); +} + +TEMPLATE +inline void CLASS::send_error(rpc::result_t&& error) NOEXCEPT +{ + using namespace std::placeholders; + send_error(std::move(error), std::bind(&CLASS::complete, + shared_from_base(), _1)); +} + +TEMPLATE +inline void CLASS::send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT +{ + using namespace std::placeholders; + send_result(std::move(result), size_hint, std::bind(&CLASS::complete, + shared_from_base(), _1)); +} + TEMPLATE inline void CLASS::send_code(const code& ec, result_handler&& handler) NOEXCEPT { diff --git a/include/bitcoin/network/protocols/protocol_rpc.hpp b/include/bitcoin/network/protocols/protocol_rpc.hpp index e820a2d7d..a3e007310 100644 --- a/include/bitcoin/network/protocols/protocol_rpc.hpp +++ b/include/bitcoin/network/protocols/protocol_rpc.hpp @@ -48,13 +48,22 @@ class protocol_rpc DECLARE_SUBSCRIBE_CHANNEL() - /// Senders (requires strand). + /// Senders with default completion (requires strand). + virtual inline void send_code(const code& ec) NOEXCEPT; + virtual inline void send_error(rpc::result_t&& error) NOEXCEPT; + virtual inline void send_result(rpc::value_t&& result, + size_t size_hint) NOEXCEPT; + + /// Senders, rpc version and identity added to responses (requires strand). virtual inline void send_code(const code& ec, - result_handler&& handler={}) NOEXCEPT; + result_handler&& handler) NOEXCEPT; virtual inline void send_error(rpc::result_t&& error, - result_handler&& handler={}) NOEXCEPT; + result_handler&& handler) NOEXCEPT; virtual inline void send_result(rpc::value_t&& result, size_t size_hint, - result_handler&& handler={}) NOEXCEPT; + result_handler&& handler) NOEXCEPT; + + /// Default noop completion handler. + virtual inline void complete(const code&) NOEXCEPT {}; private: // This is mostly thread safe, and used in a thread safe manner. From 66bb07268aa90a7d4d4b12ecdcfad456f5cf259a Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 26 Jan 2026 21:05:07 -0500 Subject: [PATCH 2/4] Rationalize peer session enabled() and logging, comments. --- src/sessions/session_manual.cpp | 7 +++++++ src/sessions/session_outbound.cpp | 2 +- src/settings.cpp | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sessions/session_manual.cpp b/src/sessions/session_manual.cpp index 778edaf94..3662b98b5 100644 --- a/src/sessions/session_manual.cpp +++ b/src/sessions/session_manual.cpp @@ -53,6 +53,13 @@ session_manual::session_manual(net& network, uint64_t identifier) NOEXCEPT void session_manual::start(result_handler&& handler) NOEXCEPT { BC_ASSERT(stranded()); + + // This applies only to "configured" manual connections (can be added). + if (!network_settings().manual.enabled()) + { + LOGN("Not configured for manual peer connections."); + } + session_peer::start(BIND(handle_started, _1, std::move(handler))); } diff --git a/src/sessions/session_outbound.cpp b/src/sessions/session_outbound.cpp index f912efe69..142cc6627 100644 --- a/src/sessions/session_outbound.cpp +++ b/src/sessions/session_outbound.cpp @@ -56,7 +56,7 @@ void session_outbound::start(result_handler&& handler) NOEXCEPT if (!network_settings().outbound.enabled()) { - LOGN("Not configured for outbound connections."); + LOGN("Not configured for outbound peer connections."); handler(error::success); unsubscribe_close(); return; diff --git a/src/settings.cpp b/src/settings.cpp index 8ae59f33b..5edca2886 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -210,7 +210,9 @@ bool settings::peer_manual::peered(const address_item& item) const NOEXCEPT bool settings::peer_manual::enabled() const NOEXCEPT { - return settings::tcp_server::enabled() && !peers.empty(); + // connections field is not currently used, and this applies only to + // initial configuration of manual connections, as they can be added. + return /* settings::tcp_server::enabled() && */ !peers.empty(); } // [network] From 12e3d70c905eb4c33f6c7bce1acc5ef871dd557f Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 26 Jan 2026 21:13:09 -0500 Subject: [PATCH 3/4] Fix message text for error::missing_parameter. --- src/error.cpp | 2 +- test/error.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.cpp b/src/error.cpp index 5bd1118b2..4380395bc 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -281,7 +281,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) { extra_named, "extra named" }, { missing_array, "missing array" }, { missing_object, "missing object" }, - { missing_parameter, "missing optional" } + { missing_parameter, "missing parameter" } }; DEFINE_ERROR_T_CATEGORY(error, "network", "network code") diff --git a/test/error.cpp b/test/error.cpp index 7b33aefcc..16283039a 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -2034,7 +2034,7 @@ BOOST_AUTO_TEST_CASE(error_t__code__missing_parameter__true_expected_message) const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "missing optional"); + BOOST_REQUIRE_EQUAL(ec.message(), "missing parameter"); } BOOST_AUTO_TEST_SUITE_END() From 6c8be51405c384db87f9792d04dbbc83fe202556 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 26 Jan 2026 21:26:33 -0500 Subject: [PATCH 4/4] Make base level rpc request/response logging more detailed. --- include/bitcoin/network/impl/channels/channel_rpc.ipp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/bitcoin/network/impl/channels/channel_rpc.ipp b/include/bitcoin/network/impl/channels/channel_rpc.ipp index d1c9af514..255f77ee0 100644 --- a/include/bitcoin/network/impl/channels/channel_rpc.ipp +++ b/include/bitcoin/network/impl/channels/channel_rpc.ipp @@ -107,7 +107,7 @@ inline void CLASS::handle_receive(const code& ec, size_t bytes, identity_ = request->message.id; version_ = request->message.jsonrpc; - LOGA("Rpc request: [" << bytes << "] " + LOGA("Rpc request: (" << bytes << ") bytes from [" << endpoint() << "] " << request->message.method << "(...)."); reading_ = false; @@ -187,8 +187,8 @@ inline void CLASS::handle_send(const code& ec, size_t bytes, // Typically a noop, but handshake may pause channel here. handler(ec); - LOGA("Rpc response: [" << bytes << "], " << - response->message.error.value_or(rpc::result_t{}).message); + LOGA("Rpc response: (" << bytes << ") bytes to [" << endpoint() << "] " + << response->message.error.value_or(rpc::result_t{}).message); // Continue read loop (does not unpause or restart channel). receive();