Skip to content

Commit fc9342b

Browse files
authored
web(topology): config-driven coin label fallback for chains absent from Blockchain enum (#420)
The dashboard topology/node_info/primary_chain_key surfaces derive the node coin symbol by switch over the consensus Blockchain enum, which has no entry for BCH or the NMC-aux sub-state. Such a node was labelled with an empty symbol/network/chain-key -- the dashboard going blank rather than truthful, against the per-node-topology charter. Add a web-layer m_coin_label captured from the raw --blockchain/cfg string and wired via set_coin_label(). node_symbol() and primary_chain_key() fall back to it (upper/lower-cased) only when the enum has no entry, so every node labels its own chain truthfully without touching the consensus enum (which address_validator / payout_manager switch on -- an enum add there ripples into consensus/address logic). Enum-supported coins are unchanged. Empty label still yields "" so callers surface an honest "chain not enabled" instead of a fabricated identity. Web layer only; never feeds consensus or address validation. Co-authored-by: frstrtr <frstrtr@users.noreply.github.com>
1 parent b0c4ce6 commit fc9342b

3 files changed

Lines changed: 51 additions & 14 deletions

File tree

src/c2pool/c2pool_refactored.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ int main(int argc, char* argv[]) {
578578
std::string doge_p2p_address; // --doge-p2p-address HOST
579579
int doge_p2p_port = 0; // --doge-p2p-port PORT
580580
Blockchain blockchain = Blockchain::LITECOIN; // Default to Litecoin
581+
std::string blockchain_label = "ltc"; // Raw coin string -> web layer node_symbol() fallback (config-driven labeling)
581582

582583
// Coin daemon P2P connection (for fast block relay alongside RPC)
583584
std::string coind_p2p_address; // defaults to rpc_host (same machine as RPC)
@@ -765,7 +766,8 @@ int main(int argc, char* argv[]) {
765766
else if (arg == "--loglevel-critical") { cli_log_level = "fatal"; cli_explicit.insert("log_level"); }
766767
// Network / blockchain selection (p2pool: --net)
767768
else if ((arg == "--net" || arg == "--blockchain") && i + 1 < argc) {
768-
blockchain = parse_blockchain(argv[++i]);
769+
blockchain_label = argv[++i];
770+
blockchain = parse_blockchain(blockchain_label);
769771
cli_explicit.insert("blockchain");
770772
}
771773
// P2Pool P2P sharechain port (p2pool: --p2pool-port)
@@ -1142,8 +1144,10 @@ int main(int argc, char* argv[]) {
11421144
else if (m == "wait") startup_mode = StartupMode::WAIT;
11431145
else startup_mode = StartupMode::AUTO;
11441146
}
1145-
if (!cli_explicit.count("blockchain") && cfg["blockchain"])
1146-
blockchain = parse_blockchain(cfg["blockchain"].as<std::string>());
1147+
if (!cli_explicit.count("blockchain") && cfg["blockchain"]) {
1148+
blockchain_label = cfg["blockchain"].as<std::string>();
1149+
blockchain = parse_blockchain(blockchain_label);
1150+
}
11471151

11481152
// Ports
11491153
if (!cli_explicit.count("p2p_port") && cfg["port"])
@@ -1568,6 +1572,7 @@ int main(int argc, char* argv[]) {
15681572
if (!external_ip.empty())
15691573
web_server.get_mining_interface()->set_external_ip(external_ip);
15701574
#ifdef C2POOL_VERSION
1575+
web_server.get_mining_interface()->set_coin_label(blockchain_label);
15711576
web_server.get_mining_interface()->set_pool_version(
15721577
"c2pool/" C2POOL_VERSION);
15731578
#endif

src/core/web_server.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,16 +5210,10 @@ nlohmann::json MiningInterface::rest_node_topology()
52105210
return str;
52115211
};
52125212

5213-
// This node's own chain.
5214-
std::string primary;
5215-
switch (m_blockchain) {
5216-
case Blockchain::LITECOIN: primary = "LTC"; break;
5217-
case Blockchain::BITCOIN: primary = "BTC"; break;
5218-
case Blockchain::DOGECOIN: primary = "DOGE"; break;
5219-
case Blockchain::DASH: primary = "DASH"; break;
5220-
case Blockchain::DIGIBYTE: primary = "DGB"; break;
5221-
default: break;
5222-
}
5213+
// This node's own chain. node_symbol() falls back to the config-driven
5214+
// coin label for chains with no Blockchain enum entry (BCH / NMC-aux),
5215+
// so a node never advertises a blank primary symbol.
5216+
std::string primary = node_symbol();
52235217

52245218
nlohmann::json coins = nlohmann::json::array();
52255219
auto has_coin = [&](const std::string& sym) {
@@ -5295,6 +5289,17 @@ nlohmann::json MiningInterface::rest_node_info()
52955289
break;
52965290
default: break;
52975291
}
5292+
// Config-driven fallback for chains absent from the Blockchain enum
5293+
// (BCH / NMC-aux): label from the configured coin string rather than
5294+
// leaving symbol/network blank.
5295+
if (!result.contains("symbol")) {
5296+
std::string sym = node_symbol();
5297+
if (!sym.empty()) result["symbol"] = sym;
5298+
}
5299+
if (!result.contains("network")) {
5300+
std::string ck = primary_chain_key();
5301+
if (!ck.empty()) result["network"] = m_testnet ? (ck + "_testnet") : ck;
5302+
}
52985303
return result;
52995304
}
53005305

src/core/web_server.hpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ class MiningInterface : public jsonrpccxx::JsonRpc2Server,
934934
std::map<std::string, nlohmann::json> m_active_work;
935935
bool m_testnet; // Store testnet flag
936936
Blockchain m_blockchain; // Store blockchain type
937+
std::string m_coin_label; // Raw configured coin string; fallback label for chains absent from the Blockchain enum
937938
std::shared_ptr<IMiningNode> m_node; // Connection to c2pool node for difficulty tracking
938939
BlockchainAddressValidator m_address_validator; // New address validator
939940
std::unique_ptr<c2pool::payout::PayoutManager> m_payout_manager; // Payout management
@@ -1199,6 +1200,23 @@ class MiningInterface : public jsonrpccxx::JsonRpc2Server,
11991200
void set_explorer_url(const std::string& url) { m_explorer_url = url; }
12001201
const std::string& get_explorer_url() const { return m_explorer_url; }
12011202

1203+
// Uppercase coin symbol for THIS node. Enum-derived for the consensus-
1204+
// supported coins; falls back to the config-driven m_coin_label when the
1205+
// chain has no Blockchain enum entry (BCH / NMC-aux), so topology and
1206+
// node_info never emit a blank symbol. "" only when truly unconfigured.
1207+
std::string node_symbol() const {
1208+
switch (m_blockchain) {
1209+
case Blockchain::LITECOIN: return "LTC";
1210+
case Blockchain::BITCOIN: return "BTC";
1211+
case Blockchain::DOGECOIN: return "DOGE";
1212+
case Blockchain::DASH: return "DASH";
1213+
case Blockchain::DIGIBYTE: return "DGB";
1214+
default: break;
1215+
}
1216+
std::string s = m_coin_label;
1217+
for (auto& ch : s) if (ch >= 'a' && ch <= 'z') ch = static_cast<char>(ch - 32);
1218+
return s;
1219+
}
12021220
// Primary chain key for THIS node, derived from its configured blockchain
12031221
// (lowercase symbol). Used as the default chain for explorer / coin-admin
12041222
// endpoints instead of a hardcoded "ltc": a DGB/DASH/BTC node must not
@@ -1211,8 +1229,11 @@ class MiningInterface : public jsonrpccxx::JsonRpc2Server,
12111229
case Blockchain::DOGECOIN: return "doge";
12121230
case Blockchain::DASH: return "dash";
12131231
case Blockchain::DIGIBYTE: return "dgb";
1214-
default: return "";
1232+
default: break;
12151233
}
1234+
std::string s = m_coin_label;
1235+
for (auto& ch : s) if (ch >= 'A' && ch <= 'Z') ch = static_cast<char>(ch + 32);
1236+
return s; // "" only when truly unconfigured -> callers surface "not enabled"
12161237
}
12171238
void set_explorer_chaininfo_fn(explorer_chaininfo_fn_t fn) { m_explorer_chaininfo_fn = thread_safe_wrap(std::move(fn)); }
12181239
void set_explorer_blockhash_fn(explorer_blockhash_fn_t fn) { m_explorer_blockhash_fn = thread_safe_wrap(std::move(fn)); }
@@ -1296,6 +1317,12 @@ class MiningInterface : public jsonrpccxx::JsonRpc2Server,
12961317
void set_worker_port(uint16_t port) { m_worker_port = port; }
12971318
void set_external_ip(const std::string& ip) { m_external_ip = ip; }
12981319
void set_pool_version(const std::string& ver) { m_pool_version = ver; }
1320+
// Config-driven coin label (raw --blockchain/cfg string). Only consulted
1321+
// by node_symbol()/primary_chain_key() when the consensus Blockchain enum
1322+
// has no entry for this chain (e.g. embedded BCH / NMC-aux), so the
1323+
// dashboard labels every node truthfully instead of going blank. Web-layer
1324+
// only -- never feeds consensus/address-validation.
1325+
void set_coin_label(const std::string& sym) { m_coin_label = sym; }
12991326
const std::string& get_pool_version() const { return m_pool_version; }
13001327

13011328
/// Auto-detect public IP and version from external services.

0 commit comments

Comments
 (0)