Skip to content

Commit

Permalink
5.3.0.0, 2021-03-16, mandatory
Browse files Browse the repository at this point in the history
Fixed
 - consensus, accrual: Fix accrual post hard-fork at 2197000 #2053 (@jamescowens, @div72, @cyrossignol)
  • Loading branch information
jamescowens committed Mar 16, 2021
2 parents 50b3067 + 8a52193 commit 7f75aec
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [5.3.0.0] 2021-03-16, mandatory
### Fixed
- consensus, accrual: Fix accrual post hard-fork at 2197000 #2053 (@jamescowens, @div72, @cyrossignol)

## [5.2.2.0] 2021-03-14, leisure
### Fixed
- beacon, contracts: Fix sync from zero issue due to ApplyContracts problem in 5.2.1.0 #2047 (@jamescowens)
- beacon, contracts: Fix sync from zero issue due to ApplyContracts problem in 5.2.1.0 #2047 (@jamescowens)

## [5.2.1.0] 2021-03-07, leisure
### Added
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 5)
define(_CLIENT_VERSION_MINOR, 2)
define(_CLIENT_VERSION_REVISION, 2)
define(_CLIENT_VERSION_MINOR, 3)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2021)
Expand Down
54 changes: 40 additions & 14 deletions src/gridcoin/accrual/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,24 @@ class SnapshotMissingError : public SnapshotStateError
}
}; // SnapshotMissingError

//!
//! \brief Thrown when the snapshot registry file format on disk does not match
//! the current version supported by the application.
//!
class SnapshotRegistryVersionMismatchError : public SnapshotStateError
{
public:
explicit SnapshotRegistryVersionMismatchError(
const uint32_t disk_version,
const uint32_t min_supported_version)
: SnapshotStateError(strprintf(
"Unsupported snapshot registry version: %" PRIu32 " < %" PRIu32,
disk_version,
min_supported_version))
{
}
}; // SnapshotRegistryVersionMismatchError

//!
//! \brief Maintains context for the set of active accrual snapshots.
//!
Expand All @@ -771,7 +789,13 @@ class AccrualSnapshotRegistry
//! \brief Version number of the current format for a serialized registry
//! file.
//!
static constexpr uint32_t CURRENT_VERSION = 1;
//! Version 1: Format released with the snapshot accrual system in v5.0.0.
//!
//! Version 2: Version incremented to force the accrual snapshot system to
//! rebuild the stored snapshot state to fix a bug for v5.2.3. Disk format
//! does not change.
//!
static constexpr uint32_t CURRENT_VERSION = 2;

//!
//! \brief A record of an accrual snapshot in the registry.
Expand Down Expand Up @@ -831,19 +855,15 @@ class AccrualSnapshotRegistry
return false;
}

try {
CAutoFile registry_file(
fsbridge::fopen(RegistryPath(), "rb"),
SER_DISK,
CURRENT_VERSION);

if (!registry_file.IsNull()) {
Unserialize(registry_file);
} else {
m_entries.clear();
}
} catch (const std::exception& e) {
return error("%s: %s", __func__, e.what());
CAutoFile registry_file(
fsbridge::fopen(RegistryPath(), "rb"),
SER_DISK,
CURRENT_VERSION);

if (!registry_file.IsNull()) {
Unserialize(registry_file);
} else {
m_entries.clear();
}

LogPrintf("Accrual snapshot registry loaded. Compacting...");
Expand Down Expand Up @@ -1171,6 +1191,12 @@ class AccrualSnapshotRegistry
uint32_t version;
file >> version;

if (version != CURRENT_VERSION) {
// When this is executed by the tally's initialization routine, the
// exception will cause the application to rebuild the snapshots:
throw SnapshotRegistryVersionMismatchError(version, CURRENT_VERSION);
}

while (true) {
try {
const DiskEntry entry(deserialize, file);
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ CAmount Tally::GetNewbieSuperblockAccrualCorrection(const Cpid& cpid, const Supe
const GRC::Magnitude magnitude = superblock->m_cpids.MagnitudeOf(cpid);

// Stop the accrual when we get to a superblock that is before the beacon advertisement.
if (pindex->nTime < beacon->m_timestamp) break;
if (pindex->nTime < beacon_ptr->m_timestamp) break;

CAmount period = tally_accrual_period(pindex->nTime, pindex_high->nTime, magnitude);

Expand Down
2 changes: 2 additions & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)
const int64_t now = GetAdjustedTime();
const GRC::ResearchAccount& account = GRC::Tally::GetAccount(*cpid);
const int64_t computed = GRC::Tally::GetAccrual(*cpid, now, pindexBest);
const int64_t newbie_correction = Tally::GetNewbieSuperblockAccrualCorrection(*cpid, GRC::Quorum::CurrentSuperblock());

bool accrual_account_exists = true;

Expand Down Expand Up @@ -506,6 +507,7 @@ UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)
result.pushKV("renewals", renewals);
result.pushKV("accrual_by_audit", accrual);
result.pushKV("accrual_by_GetAccrual", computed);
result.pushKV("newbie_correction", newbie_correction);
result.pushKV("accrual_last_period", period);

if (report_details) {
Expand Down

0 comments on commit 7f75aec

Please sign in to comment.