Skip to content

Commit

Permalink
Fix accrual snapshot heights
Browse files Browse the repository at this point in the history
Incorrect order of statements caused the snapshot system to store
snapshots with the accrual data for the previous superblock. This
fixes the issue by ordering the statements so that snapshot files
contain the accrual values for the time right up until the height
of the superblock that a snapshot is labeled for.
  • Loading branch information
cyrossignol authored and jamescowens committed Jun 16, 2020
1 parent 2c7f15c commit b28b923
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/neuralnet/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ class ResearcherTally
// switch to block version 11.
//
if (superblock->m_version >= 2) {
TallySuperblockAccrual(superblock.m_timestamp);

if (!m_snapshots.Store(superblock.m_height, m_researchers)) {
return false;
}

TallySuperblockAccrual(superblock.m_timestamp);
}

m_current_superblock = std::move(superblock);
Expand All @@ -288,8 +288,8 @@ class ResearcherTally
{
if (m_current_superblock->m_version >= 2) {
try {
return m_snapshots.ApplyLatest(m_researchers)
&& m_snapshots.Drop(m_current_superblock.m_height);
return m_snapshots.Drop(m_current_superblock.m_height)
&& m_snapshots.ApplyLatest(m_researchers);
} catch (const SnapshotStateError& e) {
LogPrintf("%s: %s", e.what());

Expand All @@ -312,7 +312,9 @@ class ResearcherTally
//! \return \c false if the snapshot system failed to initialize because of
//! an error.
//!
bool ActivateSnapshotAccrual(const CBlockIndex* const pindex)
bool ActivateSnapshotAccrual(
const CBlockIndex* const 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
Expand All @@ -324,6 +326,7 @@ class ResearcherTally
}

m_snapshot_baseline_pindex = pindex;
m_current_superblock = std::move(superblock);

try {
if (!m_snapshots.Initialize()) {
Expand Down Expand Up @@ -574,7 +577,9 @@ bool Tally::ActivateSnapshotAccrual(const CBlockIndex* const pindex)
//
Quorum::CommitSuperblock(pindex->nHeight);

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

bool Tally::IsLegacyTrigger(const uint64_t height)
Expand Down

0 comments on commit b28b923

Please sign in to comment.