Skip to content

Commit

Permalink
fix drift
Browse files Browse the repository at this point in the history
should have changed this in the last patch. ugh.
  • Loading branch information
justinvforvendetta committed May 25, 2018
1 parent 541f2e9 commit f8ca082
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c
return DoS(50, error("CheckBlock() : proof of work failed"));

// Check timestamp
if (GetBlockTime() > GetAdjustedTime() + nMaxClockDrift)
if (GetBlockTime() > GetAdjustedTime() + GetMaxClockDrift())
return error("CheckBlock() : block timestamp too far in the future");

// First transaction must be coinbase, the rest must not be
Expand All @@ -2238,7 +2238,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c
return error("CheckBlock() : coinbase output not empty for proof-of-stake block");

// Check coinbase timestamp
if (GetBlockTime() > (int64)vtx[0].nTime + nMaxClockDrift)
if (GetBlockTime() > (int64)vtx[0].nTime + GetMaxClockDrift())
return DoS(50, error("CheckBlock() : coinbase timestamp is too early"));

// Check coinstake timestamp
Expand Down Expand Up @@ -2330,7 +2330,7 @@ bool CBlock::AcceptBlock()
return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake"));

// Check timestamp against prev
if (GetBlockTime() <= pindexPrev->GetMedianTimePast() || GetBlockTime() + nMaxClockDrift < pindexPrev->GetBlockTime())
if (GetBlockTime() <= pindexPrev->GetMedianTimePast() || GetBlockTime() + GetMaxClockDrift() < pindexPrev->GetBlockTime())
return error("AcceptBlock() : block's timestamp is too early");

// Check that all transactions are finalized
Expand Down Expand Up @@ -4458,7 +4458,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int algo)
{
if (pwallet->CreateCoinStake(*pwallet, pblock->nBits, nSearchTime-nLastCoinStakeSearchTime, txCoinStake))
{
if (txCoinStake.nTime >= max(pindexPrev->GetMedianTimePast()+1, pindexPrev->GetBlockTime() - nMaxClockDrift))
if (txCoinStake.nTime >= max(pindexPrev->GetMedianTimePast()+1, pindexPrev->GetBlockTime() - GetMaxClockDrift()))
{ // make sure coinstake would meet timestamp protocol
// as it would be the same as the block timestamp
pblock->vtx[0].vout[0].SetEmpty();
Expand Down Expand Up @@ -4675,7 +4675,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int algo)
if (pblock->IsProofOfStake())
pblock->nTime = pblock->vtx[1].nTime; //same as coinstake timestamp
pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime());
pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift);
pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - GetMaxClockDrift());
if (pblock->IsProofOfWork())
pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
Expand Down Expand Up @@ -4960,11 +4960,11 @@ void VERGEMiner(CWallet *pwallet, bool fProofOfStake)

// Update nTime every few seconds
pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime());
pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift);
pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - GetMaxClockDrift());
pblock->UpdateTime(pindexPrev);
nBlockTime = ByteReverse(pblock->nTime);

if (pblock->GetBlockTime() >= (int64)pblock->vtx[0].nTime + nMaxClockDrift)
if (pblock->GetBlockTime() >= (int64)pblock->vtx[0].nTime + GetMaxClockDrift())
break; // need to update coinbase timestamp
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ static const int fHaveUPnP = false;
static const uint256 hashGenesisBlockOfficial("0x00000fc63692467faeb20cdb3b53200dc601d75bdfa1001463304cc790d77278");
static const uint256 hashGenesisBlockTestNet("0x65b4e101cacf3e1e4f3a9237e3a74ffd1186e595d8b78fa8ea22c21ef5bf9347");

static const int64 nMaxClockDrift = 2 * 60 * 60; // 2 hours
inline int64 GetMaxClockDrift(int Height=nBestHeight){
if (Height < 2218500)
return 2 * 60 * 60; // old 2 hour drift
else
return 10 * 60; // new 10 min drift
}

extern CScript COINBASE_FLAGS;

Expand Down
6 changes: 3 additions & 3 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Value getworkex(const Array& params, bool fHelp)

// if difficulty is high and nobody else is mining coinbase time stamp
// will eventually expire
if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + nMaxClockDrift) {
if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + GetMaxClockDrift()) {
int oldTime = pblock->vtx[0].nTime;
pblock->vtx[0].nTime = GetAdjustedTime();
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
Expand Down Expand Up @@ -290,7 +290,7 @@ Value getwork(const Array& params, bool fHelp)

// if difficulty is high and nobody else is mining coinbase time stamp
// will eventually expire
if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + nMaxClockDrift) {
if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + GetMaxClockDrift()) {
int oldTime = pblock->vtx[0].nTime;
pblock->vtx[0].nTime = GetAdjustedTime();
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
Expand Down Expand Up @@ -434,7 +434,7 @@ Value getblocktemplate(const Array& params, bool fHelp)

// if difficulty is high and nobody else is mining coinbase time stamp
// will eventually expire
if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + nMaxClockDrift) {
if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + GetMaxClockDrift()) {
int oldTime = pblock->vtx[0].nTime;
pblock->vtx[0].nTime = GetAdjustedTime();
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
Expand Down

0 comments on commit f8ca082

Please sign in to comment.