Additional null pindex checks
This commit is contained in:
39
src/main.cpp
39
src/main.cpp
@@ -4138,8 +4138,8 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
|
|||||||
// The resulting new best tip may not be in setBlockIndexCandidates anymore, so
|
// The resulting new best tip may not be in setBlockIndexCandidates anymore, so
|
||||||
// add it again.
|
// add it again.
|
||||||
BlockMap::iterator it = mapBlockIndex.begin();
|
BlockMap::iterator it = mapBlockIndex.begin();
|
||||||
while (it != mapBlockIndex.end() && it->second != 0 ) {
|
while (it != mapBlockIndex.end()) {
|
||||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && !setBlockIndexCandidates.value_comp()(it->second, chainActive.Tip())) {
|
if ((it->second != 0) && it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && !setBlockIndexCandidates.value_comp()(it->second, chainActive.Tip())) {
|
||||||
setBlockIndexCandidates.insert(it->second);
|
setBlockIndexCandidates.insert(it->second);
|
||||||
}
|
}
|
||||||
it++;
|
it++;
|
||||||
@@ -4159,8 +4159,8 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
|
|||||||
|
|
||||||
// Remove the invalidity flag from this block and all its descendants.
|
// Remove the invalidity flag from this block and all its descendants.
|
||||||
BlockMap::iterator it = mapBlockIndex.begin();
|
BlockMap::iterator it = mapBlockIndex.begin();
|
||||||
while (it != mapBlockIndex.end() && it->second != 0) {
|
while (it != mapBlockIndex.end()) {
|
||||||
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
|
if ((it->second != 0) && !it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
|
||||||
it->second->nStatus &= ~BLOCK_FAILED_MASK;
|
it->second->nStatus &= ~BLOCK_FAILED_MASK;
|
||||||
setDirtyBlockIndex.insert(it->second);
|
setDirtyBlockIndex.insert(it->second);
|
||||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
|
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
|
||||||
@@ -4191,6 +4191,19 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
|||||||
uint256 hash = block.GetHash();
|
uint256 hash = block.GetHash();
|
||||||
BlockMap::iterator it = mapBlockIndex.find(hash);
|
BlockMap::iterator it = mapBlockIndex.find(hash);
|
||||||
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
|
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
|
||||||
|
|
||||||
|
// the following block is for debugging, comment when not needed
|
||||||
|
int countNull = 0;
|
||||||
|
int totalIdx = 0;
|
||||||
|
for (auto bit : mapBlockIndex)
|
||||||
|
{
|
||||||
|
totalIdx++;
|
||||||
|
if (bit.second == NULL)
|
||||||
|
countNull++;
|
||||||
|
}
|
||||||
|
if (countNull)
|
||||||
|
printf("%d total, %d NULL\n", totalIdx, countNull);
|
||||||
|
|
||||||
if (it != mapBlockIndex.end())
|
if (it != mapBlockIndex.end())
|
||||||
{
|
{
|
||||||
if ( it->second != 0 ) // vNodes.size() >= KOMODO_LIMITED_NETWORKSIZE, change behavior to allow komodo_ensure to work
|
if ( it->second != 0 ) // vNodes.size() >= KOMODO_LIMITED_NETWORKSIZE, change behavior to allow komodo_ensure to work
|
||||||
@@ -4216,7 +4229,7 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
|||||||
pindexNew->phashBlock = &((*mi).first);
|
pindexNew->phashBlock = &((*mi).first);
|
||||||
if (miPrev != mapBlockIndex.end())
|
if (miPrev != mapBlockIndex.end())
|
||||||
{
|
{
|
||||||
if ( (pindexNew->pprev= (*miPrev).second) != 0 )
|
if ( (pindexNew->pprev = (*miPrev).second) != 0 )
|
||||||
pindexNew->SetHeight(pindexNew->pprev->GetHeight() + 1);
|
pindexNew->SetHeight(pindexNew->pprev->GetHeight() + 1);
|
||||||
else fprintf(stderr,"unexpected null pprev %s\n",hash.ToString().c_str());
|
else fprintf(stderr,"unexpected null pprev %s\n",hash.ToString().c_str());
|
||||||
pindexNew->BuildSkip();
|
pindexNew->BuildSkip();
|
||||||
@@ -4719,7 +4732,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
|
|||||||
if (miSelf != mapBlockIndex.end())
|
if (miSelf != mapBlockIndex.end())
|
||||||
{
|
{
|
||||||
// Block header is already known.
|
// Block header is already known.
|
||||||
if ( (pindex= miSelf->second) == 0 )
|
if ( (pindex = miSelf->second) == 0 )
|
||||||
miSelf->second = pindex = AddToBlockIndex(block);
|
miSelf->second = pindex = AddToBlockIndex(block);
|
||||||
if (ppindex)
|
if (ppindex)
|
||||||
*ppindex = pindex;
|
*ppindex = pindex;
|
||||||
@@ -4889,13 +4902,13 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned
|
|||||||
|
|
||||||
void komodo_currentheight_set(int32_t height);
|
void komodo_currentheight_set(int32_t height);
|
||||||
|
|
||||||
CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash)
|
CBlockIndex *komodo_ensure(CBlock *pblock, uint256 hash)
|
||||||
{
|
{
|
||||||
CBlockIndex *pindex = 0;
|
CBlockIndex *pindex = 0;
|
||||||
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
|
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
|
||||||
if ( miSelf != mapBlockIndex.end() )
|
if ( miSelf != mapBlockIndex.end() )
|
||||||
{
|
{
|
||||||
if ( (pindex= miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail
|
if ( (pindex = miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail
|
||||||
{
|
{
|
||||||
miSelf->second = AddToBlockIndex(*pblock);
|
miSelf->second = AddToBlockIndex(*pblock);
|
||||||
//fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second);
|
//fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second);
|
||||||
@@ -4916,10 +4929,10 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash)
|
|||||||
return(pindex);
|
return(pindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBlockIndex *oldkomodo_ensure(CBlock *pblock,uint256 hash)
|
CBlockIndex *oldkomodo_ensure(CBlock *pblock, uint256 hash)
|
||||||
{
|
{
|
||||||
CBlockIndex *pindex=0,*previndex=0;
|
CBlockIndex *pindex=0,*previndex=0;
|
||||||
if ( (pindex= mapBlockIndex[hash]) == 0 )
|
if ( (pindex = mapBlockIndex[hash]) == 0 )
|
||||||
{
|
{
|
||||||
pindex = new CBlockIndex();
|
pindex = new CBlockIndex();
|
||||||
if (!pindex)
|
if (!pindex)
|
||||||
@@ -5079,7 +5092,7 @@ void PruneOneBlockFile(const int fileNumber)
|
|||||||
{
|
{
|
||||||
for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); ++it) {
|
for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); ++it) {
|
||||||
CBlockIndex* pindex = it->second;
|
CBlockIndex* pindex = it->second;
|
||||||
if (pindex->nFile == fileNumber) {
|
if (pindex && pindex->nFile == fileNumber) {
|
||||||
pindex->nStatus &= ~BLOCK_HAVE_DATA;
|
pindex->nStatus &= ~BLOCK_HAVE_DATA;
|
||||||
pindex->nStatus &= ~BLOCK_HAVE_UNDO;
|
pindex->nStatus &= ~BLOCK_HAVE_UNDO;
|
||||||
pindex->nFile = 0;
|
pindex->nFile = 0;
|
||||||
@@ -5224,7 +5237,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
|
|||||||
|
|
||||||
// Return existing
|
// Return existing
|
||||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||||
if (mi != mapBlockIndex.end())
|
if (mi != mapBlockIndex.end() && mi->second != NULL)
|
||||||
return (*mi).second;
|
return (*mi).second;
|
||||||
|
|
||||||
// Create new
|
// Create new
|
||||||
@@ -5605,7 +5618,7 @@ bool RewindBlockIndex(const CChainParams& params, bool& clearWitnessCaches)
|
|||||||
// this block or some successor doesn't HAVE_DATA, so we were unable to
|
// this block or some successor doesn't HAVE_DATA, so we were unable to
|
||||||
// rewind all the way. Blocks remaining on chainActive at this point
|
// rewind all the way. Blocks remaining on chainActive at this point
|
||||||
// must not have their validity reduced.
|
// must not have their validity reduced.
|
||||||
if (!sufficientlyValidated(pindexIter) && !chainActive.Contains(pindexIter)) {
|
if (pindexIter && !sufficientlyValidated(pindexIter) && !chainActive.Contains(pindexIter)) {
|
||||||
// Reduce validity
|
// Reduce validity
|
||||||
pindexIter->nStatus =
|
pindexIter->nStatus =
|
||||||
std::min<unsigned int>(pindexIter->nStatus & BLOCK_VALID_MASK, BLOCK_VALID_TREE) |
|
std::min<unsigned int>(pindexIter->nStatus & BLOCK_VALID_MASK, BLOCK_VALID_TREE) |
|
||||||
|
|||||||
@@ -584,10 +584,13 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
|||||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||||
if (mi != mapBlockIndex.end()) {
|
if (mi != mapBlockIndex.end()) {
|
||||||
CBlockIndex *pindex = mi->second;
|
CBlockIndex *pindex = mi->second;
|
||||||
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
if (pindex)
|
||||||
return "duplicate";
|
{
|
||||||
if (pindex->nStatus & BLOCK_FAILED_MASK)
|
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
||||||
return "duplicate-invalid";
|
return "duplicate";
|
||||||
|
if (pindex->nStatus & BLOCK_FAILED_MASK)
|
||||||
|
return "duplicate-invalid";
|
||||||
|
}
|
||||||
return "duplicate-inconclusive";
|
return "duplicate-inconclusive";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -882,12 +885,15 @@ UniValue submitblock(const UniValue& params, bool fHelp)
|
|||||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||||
if (mi != mapBlockIndex.end()) {
|
if (mi != mapBlockIndex.end()) {
|
||||||
CBlockIndex *pindex = mi->second;
|
CBlockIndex *pindex = mi->second;
|
||||||
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
if (pindex)
|
||||||
return "duplicate";
|
{
|
||||||
if (pindex->nStatus & BLOCK_FAILED_MASK)
|
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
||||||
return "duplicate-invalid";
|
return "duplicate";
|
||||||
// Otherwise, we might only have the header - process the block before returning
|
if (pindex->nStatus & BLOCK_FAILED_MASK)
|
||||||
fBlockPresent = true;
|
return "duplicate-invalid";
|
||||||
|
// Otherwise, we might only have the header - process the block before returning
|
||||||
|
fBlockPresent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1420,10 +1420,6 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe
|
|||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// !! DISABLE THIS FOR RELEASE: THIS MAKES A CHEAT TRANSACTION FOR EVERY STAKE FOR TESTING
|
|
||||||
//CMutableTransaction cheat;
|
|
||||||
// !! DOWN TO HERE
|
|
||||||
|
|
||||||
// if we are staking with the extended format, add the opreturn data required
|
// if we are staking with the extended format, add the opreturn data required
|
||||||
if (extendedStake)
|
if (extendedStake)
|
||||||
{
|
{
|
||||||
@@ -1440,29 +1436,30 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// !! DISABLE THIS FOR RELEASE: THIS MAKES A CHEAT TRANSACTION FOR EVERY STAKE FOR TESTING
|
// !! DISABLE THIS FOR RELEASE: THIS MAKES A CHEAT TRANSACTION FOR EVERY STAKE FOR TESTING
|
||||||
//cheat = CMutableTransaction(txNew);
|
CMutableTransaction cheat;
|
||||||
//cheat.vout[1].scriptPubKey << OP_RETURN
|
cheat = CMutableTransaction(txNew);
|
||||||
// << CStakeParams(pSrcIndex->GetHeight(), tipindex->GetHeight() + 1, pSrcIndex->GetBlockHash(), pk).AsVector();
|
cheat.vout[1].scriptPubKey << OP_RETURN
|
||||||
|
<< CStakeParams(pSrcIndex->GetHeight(), tipindex->GetHeight() + 1, pSrcIndex->GetBlockHash(), pk).AsVector();
|
||||||
// !! DOWN TO HERE
|
// !! DOWN TO HERE
|
||||||
|
|
||||||
txOut1.scriptPubKey << OP_RETURN
|
txOut1.scriptPubKey << OP_RETURN
|
||||||
<< CStakeParams(pSrcIndex->GetHeight(), tipindex->GetHeight() + 1, tipindex->GetBlockHash(), pk).AsVector();
|
<< CStakeParams(pSrcIndex->GetHeight(), tipindex->GetHeight() + 1, tipindex->GetBlockHash(), pk).AsVector();
|
||||||
}
|
|
||||||
|
|
||||||
// !! DISABLE THIS FOR RELEASE: REMOVE THIS TOO
|
// !! DISABLE THIS FOR RELEASE: REMOVE THIS TOO
|
||||||
//nValue = cheat.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee;
|
nValue = cheat.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee;
|
||||||
//cheat.nLockTime = 0;
|
cheat.nLockTime = 0;
|
||||||
//CTransaction cheatConst(cheat);
|
CTransaction cheatConst(cheat);
|
||||||
//SignatureData cheatSig;
|
SignatureData cheatSig;
|
||||||
//if (!ProduceSignature(TransactionSignatureCreator(&keystore, &cheatConst, 0, nValue, SIGHASH_ALL), stakeSource.vout[voutNum].scriptPubKey, cheatSig, consensusBranchId))
|
if (!ProduceSignature(TransactionSignatureCreator(&keystore, &cheatConst, 0, nValue, SIGHASH_ALL), stakeSource.vout[voutNum].scriptPubKey, cheatSig, consensusBranchId))
|
||||||
// fprintf(stderr,"failed to create cheat test signature\n");
|
fprintf(stderr,"failed to create cheat test signature\n");
|
||||||
//else
|
else
|
||||||
//{
|
{
|
||||||
// uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
// UpdateTransaction(cheat,0,cheatSig);
|
UpdateTransaction(cheat,0,cheatSig);
|
||||||
// cheatList.Add(CTxHolder(CTransaction(cheat), tipindex->GetHeight() + 1));
|
cheatList.Add(CTxHolder(CTransaction(cheat), tipindex->GetHeight() + 1));
|
||||||
//}
|
}
|
||||||
// !! DOWN TO HERE
|
// !! DOWN TO HERE
|
||||||
|
}
|
||||||
|
|
||||||
nValue = txNew.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee;
|
nValue = txNew.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user