Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017-2018 The Bitcoin developers | // Copyright (c) 2017-2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "arith_uint256.h" | #include "arith_uint256.h" | ||||
#include "blockindexworkcomparator.h" | |||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "checkpoints.h" | #include "checkpoints.h" | ||||
#include "checkqueue.h" | #include "checkqueue.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/consensus.h" | #include "consensus/consensus.h" | ||||
#include "consensus/merkle.h" | #include "consensus/merkle.h" | ||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "fs.h" | #include "fs.h" | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
/** Constant stuff for coinbase transactions we create: */ | /** Constant stuff for coinbase transactions we create: */ | ||||
CScript COINBASE_FLAGS; | CScript COINBASE_FLAGS; | ||||
const std::string strMessageMagic = "Bitcoin Signed Message:\n"; | const std::string strMessageMagic = "Bitcoin Signed Message:\n"; | ||||
// Internal stuff | // Internal stuff | ||||
namespace { | namespace { | ||||
struct CBlockIndexWorkComparator { | |||||
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const { | |||||
// First sort by most total work, ... | |||||
if (pa->nChainWork > pb->nChainWork) { | |||||
return false; | |||||
} | |||||
if (pa->nChainWork < pb->nChainWork) { | |||||
return true; | |||||
} | |||||
// ... then by earliest time received, ... | |||||
if (pa->nSequenceId < pb->nSequenceId) { | |||||
return false; | |||||
} | |||||
if (pa->nSequenceId > pb->nSequenceId) { | |||||
return true; | |||||
} | |||||
// Use pointer address as tie breaker (should only happen with blocks | |||||
// loaded from disk, as those all have id 0). | |||||
if (pa < pb) { | |||||
return false; | |||||
} | |||||
if (pa > pb) { | |||||
return true; | |||||
} | |||||
// Identical blocks. | |||||
return false; | |||||
} | |||||
}; | |||||
CBlockIndex *pindexBestInvalid; | CBlockIndex *pindexBestInvalid; | ||||
/** | /** | ||||
* The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself | * The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself | ||||
* and all ancestors) and as good as our current tip or better. Entries may be | * and all ancestors) and as good as our current tip or better. Entries may be | ||||
* failed, though, and pruning nodes may be missing the data for the block. | * failed, though, and pruning nodes may be missing the data for the block. | ||||
*/ | */ | ||||
std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates; | std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates; | ||||
▲ Show 20 Lines • Show All 5,412 Lines • Show Last 20 Lines |