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

Change signature of IsLockTimeWithinMinutes #1422

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
18 changes: 9 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo
}

//Approve first coinstake in DPOR block
if (IsResearcher(bb.cpid) && IsLockTimeWithinMinutes(GetBlockTime(), GetAdjustedTime(), 15) && !IsResearchAgeEnabled(pindex->nHeight))
if (IsResearcher(bb.cpid) && IsLockTimeWithinMinutes(GetBlockTime(), 15, GetAdjustedTime()) && !IsResearchAgeEnabled(pindex->nHeight))
{
if (bb.ResearchSubsidy > (GetOwedAmount(bb.cpid)+1))
{
Expand Down Expand Up @@ -3310,7 +3310,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo
double popularity = 0;
std::string consensus_hash = GetNeuralNetworkSupermajorityHash(popularity);
// Only reject superblock when it is new And when QuorumHash of Block != the Popular Quorum Hash:
if ((IsLockTimeWithinMinutes(GetBlockTime(), GetAdjustedTime(), 15) || nVersion>=9) && !fColdBoot)
if ((IsLockTimeWithinMinutes(GetBlockTime(), 15, GetAdjustedTime()) || nVersion>=9) && !fColdBoot)
{
// Let this take effect together with stakev8
if (nVersion>=8)
Expand Down Expand Up @@ -4239,7 +4239,7 @@ bool CBlock::AcceptBlock(bool generated_by_me)
if (IsProofOfStake())
{
uint256 targetProofOfStake;
if (!CheckProofOfStake(pindexPrev, vtx[1], nBits, hashProof, targetProofOfStake, vtx[0].hashBoinc, generated_by_me, nNonce) && (IsLockTimeWithinMinutes(GetBlockTime(), GetAdjustedTime(), 600) || nHeight >= 999000))
if (!CheckProofOfStake(pindexPrev, vtx[1], nBits, hashProof, targetProofOfStake, vtx[0].hashBoinc, generated_by_me, nNonce) && (IsLockTimeWithinMinutes(GetBlockTime(), 600, GetAdjustedTime()) || nHeight >= 999000))
{
return error("WARNING: AcceptBlock(): check proof-of-stake failed for block %s, nonce %f ", hash.ToString().c_str(),(double)nNonce);
}
Expand Down Expand Up @@ -4596,7 +4596,7 @@ void GridcoinServices()

bool AskForOutstandingBlocks(uint256 hashStart)
{
if (IsLockTimeWithinMinutes(nLastAskedForBlocks, GetAdjustedTime(), 2)) return true;
if (IsLockTimeWithinMinutes(nLastAskedForBlocks, 2, GetAdjustedTime())) return true;
nLastAskedForBlocks = GetAdjustedTime();

int iAsked = 0;
Expand Down Expand Up @@ -4645,7 +4645,7 @@ void ClearOrphanBlocks()

void CleanInboundConnections(bool bClearAll)
{
if (IsLockTimeWithinMinutes(nLastCleaned, GetAdjustedTime(), 10)) return;
if (IsLockTimeWithinMinutes(nLastCleaned, 10, GetAdjustedTime())) return;
nLastCleaned = GetAdjustedTime();
LOCK(cs_vNodes);
for(CNode* pNode : vNodes)
Expand Down Expand Up @@ -5383,7 +5383,7 @@ bool GetEarliestStakeTime(std::string grcaddress, std::string cpid)

int64_t nGRCTime = ReadCache(Section::GLOBAL, "nGRCTime").timestamp;
int64_t nCPIDTime = ReadCache(Section::GLOBAL, "nCPIDTime").timestamp;
if (IsLockTimeWithinMinutes(nLastGRCtallied, GetAdjustedTime(), 100) &&
if (IsLockTimeWithinMinutes(nLastGRCtallied, 100, GetAdjustedTime()) &&
(nGRCTime > 0 || nCPIDTime > 0))
return true;

Expand Down Expand Up @@ -6168,9 +6168,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}

// Stay in Sync - 8-9-2016
if (!IsLockTimeWithinMinutes(nBootup, GetAdjustedTime(), 15))
if (!IsLockTimeWithinMinutes(nBootup, 15, GetAdjustedTime()))
{
if ((!IsLockTimeWithinMinutes(nLastAskedForBlocks, GetAdjustedTime(), 5) && WalletOutOfSync()) || (WalletOutOfSync() && fTestNet))
if ((!IsLockTimeWithinMinutes(nLastAskedForBlocks, 5, GetAdjustedTime()) && WalletOutOfSync()) || (WalletOutOfSync() && fTestNet))
{
if(fDebug) LogPrintf("Bootup");
AskForOutstandingBlocks(uint256(0));
Expand Down Expand Up @@ -8207,7 +8207,7 @@ int64_t ComputeResearchAccrual(int64_t nTime, std::string cpid, std::string oper
// New rules - 12-4-2015 - Pay newbie from the moment beacon was sent as long as it is within 6 months old and NN mag > 0 and newbie is in the superblock and their lifetime paid is zero
// Note: If Magnitude is zero, or researcher is not in superblock, or lifetimepaid > 0, this function returns zero
int64_t iBeaconTimestamp = BeaconTimeStamp(cpid, true);
if (IsLockTimeWithinMinutes(iBeaconTimestamp, pindexBest->GetBlockTime(), 60*24*30*6))
if (IsLockTimeWithinMinutes(iBeaconTimestamp, 60*24*30*6, pindexBest->GetBlockTime()))
{
double dNewbieAccrualAge = ((double)nTime - (double)iBeaconTimestamp) / 86400;
int64_t iAccrual = (int64_t)((dNewbieAccrualAge*dCurrentMagnitude*dMagnitudeUnit*COIN) + (1*COIN));
Expand Down
4 changes: 2 additions & 2 deletions src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ BOOST_AUTO_TEST_CASE(util_IsLockTimeWithinMinutes)
int64_t minutesInSeconds = minutes * 60;
int64_t time = now - minutesInSeconds;

BOOST_CHECK(IsLockTimeWithinMinutes(time, now, minutes) == true);
BOOST_CHECK(IsLockTimeWithinMinutes(time - 1, now, minutes) == false);
BOOST_CHECK(IsLockTimeWithinMinutes(time, minutes, now) == true);
BOOST_CHECK(IsLockTimeWithinMinutes(time - 1, minutes, now) == false);
}

BOOST_AUTO_TEST_CASE(util_VerifyRound)
Expand Down
4 changes: 2 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,10 +1288,10 @@ int64_t GetAdjustedTime()

bool IsLockTimeWithin14days(int64_t locktime, int64_t reference)
{
return IsLockTimeWithinMinutes(locktime, reference, 14 * 24 * 60);
return IsLockTimeWithinMinutes(locktime, 14 * 24 * 60, reference);
}

bool IsLockTimeWithinMinutes(int64_t locktime, int64_t reference, int minutes)
bool IsLockTimeWithinMinutes(int64_t locktime, int minutes, int64_t reference)
{
int64_t cutOff = reference - minutes * 60;
return locktime >= cutOff;
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void SetMockTime(int64_t nMockTimeIn);
int64_t GetAdjustedTime();
int64_t GetTimeOffset();
bool IsLockTimeWithin14days(int64_t locktime, int64_t reference);
bool IsLockTimeWithinMinutes(int64_t locktime, int64_t reference, int minutes);
bool IsLockTimeWithinMinutes(int64_t locktime, int minutes, int64_t reference);
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample);
Expand Down