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

accrual: Fix snapshot accrual superblock state transitions #1752

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
17 changes: 9 additions & 8 deletions src/neuralnet/quorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,14 @@ class SuperblockValidator
return &m_resolved_projects.at(project);
}

// The special beacon list and verified beacons parts are stored as
// projects parts. These are not considered for convergence at this
// stage:
//
if (project == "BeaconList" || project == "VerifiedBeacons") {
return nullptr;
}

m_other_projects[project].emplace(scraper_id);

return nullptr;
Expand Down Expand Up @@ -1205,14 +1213,7 @@ class SuperblockValidator
// If this project does not exist in the superblock, skip the
// attempt to associate its parts:
//
// Skip the BeaconList, which is always part 0, and skip
// the VerifiedBeacons "project", which is matched by project
// name.
if (!project_option
|| entry.part1 < 1
|| entry.project == "VerifiedBeacons"
|| entry.part1 >= (int)manifest.vParts.size())
{
if (!project_option || entry.part1 >= (int)manifest.vParts.size()) {
continue;
}

Expand Down
20 changes: 8 additions & 12 deletions src/neuralnet/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ class ResearcherTally
{
if (m_current_superblock->m_version >= 2) {
try {
return m_snapshots.Drop(m_current_superblock.m_height)
&& m_snapshots.ApplyLatest(m_researchers);
return m_snapshots.ApplyLatest(m_researchers)
&& m_snapshots.Drop(m_current_superblock.m_height);
} catch (const SnapshotStateError& e) {
LogPrintf("%s: %s", e.what());

Expand All @@ -357,13 +357,8 @@ class ResearcherTally
const CBlockIndex* const baseline_pindex,
SuperblockPtr superblock)
{
// Someone might run one of the snapshot accrual testing RPCs before
// the chain is synchronized. We allow this after passing version 10
// for testing, but it won't actually apply to accrual until version
// 11 blocks arrive.
//
if (!baseline_pindex || !IsV10Enabled(baseline_pindex->nHeight)) {
return true;
if (!baseline_pindex || !IsV11Enabled(baseline_pindex->nHeight + 1)) {
return false;
}

m_snapshot_baseline_pindex = baseline_pindex;
Expand Down Expand Up @@ -491,14 +486,15 @@ class ResearcherTally
{
const SnapshotCalculator calc(payment_time, m_current_superblock);

for (const auto& cpid_pair : m_current_superblock->m_cpids) {
ResearchAccount& account = m_researchers[cpid_pair.Cpid()];
for (auto& account_pair : m_researchers) {
const Cpid cpid = account_pair.first;
ResearchAccount& account = account_pair.second;

if (account.LastRewardHeight() >= m_current_superblock.m_height) {
account.m_accrual = 0;
}

account.m_accrual += calc.AccrualDelta(cpid_pair.Cpid(), account);
account.m_accrual += calc.AccrualDelta(cpid, account);
}
}

Expand Down
22 changes: 4 additions & 18 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,6 @@ UniValue getmininginfo(const UniValue& params, bool fHelp)
return obj;
}


UniValue activatesnapshotaccrual(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"activatesnapshotaccrual\n"
"\n"
"TESTING ONLY: enable delta research reward accrual calculations.\n");

LOCK(cs_main);

return NN::Tally::ActivateSnapshotAccrual(pindexBest);
}

UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 1)
Expand Down Expand Up @@ -191,8 +177,8 @@ UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)

LOCK(cs_main);

if (!NN::Tally::ActivateSnapshotAccrual(pindexBest)) {
throw JSONRPCError(RPC_MISC_ERROR, "Snapshot accrual activation failed.");
if (!IsV11Enabled(nBestHeight + 1)) {
throw JSONRPCError(RPC_INVALID_REQUEST, "Wait for block v11 protocol");
}

const int64_t now = GetAdjustedTime();
Expand Down Expand Up @@ -419,8 +405,8 @@ UniValue comparesnapshotaccrual(const UniValue& params, bool fHelp)

LOCK(cs_main);

if (!NN::Tally::ActivateSnapshotAccrual(pindexBest)) {
throw JSONRPCError(RPC_MISC_ERROR, "Snapshot accrual activation failed.");
if (!IsV11Enabled(nBestHeight + 1)) {
throw JSONRPCError(RPC_INVALID_REQUEST, "Wait for block v11 protocol");
}

for (const auto& account_pair : NN::Tally::Accounts()) {
Expand Down
1 change: 0 additions & 1 deletion src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ static const CRPCCommand vRPCCommands[] =
{ "superblocks", &superblocks, cat_mining },

// Developer commands
{ "activatesnapshotaccrual", &activatesnapshotaccrual, cat_developer },
{ "auditsnapshotaccrual", &auditsnapshotaccrual, cat_developer },
{ "addkey", &addkey, cat_developer },
{ "comparesnapshotaccrual", &comparesnapshotaccrual, cat_developer },
Expand Down
1 change: 0 additions & 1 deletion src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ extern UniValue superblockage(const UniValue& params, bool fHelp);
extern UniValue superblocks(const UniValue& params, bool fHelp);

// Developers
extern UniValue activatesnapshotaccrual(const UniValue& params, bool fHelp);
extern UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp);
extern UniValue addkey(const UniValue& params, bool fHelp);
extern UniValue comparesnapshotaccrual(const UniValue& params, bool fHelp);
Expand Down