Skip to content

Commit

Permalink
3.7.10.0-Leisure
Browse files Browse the repository at this point in the history
Fixed:
 - Fix sync issues due to beacon age checks, #1003 (@denravonska).
  • Loading branch information
denravonska committed Mar 5, 2018
2 parents 3357395 + ca11b8e commit 250d96a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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/).

## [3.7.10.0] 2018-03-05, leisure
### Fixed
- Fix sync issues due to beacon age checks, #1003 (@denravonska).

## [3.7.9.0] 2018-03-03, leisure
### Fixed
- Fix issues with NN participation on Windows, #986 (@Foggyx420).
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 7
#define CLIENT_VERSION_REVISION 9
#define CLIENT_VERSION_REVISION 10
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
Expand Down
28 changes: 14 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3205,7 +3205,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo
}

//Approve first coinstake in DPOR block
if (IsResearcher(bb.cpid) && IsLockTimeWithinMinutes(GetBlockTime(),15) && !IsResearchAgeEnabled(pindex->nHeight))
if (IsResearcher(bb.cpid) && IsLockTimeWithinMinutes(GetBlockTime(), GetAdjustedTime(), 15) && !IsResearchAgeEnabled(pindex->nHeight))
{
if (bb.ResearchSubsidy > (GetOwedAmount(bb.cpid)+1))
{
Expand Down Expand Up @@ -3257,7 +3257,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(),15) || nVersion>=9) && !fColdBoot)
if ((IsLockTimeWithinMinutes(GetBlockTime(), GetAdjustedTime(), 15) || nVersion>=9) && !fColdBoot)
{
// Let this take effect together with stakev8
if (nVersion>=8)
Expand Down Expand Up @@ -4207,7 +4207,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(),600) || nHeight >= 999000))
if (!CheckProofOfStake(pindexPrev, vtx[1], nBits, hashProof, targetProofOfStake, vtx[0].hashBoinc, generated_by_me, nNonce) && (IsLockTimeWithinMinutes(GetBlockTime(), GetAdjustedTime(), 600) || nHeight >= 999000))
{
return error("WARNING: AcceptBlock(): check proof-of-stake failed for block %s, nonce %f \n", hash.ToString().c_str(),(double)nNonce);
}
Expand Down Expand Up @@ -4616,7 +4616,7 @@ void GridcoinServices()

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

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

void CleanInboundConnections(bool bClearAll)
{
if (IsLockTimeWithinMinutes(nLastCleaned,10)) return;
if (IsLockTimeWithinMinutes(nLastCleaned, GetAdjustedTime(), 10)) return;
nLastCleaned = GetAdjustedTime();
LOCK(cs_vNodes);
for(CNode* pNode : vNodes)
Expand Down Expand Up @@ -5373,7 +5373,7 @@ double GetOutstandingAmountOwed(StructCPID &mag, std::string cpid, int64_t lockt

bool BlockNeedsChecked(int64_t BlockTime)
{
if (IsLockTimeWithin14days(BlockTime))
if (IsLockTimeWithin14days(BlockTime, GetAdjustedTime()))
{
if (fColdBoot) return false;
bool fOut = OutOfSyncByAge();
Expand Down Expand Up @@ -5455,7 +5455,7 @@ bool GetEarliestStakeTime(std::string grcaddress, std::string cpid)
return true;
}

if (IsLockTimeWithinMinutes(nLastGRCtallied,100) && (mvApplicationCacheTimestamp["nGRCTime"] > 0 ||
if (IsLockTimeWithinMinutes(nLastGRCtallied, GetAdjustedTime(), 100) && (mvApplicationCacheTimestamp["nGRCTime"] > 0 ||
mvApplicationCacheTimestamp["nCPIDTime"] > 0)) return true;

nLastGRCtallied = GetAdjustedTime();
Expand Down Expand Up @@ -6326,9 +6326,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}

// Stay in Sync - 8-9-2016
if (!IsLockTimeWithinMinutes(nBootup,15))
if (!IsLockTimeWithinMinutes(nBootup, GetAdjustedTime(), 15))
{
if ((!IsLockTimeWithinMinutes(nLastAskedForBlocks,5) && WalletOutOfSync()) || (WalletOutOfSync() && fTestNet))
if ((!IsLockTimeWithinMinutes(nLastAskedForBlocks, GetAdjustedTime(), 5) && WalletOutOfSync()) || (WalletOutOfSync() && fTestNet))
{
if(fDebug) printf("\r\nBootup\r\n");
AskForOutstandingBlocks(uint256(0));
Expand Down Expand Up @@ -8669,16 +8669,16 @@ int64_t ComputeResearchAccrual(int64_t nTime, std::string cpid, std::string oper
if(fDebug && !bVerifyingBlock) printf("CRE: No prior block exists...\n");
if (!AreBinarySuperblocksEnabled(pindexLast->nHeight))
{
if(fDebug && !bVerifyingBlock) printf("CRE: Newbie Stake, Binary SB not enabled, "
"dCurrentMagnitude= %.1f\n", dCurrentMagnitude);
return dCurrentMagnitude > 0 ? ((dCurrentMagnitude/100)*COIN) : 0;
if(fDebug && !bVerifyingBlock) printf("CRE: Newbie Stake, Binary SB not enabled, "
"dCurrentMagnitude= %.1f\n", dCurrentMagnitude);
return dCurrentMagnitude > 0 ? ((dCurrentMagnitude/100)*COIN) : 0;
}
else
{
// 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, 60*24*30*6))
if (IsLockTimeWithinMinutes(iBeaconTimestamp, pindexBest->GetBlockTime(), 60*24*30*6))
{
double dNewbieAccrualAge = ((double)nTime - (double)iBeaconTimestamp) / 86400;
int64_t iAccrual = (int64_t)((dNewbieAccrualAge*dCurrentMagnitude*dMagnitudeUnit*COIN) + (1*COIN));
Expand Down Expand Up @@ -8813,7 +8813,7 @@ bool LoadAdminMessages(bool bFullTableScan, std::string& out_errors)
{
int nMaxDepth = nBestHeight;
int nMinDepth = fTestNet ? 1 : 164618;
nMinDepth = pindexBest->nHeight - (BLOCKS_PER_DAY*30*6);
nMinDepth = pindexBest->nHeight - (BLOCKS_PER_DAY*30*12);
if (nMinDepth < 2) nMinDepth=2;
if (!bFullTableScan) nMinDepth = nMaxDepth-6;
if (nMaxDepth < nMinDepth) return false;
Expand Down
16 changes: 7 additions & 9 deletions src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,23 +329,21 @@ BOOST_AUTO_TEST_CASE(util_VerifyIsLockTimeWithin14days)
{
int64_t now = 1494060475;
int64_t twoWeeksInSeconds = 1209600;
int64_t time = now - twoWeeksInSeconds;

SetMockTime(now);
BOOST_CHECK(IsLockTimeWithin14days(now) == true);
BOOST_CHECK(IsLockTimeWithin14days(now - twoWeeksInSeconds) == true);
BOOST_CHECK(IsLockTimeWithin14days(now - twoWeeksInSeconds - 1) == false);
BOOST_CHECK(IsLockTimeWithin14days(time, now) == true);
BOOST_CHECK(IsLockTimeWithin14days(time - 1, now) == false);
}

BOOST_AUTO_TEST_CASE(util_IsLockTimeWithinMinutes)
{
{
int64_t now = 1494060475;
int64_t minutes = 6;
int64_t minutesInSeconds = minutes * 60;
int64_t time = now - minutesInSeconds;

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

BOOST_AUTO_TEST_CASE(util_VerifyRound)
Expand Down
8 changes: 4 additions & 4 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,14 +1338,14 @@ int64_t GetAdjustedTime()
return GetTime() + GetTimeOffset();
}

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

bool IsLockTimeWithinMinutes(int64_t locktime, int minutes)
bool IsLockTimeWithinMinutes(int64_t locktime, int64_t reference, int minutes)
{
int64_t cutOff = GetAdjustedTime() - minutes * 60;
int64_t cutOff = reference - minutes * 60;
return locktime >= cutOff;
}

Expand Down
4 changes: 2 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ int64_t GetTime();
void SetMockTime(int64_t nMockTimeIn);
int64_t GetAdjustedTime();
int64_t GetTimeOffset();
bool IsLockTimeWithin14days(int64_t locktime);
bool IsLockTimeWithinMinutes(int64_t locktime, int minutes);
bool IsLockTimeWithin14days(int64_t locktime, int64_t reference);
bool IsLockTimeWithinMinutes(int64_t locktime, int64_t reference, int minutes);
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 nTime);
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
printf("reward locktime %f curr time %f",(double)wtxIn.nTime,(double)GetAdjustedTime());
printf(" reward shared %f",(double)dRewardShare);
printf(" addr %s",sRewardAddress.c_str());
if (IsLockTimeWithinMinutes(wtxIn.nTime,10))
if (IsLockTimeWithinMinutes(wtxIn.nTime, GetAdjustedTime(), 10))
{
std::string sResult = SendReward(sRewardAddress,CoinFromValue(dRewardShare));
printf("\r\nIssuing Reward Share of %f GRC to %s. Response: %s\r\n",dRewardShare,sRewardAddress.c_str(),sResult.c_str());
Expand Down

0 comments on commit 250d96a

Please sign in to comment.