Skip to content

Commit

Permalink
More updates regarding block timedrift fix
Browse files Browse the repository at this point in the history
  • Loading branch information
durkmurder committed May 31, 2019
1 parent 3dbea94 commit 8b65e89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* current network-adjusted time before the block will be accepted.
*/
static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;
static const int64_t MAX_FUTURE_BLOCK_TIME_POST_FORK = 3 * 60;

/**
* Timestamp window used as a grace period by code that compares external
Expand Down
8 changes: 7 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
return chain.Genesis();
}

static int64_t GetMaxFutureBlockTime(CBlockIndex *pindexPrev, const Consensus::Params &params)
{
return pindexPrev->nHeight > params.nMaxBlockSpacingFixDeploymentHeight ? MAX_FUTURE_BLOCK_TIME_POST_FORK :
MAX_FUTURE_BLOCK_TIME;
}

std::unique_ptr<CCoinsViewDB> pcoinsdbview;
std::unique_ptr<CCoinsViewCache> pcoinsTip;
std::unique_ptr<CBlockTreeDB> pblocktree;
Expand Down Expand Up @@ -3410,7 +3416,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
return state.Invalid(false, REJECT_INVALID, "time-too-old", "block's timestamp is too early");

// Check timestamp
if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME)
if (block.GetBlockTime() > nAdjustedTime + GetMaxFutureBlockTime(pindexPrev))
return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future");

// Reject outdated version blocks when 95% (75% on testnet) of the network has upgraded:
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ bool CWallet::CreateCoinStakeKernel(CScript &kernelScript, const CScript &stakeS

for(unsigned int i = 0; i < nHashDrift; ++i)
{
nTryTime = nTimeTx - i;
nTryTime = nTimeTx + nHashDrift - i;
if (CheckStakeKernelHash(nBits, blockFrom, nTxPrevOffset, txPrev, prevout, nTryTime, hashProofOfStake, fPrintProofOfStake))
{
//Double check that this will pass time requirements
Expand Down

0 comments on commit 8b65e89

Please sign in to comment.