Skip to content

Commit a1444b4

Browse files
authored
dash(s8-p2p.2): Legacy/Actual/NodeBridge sharechain-p2p dispatch layer + 12-handler KATs (#656)
1 parent be49a1b commit a1444b4

5 files changed

Lines changed: 781 additions & 0 deletions

File tree

src/impl/dash/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,25 @@ target_include_directories(dash_rpc PRIVATE
3535
${CMAKE_SOURCE_DIR}/src/btclibs
3636
${CMAKE_SOURCE_DIR}/include)
3737
target_link_libraries(dash_rpc PRIVATE core nlohmann_json::nlohmann_json ${Boost_LIBRARIES})
38+
39+
# S8 sharechain-p2p dispatch layer (slice S8-p2p.2). Mirrors the dgb pool OBJECT
40+
# lib (src/impl/dgb/CMakeLists.txt add_library(dgb OBJECT ...)): compiles the
41+
# Legacy/Actual established-peer protocol handlers so the 12-message dispatch
42+
# surface is a real compiled TU. node.cpp (the NodeImpl reception/think TU) is
43+
# slice .4 and does NOT exist yet, so this OBJECT lib is intentionally NOT linked
44+
# into any executable here -- processing_shares()/handle_get_share() are declared
45+
# in node.hpp and their definitions are link-deferred to slice .4. Object-compile
46+
# only; SAFE-ADDITIVE (no existing target links `dash`, so ltc/btc/doge/dgb build
47+
# + ctest surfaces are untouched). Per-coin isolation held: src/impl/dash only.
48+
add_library(dash OBJECT
49+
node.hpp
50+
peer.hpp
51+
messages.hpp
52+
share.hpp
53+
protocol_actual.cpp protocol_legacy.cpp
54+
)
55+
target_include_directories(dash PRIVATE
56+
${CMAKE_SOURCE_DIR}/src
57+
${CMAKE_SOURCE_DIR}/src/btclibs
58+
${CMAKE_SOURCE_DIR}/include)
59+
target_link_libraries(dash core pool sharechain c2pool_storage dash_x11 btclibs nlohmann_json::nlohmann_json ${Boost_LIBRARIES} ${SECP256K1_LIBRARIES})

src/impl/dash/node.hpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
#include "coin/transaction.hpp"
2626

2727
#include <pool/node.hpp>
28+
#include <pool/protocol.hpp>
2829
#include <core/reply_matcher.hpp>
2930
#include <c2pool/storage/sharechain_storage.hpp>
3031

3132
#include <boost/asio/thread_pool.hpp>
3233
#include <boost/asio/steady_timer.hpp>
3334

3435
#include <atomic>
36+
#include <functional>
3537
#include <map>
3638
#include <memory>
3739
#include <mutex>
@@ -97,6 +99,14 @@ class NodeImpl : public pool::BaseNode<dash::Config, dash::ShareChain, dash::Pee
9799
// daemon. Reception-slice protocol handlers look up tx hashes here.
98100
std::map<uint256, coin::Transaction> m_known_txs;
99101

102+
// Wire-message parser used by the Legacy/Actual dispatch protocols to turn
103+
// a RawMessage into a typed message variant. Mirrors dgb::NodeImpl::m_handler.
104+
dash::Handler m_handler;
105+
106+
// Callback fired when a bestblock message is received from a peer; wired by
107+
// the work layer (slice .4) to trigger a work refresh. Mirrors dgb.
108+
std::function<void(const uint256&)> m_on_bestblock;
109+
100110
// Thread pool for parallel share_init_verify (X11 CPU work). Keeps the
101111
// expensive crypto off the io_context thread.
102112
boost::asio::thread_pool m_verify_pool{4};
@@ -309,6 +319,27 @@ class NodeImpl : public pool::BaseNode<dash::Config, dash::ShareChain, dash::Pee
309319
: pool::PeerConnectionType::legacy;
310320
}
311321

322+
// ── Reception-slice (B) dispatch surface ───────────────────
323+
// Declarations consumed by the Legacy/Actual protocol handlers
324+
// (protocol_legacy.cpp / protocol_actual.cpp). The bodies of
325+
// processing_shares() and handle_get_share() live in the node.cpp
326+
// translation unit (slice .4) and are intentionally link-deferred here;
327+
// the dispatch layer object-compiles against these declarations.
328+
void processing_shares(HandleSharesData& data, NetService addr);
329+
std::vector<dash::ShareType> handle_get_share(std::vector<uint256> hashes,
330+
uint64_t parents, std::vector<uint256> stops, NetService peer_addr);
331+
332+
// Completes a pending async share request when a sharereply arrives.
333+
// Inline (mirrors dgb) so the reply-matcher plumbing needs no node.cpp.
334+
void got_share_reply(uint256 id, dash::ShareReplyData shares)
335+
{
336+
try { m_share_getter.got_response(id, shares); }
337+
catch (const std::invalid_argument&) { /* request already timed out */ }
338+
}
339+
340+
// Register a callback fired when a bestblock message is received from a peer.
341+
void set_on_bestblock(std::function<void(const uint256&)> fn) { m_on_bestblock = std::move(fn); }
342+
312343
// ── Tracker accessors ───────────────────────────────────────────────
313344

314345
/// Direct tracker access — compute-thread-only (already holds the exclusive
@@ -379,4 +410,53 @@ class NodeImpl : public pool::BaseNode<dash::Config, dash::ShareChain, dash::Pee
379410
}
380411
};
381412

413+
// ── Sharechain-p2p dispatch layer (slice S8-p2p.2) ──────────────────
414+
// Namespace-only port of the dgb reference (src/impl/dgb/node.hpp:647). The
415+
// version-handshake reception rides NodeImpl::handle_version above; the two
416+
// established-peer protocols below dispatch the 12 post-handshake messages.
417+
// Both Legacy and Actual register the identical handler set; the divergence
418+
// between them lives in the handler BODIES (protocol_legacy.cpp vs
419+
// protocol_actual.cpp), byte-parity with dgb. handle_message() bodies + the
420+
// 12 HANDLER() bodies are defined in those two .cpp translation units.
421+
422+
class Legacy : public pool::Protocol<NodeImpl>
423+
{
424+
public:
425+
void handle_message(std::unique_ptr<RawMessage> rmsg, NodeImpl::peer_ptr peer) override;
426+
427+
ADD_HANDLER(addrs, dash::message_addrs);
428+
ADD_HANDLER(addrme, dash::message_addrme);
429+
ADD_HANDLER(ping, dash::message_ping);
430+
ADD_HANDLER(getaddrs, dash::message_getaddrs);
431+
ADD_HANDLER(shares, dash::message_shares);
432+
ADD_HANDLER(sharereq, dash::message_sharereq);
433+
ADD_HANDLER(sharereply, dash::message_sharereply);
434+
ADD_HANDLER(bestblock, dash::message_bestblock);
435+
ADD_HANDLER(have_tx, dash::message_have_tx);
436+
ADD_HANDLER(losing_tx, dash::message_losing_tx);
437+
ADD_HANDLER(remember_tx, dash::message_remember_tx);
438+
ADD_HANDLER(forget_tx, dash::message_forget_tx);
439+
};
440+
441+
class Actual : public pool::Protocol<NodeImpl>
442+
{
443+
public:
444+
void handle_message(std::unique_ptr<RawMessage> rmsg, NodeImpl::peer_ptr peer) override;
445+
446+
ADD_HANDLER(addrs, dash::message_addrs);
447+
ADD_HANDLER(addrme, dash::message_addrme);
448+
ADD_HANDLER(ping, dash::message_ping);
449+
ADD_HANDLER(getaddrs, dash::message_getaddrs);
450+
ADD_HANDLER(shares, dash::message_shares);
451+
ADD_HANDLER(sharereq, dash::message_sharereq);
452+
ADD_HANDLER(sharereply, dash::message_sharereply);
453+
ADD_HANDLER(bestblock, dash::message_bestblock);
454+
ADD_HANDLER(have_tx, dash::message_have_tx);
455+
ADD_HANDLER(losing_tx, dash::message_losing_tx);
456+
ADD_HANDLER(remember_tx, dash::message_remember_tx);
457+
ADD_HANDLER(forget_tx, dash::message_forget_tx);
458+
};
459+
460+
using Node = pool::NodeBridge<NodeImpl, Legacy, Actual>;
461+
382462
} // namespace dash

0 commit comments

Comments
 (0)