Skip to content

Commit 103594e

Browse files
authored
Merge pull request #79 from frstrtr/ltc-doge/p2-clusterA-ltc-coinnode
ltc: concrete core::coin::ICoinNode (CoinNode) for P2 WorkView seam [PR-A/3]
2 parents de552dd + ad05cc0 commit 103594e

4 files changed

Lines changed: 147 additions & 0 deletions

File tree

src/impl/bitcoin_family/coin/base_p2p_messages.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
#include <core/message.hpp>
2020
#include <core/message_macro.hpp>
2121

22+
// READWRITE collision guard.
23+
// The C2POOL_SERIALIZE_METHODS bodies below rely on core/pack.hpp's READWRITE
24+
// contract (formatter.action(stream, ...)). btclibs/serialize.h, pulled
25+
// transitively into some translation units, re-#defines READWRITE to the legacy
26+
// (s, ser_action) contract and can win by include order, breaking every body here
27+
// ("use of undeclared identifier 's' / 'ser_action'" on macOS arm64 / Linux).
28+
// Re-assert the core contract so this header is include-order-independent; mirrors
29+
// btc/coin/p2p_messages.hpp, whose include chain keeps the core macro active.
30+
#ifdef READWRITE
31+
# undef READWRITE
32+
#endif
33+
#define READWRITE(...) formatter.action(stream, __VA_ARGS__)
34+
2235
namespace bitcoin_family
2336
{
2437
namespace coin

src/impl/ltc/coin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(ltc_coin_impl
66
p2p_node.cpp p2p_node.hpp
77
p2p_messages.hpp
88
node.hpp
9+
coin_node.hpp coin_node.cpp
910
)
1011

1112
set(ltc_coin_interface

src/impl/ltc/coin/coin_node.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "coin_node.hpp"
2+
3+
#include <stdexcept>
4+
#include <utility>
5+
6+
namespace ltc
7+
{
8+
9+
namespace coin
10+
{
11+
12+
core::coin::WorkView CoinNode::get_work_view()
13+
{
14+
// No work source configured at all -> empty view.
15+
if (!m_embedded && !m_rpc)
16+
return {};
17+
18+
// Embedded preferred, external RPC fallback. getwork() throws
19+
// std::runtime_error when no template can be produced -- propagated to the
20+
// caller (web_server), matching the ICoinNode contract. Folds the old
21+
// web_server.cpp:2167-2168 embedded-vs-rpc decision coin-side.
22+
rpc::WorkData wd = m_embedded ? m_embedded->getwork() : m_rpc->getwork();
23+
24+
// Retain the FULL WorkData (incl. m_txs) coin-side. Variable::set takes its
25+
// argument BY VALUE, so this copies wd; sequenced BEFORE the std::move()s
26+
// below so the copy completes first -- never move out of wd beforehand.
27+
// (Pre-seam this was web_server.cpp:2171-2172 m_coin_node->work.set(wd),
28+
// which only ran in rpc mode; keeping it unconditional here is strictly
29+
// safe -- the agnostic slice still leaves, the payload still stays.)
30+
work.set(wd);
31+
32+
core::coin::WorkView v;
33+
v.m_data = std::move(wd.m_data);
34+
v.m_hashes = std::move(wd.m_hashes);
35+
v.m_latency = wd.m_latency;
36+
return v;
37+
}
38+
39+
bool CoinNode::submit_block_hex(const std::string& block_hex, bool ignore_failure)
40+
{
41+
// Guard sits ahead of the submit: in embedded-only mode m_rpc can be null.
42+
// Returning false is the correct "no RPC sink" result (mirrors the old
43+
// web_server.cpp:2728 `if (m_coin_rpc)` guard).
44+
if (!m_rpc)
45+
return false;
46+
47+
// MWEB arity bridge: ltc NodeRPC::submit_block_hex is the 3-arg
48+
// (block_hex, mweb, ignore_failure) form. The ICoinNode contract is the
49+
// 2-arg coin-agnostic form, so we supply mweb="" here. The sole pre-seam
50+
// caller (web_server.cpp:2730) already passed "" for mweb, so this is
51+
// behaviour-preserving. FLAG (per integrator, for review): when MWEB
52+
// submit grows a non-empty extension-block path, mweb must NOT be hard-""
53+
// -- it would need a coin-side source (e.g. the retained WorkData) rather
54+
// than a new arg on the shared seam, since mweb is LTC-specific.
55+
return m_rpc->submit_block_hex(block_hex, "", ignore_failure);
56+
}
57+
58+
} // namespace coin
59+
60+
} // namespace ltc

src/impl/ltc/coin/coin_node.hpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#pragma once
2+
3+
// ---------------------------------------------------------------------------
4+
// ltc::coin::CoinNode -- concrete core::coin::ICoinNode for LTC (family-1 P2
5+
// WorkView seam). This is the REFERENCE impl the btc::coin::CoinNode mirrors
6+
// (piece-5(c)); the control flow / sequencing here are the load-bearing part.
7+
//
8+
// m_embedded : CoinNodeInterface* -- EmbeddedCoinNode in-process source
9+
// m_rpc : NodeRPC* -- external coin-RPC client
10+
// work : Variable<rpc::WorkData> -- full per-coin WorkData kept coin-side
11+
//
12+
// web_server (shared core) historically held raw pointers to CONCRETE ltc types
13+
// (ltc::coin::NodeRPC, ltc::interfaces::Node) and called getwork()/submit on
14+
// them directly -- that names ltc:: symbols in web_server.cpp.o and breaks the
15+
// BTC link. This type collapses the embedded-vs-rpc decision plus the full
16+
// WorkData retention coin-side, and exposes only the coin-agnostic
17+
// core::coin::ICoinNode contract across the seam (WorkView, 2-arg submit).
18+
//
19+
// MWEB arity: ltc::coin::NodeRPC::submit_block_hex is the 3-arg
20+
// (block_hex, mweb, ignore_failure) LTC form. The ICoinNode override is the
21+
// coin-agnostic 2-arg form; it forwards to the 3-arg rpc with mweb="" coin-side.
22+
// The sole pre-seam caller (web_server.cpp:2730) already passed mweb="", so
23+
// dropping the mweb slot across the seam is behaviour-preserving for MWEB
24+
// submit. (See coin_node.cpp for the forward + the standing flag.)
25+
// ---------------------------------------------------------------------------
26+
27+
#include <string>
28+
29+
#include <core/coin/node_iface.hpp>
30+
#include <core/coin/work_view.hpp>
31+
#include <core/events.hpp>
32+
33+
#include "rpc.hpp"
34+
#include "rpc_data.hpp"
35+
#include "template_builder.hpp"
36+
37+
namespace ltc
38+
{
39+
40+
namespace coin
41+
{
42+
43+
class CoinNode : public core::coin::ICoinNode
44+
{
45+
// Embedded in-process template source (EmbeddedCoinNode, via the
46+
// CoinNodeInterface base). May be null when the node runs RPC-only.
47+
// is_embedded() reports its presence.
48+
CoinNodeInterface* m_embedded = nullptr;
49+
50+
// External coin-RPC client. May be null in embedded-only mode; it is the
51+
// sole sink for submit_block_hex(). has_rpc() reports its presence.
52+
NodeRPC* m_rpc = nullptr;
53+
54+
// Full per-coin WorkData (incl. vector<Transaction> m_txs) retained
55+
// coin-side via work.set(wd); only the agnostic WorkView slice crosses the
56+
// seam into core/web_server. Replaces the old ltc::interfaces::Node::work
57+
// slot that web_server used to reach through m_coin_node.
58+
Variable<rpc::WorkData> work;
59+
60+
public:
61+
CoinNode(CoinNodeInterface* embedded, NodeRPC* rpc)
62+
: m_embedded(embedded), m_rpc(rpc) {}
63+
64+
core::coin::WorkView get_work_view() override;
65+
bool submit_block_hex(const std::string& block_hex, bool ignore_failure) override;
66+
67+
bool is_embedded() const override { return m_embedded != nullptr; }
68+
bool has_rpc() const override { return m_rpc != nullptr; }
69+
};
70+
71+
} // namespace coin
72+
73+
} // namespace ltc

0 commit comments

Comments
 (0)