Skip to content

Commit b464ce0

Browse files
committed
dgb(#82): construct dgb::Node sharechain peer + bind P2P listener (--run)
Second stacked run-loop slice. main_dgb.cpp --run now constructs the real dgb::Config + dgb::Node (pool::NodeBridge<NodeImpl, Legacy, Actual>) on the spine io_context, opens the sharechain LevelDB, and binds the P2P listener on PoolConfig::P2P_PORT (5024) — the sharechain peer is live, not just the io_context spine. Config is set directly from the p2pool-dgb-scrypt oracle constants (PREFIX 1c0553f2..., IDENTIFIER 4b62545b...), skipping Config::init() yaml load, the same contract main_btc.cpp uses. DEFAULT_BOOTSTRAP_HOSTS is empty until DGB p2pool nodes come online, so there are no outbound seeds to dial this slice; the node listens and waits for inbound peers. The per-coin net dir is digibyte/ (bucket-1 isolation). Constructing the node pulls BaseNode::connected (boost::log) and the NodeImpl TU, so the c2pool-dgb exe must link the real dgb pool runtime, not just the header-only score path. Wire the exe to link the dgb OBJECT lib + dgb_coin + core/pool/sharechain/storage base, mirroring the c2pool-btc link set; c2pool_merged_mining is pulled for symbol resolution of the core web_server tangle only (same as c2pool-btc) and does NOT enable -DAUX_DOGE — DGB default build stays standalone. Only the c2pool-dgb target stanza changes; per-coin isolation holds. Build EXIT=0. Smoke: --run binds 0.0.0.0:5024 (ss-confirmed), SIGINT -> graceful shutdown -> clean exit 0, LevelDB closed cleanly; --selftest still drives the live score() path; --version OK. SEAM (next slice): stand up the Stratum work source + bind make_on_block_found(reconstruct_won_block, p2p_sink) into m_on_block_found to close the #82 embedded P2P relay path (submitblock RPC fallback at rpc.cpp:387 is already real, not a stub).
1 parent c74351a commit b464ce0

2 files changed

Lines changed: 86 additions & 22 deletions

File tree

src/c2pool/CMakeLists.txt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,31 @@ target_link_libraries(c2pool-btc
183183
# json/Boost. Per-coin isolation held. The embedded run-loop (NodeBridge over
184184
# digibyted P2P + Stratum) and its pool-runtime link land in a later Phase B
185185
# slice.
186-
add_executable(c2pool-dgb
187-
main_dgb.cpp
188-
${CMAKE_SOURCE_DIR}/src/core/uint256.cpp
189-
)
186+
# RUN-LOOP slice (#82): main_dgb.cpp --run now constructs dgb::Config + the
187+
# dgb::Node sharechain peer (pool::NodeBridge<NodeImpl,...>) and binds its P2P
188+
# listener, so the exe must link the real dgb pool runtime — not just the
189+
# header-only score path. We link the `dgb` OBJECT lib (node.cpp + protocol
190+
# handlers) and the shared core/pool/sharechain/storage base it sits on,
191+
# mirroring the c2pool-btc link set. c2pool_merged_mining is pulled for SYMBOL
192+
# RESOLUTION of the core web_server/stratum tangle ONLY (same reason c2pool-btc
193+
# links it) — it does NOT enable -DAUX_DOGE; DGB default build stays standalone
194+
# (no DOGE aux). core provides core/uint256.cpp, so the explicit source is
195+
# dropped to avoid a duplicate-symbol link. Per-coin isolation holds: only the
196+
# c2pool-dgb target stanza changes.
197+
add_executable(c2pool-dgb main_dgb.cpp)
190198
target_compile_definitions(c2pool-dgb PRIVATE C2POOL_VERSION="${C2POOL_GIT_VERSION}")
191199
target_link_libraries(c2pool-dgb
192-
btclibs # STATIC util lib: HexStr/HexDigit (strencodings) for base_uint hex - pure utility, no pool runtime
193-
yaml-cpp::yaml-cpp # config_{coin,pool}.hpp -> core/netaddress.hpp -> <yaml-cpp/yaml.h>
200+
c2pool_payout
201+
c2pool_merged_mining # symbol resolution for core web_server tangle (NOT -DAUX_DOGE)
202+
c2pool_hashrate
203+
core
204+
dgb # DGB pool-layer OBJECT lib: node.cpp NodeImpl + protocol handlers
205+
dgb_coin # DGB coin-layer: embedded P2P + mempool + transaction ctors
206+
pool
207+
sharechain
208+
c2pool_storage
209+
btclibs
210+
yaml-cpp::yaml-cpp
194211
nlohmann_json::nlohmann_json
195212
${Boost_LIBRARIES}
196213
)

src/c2pool/main_dgb.cpp

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626

2727
#include <impl/dgb/node.hpp>
2828

29+
#include <core/filesystem.hpp>
30+
#include <btclibs/util/strencodings.h>
31+
2932
#include <boost/asio.hpp>
3033

3134
#include <cstdint>
3235
#include <cstring>
36+
#include <filesystem>
3337
#include <iostream>
3438
#include <string>
39+
#include <system_error>
3540

3641
#ifndef C2POOL_VERSION
3742
#define C2POOL_VERSION "dev"
@@ -93,28 +98,54 @@ int run_selftest(const core::CoinParams& params)
9398
return 0;
9499
}
95100

96-
// Run-loop SPINE. Stands up the io_context that every node subsystem
97-
// (sharechain peer dgb::Node, embedded digibyted P2P, Stratum acceptor) and
98-
// the #82 won-block dispatch handler will hang off, plus an explicit graceful
99-
// shutdown driven from boost::asio::signal_set.
101+
// Run-loop SPINE + sharechain peer bring-up. Stands up the io_context that
102+
// every node subsystem hangs off, an explicit graceful shutdown driven from
103+
// boost::asio::signal_set, and (this slice) constructs the dgb::Config +
104+
// dgb::Node sharechain peer and binds its P2P listener.
100105
//
101106
// Why signal_set and not std::signal: std::signal handlers run in the
102107
// async-signal-only delivery context; io_context::stop is thread-safe but not
103108
// documented signal-safe. signal_set delivers SIGINT/SIGTERM as an ordinary
104109
// async callback on the io_context thread, so the shutdown path can do real
105110
// work (stop the stratum acceptor, close sessions) before ioc.stop() drains
106-
// the rest — mirrors main_btc.cpp s teardown contract.
111+
// the rest — mirrors main_btc.cpp's teardown contract.
107112
//
108-
// SEAM (next stacked slice): construct dgb::Config + dgb::Node(&ioc, &config),
109-
// listen on the sharechain P2P port, stand up the Stratum work source, and
110-
// bind make_on_block_found(reconstruct_won_block, p2p_sink) into
111-
// m_on_block_found so a won share reaches the network (closes #82). Those
112-
// subsystems open LevelDB + bind sockets, so they land as their own
113-
// build-verified increment rather than inline here.
114-
int run_node(const core::CoinParams& params)
113+
// SEAM (next stacked slice): stand up the Stratum work source and bind
114+
// make_on_block_found(reconstruct_won_block, p2p_sink) into m_on_block_found
115+
// so a won share reaches the network (closes #82's embedded P2P relay path);
116+
// the submitblock RPC fallback (rpc.cpp:387, already real — NOT a stub) is the
117+
// second arm of the dual-path broadcaster gate.
118+
int run_node(const core::CoinParams& params, bool testnet)
115119
{
116120
io::io_context ioc;
117121

122+
// Per-coin config root: ~/.c2pool/<net>/ (sharechain LevelDB + addrs.json
123+
// open underneath). Bucket-1 isolation primitive: DGB never shares LTC's
124+
// net dir — keep the subdir per-coin in v36 AND v37.
125+
const std::string net_subdir = testnet ? "digibyte_testnet" : "digibyte";
126+
const std::filesystem::path net_dir =
127+
core::filesystem::config_path() / net_subdir;
128+
std::error_code mkdir_ec;
129+
std::filesystem::create_directories(net_dir, mkdir_ec); // best effort
130+
131+
// dgb::Config = core::Config<PoolConfig, CoinConfig>. Skip Config::init()
132+
// (it would load pool.yaml + coin.yaml from disk); set the sharechain
133+
// identity directly from the oracle-sourced constants instead — the same
134+
// contract main_btc.cpp uses for its net smoke. prefix/identifier come from
135+
// the p2pool-dgb-scrypt oracle (PREFIX 1c0553f2…, IDENTIFIER 4b62545b…).
136+
dgb::Config config(net_subdir);
137+
config.pool()->m_prefix = ParseHexBytes(dgb::PoolConfig::DEFAULT_PREFIX_HEX);
138+
config.m_testnet = testnet;
139+
// DEFAULT_BOOTSTRAP_HOSTS is empty until DGB p2pool nodes come online, so
140+
// there are no outbound seeds to dial this slice — the node binds its
141+
// listener and waits for inbound sharechain peers.
142+
for (const auto& host : dgb::PoolConfig::DEFAULT_BOOTSTRAP_HOSTS) {
143+
const std::string addr = host.find(':') == std::string::npos
144+
? host + ":" + std::to_string(dgb::PoolConfig::P2P_PORT)
145+
: host;
146+
config.pool()->m_bootstrap_addrs.emplace_back(addr);
147+
}
148+
118149
bool shutdown_initiated = false;
119150
io::signal_set signals(ioc, SIGINT, SIGTERM);
120151
signals.async_wait(
@@ -126,13 +157,29 @@ int run_node(const core::CoinParams& params)
126157
std::cout << "[DGB] received signal " << signo
127158
<< " — initiating graceful shutdown" << std::endl;
128159
// Next slice: stop stratum acceptor + close sessions here BEFORE
129-
// ioc.stop(), so their pending async ops cancel cleanly.
160+
// ioc.stop(), so their pending async ops cancel cleanly. The
161+
// sharechain peer's sockets close when p2p_node destructs at scope
162+
// exit after ioc.run() returns.
130163
ioc.stop();
131164
});
132165

133-
std::cout << "[DGB] run-loop spine up: " << network_summary(params) << "\n";
166+
// Sharechain peer node: pool::NodeBridge<NodeImpl, Legacy, Actual>. The
167+
// NodeImpl ctor opens ~/.c2pool/<net>/sharechain_leveldb and seeds the addr
168+
// store from m_bootstrap_addrs, so config must be populated BEFORE
169+
// construction (above).
170+
dgb::Node p2p_node(&ioc, &config);
171+
p2p_node.set_target_outbound_peers(4);
172+
p2p_node.core::Server::listen(dgb::PoolConfig::P2P_PORT);
173+
std::cout << "[DGB] sharechain peer listening on port "
174+
<< dgb::PoolConfig::P2P_PORT
175+
<< " — proto adv=" << dgb::PoolConfig::ADVERTISED_PROTOCOL_VERSION
176+
<< " min=" << dgb::PoolConfig::MINIMUM_PROTOCOL_VERSION
177+
<< " prefix=" << dgb::PoolConfig::DEFAULT_PREFIX_HEX << std::endl;
178+
p2p_node.start_outbound_connections(); // no-op until seed hosts exist
179+
180+
std::cout << "[DGB] run-loop up: " << network_summary(params) << "\n";
134181
std::cout << "[DGB] io_context running. Ctrl-C to stop. "
135-
<< "(node/stratum/P2P + won-block dispatch bind in the next slice)"
182+
<< "(Stratum work source + won-block dispatch bind in the next slice)"
136183
<< std::endl;
137184

138185
ioc.run();
@@ -166,7 +213,7 @@ int main(int argc, char** argv)
166213

167214
// --run: stand up the run-loop spine (io_context + graceful shutdown).
168215
if (want_run)
169-
return run_node(params);
216+
return run_node(params, /*testnet=*/false);
170217

171218
// --selftest, or a bare invocation: drive the live score path so the
172219
// binary exercises real consensus code, then exit cleanly.

0 commit comments

Comments
 (0)