Auto merge of #4427 - nuttycom:simplify_connect_tip, r=daira
Remove option to load new blocks from ConnectTip A minor refactoring to move file IO out of ConnectTip, which has only a single caller.
This commit is contained in:
commit
9e86cc2d82
22
src/main.cpp
22
src/main.cpp
|
@ -3212,15 +3212,8 @@ uint64_t nNotifiedSequence = 0;
|
|||
*/
|
||||
bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock)
|
||||
{
|
||||
assert(pindexNew->pprev == chainActive.Tip());
|
||||
// Read block from disk.
|
||||
assert(pblock && pindexNew->pprev == chainActive.Tip());
|
||||
int64_t nTime1 = GetTimeMicros();
|
||||
CBlock block;
|
||||
if (!pblock) {
|
||||
if (!ReadBlockFromDisk(block, pindexNew, chainparams.GetConsensus()))
|
||||
return AbortNode(state, "Failed to read block");
|
||||
pblock = █
|
||||
}
|
||||
// Apply the block atomically to the chain state.
|
||||
int64_t nTime2 = GetTimeMicros(); nTimeReadFromDisk += nTime2 - nTime1;
|
||||
int64_t nTime3;
|
||||
|
@ -3431,7 +3424,18 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
|
|||
|
||||
// Connect new blocks.
|
||||
BOOST_REVERSE_FOREACH(CBlockIndex *pindexConnect, vpindexToConnect) {
|
||||
if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL)) {
|
||||
const CBlock* pconnectBlock;
|
||||
CBlock block;
|
||||
if (pblock && pindexConnect == pindexMostWork) {
|
||||
pconnectBlock = pblock;
|
||||
} else {
|
||||
// read the block to be connected from disk
|
||||
if (!ReadBlockFromDisk(block, pindexConnect, chainparams.GetConsensus()))
|
||||
return AbortNode(state, "Failed to read block");
|
||||
pconnectBlock = █
|
||||
}
|
||||
|
||||
if (!ConnectTip(state, chainparams, pindexConnect, pconnectBlock)) {
|
||||
if (state.IsInvalid()) {
|
||||
// The block violates a consensus rule.
|
||||
if (!state.CorruptionPossible())
|
||||
|
|
Loading…
Reference in New Issue