Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tweaks for block version 11 #1700

Merged
merged 4 commits into from
Jun 1, 2020
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: 6 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3426,12 +3426,16 @@ bool CBlock::CheckBlock(std::string sCaller, int height1, int64_t Mint, bool fCh
// is placed in the coinbase transaction instead to verify its integrity:
//
if (nVersion >= 11) {
if (claim.m_version <= 1) {
return DoS(100, error("%s: legacy claim", __func__));
}

if (!claim.WellFormed()) {
return DoS(100, error("CheckBlock[] : malformed claim"));
return DoS(100, error("%s: malformed claim", __func__));
}

if (claim.GetHash() != uint256S(vtx[0].hashBoinc)) {
return DoS(100, error("CheckBlock[] : claim hash mismatch"));
return DoS(100, error("%s: claim hash mismatch", __func__));
}
}

Expand Down
41 changes: 31 additions & 10 deletions src/neuralnet/claim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,37 @@ Claim Claim::Parse(const std::string& claim, int block_version)

bool Claim::WellFormed() const
{
return m_version > 0 && m_version <= Claim::CURRENT_VERSION
&& (m_version == 1
|| (m_mining_id.Valid()
&& !m_client_version.empty()
&& m_block_subsidy > 0
&& (m_mining_id.Which() == MiningId::Kind::INVESTOR
|| (m_research_subsidy > 0 && m_signature.size() > 0))
&& (!m_quorum_hash.Valid() || m_quorum_address.size() > 0)
)
);
if (m_version <= 0 || m_version > Claim::CURRENT_VERSION) {
return false;
}

if (m_version == 1) {
return true;
}

if (!m_mining_id.Valid()) {
return false;
}

if (m_client_version.empty()) {
return false;
}

if (m_block_subsidy <= 0) {
return false;
}

if (m_mining_id.Which() == MiningId::Kind::CPID) {
if (m_research_subsidy <= 0 || m_signature.empty()) {
return false;
}
}

if (m_quorum_hash.Valid() && !m_superblock.WellFormed()) {
return false;
}

return true;
}

bool Claim::HasResearchReward() const
Expand Down
24 changes: 20 additions & 4 deletions src/neuralnet/quorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ class SuperblockIndex
//!
void Reload(const CBlockIndex* pindexLast)
{
// Version 11+ blocks no longer rely on the tally trigger heights. We
// just find and load the most recent superblock:
//
if (pindexLast->nVersion >= 11) {
m_pending.clear();
m_cache.clear();

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

CBlock block;
block.ReadFromDisk(pindex);

PushSuperblock(SuperblockPtr::BindShared(
block.PullSuperblock(),
pindex));

return;
}

// Move committed superblocks back to pending. The next tally recount
// will commit the superblocks at the appropriate height.
//
Expand Down Expand Up @@ -1609,10 +1629,6 @@ void Quorum::LoadSuperblockIndex(const CBlockIndex* pindexLast)
}

g_superblock_index.Reload(pindexLast);

if (pindexLast->nVersion >= 11) {
g_superblock_index.Commit(pindexLast->nHeight);
}
}

Superblock Quorum::CreateSuperblock()
Expand Down
6 changes: 6 additions & 0 deletions src/neuralnet/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ bool Tally::ActivateSnapshotAccrual(const CBlockIndex* const pindex)
{
LogPrint(LogFlags::TALLY, "Activating snapshot accrual...");

// Activate any pending superblocks that may exist before the snapshot
// system kicks-in. The legacy tally caches superblocks in the pending
// state for 10 blocks before the recount trigger height.
//
Quorum::CommitSuperblock(pindex->nHeight);

return g_researcher_tally.ActivateSnapshotAccrual(
pindex,
Quorum::CurrentSuperblock());
Expand Down