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:
@@ -3231,6 +3231,19 @@ void testRendererHelpers()
|
||||
EXPECT_EQ(dragonx::ui::defaultPoolWorkerAddress(poolAddresses), std::string("zs-default-worker"));
|
||||
EXPECT_TRUE(dragonx::ui::miningValueAlreadySaved({"pool-a", "pool-b"}, "pool-b"));
|
||||
EXPECT_FALSE(dragonx::ui::miningValueAlreadySaved({"pool-a"}, ""));
|
||||
|
||||
// resolveMiningUserAddress: the configured payout address is the xmrig "user"
|
||||
// (where rewards go) and must win over the wallet's own addresses.
|
||||
EXPECT_EQ(dragonx::ui::resolveMiningUserAddress("zs-payout", "zs-own", "R-own"),
|
||||
std::string("zs-payout")); // explicit payout wins
|
||||
EXPECT_EQ(dragonx::ui::resolveMiningUserAddress("", "zs-own", "R-own"),
|
||||
std::string("zs-own")); // unset -> own shielded
|
||||
EXPECT_EQ(dragonx::ui::resolveMiningUserAddress("x", "zs-own", "R-own"),
|
||||
std::string("zs-own")); // "x" placeholder counts as unset
|
||||
EXPECT_EQ(dragonx::ui::resolveMiningUserAddress("x", "", "R-own"),
|
||||
std::string("R-own")); // no shielded -> transparent
|
||||
EXPECT_EQ(dragonx::ui::resolveMiningUserAddress("", "", ""),
|
||||
std::string("")); // nothing anywhere -> caller errors
|
||||
EXPECT_EQ(std::string(dragonx::ui::defaultPoolUrl()), std::string("pool.dragonx.is:3433"));
|
||||
|
||||
dragonx::TransactionInfo tx;
|
||||
@@ -5828,6 +5841,94 @@ void testPoolHashrateParsing()
|
||||
EXPECT_FALSE(ok);
|
||||
}
|
||||
|
||||
// Schema-aware pool fee parsing (fed to the mining-tab "N% fee" display).
|
||||
void testPoolFeeParsing()
|
||||
{
|
||||
using namespace dragonx::util;
|
||||
bool ok = false;
|
||||
|
||||
// pool.dragonx.is custom schema: pools.dragonx.poolFee (a whole-percent number).
|
||||
const std::string isJson =
|
||||
R"({"pools":{"dragonx":{"hashrate":27670.14,"poolFee":1,"soloFee":3}}})";
|
||||
double fee = parsePoolFee(PoolStatsSchema::DragonXIs, isJson, "", ok);
|
||||
EXPECT_TRUE(ok);
|
||||
EXPECT_NEAR(fee, 1.0, 0.001);
|
||||
|
||||
// Fractional fees survive (display rounds, but the parse must not).
|
||||
const std::string isFrac = R"({"pools":{"dragonx":{"poolFee":1.5}}})";
|
||||
fee = parsePoolFee(PoolStatsSchema::DragonXIs, isFrac, "", ok);
|
||||
EXPECT_TRUE(ok);
|
||||
EXPECT_NEAR(fee, 1.5, 0.001);
|
||||
|
||||
// Miningcore schema: the requested pool id's poolFeePercent.
|
||||
const std::string ccJson =
|
||||
R"({"pools":[)"
|
||||
R"({"id":"dragonx-solo","poolFeePercent":2.0,"poolStats":{"poolHashrate":88780.0}},)"
|
||||
R"({"id":"dragonx-pplns","poolFeePercent":0.9,"poolStats":{"poolHashrate":1585.9}}]})";
|
||||
fee = parsePoolFee(PoolStatsSchema::Miningcore, ccJson, "dragonx-pplns", ok);
|
||||
EXPECT_TRUE(ok);
|
||||
EXPECT_NEAR(fee, 0.9, 0.001);
|
||||
|
||||
// Missing field / malformed / wrong-schema input all fail closed (caller keeps
|
||||
// the compile-time fallback rather than showing a bogus 0%).
|
||||
parsePoolFee(PoolStatsSchema::DragonXIs, R"({"pools":{"dragonx":{"hashrate":1.0}}})", "", ok);
|
||||
EXPECT_FALSE(ok); // no poolFee key
|
||||
parsePoolFee(PoolStatsSchema::DragonXIs, "not json", "", ok);
|
||||
EXPECT_FALSE(ok);
|
||||
parsePoolFee(PoolStatsSchema::Miningcore, ccJson, "does-not-exist", ok);
|
||||
EXPECT_FALSE(ok);
|
||||
parsePoolFee(PoolStatsSchema::DragonXIs, R"({"pools":{"dragonx":{"poolFee":"1"}}})", "", ok);
|
||||
EXPECT_FALSE(ok); // string, not number
|
||||
}
|
||||
|
||||
// The effective pool list = official pools ∪ saved favorites ∪ current custom pool,
|
||||
// endpoint-deduped, with synthetic user rows flagged official=false.
|
||||
void testEffectivePools()
|
||||
{
|
||||
using namespace dragonx::util;
|
||||
const int base = (int)knownPools().size();
|
||||
|
||||
// Current pool is the official one, nothing saved -> just the official pools.
|
||||
auto a = effectivePools("pool.dragonx.is:3433", {});
|
||||
EXPECT_EQ((int)a.size(), base);
|
||||
|
||||
// A custom current pool (neither official nor saved) appears as an extra row.
|
||||
auto b = effectivePools("my.pool.example:3333", {});
|
||||
EXPECT_EQ((int)b.size(), base + 1);
|
||||
const KnownPool* custom = findPoolByUrl(b, "my.pool.example:3333");
|
||||
EXPECT_TRUE(custom != nullptr);
|
||||
EXPECT_FALSE(custom->official);
|
||||
EXPECT_TRUE(custom->feePercent < 0.0); // unknown fee
|
||||
|
||||
// Saved pools are appended; an official one among them and a duplicate collapse.
|
||||
auto c = effectivePools("pool.dragonx.is:3433",
|
||||
{"pool.dragonx.is:3433", "alt.pool:1", "alt.pool:1"});
|
||||
EXPECT_EQ((int)c.size(), base + 1);
|
||||
EXPECT_TRUE(findPoolByUrl(c, "alt.pool:1") != nullptr);
|
||||
|
||||
// Current pool equal to a saved one is not listed twice.
|
||||
auto d = effectivePools("alt.pool:1", {"alt.pool:1"});
|
||||
EXPECT_EQ((int)d.size(), base + 1);
|
||||
|
||||
// Blank/whitespace URLs are ignored (no phantom rows).
|
||||
auto e = effectivePools(" ", {"", " "});
|
||||
EXPECT_EQ((int)e.size(), base);
|
||||
}
|
||||
|
||||
// Fee formatting: whole numbers stay clean, fractional fees keep their decimals.
|
||||
void testFormatFeePercent()
|
||||
{
|
||||
using dragonx::ui::FormatFeePercent;
|
||||
EXPECT_TRUE(FormatFeePercent(1.0) == "1");
|
||||
EXPECT_TRUE(FormatFeePercent(0.0) == "0");
|
||||
EXPECT_TRUE(FormatFeePercent(3.0) == "3");
|
||||
EXPECT_TRUE(FormatFeePercent(1.5) == "1.5");
|
||||
EXPECT_TRUE(FormatFeePercent(0.9) == "0.9");
|
||||
EXPECT_TRUE(FormatFeePercent(1.25) == "1.25");
|
||||
EXPECT_TRUE(FormatFeePercent(2.50) == "2.5"); // trailing zero trimmed
|
||||
EXPECT_TRUE(FormatFeePercent(100.0) == "100");
|
||||
}
|
||||
|
||||
// Weighted-random pool selection: smaller pools favored, incumbent sticky, fails safe.
|
||||
void testPoolWeightedSelection()
|
||||
{
|
||||
@@ -6590,6 +6691,9 @@ int main()
|
||||
testLiteOfficialServerDetection();
|
||||
testPoolRegistryLookup();
|
||||
testPoolHashrateParsing();
|
||||
testPoolFeeParsing();
|
||||
testEffectivePools();
|
||||
testFormatFeePercent();
|
||||
testPoolWeightedSelection();
|
||||
testAtomicFileWrite();
|
||||
testHushChatCrypto();
|
||||
|
||||
Reference in New Issue
Block a user