From 82eb56cb94e6838aa7fb93e3fc400c64a054c72c Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Mon, 2 Oct 2023 17:41:35 -0400 Subject: [PATCH] Change operation of fEnableSideStaking flag The fEnableSideStaking flag should only control local sidestakes, not mandatory ones. --- src/gridcoin/sidestake.cpp | 18 ++++++++++++------ src/miner.cpp | 7 +++---- src/rpc/mining.cpp | 22 +++++++++++----------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/gridcoin/sidestake.cpp b/src/gridcoin/sidestake.cpp index ebed05a63e..c310c625c9 100644 --- a/src/gridcoin/sidestake.cpp +++ b/src/gridcoin/sidestake.cpp @@ -211,12 +211,18 @@ const std::vector SideStakeRegistry::ActiveSideStakeEntries() } } - // Followed by local active sidestakes - for (const auto& entry : m_sidestake_entries) - { - if (entry.second->m_status == SideStakeStatus::ACTIVE && allocation_sum + entry.second->m_allocation <= 1.0) { - sidestakes.push_back(entry.second); - allocation_sum += entry.second->m_allocation; + // Followed by local active sidestakes if sidestaking is enabled. Note that mandatory sidestaking cannot be disabled. + bool fEnableSideStaking = gArgs.GetBoolArg("-enablesidestaking"); + + if (fEnableSideStaking) { + LogPrint(BCLog::LogFlags::MINER, "INFO: %s: fEnableSideStaking = %u", __func__, fEnableSideStaking); + + for (const auto& entry : m_sidestake_entries) + { + if (entry.second->m_status == SideStakeStatus::ACTIVE && allocation_sum + entry.second->m_allocation <= 1.0) { + sidestakes.push_back(entry.second); + allocation_sum += entry.second->m_allocation; + } } } diff --git a/src/miner.cpp b/src/miner.cpp index 9584982c9a..ca028355c0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1319,10 +1319,9 @@ void StakeMiner(CWallet *pwallet) bool fEnableSideStaking = gArgs.GetBoolArg("-enablesidestaking"); - LogPrint(BCLog::LogFlags::MINER, "INFO: %s: fEnableSideStaking = %u", __func__, fEnableSideStaking); - - // vSideStakeAlloc is an out parameter. - if (fEnableSideStaking) vSideStakeAlloc = GRC::GetSideStakeRegistry().ActiveSideStakeEntries(); + // Note that fEnableSideStaking is now processed internal to ActiveSideStakeEntries. The sidestaking flag only + // controls local sidestakes. If there exists mandatory sidestakes, they occur regardless of the flag. + vSideStakeAlloc = GRC::GetSideStakeRegistry().ActiveSideStakeEntries(); // wait for next round if (!MilliSleep(nMinerSleep)) return; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e4befd87e3..f7b9123a3f 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -110,20 +110,20 @@ UniValue getstakinginfo(const UniValue& params, bool fHelp) } obj.pushKV("stake-splitting", stakesplitting); - sidestaking.pushKV("side-staking-enabled", fEnableSideStaking); - if (fEnableSideStaking) + sidestaking.pushKV("local_side_staking_enabled", fEnableSideStaking); + + // Note that if local_side_staking_enabled is true, then local sidestakes will be applicable and shown. Mandatory + // sidestakes are always included. + for (const auto& alloc : vSideStakeAlloc) { - for (const auto& alloc : vSideStakeAlloc) - { - sidestakingalloc.pushKV("address", alloc->m_key.ToString()); - sidestakingalloc.pushKV("allocation-pct", alloc->m_allocation * 100); - sidestakingalloc.pushKV("status", alloc->StatusToString()); + sidestakingalloc.pushKV("address", alloc->m_key.ToString()); + sidestakingalloc.pushKV("allocation_pct", alloc->m_allocation * 100); + sidestakingalloc.pushKV("status", alloc->StatusToString()); - vsidestakingalloc.push_back(sidestakingalloc); - } - sidestaking.pushKV("side-staking-allocations", vsidestakingalloc); + vsidestakingalloc.push_back(sidestakingalloc); } - obj.pushKV("side-staking", sidestaking); + sidestaking.pushKV("side_staking_allocations", vsidestakingalloc); + obj.pushKV("side_staking", sidestaking); obj.pushKV("difficulty", diff); obj.pushKV("errors", GetWarnings("statusbar"));