feat(mining): live pool fee, saved/custom pool rows, and payout-address fix

Several related mining-tab pool improvements:

- Report the default pool fee correctly: pool.dragonx.is is 1%, not 0%.
  The registry constant was hardcoded to 0. It now also fetches the live
  poolFee from the pool's /api/stats alongside hashrate (no extra
  request), so the displayed fee self-corrects and falls back to the
  compile-time value only when the fetch hasn't landed.

- Show fractional fees: new FormatFeePercent trims trailing zeros so
  whole fees read "1%" and fractional ones keep their decimals ("1.5%").

- Surface saved + custom pools in the pool list card: the list is now
  the union of the official pools, the user's saved favorites, and the
  currently-mined pool (effectivePools), each a selectable, endpoint-
  deduped row. Previously the card only showed the hardcoded knownPools().

- Fix the xmrig "user" field: the "Payout Address" field now drives the
  pool login rewards are credited to (resolveMiningUserAddress), instead
  of being written only to "pass" while "user" was auto-derived from the
  wallet's own first z-address -- which silently ignored a configured
  payout address and could route rewards to the wrong address.

Unit tests cover parsePoolFee, FormatFeePercent, effectivePools, and
resolveMiningUserAddress; full app + ObsidianDragonTests build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 03:48:05 -05:00
parent fffee9f0b5
commit 45b652f514
10 changed files with 311 additions and 27 deletions

View File

@@ -45,16 +45,30 @@ struct PoolHashrate {
std::string id;
double hashrateHs = 0.0;
bool ok = false;
// Live pool fee (%) read from the same stats JSON. <0 means "not available" —
// callers fall back to the compile-time KnownPool.feePercent.
double feePercent = -1.0;
};
// The built-in official pools (PPLNS only — never a SOLO pool, whose hashrate is
// meaningless to balance against). Stable order.
const std::vector<KnownPool>& knownPools();
// The known pool whose stratum matches `url` (host, and port when both specify one),
// or nullptr. `url` may be a bare host, host:port, or carry a scheme/userinfo/path.
// The pool in `pools` whose stratum matches `url` (host, and port when both specify
// one), or nullptr. `url` may be a bare host, host:port, or carry a scheme/path.
const KnownPool* findPoolByUrl(const std::vector<KnownPool>& pools, const std::string& url);
// Same, over the built-in official pools only.
const KnownPool* findKnownPoolByUrl(const std::string& url);
// The full list the UI should show: the official knownPools(), plus a row for every
// user-saved pool URL and for `currentPoolUrl` when it isn't one of those — so a
// custom/bookmarked pool is a first-class, selectable row. Synthetic (user) rows are
// official=false and carry no statsUrl (feePercent<0, no live hashrate), and endpoints
// are de-duplicated so a saved URL that equals an official pool isn't listed twice.
std::vector<KnownPool> effectivePools(const std::string& currentPoolUrl,
const std::vector<std::string>& savedPoolUrls);
// The algo xmrig must use for `url`: the matching known pool's algo, else `fallback`.
std::string resolvePoolAlgo(const std::string& url, const std::string& fallback);
@@ -64,6 +78,13 @@ std::string resolvePoolAlgo(const std::string& url, const std::string& fallback)
double parsePoolHashrate(PoolStatsSchema schema, const std::string& json,
const std::string& miningcorePoolId, bool& ok);
// Parse a pool's advertised fee (%) out of the same stats JSON (DragonXIs:
// pools.<name>.poolFee; Miningcore: pools[id].poolFeePercent). Selects the same
// pool entry as parsePoolHashrate. Sets ok=false and returns 0 when the field is
// absent / malformed, so the caller keeps the compile-time fallback.
double parsePoolFee(PoolStatsSchema schema, const std::string& json,
const std::string& miningcorePoolId, bool& ok);
// Weighted-random pick among the usable (ok==true) pools: probability is inversely
// proportional to hashrate (smaller pools favored), so miners spread out instead of
// all stampeding to the single lowest pool. The current pool (`currentId`, may be

View File

@@ -28,7 +28,7 @@ const std::vector<KnownPool>& knownPools()
KnownPool{
"dragonx-is", "pool.dragonx.is", "pool.dragonx.is:3433", "rx/hush",
"https://pool.dragonx.is/api/stats", PoolStatsSchema::DragonXIs,
/*miningcorePoolId=*/"", /*feePercent=*/0.0, /*official=*/true,
/*miningcorePoolId=*/"", /*feePercent=*/1.0, /*official=*/true,
},
};
return pools;
@@ -83,13 +83,62 @@ bool sameEndpoint(const std::string& a, const std::string& b)
return pa == pb;
}
// Build a synthetic, selectable pool row for a user-supplied URL (a saved favorite
// or the current custom pool). We don't know its stats API, so it carries no
// statsUrl / live hashrate and an unknown (<0) fee — the UI falls back to "—".
KnownPool makeUserPool(const std::string& url)
{
KnownPool p;
const std::string hp = hostPortOf(url);
std::string host, port;
splitHostPort(hp, host, port);
p.id = "user:" + trimmed(url); // stable + unique (used as the ImGui id)
p.label = host.empty() ? hp : host;
p.stratum = trimmed(url); // what the miner connects to / a row-click restores
p.algo = ""; // unknown; xmrig resolves via resolvePoolAlgo's fallback
p.statsUrl = ""; // no known stats endpoint -> no live hashrate/fee
p.schema = PoolStatsSchema::DragonXIs;
p.miningcorePoolId = "";
p.feePercent = -1.0; // unknown fee
p.official = false;
return p;
}
} // namespace
const KnownPool* findPoolByUrl(const std::vector<KnownPool>& pools, const std::string& url)
{
for (const auto& p : pools)
if (sameEndpoint(p.stratum, url)) return &p;
return nullptr;
}
const KnownPool* findKnownPoolByUrl(const std::string& url)
{
for (const auto& p : knownPools())
if (sameEndpoint(p.stratum, url)) return &p;
return nullptr;
return findPoolByUrl(knownPools(), url);
}
std::vector<KnownPool> effectivePools(const std::string& currentPoolUrl,
const std::vector<std::string>& savedPoolUrls)
{
std::vector<KnownPool> pools = knownPools();
// Skip anything whose endpoint already appears (official or an earlier user row).
auto listed = [&](const std::string& url) {
return findPoolByUrl(pools, url) != nullptr;
};
for (const auto& url : savedPoolUrls) {
if (trimmed(url).empty() || listed(url)) continue;
pools.push_back(makeUserPool(url));
}
// The pool currently being mined, if not already shown, so the active pool is
// always visible even before it's bookmarked.
if (!trimmed(currentPoolUrl).empty() && !listed(currentPoolUrl))
pools.push_back(makeUserPool(currentPoolUrl));
return pools;
}
std::string resolvePoolAlgo(const std::string& url, const std::string& fallback)
@@ -159,6 +208,64 @@ double parsePoolHashrate(PoolStatsSchema schema, const std::string& jsonStr,
return 0.0;
}
double parsePoolFee(PoolStatsSchema schema, const std::string& jsonStr,
const std::string& miningcorePoolId, bool& ok)
{
ok = false;
try {
const json j = json::parse(jsonStr);
if (schema == PoolStatsSchema::DragonXIs) {
// { "pools": { "dragonx": { "poolFee": <num>, ... }, ... } }
if (j.contains("pools") && j["pools"].is_object()) {
const auto& pools = j["pools"];
auto readFee = [&](const json& pool, double& out) -> bool {
if (pool.is_object() && pool.contains("poolFee") &&
pool["poolFee"].is_number()) {
out = pool["poolFee"].get<double>();
return true;
}
return false;
};
double fee = 0.0;
if (pools.contains("dragonx") && readFee(pools["dragonx"], fee)) {
ok = true;
return fee;
}
for (auto it = pools.begin(); it != pools.end(); ++it) {
if (readFee(it.value(), fee)) {
ok = true;
return fee;
}
}
}
} else { // Miningcore: pools[id].poolFeePercent
if (j.contains("pools") && j["pools"].is_array()) {
const json* chosen = nullptr;
for (const auto& pool : j["pools"]) {
if (!pool.is_object()) continue;
if (!miningcorePoolId.empty()) {
if (pool.value("id", std::string{}) == miningcorePoolId) {
chosen = &pool;
break;
}
} else if (!chosen) {
chosen = &pool; // first pool when no id requested
}
}
if (chosen && chosen->contains("poolFeePercent") &&
(*chosen)["poolFeePercent"].is_number()) {
ok = true;
return (*chosen)["poolFeePercent"].get<double>();
}
}
}
} catch (...) {
// fall through — ok stays false
}
return 0.0;
}
std::string chooseWeightedPool(const std::vector<PoolHashrate>& pools,
const std::string& currentId,
std::mt19937& rng)

View File

@@ -94,6 +94,12 @@ void PoolStatsService::run(std::vector<KnownPool> pools)
const double v = parsePoolHashrate(p.schema, body, p.miningcorePoolId, ok);
hr.ok = ok;
hr.hashrateHs = ok ? v : 0.0;
bool feeOk = false;
const double fee = parsePoolFee(p.schema, body, p.miningcorePoolId, feeOk);
// Only trust a sane fee; anything else leaves feePercent < 0 so the UI
// falls back to the compile-time KnownPool.feePercent.
if (feeOk && fee >= 0.0 && fee <= 100.0) hr.feePercent = fee;
}
results[p.id] = hr;
}