Skip to content

Commit

Permalink
Merge pull request #2567 from jamescowens/fix_mrc_fees_to_staker
Browse files Browse the repository at this point in the history
rpc, mrc: Fix field name and initialization of mrc_fees_to_staker
  • Loading branch information
jamescowens authored Aug 16, 2022
2 parents 4559d99 + 1c0b846 commit 64e3731
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
7 changes: 0 additions & 7 deletions src/gridcoin/claim.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,6 @@ class Claim : public IContractPayload
//!
std::map<Cpid, uint256> 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.
//!
Expand Down
40 changes: 40 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GRC::MRC>();

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;
}
11 changes: 11 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ bool CreateMRCRewards(CBlock &blocknew, std::map<GRC::Cpid, std::pair<uint256, G

// Put the mrc_tx_map in the claim
claim.m_mrc_tx_map = mrc_tx_map;

// Put the staker_fees in the claim
claim.m_mrc_fees_to_staker = staker_fees;
}

// Do a dry run for the claim signature to ensure that we can sign for a
Expand All @@ -284,11 +281,11 @@ bool CreateMRCRewards(CBlock &blocknew, std::map<GRC::Cpid, std::pair<uint256, G
"MRC fees to foundation %s, MRC rewards %s",
__func__,
claim.m_mining_id.ToString(),
FormatMoney(claim.m_research_subsidy + claim.m_block_subsidy + claim.m_mrc_fees_to_staker),
FormatMoney(claim.m_research_subsidy + claim.m_block_subsidy + staker_fees),
claim.m_magnitude,
FormatMoney(claim.m_research_subsidy),
FormatMoney(claim.m_block_subsidy),
FormatMoney(claim.m_mrc_fees_to_staker),
FormatMoney(staker_fees),
FormatMoney(foundation_fees),
FormatMoney(rewards));

Expand Down
9 changes: 8 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ UniValue ClaimToJson(const GRC::Claim& claim, const CBlockIndex* const pindex)
json.pushKV("magnitude_unit", claim.m_magnitude_unit);
}

json.pushKV("fees_to_staker", ValueFromAmount(claim.m_mrc_fees_to_staker));
json.pushKV("m_mrc_tx_map_size", (uint64_t) claim.m_mrc_tx_map.size());
UniValue mrcs(UniValue::VARR);
if (claim.m_version >= 4) {
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 64e3731

Please sign in to comment.