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
8 changes: 4 additions & 4 deletions src/gridcoin/accrual/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ class SnapshotBaselineBuilder
int64_t payment_time = current_superblock.m_timestamp;

for (; pindex && pindex->nHeight > max_depth; pindex = pindex->pprev) {
if (pindex->nIsSuperBlock != 1) {
if (!pindex->IsSuperblock()) {
continue;
}

Expand All @@ -1533,7 +1533,7 @@ class SnapshotBaselineBuilder

// If the maximum depth is a superblock, we're done.
//
if (pindex->nIsSuperBlock == 1) {
if (pindex->IsSuperblock()) {
return true;
}

Expand All @@ -1547,7 +1547,7 @@ class SnapshotBaselineBuilder
const CBlockIndex* const pindex_max = pindex;

for (; pindex; pindex = pindex->pprev) {
if (pindex->nIsSuperBlock != 1) {
if (!pindex->IsSuperblock()) {
continue;
}

Expand Down Expand Up @@ -1590,7 +1590,7 @@ class SnapshotBaselineBuilder
const CBlockIndex* const pindex,
const CBlockIndex* const pindex_bind = nullptr)
{
assert(pindex->nIsSuperBlock == 1);
assert(pindex->IsSuperblock());

LogPrint(LogFlags::TALLY, " Superblock: %" PRId64, pindex->nHeight);

Expand Down
4 changes: 2 additions & 2 deletions src/gridcoin/contract/contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ void GRC::ReplayContracts(const CBlockIndex* pindex)

// These are memorized consecutively in order from oldest to newest.
for (; pindex; pindex = pindex->pnext) {
if (pindex->nIsContract == 1) {
if (pindex->IsContract()) {
if (!block.ReadFromDisk(pindex)) {
continue;
}
Expand All @@ -437,7 +437,7 @@ void GRC::ReplayContracts(const CBlockIndex* pindex)
ApplyContracts(block, pindex, unused);
}

if (pindex->nIsSuperBlock == 1 && pindex->nVersion >= 11) {
if (pindex->IsSuperblock() && pindex->nVersion >= 11) {
if (block.hashPrevBlock != pindex->pprev->GetBlockHash()
&& !block.ReadFromDisk(pindex))
{
Expand Down
4 changes: 2 additions & 2 deletions src/gridcoin/quorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class SuperblockIndex
m_cache.clear();

const CBlockIndex* pindex = pindexLast;
for (; pindex && pindex->nIsSuperBlock != 1; pindex = pindex->pprev);
for (; pindex && !pindex->IsSuperblock(); pindex = pindex->pprev);

m_cache.emplace_front(SuperblockPtr::ReadFromDisk(pindex));

Expand Down Expand Up @@ -213,7 +213,7 @@ class SuperblockIndex
// better index when we implement superblock windows:
//
while (m_pending.size() < CACHE_SIZE) {
while (pindexLast->nIsSuperBlock != 1) {
while (!pindexLast->IsSuperblock()) {
if (!pindexLast->pprev) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/superblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ SuperblockPtr SuperblockPtr::ReadFromDisk(const CBlockIndex* const pindex)
return Empty();
}

if (pindex->nIsSuperBlock != 1) {
if (!pindex->IsSuperblock()) {
error("%s: %" PRId64 " is not a superblock", __func__, pindex->nHeight);
return Empty();
}
Expand Down
6 changes: 3 additions & 3 deletions src/gridcoin/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class ResearcherTally
pindex;
pindex = pindex->pnext)
{
if (pindex->nIsSuperBlock == 1) {
if (pindex->IsSuperblock()) {
m_snapshots.AssertMatch(pindex->nHeight);
}

Expand Down Expand Up @@ -584,7 +584,7 @@ class ResearcherTally
pindex;
pindex = pindex->pprev)
{
if (pindex->nIsSuperBlock != 1) {
if (!pindex->IsSuperblock()) {
continue;
}

Expand Down Expand Up @@ -665,7 +665,7 @@ class ResearcherTally
pindex;
pindex = pindex->pnext)
{
if (pindex->nIsSuperBlock == 1) {
if (pindex->IsSuperblock()) {
if (!ApplySuperblock(SuperblockPtr::ReadFromDisk(pindex))) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/voting/builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class MagnitudeClaimBuilder
for (; pindex && pindex->nTime > max_time; pindex = pindex->pprev);

for (; pindex && pindex->nTime > min_time; pindex = pindex->pprev) {
if (pindex->nIsContract != 1) {
if (!pindex->IsContract()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/voting/result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ SuperblockPtr ResolveSuperblockForPoll(const Poll& poll)

// Find the superblock active at the end of the poll:
for (; pindex; pindex = pindex->pprev) {
if (pindex->nIsSuperBlock != 1 || poll.Expired(pindex->nTime)) {
if (!pindex->IsSuperblock() || poll.Expired(pindex->nTime)) {
continue;
}

Expand Down
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ bool GridcoinConnectBlock(
return false;
}

pindex->nIsSuperBlock = 1;
pindex->MarkAsSuperblock();
} else if (block.nVersion <= 10) {
// Block versions 11+ validate superblocks from scraper convergence
// instead of the legacy quorum system so we only record votes from
Expand All @@ -2085,7 +2085,10 @@ bool GridcoinConnectBlock(
pindex->SetMiningId(claim.m_mining_id);
pindex->nResearchSubsidy = claim.m_research_subsidy;
pindex->nInterestSubsidy = claim.m_block_subsidy;
pindex->nIsContract = found_contract;

if (found_contract) {
pindex->MarkAsContract();
}

if (block.nVersion >= 11) {
pindex->nMagnitude = GRC::Quorum::GetMagnitude(claim.m_mining_id).Floating();
Expand Down Expand Up @@ -2367,7 +2370,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list<CTransaction>& vResurrect, unsigned
GRC::Tally::ForgetRewardBlock(pindexBest);
}

if (pindexBest->nIsSuperBlock == 1) {
if (pindexBest->IsSuperblock()) {
GRC::Quorum::PopSuperblock(pindexBest);
GRC::Quorum::LoadSuperblockIndex(pindexBest->pprev);

Expand Down
58 changes: 43 additions & 15 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -1300,9 +1300,6 @@ class CBlockIndex
int64_t nResearchSubsidy;
int64_t nInterestSubsidy;
double nMagnitude;
// Indicators (9-13-2015)
unsigned int nIsSuperBlock;
unsigned int nIsContract;

unsigned int nFlags; // ppcoin: block index flags
enum
Expand All @@ -1312,6 +1309,8 @@ class CBlockIndex
BLOCK_STAKE_MODIFIER = (1 << 2), // regenerated stake modifier
EMPTY_CPID = (1 << 3), // CPID is empty
INVESTOR_CPID = (1 << 4), // CPID equals "INVESTOR"
SUPERBLOCK = (1 << 5), // Block contains a superblock
CONTRACT = (1 << 6), // Block contains a contract
};

uint64_t nStakeModifier; // hash modifier for proof-of-stake
Expand Down Expand Up @@ -1374,8 +1373,6 @@ class CBlockIndex
nResearchSubsidy = 0;
nInterestSubsidy = 0;
nMagnitude = 0;
nIsSuperBlock = 0;
nIsContract = 0;
}

CBlockHeader GetBlockHeader() const
Expand Down Expand Up @@ -1509,6 +1506,25 @@ class CBlockIndex
return GRC::MiningId(cpid);
}

bool IsSuperblock() const
{
return nFlags & SUPERBLOCK;
}

void MarkAsSuperblock()
{
nFlags |= SUPERBLOCK;
}

bool IsContract() const
{
return nFlags & CONTRACT;
}

void MarkAsContract()
{
nFlags |= CONTRACT;
}

std::string ToString() const
{
Expand Down Expand Up @@ -1599,19 +1615,15 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(cpid_hex);
READWRITE(research_subsidy_grc);
READWRITE(interest_subsidy_grc);

if (ser_action.ForRead()) {
const_cast<CDiskBlockIndex*>(this)->SetMiningId(GRC::MiningId::Parse(cpid_hex));
nResearchSubsidy = research_subsidy_grc * COIN;
nInterestSubsidy = interest_subsidy_grc * COIN;
}

READWRITE(nMagnitude);

//9-13-2015 - Indicators
// Superblock and contract flags merged into nFlags:
uint32_t is_superblock = this->IsSuperblock();
uint32_t is_contract = this->IsContract();

if (this->nHeight > nNewIndex2) {
READWRITE(nIsSuperBlock);
READWRITE(nIsContract);
READWRITE(is_superblock);
READWRITE(is_contract);

std::string dummy;

Expand All @@ -1622,6 +1634,22 @@ class CDiskBlockIndex : public CBlockIndex
// it until it's used.
READWRITE(dummy);
}

// Translate legacy disk format to memory format:
//
if (ser_action.ForRead()) {
NCONST_PTR(this)->SetMiningId(GRC::MiningId::Parse(cpid_hex));
nResearchSubsidy = research_subsidy_grc * COIN;
nInterestSubsidy = interest_subsidy_grc * COIN;

if (is_superblock == 1) {
NCONST_PTR(this)->MarkAsSuperblock();
}

if (is_contract == 1) {
NCONST_PTR(this)->MarkAsContract();
}
}
}

uint256 GetBlockHash() const
Expand Down
8 changes: 4 additions & 4 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fP

if (LogInstance().WillLogCategory(BCLog::LogFlags::NET)) result.pushKV("BoincHash",block.vtx[0].hashBoinc);

if (fPrintTransactionDetail && blockindex->nIsSuperBlock == 1) {
if (fPrintTransactionDetail && blockindex->IsSuperblock()) {
result.pushKV("superblock", SuperblockToJson(block.GetSuperblock()));
}

result.pushKV("fees_collected", ValueFromAmount(GetFeesCollected(block)));
result.pushKV("IsSuperBlock", (int)blockindex->nIsSuperBlock);
result.pushKV("IsContract", (int)blockindex->nIsContract);
result.pushKV("IsSuperBlock", blockindex->IsSuperblock());
result.pushKV("IsContract", blockindex->IsContract());

return result;
}
Expand Down Expand Up @@ -1809,7 +1809,7 @@ UniValue SuperblockReport(int lookback, bool displaycontract, std::string cpid)
pblockindex = pblockindex->pprev;
if (pblockindex == pindexGenesisBlock) return results;
if (!pblockindex->IsInMainChain()) continue;
if (pblockindex->nIsSuperBlock == 1)
if (pblockindex->IsSuperblock())
{
const GRC::ClaimOption claim = GetClaimByIndex(pblockindex);

Expand Down
14 changes: 7 additions & 7 deletions src/rpcdataacq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ UniValue rpc_getsupervotes(const UniValue& params, bool fHelp)
result1.pushKV("error","Superblock not found in block index");
return result1;
}
if(!pblockindex->nIsSuperBlock)
if(!pblockindex->IsSuperblock())
{
result1.pushKV("height_cache", height);
result1.pushKV("block_hash",pblockindex->GetBlockHash().GetHex());
Expand Down Expand Up @@ -384,7 +384,7 @@ UniValue rpc_getsupervotes(const UniValue& params, bool fHelp)

CBlockIndex* pblockindex = mapBlockIndex[hash];

if(!pblockindex->nIsSuperBlock)
if(!pblockindex->IsSuperblock())
{
result1.pushKV("block_hash",pblockindex->GetBlockHash().GetHex());
result1.pushKV("error","Requested block is not a Superblock");
Expand Down Expand Up @@ -584,7 +584,7 @@ UniValue rpc_exportstats(const UniValue& params, bool fHelp)
max_spacing=std::max(max_spacing,i_spacing);

cnt_investor += !! (cur->nFlags & CBlockIndex::INVESTOR_CPID);
cnt_contract += !! cur->nIsContract;
cnt_contract += !! cur->IsContract();

CBlock block;
if(!block.ReadFromDisk(cur->nFile,cur->nBlockPos,true))
Expand Down Expand Up @@ -743,7 +743,7 @@ UniValue rpc_getrecentblocks(const UniValue& params, bool fHelp)
+ "<|>"+ToString(delta);

line+= "<|>"
+ std::string((cur->nIsSuperBlock?"S":(cur->nIsContract?"C":"-")))
+ std::string((cur->IsSuperblock()?"S":(cur->IsContract()?"C":"-")))
+ (cur->IsUserCPID()? (cur->nResearchSubsidy>0? "R": "U"): "I")
//+ (cur->GeneratedStakeModifier()? "M": "-")
;
Expand All @@ -761,9 +761,9 @@ UniValue rpc_getrecentblocks(const UniValue& params, bool fHelp)
result2.pushKV("hash", line );
result2.pushKV("difficulty", diff );
result2.pushKV("deltatime", (int64_t)delta );
result2.pushKV("issuperblock", (bool)cur->nIsSuperBlock );
result2.pushKV("iscontract", (bool)cur->nIsContract );
result2.pushKV("ismodifier", (bool)cur->GeneratedStakeModifier() );
result2.pushKV("issuperblock", cur->IsSuperblock());
result2.pushKV("iscontract", cur->IsContract());
result2.pushKV("ismodifier", cur->GeneratedStakeModifier());
result2.pushKV("cpid", cur->GetMiningId().ToString() );
result2.pushKV("research", ValueFromAmount(cur->nResearchSubsidy));
result2.pushKV("interest", ValueFromAmount(cur->nInterestSubsidy));
Expand Down
6 changes: 3 additions & 3 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)
pindex_superblock;
pindex_superblock = pindex_superblock->pprev)
{
if (pindex_superblock->nIsSuperBlock == 1) {
if (pindex_superblock->IsSuperblock()) {
superblock = SuperblockPtr::ReadFromDisk(pindex_superblock);
break;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)

accrual = 0;
pindex_low = pindex;
} else if (pindex->nIsSuperBlock == 1) {
} else if (pindex->IsSuperblock()) {
tally_accrual_period(
"superblock",
pindex->nHeight,
Expand All @@ -321,7 +321,7 @@ UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)
pindex_low = pindex;
}

if (pindex->nIsSuperBlock == 1) {
if (pindex->IsSuperblock()) {
superblock = SuperblockPtr::ReadFromDisk(pindex);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/txdb-leveldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,6 @@ bool CTxDB::LoadBlockIndex()
pindexNew->nResearchSubsidy = diskindex.nResearchSubsidy;
pindexNew->nInterestSubsidy = diskindex.nInterestSubsidy;
pindexNew->nMagnitude = diskindex.nMagnitude;
pindexNew->nIsContract = diskindex.nIsContract;
pindexNew->nIsSuperBlock = diskindex.nIsSuperBlock;

nBlockCount++;
// Watch for genesis block
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,7 @@ MinedType GetGeneratedType(const CWallet *wallet, const uint256& tx, unsigned in
// that corresponds (is integral to) the block. We check whether
// the block is a superblock, and if so we set the MinedType to
// SUPERBLOCK if vout is 1 as that should override the others here.
if (vout == 1 && blkindex->nIsSuperBlock)
if (vout == 1 && blkindex->IsSuperblock())
{
return MinedType::SUPERBLOCK;
}
Expand Down