Changeset View
Changeset View
Standalone View
Standalone View
src/config.cpp
// Copyright (c) 2017 The Bitcoin developers | // Copyright (c) 2017 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 "config.h" | #include "config.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "consensus/consensus.h" | #include "consensus/consensus.h" | ||||
#include "globals.h" | #include "globals.h" | ||||
#include "validation.h" | |||||
GlobalConfig::GlobalConfig() {} | |||||
bool GlobalConfig::SetMaxBlockSize(uint64_t maxBlockSize) { | bool GlobalConfig::SetMaxBlockSize(uint64_t maxBlockSize) { | ||||
// Do not allow maxBlockSize to be set below historic 1MB limit | // Do not allow maxBlockSize to be set below historic 1MB limit | ||||
// It cannot be equal either because of the "must be big" UAHF rule. | // It cannot be equal either because of the "must be big" UAHF rule. | ||||
if (maxBlockSize <= LEGACY_MAX_BLOCK_SIZE) { | if (maxBlockSize <= LEGACY_MAX_BLOCK_SIZE) { | ||||
return false; | return false; | ||||
} | } | ||||
nMaxBlockSize = maxBlockSize; | nMaxBlockSize = maxBlockSize; | ||||
return true; | return true; | ||||
} | } | ||||
uint64_t GlobalConfig::GetMaxBlockSize() const { | uint64_t GlobalConfig::GetMaxBlockSize() const { | ||||
return nMaxBlockSize; | return nMaxBlockSize; | ||||
} | } | ||||
bool GlobalConfig::SetUAHFStartTime(int64_t uahfStartTime) { | bool GlobalConfig::SetUAHFStartTime(int64_t uahfStartTime) { | ||||
nUAHFStartTime = uahfStartTime; | nUAHFStartTime = uahfStartTime; | ||||
return true; | return true; | ||||
} | } | ||||
int64_t GlobalConfig::GetUAHFStartTime() const { | int64_t GlobalConfig::GetUAHFStartTime() const { | ||||
return nUAHFStartTime; | return nUAHFStartTime; | ||||
} | } | ||||
// EC Functions | |||||
bool GlobalConfig::CheckBlockWithCurrentConsensus( | |||||
const CBlockIndex *blockIndex) const { | |||||
// Policy checks, the checks that were removed from the checkblock function | |||||
// must be validated here | |||||
// TODO: move the rest of the CheckBlock checks here | |||||
CBlock block; | |||||
if (!ReadBlockFromDisk(block, blockIndex, Params().GetConsensus())) { | |||||
return false; | |||||
} | |||||
// Size limits. | |||||
auto nMaxBlockSize = GetMaxBlockSize(); | |||||
// Bail early if there is no way this block is of reasonable size. | |||||
if ((block.vtx.size() * MIN_TRANSACTION_SIZE) > nMaxBlockSize) { | |||||
return false; | |||||
} | |||||
auto currentBlockSize = | |||||
::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); | |||||
if (currentBlockSize > nMaxBlockSize) { | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
CBlockIndex *GlobalConfig::SelectBestChain( | |||||
const std::pair<CBlockIndex *, CBlockIndex *> ¬YetValidChain, | |||||
const std::pair<CBlockIndex *, CBlockIndex *> &validChain) const { | |||||
// The first element is the tip of the chain and the second one is the last | |||||
// element before joining the current chain | |||||
// TODO: make the selection of the best chain something more complex | |||||
if (notYetValidChain.first->nChainWork > validChain.first->nChainWork + 4) { | |||||
return notYetValidChain.first; | |||||
} else { | |||||
return validChain.first; | |||||
} | |||||
} | |||||
const CChainParams &GlobalConfig::GetChainParams() const { | const CChainParams &GlobalConfig::GetChainParams() const { | ||||
return Params(); | return Params(); | ||||
} | } | ||||
static GlobalConfig gConfig; | static GlobalConfig gConfig; | ||||
const Config &GetConfig() { | const Config &GetConfig() { | ||||
return gConfig; | return gConfig; | ||||
} | } |