Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,6 @@ bool GridcoinConnectBlock(
}

pindex->SetResearcherContext(claim.m_mining_id, claim.m_research_subsidy, magnitude);
pindex->nInterestSubsidy = claim.m_block_subsidy;

GRC::Tally::RecordRewardBlock(pindex);
GRC::Researcher::Refresh();
Expand Down Expand Up @@ -2264,7 +2263,6 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
return false;
}

pindex->nMint = nValueOut - nValueIn + nFees;
pindex->nMoneySupply = ReturnCurrentMoneySupply(pindex) + nValueOut - nValueIn;

if (!txdb.WriteBlockIndex(CDiskBlockIndex(pindex)))
Expand Down Expand Up @@ -3540,14 +3538,13 @@ void PrintBlockTree()
// print item
CBlock block;
block.ReadFromDisk(pindex);
LogPrintf("%d (%u,%u) %s %08x %s mint %7s tx %" PRIszu "",
LogPrintf("%d (%u,%u) %s %08x %s tx %" PRIszu "",
pindex->nHeight,
pindex->nFile,
pindex->nBlockPos,
block.GetHash(true).ToString().c_str(),
block.nBits,
DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(),
FormatMoney(pindex->nMint).c_str(),
block.vtx.size());

PrintWallets(block);
Expand Down Expand Up @@ -4849,42 +4846,37 @@ GRC::ClaimOption GetClaimByIndex(const CBlockIndex* const pblockindex)
return block.PullClaim();
}

/** Fees collected in block by miner **/
int64_t GetFeesCollected(const CBlock& block)
GRC::MintSummary CBlock::GetMint() const
{
// Return 0 if there is no transactions in block.
if (block.vtx.size() < 2)
return 0;

int64_t nFees = 0;
AssertLockHeld(cs_main);

CTxDB txdb("r");
GRC::MintSummary mint;

for (unsigned int i = 2; i < block.vtx.size(); i++)
{
int64_t nDebit = 0;
int64_t nCredit = 0;
const CTransaction& txData = block.vtx[i];
for (const auto& tx : vtx) {
const CAmount tx_amount_out = tx.GetValueOut();

// Scan inputs
for (const auto& txvinDataParse : txData.vin)
{
CTransaction txvinData;
if (tx.IsCoinBase()) {
mint.m_total += tx_amount_out;
continue;
}

if (txdb.ReadDiskTx(txvinDataParse.prevout.hash, txvinData))
nDebit += txvinData.vout[txvinDataParse.prevout.n].nValue;
CAmount tx_amount_in = 0;

else
return 0;
}
for (const auto& input : tx.vin) {
CTransaction input_tx;

// Scan outputs
for (const auto& txvoutDataParse : txData.vout)
nCredit += txvoutDataParse.nValue;
if (txdb.ReadDiskTx(input.prevout.hash, input_tx)) {
tx_amount_in += input_tx.vout[input.prevout.n].nValue;
}
}

// Since we now have the input and output amount results we calculate the fees spent
nFees += nDebit - nCredit;
if (tx.IsCoinStake()) {
mint.m_total += tx_amount_out - tx_amount_in;
} else {
mint.m_fees += tx_amount_in - tx_amount_out;
}
}

return nFees;
return mint;
}
31 changes: 18 additions & 13 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,19 @@ class CBlockHeader
}
};

namespace GRC {
//!
//! \brief A report that contains the calculated subsidy claimed in a block.
//! Produced by the CBlock::GetMint() method.
//!
class MintSummary
{
public:
CAmount m_total = 0; //!< Total value claimed by the block producer.
CAmount m_fees = 0; //!< Fees paid for the block's transactions.
};
}

class CBlock : public CBlockHeader
{
public:
Expand Down Expand Up @@ -1103,6 +1116,7 @@ class CBlock : public CBlockHeader
GRC::Claim PullClaim();
GRC::SuperblockPtr GetSuperblock() const;
GRC::SuperblockPtr GetSuperblock(const CBlockIndex* const pindex) const;
GRC::MintSummary GetMint() const;

// entropy bit for stake modifier if chosen by modifier
unsigned int GetStakeEntropyBit() const
Expand Down Expand Up @@ -1288,11 +1302,7 @@ class CBlockIndex
unsigned int nBlockPos;
arith_uint256 nChainTrust; // ppcoin: trust score of block chain
int nHeight;

int64_t nMint;
int64_t nMoneySupply;
int64_t nInterestSubsidy;

GRC::ResearcherContext* m_researcher;

unsigned int nFlags; // ppcoin: block index flags
Expand Down Expand Up @@ -1351,7 +1361,6 @@ class CBlockIndex
nBlockPos = 0;
nHeight = 0;
nChainTrust = 0;
nMint = 0;
nMoneySupply = 0;
nFlags = EMPTY_CPID;
nStakeModifier = 0;
Expand All @@ -1363,7 +1372,6 @@ class CBlockIndex
nBits = 0;
nNonce = 0;

nInterestSubsidy = 0;
m_researcher = nullptr;
}

Expand Down Expand Up @@ -1547,9 +1555,9 @@ class CBlockIndex

std::string ToString() const
{
return strprintf("CBlockIndex(nprev=%p, pnext=%p, nFile=%u, nBlockPos=%-6d nHeight=%d, nMint=%s, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016" PRIx64 ", hashProof=%s, merkle=%s, hashBlock=%s)",
return strprintf("CBlockIndex(nprev=%p, pnext=%p, nFile=%u, nBlockPos=%-6d nHeight=%d, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016" PRIx64 ", hashProof=%s, merkle=%s, hashBlock=%s)",
pprev, pnext, nFile, nBlockPos, nHeight,
FormatMoney(nMint), FormatMoney(nMoneySupply),
FormatMoney(nMoneySupply),
GeneratedStakeModifier() ? "MOD" : "-", GetStakeEntropyBit(), IsProofOfStake()? "PoS" : "PoW",
nStakeModifier,
hashProof.ToString(),
Expand Down Expand Up @@ -1601,6 +1609,7 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(nFile);
READWRITE(nBlockPos);
READWRITE(nHeight);
int64_t nMint = 0; // removed
READWRITE(nMint);
READWRITE(nMoneySupply);
READWRITE(nFlags);
Expand Down Expand Up @@ -1629,7 +1638,7 @@ class CDiskBlockIndex : public CBlockIndex
//7-11-2015 - Gridcoin - New Accrual Fields (Note, Removing the deterministic block number to make this happen all the time):
std::string cpid_hex = GetMiningId().ToString();
double research_subsidy_grc = ResearchSubsidy() / (double)COIN;
double interest_subsidy_grc = nInterestSubsidy / (double)COIN;
double interest_subsidy_grc = 0; // removed
double magnitude = Magnitude();

READWRITE(cpid_hex);
Expand Down Expand Up @@ -1663,8 +1672,6 @@ class CDiskBlockIndex : public CBlockIndex
research_subsidy_grc * COIN,
magnitude);

nInterestSubsidy = interest_subsidy_grc * COIN;

if (is_superblock == 1) {
NCONST_PTR(this)->MarkAsSuperblock();
}
Expand Down Expand Up @@ -1888,6 +1895,4 @@ class CTxMemPool
};

extern CTxMemPool mempool;

int64_t GetFeesCollected(const CBlock& block);
#endif
13 changes: 4 additions & 9 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fP

result.pushKV("hash", block.GetHash().GetHex());

const GRC::MintSummary mint = block.GetMint();

CMerkleTx txGen(block.vtx[0]);
txGen.SetMerkleBranch(&block);

Expand All @@ -133,7 +135,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fP
result.pushKV("height", blockindex->nHeight);
result.pushKV("version", block.nVersion);
result.pushKV("merkleroot", block.hashMerkleRoot.GetHex());
result.pushKV("mint", ValueFromAmount(blockindex->nMint));
result.pushKV("mint", ValueFromAmount(mint.m_total));
result.pushKV("MoneySupply", ValueFromAmount(blockindex->nMoneySupply));
result.pushKV("time", block.GetBlockTime());
result.pushKV("nonce", (uint64_t)block.nNonce);
Expand Down Expand Up @@ -192,7 +194,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fP
result.pushKV("superblock", SuperblockToJson(block.GetSuperblock()));
}

result.pushKV("fees_collected", ValueFromAmount(GetFeesCollected(block)));
result.pushKV("fees_collected", ValueFromAmount(mint.m_fees));
result.pushKV("IsSuperBlock", blockindex->IsSuperblock());
result.pushKV("IsContract", blockindex->IsContract());

Expand Down Expand Up @@ -1456,14 +1458,12 @@ UniValue network(const UniValue& params, bool fHelp)
const double money_supply = pindexBest->nMoneySupply;
const GRC::SuperblockPtr superblock = GRC::Quorum::CurrentSuperblock();

int64_t two_week_block_subsidy = 0;
int64_t two_week_research_subsidy = 0;

for (const CBlockIndex* pindex = pindexBest;
pindex && pindex->nTime > two_weeks_ago;
pindex = pindex->pprev)
{
two_week_block_subsidy += pindex->nInterestSubsidy;
two_week_research_subsidy += pindex->ResearchSubsidy();
}

Expand All @@ -1473,12 +1473,7 @@ UniValue network(const UniValue& params, bool fHelp)
res.pushKV("research_paid_two_weeks", ValueFromAmount(two_week_research_subsidy));
res.pushKV("research_paid_daily_average", ValueFromAmount(two_week_research_subsidy / 14));
res.pushKV("research_paid_daily_limit", ValueFromAmount(GRC::Tally::MaxEmission(now)));
res.pushKV("stake_paid_two_weeks", ValueFromAmount(two_week_block_subsidy));
res.pushKV("stake_paid_daily_average", ValueFromAmount(two_week_block_subsidy / 14));
res.pushKV("total_money_supply", ValueFromAmount(money_supply));
res.pushKV("network_interest_percent", money_supply > 0
? (two_week_block_subsidy / 14) * 365 / money_supply
: 0);

return res;
}
Expand Down
13 changes: 9 additions & 4 deletions src/rpcdataacq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ UniValue rpc_getblockstats(const UniValue& params, bool fHelp)
int64_t researchtotal = 0;
int64_t interesttotal = 0;
int64_t minttotal = 0;
int64_t feetotal = 0;
int64_t poscount = 0;
int64_t emptyblockscount = 0;
int64_t l_first = std::numeric_limits<int>::max();
Expand Down Expand Up @@ -168,6 +169,8 @@ UniValue rpc_getblockstats(const UniValue& params, bool fHelp)
}
}

const GRC::MintSummary mint = block.GetMint();

transactioncount += txcountinblock;
emptyblockscount += (txcountinblock == 0);
c_blockversion[block.nVersion]++;
Expand All @@ -178,7 +181,8 @@ UniValue rpc_getblockstats(const UniValue& params, bool fHelp)
researchtotal += claim.m_research_subsidy;
interesttotal += claim.m_block_subsidy;
researchcount += claim.HasResearchReward();
minttotal += cur->nMint;
minttotal += mint.m_total;
feetotal += mint.m_fees;
unsigned sizeblock = GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION);
size_min_blk = std::min(size_min_blk,sizeblock);
size_max_blk = std::max(size_max_blk,sizeblock);
Expand Down Expand Up @@ -241,6 +245,7 @@ UniValue rpc_getblockstats(const UniValue& params, bool fHelp)
result.pushKV("research", ValueFromAmount(researchtotal));
result.pushKV("interest", ValueFromAmount(interesttotal));
result.pushKV("mint", ValueFromAmount(minttotal));
result.pushKV("fees", ValueFromAmount(feetotal));
result.pushKV("blocksizek", size_sum_blk / (double) 1024);
result.pushKV("posdiff", diff_sum);
result1.pushKV("totals", result);
Expand All @@ -256,6 +261,7 @@ UniValue rpc_getblockstats(const UniValue& params, bool fHelp)
result.pushKV("research", ValueFromAmount(research_average));
result.pushKV("interest", ValueFromAmount(interesttotal / blockcount));
result.pushKV("mint", ValueFromAmount(minttotal / blockcount));
result.pushKV("fees", ValueFromAmount(feetotal / blockcount));

double spacing_sec = (l_last_time - l_first_time) / (double) (blockcount - 1);
result.pushKV("spacing_sec", spacing_sec);
Expand Down Expand Up @@ -752,8 +758,7 @@ UniValue rpc_getrecentblocks(const UniValue& params, bool fHelp)
if(detail>=2 && detail<20)
{
line+="<|>"+cur->GetMiningId().ToString()
+ "<|>"+FormatMoney(cur->ResearchSubsidy())
+ "<|>"+FormatMoney(cur->nInterestSubsidy);
+ "<|>"+FormatMoney(cur->ResearchSubsidy());
}
}
else
Expand All @@ -766,7 +771,6 @@ UniValue rpc_getrecentblocks(const UniValue& params, bool fHelp)
result2.pushKV("ismodifier", cur->GeneratedStakeModifier());
result2.pushKV("cpid", cur->GetMiningId().ToString() );
result2.pushKV("research", ValueFromAmount(cur->ResearchSubsidy()));
result2.pushKV("interest", ValueFromAmount(cur->nInterestSubsidy));
result2.pushKV("magnitude", cur->Magnitude());
}

Expand Down Expand Up @@ -794,6 +798,7 @@ UniValue rpc_getrecentblocks(const UniValue& params, bool fHelp)
}
else
{
result2.pushKV("interest", ValueFromAmount(claim.m_block_subsidy));
result2.pushKV("organization", claim.m_organization);
result2.pushKV("cversion", claim.m_client_version);
result2.pushKV("quorum_hash", claim.m_quorum_hash.ToString());
Expand Down
3 changes: 2 additions & 1 deletion src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ std::vector<std::pair<std::string, std::string>> GetTxStakeBoincHashInfo(const C
}

const GRC::Claim& claim = block.GetClaim();
const GRC::MintSummary mint = block.GetMint();

res.push_back(std::make_pair(_("Height"), ToString(pindex->nHeight)));
res.push_back(std::make_pair(_("Block Version"), ToString(block.nVersion)));
Expand All @@ -63,7 +64,7 @@ std::vector<std::pair<std::string, std::string>> GetTxStakeBoincHashInfo(const C
res.push_back(std::make_pair(_("Magnitude"), RoundToString(pindex->Magnitude(), 8)));
}

res.push_back(std::make_pair(_("Fees Collected"), FormatMoney(GetFeesCollected(block))));
res.push_back(std::make_pair(_("Fees Collected"), FormatMoney(mint.m_fees)));
res.push_back(std::make_pair(_("Is Superblock"), (claim.ContainsSuperblock() ? "Yes" : "No")));

if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE))
Expand Down
5 changes: 1 addition & 4 deletions src/txdb-leveldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ bool CTxDB::LoadBlockIndex()
pindexNew->nFile = diskindex.nFile;
pindexNew->nBlockPos = diskindex.nBlockPos;
pindexNew->nHeight = diskindex.nHeight;
pindexNew->nMint = diskindex.nMint;
pindexNew->nMoneySupply = diskindex.nMoneySupply;
pindexNew->nFlags = diskindex.nFlags;
pindexNew->nStakeModifier = diskindex.nStakeModifier;
Expand All @@ -369,9 +368,7 @@ bool CTxDB::LoadBlockIndex()
pindexNew->nTime = diskindex.nTime;
pindexNew->nBits = diskindex.nBits;
pindexNew->nNonce = diskindex.nNonce;

pindexNew->nInterestSubsidy = diskindex.nInterestSubsidy;
pindexNew->m_researcher = diskindex.m_researcher;
pindexNew->m_researcher = diskindex.m_researcher;

nBlockCount++;
// Watch for genesis block
Expand Down