Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/c2pool/main_dgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ int run_node(const core::CoinParams& params, bool testnet,
// audited rather than silently dropped, and NO malformed block is emitted.
// Assigned at setup (single-threaded, pre-ioc.run) — the only safe point to
// touch tracker() off the compute thread.
// Declared ahead of the m_on_block_found binding so the won-block P2P-relay
// sink below can capture it. Constructed later only when --coin-daemon is
// supplied (stays null otherwise -> sink no-ops, RPC fallback still fires).
std::unique_ptr<dgb::coin::p2p::NodeP2P<dgb::Config>> coin_p2p;

p2p_node.tracker().m_on_block_found = dgb::coin::make_on_block_found(
/*reconstruct=*/[](const uint256& share_hash)
-> std::optional<std::pair<std::vector<unsigned char>, std::string>> {
Expand All @@ -257,7 +262,17 @@ int run_node(const core::CoinParams& params, bool testnet,
"pending Phase B); not broadcast this build" << std::endl;
return std::nullopt;
},
/*p2p_relay=*/dgb::coin::P2pRelaySink{}, // no embedded P2P sink yet (guarded)
/*p2p_relay=*/[&ioc, &coin_p2p](const std::vector<unsigned char>& block_bytes) {
// #82 PRIMARY arm: relay the won block over the embedded coin-daemon
// P2P producer. The sink fires from the compute thread, so post the
// peer write onto the io thread (NodeP2P is single-thread-confined).
// No-op when --coin-daemon is absent (coin_p2p null) — the RPC
// fallback below still fires (dual-path rule).
if (!coin_p2p) return;
io::post(ioc, [&coin_p2p, bytes = block_bytes]() {
if (coin_p2p) coin_p2p->submit_block_p2p_raw(bytes);
});
},
/*seam=*/&coin_node); // external-digibyted submitblock fallback

// ── #82 dual-path won-block CLOSER: miner-facing Stratum standup ───────
Expand Down Expand Up @@ -320,7 +335,6 @@ int run_node(const core::CoinParams& params, bool testnet,
//
// No behavior change when --coin-daemon is absent: coin_p2p stays null, the
// consumer seam idles exactly as before this slice.
std::unique_ptr<dgb::coin::p2p::NodeP2P<dgb::Config>> coin_p2p;
io::steady_timer coin_getheaders_timer(ioc);
if (!coin_daemon.empty()) {
if (coin_magic.empty())
Expand Down
19 changes: 19 additions & 0 deletions src/impl/dgb/coin/p2p_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ class NodeP2P : public core::ICommunicator, public core::INetwork, public core::
}
}

// Broadcast an ALREADY-serialized won block to the connected coin daemon as
// a `block` P2P message. The #82 won-block dispatcher hands raw block bytes
// (the reconstructed blob), so unlike submit_block(BlockType&) this frames
// the pre-serialized payload directly — no decode/re-encode round trip. The
// embedded P2P-relay (PRIMARY) arm of the dual-path broadcaster binds this.
void submit_block_p2p_raw(const std::vector<unsigned char>& raw_block)
{
if (!m_peer)
{
LOG_ERROR << "[" << m_chain_label << "] No coin-daemon connection; "
"cannot relay won block over embedded P2P";
return;
}
auto rmsg = std::make_unique<RawMessage>("block", PackStream(raw_block));
m_peer->write(rmsg);
LOG_INFO << "[" << m_chain_label << "] won-block relayed over embedded P2P ("
<< raw_block.size() << " bytes)";
}

/// Set callback for received addr messages (peer discovery).
void set_addr_callback(AddrCallback cb) { m_addr_callback = std::move(cb); }
/// Set callback for peer's reported chain height (from version message).
Expand Down
Loading