Changeset View
Changeset View
Standalone View
Standalone View
src/chain.h
// 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 | ||||
// 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. | ||||
#ifndef BITCOIN_CHAIN_H | #ifndef BITCOIN_CHAIN_H | ||||
#define BITCOIN_CHAIN_H | #define BITCOIN_CHAIN_H | ||||
#include "arith_uint256.h" | #include "arith_uint256.h" | ||||
#include "blockstatus.h" | #include "blockstatus.h" | ||||
#include "blockvalidity.h" | #include "blockvalidity.h" | ||||
#include "consensus/params.h" | #include "consensus/params.h" | ||||
#include "diskblockpos.h" | #include "diskblockpos.h" | ||||
#include "pow.h" | #include "pow.h" | ||||
#include "primitives/block.h" | #include "primitives/block.h" | ||||
#include "sync.h" | |||||
#include "tinyformat.h" | #include "tinyformat.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include <unordered_map> | #include <unordered_map> | ||||
#include <vector> | #include <vector> | ||||
/** | /** | ||||
* Maximum amount of time that a block timestamp is allowed to exceed the | * Maximum amount of time that a block timestamp is allowed to exceed the | ||||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | |||||
* Maintain a map of CBlockIndex for all known headers. | * Maintain a map of CBlockIndex for all known headers. | ||||
*/ | */ | ||||
struct BlockHasher { | struct BlockHasher { | ||||
size_t operator()(const uint256 &hash) const { return hash.GetCheapHash(); } | size_t operator()(const uint256 &hash) const { return hash.GetCheapHash(); } | ||||
}; | }; | ||||
typedef std::unordered_map<uint256, CBlockIndex *, BlockHasher> BlockMap; | typedef std::unordered_map<uint256, CBlockIndex *, BlockHasher> BlockMap; | ||||
extern BlockMap &mapBlockIndex; | extern BlockMap &mapBlockIndex; | ||||
extern CCriticalSection cs_main; | |||||
inline CBlockIndex *LookupBlockIndex(const uint256 &hash) { | |||||
AssertLockHeld(cs_main); | |||||
BlockMap::const_iterator it = mapBlockIndex.find(hash); | |||||
return it == mapBlockIndex.end() ? nullptr : it->second; | |||||
} | |||||
arith_uint256 GetBlockProof(const CBlockIndex &block); | arith_uint256 GetBlockProof(const CBlockIndex &block); | ||||
/** | /** | ||||
* Return the time it would take to redo the work difference between from and | * Return the time it would take to redo the work difference between from and | ||||
* to, assuming the current hashrate corresponds to the difficulty at tip, in | * to, assuming the current hashrate corresponds to the difficulty at tip, in | ||||
* seconds. | * seconds. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines |