Skip to content

Commit c02c68b

Browse files
authored
Merge pull request #1774 from cyrossignol/superblock-needed
consensus: Use explicit time to check if superblock needed
2 parents 9c7f556 + 2c33b92 commit c02c68b

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3789,7 +3789,7 @@ bool GridcoinServices()
37893789
// timestamps in the beacon registry in a way that causes the renewed
37903790
// beacon to appear ahead of the scraper beacon consensus window.
37913791
//
3792-
if (!researcher->Eligible() || !NN::Quorum::SuperblockNeeded()) {
3792+
if (!researcher->Eligible() || !NN::Quorum::SuperblockNeeded(pindexBest->nTime)) {
37933793
researcher->AdvertiseBeacon();
37943794
}
37953795
}

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ void AddNeuralContractOrVote(CBlock& blocknew)
930930
return;
931931
}
932932

933-
if (!NN::Quorum::SuperblockNeeded()) {
933+
if (!NN::Quorum::SuperblockNeeded(blocknew.nTime)) {
934934
LogPrintf("AddNeuralContractOrVote: Not needed.");
935935
return;
936936
}

src/neuralnet/quorum.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ class SuperblockValidator
593593
return Result::UNKNOWN;
594594
}
595595

596-
if (m_superblock.Age() > SCRAPER_CMANIFEST_RETENTION_TIME) {
596+
if (m_superblock.Age(GetAdjustedTime()) > SCRAPER_CMANIFEST_RETENTION_TIME) {
597597
return Result::HISTORICAL;
598598
}
599599

@@ -1499,7 +1499,7 @@ bool Quorum::ValidateSuperblockClaim(
14991499
const SuperblockPtr& superblock,
15001500
const CBlockIndex* const pindex)
15011501
{
1502-
if (!SuperblockNeeded()) {
1502+
if (!SuperblockNeeded(pindex->nTime)) {
15031503
return error("ValidateSuperblockClaim(): superblock too early.");
15041504
}
15051505

@@ -1656,7 +1656,7 @@ bool Quorum::HasPendingSuperblock()
16561656
return g_superblock_index.HasPending();
16571657
}
16581658

1659-
bool Quorum::SuperblockNeeded()
1659+
bool Quorum::SuperblockNeeded(const int64_t now)
16601660
{
16611661
if (HasPendingSuperblock()) {
16621662
return false;
@@ -1665,7 +1665,7 @@ bool Quorum::SuperblockNeeded()
16651665
const SuperblockPtr superblock = g_superblock_index.Current();
16661666

16671667
return !superblock->WellFormed()
1668-
|| superblock.Age() > GetSuperblockAgeSpacing(nBestHeight);
1668+
|| superblock.Age(now) > GetSuperblockAgeSpacing(nBestHeight);
16691669

16701670
}
16711671

src/neuralnet/quorum.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,12 @@ class Quorum
191191
//!
192192
//! \brief Determine whether the network expects a new superblock.
193193
//!
194+
//! \param now Timestamp to consider as the current time.
195+
//!
194196
//! \return \c true if the age of the current superblock exceeds the
195197
//! protocol's superblock spacing parameter.
196198
//!
197-
static bool SuperblockNeeded();
199+
static bool SuperblockNeeded(const int64_t now);
198200

199201
//!
200202
//! \brief Initialze the tally's superblock context.

src/neuralnet/superblock.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,11 +1431,13 @@ class SuperblockPtr
14311431
//!
14321432
//! \brief Get the current age of the superblock.
14331433
//!
1434+
//! \param now Timestamp to consider as the current time.
1435+
//!
14341436
//! \return Superblock age in seconds.
14351437
//!
1436-
int64_t Age() const
1438+
int64_t Age(const int64_t now) const
14371439
{
1438-
return GetAdjustedTime() - m_timestamp;
1440+
return now - m_timestamp;
14391441
}
14401442

14411443
ADD_SERIALIZE_METHODS;

src/rpcblockchain.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ UniValue superblockage(const UniValue& params, bool fHelp)
11611161

11621162
const NN::SuperblockPtr superblock = NN::Quorum::CurrentSuperblock();
11631163

1164-
res.pushKV("Superblock Age", superblock.Age());
1164+
res.pushKV("Superblock Age", superblock.Age(GetAdjustedTime()));
11651165
res.pushKV("Superblock Timestamp", TimestampToHRDate(superblock.m_timestamp));
11661166
res.pushKV("Superblock Block Number", superblock.m_height);
11671167
res.pushKV("Pending Superblock Height", NN::Quorum::PendingSuperblock().m_height);
@@ -1717,13 +1717,14 @@ UniValue superblockaverage(const UniValue& params, bool fHelp)
17171717
LOCK(cs_main);
17181718

17191719
const NN::SuperblockPtr superblock = NN::Quorum::CurrentSuperblock();
1720+
const int64_t now = GetAdjustedTime();
17201721

17211722
res.pushKV("beacon_count", (uint64_t)superblock->m_cpids.TotalCount());
17221723
res.pushKV("beacon_participant_count", (uint64_t)superblock->m_cpids.size());
17231724
res.pushKV("average_magnitude", superblock->m_cpids.AverageMagnitude());
17241725
res.pushKV("superblock_valid", superblock->WellFormed());
1725-
res.pushKV("Superblock Age", superblock.Age());
1726-
res.pushKV("Dire Need of Superblock", NN::Quorum::SuperblockNeeded());
1726+
res.pushKV("Superblock Age", superblock.Age(now));
1727+
res.pushKV("Dire Need of Superblock", NN::Quorum::SuperblockNeeded(now));
17271728

17281729
return res;
17291730
}

src/scraper/scraper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ int64_t SuperblockAge()
705705
{
706706
LOCK(cs_main);
707707

708-
return NN::Quorum::CurrentSuperblock().Age();
708+
return NN::Quorum::CurrentSuperblock().Age(GetAdjustedTime());
709709
}
710710

711711
std::vector<std::string> GetTeamWhiteList()

0 commit comments

Comments
 (0)