From 4ac854ea908bb5446b0713df1e8467f527d08bab Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 01:37:43 +0300 Subject: [PATCH] Simplify ensure --- src/main.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index a6d2fee8f..250a72f72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4195,6 +4195,32 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned void komodo_currentheight_set(int32_t height); CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) +{ + CBlockIndex *pindex; + BlockMap::iterator miSelf = mapBlockIndex.find(hash); + if ( miSelf != mapBlockIndex.end() ) + { + if ( (pindex= miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail + { + miSelf->second = AddToBlockIndex(*pblock); + //fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); + } + if ( hash != Params.GetConsensus().hashGenesisBlock ) + { + miSelf = mapBlockIndex.find(pblock->hashPrevBlock); + if ( miSelf != mapBlockIndex.end() ) + { + if ( miSelf->second == 0 ) + { + miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); + fprintf(stderr,"autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } + } + } + } +} + +CBlockIndex *oldkomodo_ensure(CBlock *pblock,uint256 hash) { CBlockIndex *pindex=0,*previndex=0; if ( (pindex= mapBlockIndex[hash]) == 0 )