Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
Lint: Code style violation: '/home/jason/projects/bitcoin-abc/src/validation.cpp' has code style errors. | |||||
// 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" | ||||
▲ Show 20 Lines • Show All 3,860 Lines • ▼ Show 20 Lines | if (isSameHeightAndMoreHonestlyMined) { | ||||
chainActive.Tip()->GetBlockHash().ToString(), | chainActive.Tip()->GetBlockHash().ToString(), | ||||
chainTipTimeDiff); | chainTipTimeDiff); | ||||
LogPrintf("New block timestamp-to-received-time difference: hash=%s, " | LogPrintf("New block timestamp-to-received-time difference: hash=%s, " | ||||
"diff=%d\n", | "diff=%d\n", | ||||
pindex->GetBlockHash().ToString(), newBlockTimeDiff); | pindex->GetBlockHash().ToString(), newBlockTimeDiff); | ||||
} | } | ||||
bool fHasMoreWork = | bool fHasMoreWork = | ||||
(chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork | (chainActive.Tip() | ||||
? (pindex->nChainWork > chainActive.Tip()->nChainWork) || | |||||
isSameHeightAndMoreHonestlyMined | |||||
: true); | : true); | ||||
// Blocks that are too out-of-order needlessly limit the effectiveness of | // Blocks that are too out-of-order needlessly limit the effectiveness of | ||||
// pruning, because pruning will not delete block files that contain any | // pruning, because pruning will not delete block files that contain any | ||||
// blocks which are too close in height to the tip. Apply this test | // blocks which are too close in height to the tip. Apply this test | ||||
// regardless of whether pruning is enabled; it should generally be safe to | // regardless of whether pruning is enabled; it should generally be safe to | ||||
// not process unrequested blocks. | // not process unrequested blocks. | ||||
bool fTooFarAhead = | bool fTooFarAhead = | ||||
(pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); | (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); | ||||
Show All 40 Lines | if (!CheckBlock(config, block, state) || | ||||
} | } | ||||
return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | ||||
block.GetHash().ToString()); | block.GetHash().ToString()); | ||||
} | } | ||||
// Header is valid/has work and the merkle tree is good. | // Header is valid/has work and the merkle tree is good. | ||||
// Relay now, but if it does not build on our best tip, let the | // Relay now, but if it does not build on our best tip, let the | ||||
// SendMessages loop relay it. | // SendMessages loop relay it. | ||||
if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) { | if (!IsInitialBlockDownload() && fHasMoreWork) { | ||||
GetMainSignals().NewPoWValidBlock(pindex, pblock); | GetMainSignals().NewPoWValidBlock(pindex, pblock); | ||||
} | } | ||||
int nHeight = pindex->nHeight; | int nHeight = pindex->nHeight; | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
// Write block to history file | // Write block to history file | ||||
try { | try { | ||||
Show All 14 Lines | try { | ||||
} | } | ||||
if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) { | if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) { | ||||
return error("AcceptBlock(): ReceivedBlockTransactions failed"); | return error("AcceptBlock(): ReceivedBlockTransactions failed"); | ||||
} | } | ||||
} catch (const std::runtime_error &e) { | } catch (const std::runtime_error &e) { | ||||
return AbortNode(state, std::string("System error: ") + e.what()); | return AbortNode(state, std::string("System error: ") + e.what()); | ||||
} | } | ||||
if (fHasMoreWork && isSameHeightAndMoreHonestlyMined) { | |||||
if (PreciousBlock(config, state, pindex)) { | |||||
LogPrintf("More honestly broadcasted block has replaced chain tip " | |||||
"(set as precious block): %s\n", | |||||
pindex->GetBlockHash().ToString()); | |||||
} | |||||
} | |||||
deadalnixUnsubmitted Done Inline ActionsI do think you should edit CBlockIndexWorkComparator to select for more accurate timestamps if possible rather than use precious block. deadalnix: I do think you should edit `CBlockIndexWorkComparator` to select for more accurate timestamps… | |||||
if (fCheckForPruning) { | if (fCheckForPruning) { | ||||
// we just allocated more disk space for block files. | // we just allocated more disk space for block files. | ||||
FlushStateToDisk(config.GetChainParams(), state, FLUSH_STATE_NONE); | FlushStateToDisk(config.GetChainParams(), state, FLUSH_STATE_NONE); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,511 Lines • Show Last 20 Lines |
'/home/jason/projects/bitcoin-abc/src/validation.cpp' has code style errors.