Skip to content

Commit cbf23ee

Browse files
committed
Remove default for GetMRCOutputLimit and update comments
Plus a couple of other minor changes
1 parent dcc6efc commit cbf23ee

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/main.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ unsigned int GetCoinstakeOutputLimit(const int& block_version)
860860
{
861861
int output_limit = (block_version >= 10) ? 8 : 3;
862862

863-
output_limit += GetMRCOutputLimit(block_version);
863+
output_limit += GetMRCOutputLimit(block_version, true);
864864

865865
return output_limit;
866866
}
@@ -891,7 +891,7 @@ unsigned int GetMRCOutputLimit(const int& block_version, bool include_foundation
891891

892892
// If the include_foundation_sidestake is false (meaning that the foundation sidestake should not be counted
893893
// in the returned limit) AND the foundation sidestake allocation is greater than zero, then reduce the reported
894-
// output limit by 1. If the foundation sidestake allocation is 0.0, then there will be no foundation sidestake
894+
// output limit by 1. If the foundation sidestake allocation is zero, then there will be no foundation sidestake
895895
// output, so the output_limit should be as above. If the output limit was already zero then it remains zero.
896896
if (!include_foundation_sidestake && FoundationSideStakeAllocation().isNonZero() && output_limit) {
897897
--output_limit;
@@ -1337,10 +1337,6 @@ class ClaimValidator
13371337
}
13381338

13391339
// The loop here is similar to that in CreateMRCRewards. Note the parameters are out parameters.
1340-
// We do not need to split the mrc fees to the foundation and the staker here, because the total value on the
1341-
// coinstake, which includes ALL coinstake outputs is what is validated as the total claimed. This readds together
1342-
// the fees combined with the RR and stake reward to the staker + the fees sidestaked to the foundation. Note that
1343-
// any normal sidestakes come OUT of the RR to the staker and so are NOT double counted.
13441340
// Note that it is possible that someone could try and circumvent the 100% fee penalty for submitting an MRC within
13451341
// the zero payout interval by purposefully miscomputing the fee. This is one of the reasons why the fee is
13461342
// recomputed by the checking node as part of the ValidateMRC function. In that case, the MRC abuser will accumulate
@@ -1528,6 +1524,8 @@ bool GridcoinConnectBlock(
15281524

15291525
int beacon_db_height = beacons.GetDBHeight();
15301526

1527+
// Note this does NOT handle mrc's. The recording of MRC's is a block level event controlled by the claim.
1528+
// See below.
15311529
GRC::ApplyContracts(block, pindex, beacon_db_height, found_contract);
15321530

15331531
if (found_contract) {
@@ -1564,7 +1562,6 @@ bool GridcoinConnectBlock(
15641562
}
15651563
}
15661564

1567-
// TODO: Extend RecorRewardBlock to record MRC recipient tallies.
15681565
GRC::Tally::RecordRewardBlock(pindex);
15691566
GRC::Researcher::Refresh();
15701567

src/main.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ GRC::ClaimOption GetClaimByIndex(const CBlockIndex* const pblockindex);
130130
unsigned int GetCoinstakeOutputLimit(const int& block_version);
131131
Fraction FoundationSideStakeAllocation();
132132
CBitcoinAddress FoundationSideStakeAddress();
133-
unsigned int GetMRCOutputLimit(const int& block_version, bool include_foundation_sidestake = true);
133+
unsigned int GetMRCOutputLimit(const int& block_version, bool include_foundation_sidestake);
134134
bool ValidateMRC(const CBlockIndex* mrc_last_pindex, const GRC::MRC &mrc);
135135

136136
int GetNumBlocksOfPeers();
@@ -678,7 +678,7 @@ class CBlockIndex
678678
const int64_t research_subsidy,
679679
const double magnitude)
680680
{
681-
if (const auto cpid_option = mining_id.TryCpid()) {
681+
if (const GRC::CpidOption cpid_option = mining_id.TryCpid()) {
682682
if (research_subsidy > 0) {
683683
GRC::ResearcherContext* mrc_researcher = GRC::BlockIndexPool::GetNextResearcherContext();
684684

src/miner.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev,
424424
for (const auto& contract : tx.GetContracts()) {
425425
if (contract.m_type == GRC::ContractType::MRC) {
426426
// If we have reached the MRC output limit then don't include transactions with MRC contracts in the
427-
// mrc_tx_map. The intended foundation sidestake (if active) is excluded from the output limit here,
427+
// mrc_map. The intended foundation sidestake (if active) is excluded from the output limit here,
428428
// because that slot will be used in a sidestake of the fees to the foundation rather than an MRC
429429
// transaction output. Note that the transaction processing for the MRC that is not included still
430430
// occurs; it simply will not be paid out.
@@ -435,15 +435,18 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev,
435435
// This check as to whether CpidOption actually points to a valid Cpid should not be
436436
// strictly necessary, but is included here anyway for safety.
437437
if (const GRC::CpidOption mrc_cpid = mrc.m_mining_id.TryCpid()) {
438-
// The MRC should have already been checked in accept to mempool, but check again here?
439-
// TODO: Think about the use of pindexPrev here. If another block goes by and a straggler MRC
440-
// transaction is still in the memory pool, the validation will fail for that MRC here, because
441-
// the pindex recorded in the MRC will not match pindexPrev here.
438+
// The MRC should have already been checked in accept to mempool, but we will check again here.
442439
//
443-
// To insert an mrc onto the claim mrc_tx_map, the mrc_cpid must be a cpid, the mrc_cpid must
444-
// not be the same as the stakers cpid and the MRC must validate. This prevents the situation
440+
// To insert an mrc into the claim mrc_map, the mrc_cpid must be a cpid, the mrc_cpid must
441+
// not be the same as the stakers cpid, the cpid must be unique (i.e. the same cpid cannot
442+
// have more than one MRC per block, and the MRC must validate. This prevents the situation
445443
// where a researcher is staking and trying to process an MRC sent from themselves just before.
446-
// the researcher staker's MRC transaction will be expended just like other that are overflow.
444+
// the researcher staker's MRC transaction will be expended just like other that are overflow,
445+
// and ensures that only the highest priority mrc in the mempool gets processed for a unique
446+
// cpid. Note that the other mrc transactions will be bound to the mempool, but will be ignored,
447+
// so the mrc requester will lose the burn fees for the extra mrc requests. Note that the
448+
// production createmrcrequest will prevent more than one mrc in the mempool at a time for a
449+
// unique cpid, but it is also enforced here, because the sender could be modified.
447450
if ((!cpid || (mrc_cpid && cpid && *mrc_cpid != *cpid)) && ValidateMRC(pindexPrev, mrc)) {
448451
// Here the insert form instead of [] is used, because we want to use the first
449452
// mrc transaction in the mempool for a given cpid in order or priority, not the last
@@ -709,7 +712,9 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake
709712
// The maximum number of outputs allowed on the coinstake txn is 3 for block version 9 and below and
710713
// 8 for 10 and above (excluding MRC outputs). The first one must be empty, so that gives 2 and 7 usable ones,
711714
// respectively. MRC outputs are excluded here. They are above and beyond the below and addressed in CreateMRC.
712-
unsigned int nMaxOutputs = GetCoinstakeOutputLimit(blocknew.nVersion) - GetMRCOutputLimit(blocknew.nVersion);
715+
// Unlike in other areas, the foundation sidestake IS COUNTED in the GetMRCOutputLimit because it is a sidestake, but
716+
// handled in the CreateMRCRewards function and not here.
717+
unsigned int nMaxOutputs = GetCoinstakeOutputLimit(blocknew.nVersion) - GetMRCOutputLimit(blocknew.nVersion, true);
713718
// Set the maximum number of sidestake outputs to two less than the maximum allowable coinstake outputs
714719
// to ensure outputs are reserved for the coinstake output itself and the empty one. Any sidestake
715720
// addresses and percentages in excess of this number will be ignored.
@@ -1077,11 +1082,15 @@ bool CreateMRCRewards(CBlock &blocknew, std::map<GRC::Cpid, std::pair<uint256, G
10771082
CAmount rewards = 0;
10781083
CAmount staker_fees = 0;
10791084
CAmount foundation_fees = 0;
1085+
1086+
// Note that GetMRCOutputLimit handles the situation where FoundationSideStakeAllocation.IsNonZero is false or true.
10801087
unsigned int output_limit = GetMRCOutputLimit(blocknew.nVersion, false);
10811088

10821089
if (output_limit > 0) {
10831090
Fraction foundation_fee_fraction = FoundationSideStakeAllocation();
10841091

1092+
LogPrintf("INFO: %s: output_limit = %u", __func__, output_limit);
1093+
10851094
// We do not need to validate the MRCs here because that was already done in CreateRestOfTheBlock. This also means
10861095
// that the mrc tx hashes have been validated and the mrc_last_pindex matches the pindexPrev here (the head of the
10871096
// chain from the miner's point of view).

0 commit comments

Comments
 (0)