From 1c0b8466ee08b34a21a183a9b1924790d88205c0 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sat, 13 Aug 2022 21:39:10 -0400 Subject: [PATCH] Remove unused m_mrc_fees_to_staker in Claim class Implement GetMRCFees in CBlock(). Place output of GetMRCFees() in blocktoJSON conditioned on block.nVersion >= 12. --- src/gridcoin/claim.h | 7 ------- src/main.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/main.h | 11 +++++++++++ src/miner.cpp | 7 ++----- src/rpc/blockchain.cpp | 9 ++++++++- 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/src/gridcoin/claim.h b/src/gridcoin/claim.h index 36021597f7..0c822fcdab 100644 --- a/src/gridcoin/claim.h +++ b/src/gridcoin/claim.h @@ -193,13 +193,6 @@ class Claim : public IContractPayload //! std::map m_mrc_tx_map; - //! - //! \brief This represents the fees taken from the MRC research subsidies that are awarded to the staker. - //! This must be tracked because this value is added to coinstake award for the staker and must be - //! included in the claim validation. - //! - CAmount m_mrc_fees_to_staker; - //! //! \brief Initialize an empty, invalid reward claim object. //! diff --git a/src/main.cpp b/src/main.cpp index 8109ce57ac..d7e6302af8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3095,3 +3095,43 @@ GRC::MintSummary CBlock::GetMint() const EXCLUSIVE_LOCKS_REQUIRED(cs_main) return mint; } +GRC::MRCFees CBlock::GetMRCFees() const EXCLUSIVE_LOCKS_REQUIRED(cs_main) +{ + GRC::MRCFees mrc_fees; + unsigned int mrc_output_limit = GetMRCOutputLimit(nVersion, false); + + // Return zeroes for mrc fees if MRC not allowed. (This could have also been done + // by block version check, but this is more correct.) + if (!mrc_output_limit) { + return mrc_fees; + } + + Fraction foundation_fee_fraction = FoundationSideStakeAllocation(); + + const GRC::Claim claim = NCONST_PTR(this)->PullClaim(); + + CAmount mrc_total_fees = 0; + + // This is similar to the code in CheckMRCRewards in the Validator class, but with the validation removed because + // the block has already been validated. We also only need the MRC fee calculation portion. + for (const auto& tx: vtx) { + for (const auto& mrc : claim.m_mrc_tx_map) { + if (mrc.second == tx.GetHash() && !tx.GetContracts().empty()) { + // An MRC contract must be the first and only contract on a transaction by protocol. + GRC::Contract contract = tx.GetContracts()[0]; + + if (contract.m_type != GRC::ContractType::MRC) continue; + + GRC::MRC mrc = contract.CopyPayloadAs(); + + mrc_total_fees += mrc.m_fee; + mrc_fees.m_mrc_foundation_fees += mrc.m_fee * foundation_fee_fraction.GetNumerator() + / foundation_fee_fraction.GetDenominator(); + } + } + } + + mrc_fees.m_mrc_staker_fees = mrc_total_fees - mrc_fees.m_mrc_foundation_fees; + + return mrc_fees; +} diff --git a/src/main.h b/src/main.h index 3f09326b9a..e04001d6a4 100644 --- a/src/main.h +++ b/src/main.h @@ -310,6 +310,16 @@ class CBlockHeader }; namespace GRC { +//! +//! \brief A report that contains the mrc fees paid in a block. +//! +class MRCFees +{ +public: + CAmount m_mrc_foundation_fees = 0; //!< mrc fees to the foundation + CAmount m_mrc_staker_fees = 0; //!< mrc fees to the staker +}; + //! //! \brief A report that contains the calculated subsidy claimed in a block. //! Produced by the CBlock::GetMint() method. @@ -393,6 +403,7 @@ class CBlock : public CBlockHeader GRC::SuperblockPtr GetSuperblock() const; GRC::SuperblockPtr GetSuperblock(const CBlockIndex* const pindex) const; GRC::MintSummary GetMint() const; + GRC::MRCFees GetMRCFees() const; // entropy bit for stake modifier if chosen by modifier unsigned int GetStakeEntropyBit() const diff --git a/src/miner.cpp b/src/miner.cpp index f7c1eaf0a1..118a968987 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -262,9 +262,6 @@ bool CreateMRCRewards(CBlock &blocknew, std::map= 4) { @@ -228,6 +227,14 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fP } result.pushKV("fees_collected", ValueFromAmount(mint.m_fees)); + + if (block.nVersion >= 12) { + GRC::MRCFees mrc_fees = block.GetMRCFees(); + + result.pushKV("mrc_foundation_fees", ValueFromAmount(mrc_fees.m_mrc_foundation_fees)); + result.pushKV("mrc_staker_fees", ValueFromAmount(mrc_fees.m_mrc_staker_fees)); + } + result.pushKV("IsSuperBlock", blockindex->IsSuperblock()); result.pushKV("IsContract", blockindex->IsContract());