mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
ccee103a0e
* IBD check uses minimumchain work instead of checkpoints. This introduces a 'minimum chain work' chainparam which is intended to be the known amount of work in the chain for the network at the time of software release. If you don't have this much work, you're not yet caught up. This is used instead of the count of blocks test from checkpoints. This criteria is trivial to keep updated as there is no element of subjectivity, trust, or position dependence to it. It is also a more reliable metric of sync status than a block count. * Remove GetTotalBlocksEstimate and checkpoint tests that test nothing. GetTotalBlocksEstimate is no longer used and it was the only thing the checkpoint tests were testing. Since checkpoints are on their way out it makes more sense to remove the test file than to cook up a new pointless test. # Conflicts: # src/Makefile.test.include # src/test/Checkpoints_tests.cpp * IsInitialBlockDownload no longer uses header-only timestamps. This avoids a corner case (mostly visible on testnet) where bogus headers can keep nodes in IsInitialBlockDownload. * Delay parallel block download until chain has sufficient work nMinimumChainWork is an anti-DoS threshold; wait until we have a proposed tip with more work than that before downloading blocks towards that tip. * Add timeout for headers sync At startup, we choose one peer to serve us the headers chain, until our best header is close to caught up. Disconnect this peer if more than 15 minutes + 1ms/expected_header passes and our best header is still more than 1 day away from current time. * Introduce assumevalid setting to skip presumed valid scripts. This disentangles the script validation skipping from checkpoints. A new option is introduced "assumevalid" which specifies a block whos ancestors we assume all have valid scriptsigs and so we do not check them when they are also burried under the best header by two weeks worth of work. Unlike checkpoints this has no influence on consensus unless you set it to a block with an invalid history. Because of this it can be easily be updated without risk of influencing the network consensus. This results in a massive IBD speedup. This approach was independently recommended by Peter Todd and Luke-Jr since POW based signature skipping (see PR#9180) does not have the verifiable properties of a specific hash and may create bad incentives. The downside is that, like checkpoints, the defaults bitrot and older releases will sync slower. On the plus side users can provide their own value here, and if they set it to something crazy all that will happen is more time will be spend validating signatures. Checkblocks and checklevel are also moved to the hidden debug options: Especially now that checkblocks has a low default there is little need to change these settings, and users frequently misunderstand them as influencing security or IBD speed. By hiding them we offset the space added by this new option. * Add consensusParams to FindNextBlocksToDownload * Adjust check in headers timeout logic to align with 144 blocks in Dash
74 lines
3.0 KiB
C++
74 lines
3.0 KiB
C++
// Copyright (c) 2009-2014 The Bitcoin developers
|
|
// Copyright (c) 2014-2017 The Dash Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include "checkpoints.h"
|
|
|
|
#include "chain.h"
|
|
#include "chainparams.h"
|
|
#include "validation.h"
|
|
#include "uint256.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
namespace Checkpoints {
|
|
|
|
/**
|
|
* How many times slower we expect checking transactions after the last
|
|
* checkpoint to be (from checking signatures, which is skipped up to the
|
|
* last checkpoint). This number is a compromise, as it can't be accurate
|
|
* for every system. When reindexing from a fast disk with a slow CPU, it
|
|
* can be up to 20, while when downloading from a slow network with a
|
|
* fast multicore CPU, it won't be much higher than 1.
|
|
*/
|
|
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
|
|
|
|
//! Guess how far we are in the verification process at the given block index
|
|
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
|
|
if (pindex==NULL)
|
|
return 0.0;
|
|
|
|
int64_t nNow = time(NULL);
|
|
|
|
double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
|
|
double fWorkBefore = 0.0; // Amount of work done before pindex
|
|
double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
|
|
// Work is defined as: 1.0 per transaction before the last checkpoint, and
|
|
// fSigcheckVerificationFactor per transaction after.
|
|
|
|
if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
|
|
double nCheapBefore = pindex->nChainTx;
|
|
double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
|
|
double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
|
|
fWorkBefore = nCheapBefore;
|
|
fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
|
|
} else {
|
|
double nCheapBefore = data.nTransactionsLastCheckpoint;
|
|
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
|
|
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
|
|
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
|
|
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
|
|
}
|
|
|
|
return fWorkBefore / (fWorkBefore + fWorkAfter);
|
|
}
|
|
|
|
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
|
|
{
|
|
const MapCheckpoints& checkpoints = data.mapCheckpoints;
|
|
|
|
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
|
|
{
|
|
const uint256& hash = i.second;
|
|
BlockMap::const_iterator t = mapBlockIndex.find(hash);
|
|
if (t != mapBlockIndex.end())
|
|
return t->second;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
} // namespace Checkpoints
|