Changes for most chain power rule

This commit is contained in:
miketout
2018-09-28 01:38:14 -07:00
parent f82b75eb8b
commit 4b729ec577
51 changed files with 666 additions and 444 deletions

View File

@@ -630,13 +630,13 @@ int32_t komodo_isPoS(CBlock *pblock)
void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
{
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
//fprintf(stderr,"disconnect ht.%d\n",pindex->nHeight);
komodo_init(pindex->nHeight);
//fprintf(stderr,"disconnect ht.%d\n",pindex->GetHeight());
komodo_init(pindex->GetHeight());
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
{
//sp->rewinding = pindex->nHeight;
//fprintf(stderr,"-%d ",pindex->nHeight);
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->nHeight,ASSETCHAINS_SYMBOL);
//sp->rewinding = pindex->GetHeight();
//fprintf(stderr,"-%d ",pindex->GetHeight());
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->GetHeight(),ASSETCHAINS_SYMBOL);
}
int32_t komodo_is_notarytx(const CTransaction& tx)
@@ -665,7 +665,7 @@ int32_t komodo_block2height(CBlock *block)
int32_t i,n,height2=-1,height = 0; uint8_t *ptr; CBlockIndex *pindex;
if ( (pindex= mapBlockIndex[block->GetHash()]) != 0 )
{
height2 = (int32_t)pindex->nHeight;
height2 = (int32_t)pindex->GetHeight();
if ( height2 >= 0 )
return(height2);
}
@@ -750,9 +750,9 @@ CBlockIndex *komodo_chainactive(int32_t height)
{
if ( chainActive.LastTip() != 0 )
{
if ( height <= chainActive.LastTip()->nHeight )
if ( height <= chainActive.LastTip()->GetHeight() )
return(chainActive[height]);
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->nHeight);
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->GetHeight());
}
//fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height);
return(0);
@@ -772,7 +772,7 @@ uint32_t komodo_heightstamp(int32_t height)
int32_t i,num; uint8_t pubkeys[64][33]; CBlock block;
if ( pindex->didinit != 0 )
return;
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->nHeight,pindex->notaryid,height);
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->GetHeight(),pindex->notaryid,height);
if ( pindex->didinit == 0 )
{
pindex->notaryid = -1;
@@ -784,12 +784,12 @@ uint32_t komodo_heightstamp(int32_t height)
komodo_block2pubkey33(pindex->pubkey33,&block);
//for (i=0; i<33; i++)
// fprintf(stderr,"%02x",pindex->pubkey33[i]);
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->nHeight,height);
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->GetHeight(),height);
//if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
// pindex->didinit = (KOMODO_LOADINGBLOCKS == 0);
} // else fprintf(stderr,"error loading block at %d/%d",pindex->nHeight,height);
} // else fprintf(stderr,"error loading block at %d/%d",pindex->GetHeight(),height);
}
if ( pindex->didinit != 0 && pindex->nHeight >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
if ( pindex->didinit != 0 && pindex->GetHeight() >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->GetHeight(),(uint32_t)pindex->nTime)) > 0 )
{
for (i=0; i<num; i++)
{
@@ -803,7 +803,7 @@ uint32_t komodo_heightstamp(int32_t height)
{
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pindex->pubkey33[i]);
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->nHeight,height);
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->GetHeight(),height);
}
}
}*/
@@ -986,12 +986,12 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex;
if ( (pindex= chainActive.LastTip()) == 0 )
return(-1);
notarized_height = komodo_notarizeddata(pindex->nHeight,&notarized_hash,&notarized_desttxid);
notarized_height = komodo_notarizeddata(pindex->GetHeight(),&notarized_hash,&notarized_desttxid);
*notarized_heightp = notarized_height;
if ( notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
if ( notarized_height >= 0 && notarized_height <= pindex->GetHeight() && (notary= mapBlockIndex[notarized_hash]) != 0 )
{
//printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str());
if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg
//printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->GetHeight(),notarized_height,notarized_hash.ToString().c_str());
if ( notary->GetHeight() == notarized_height ) // if notarized_hash not in chain, reorg
{
if ( nHeight < notarized_height )
{
@@ -1003,10 +1003,10 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
fprintf(stderr,"[%s] nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height);
return(-1);
}
} //else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
} //else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->GetHeight());
}
//else if ( notarized_height > 0 && notarized_height != 73880 && notarized_height >= 170000 )
// fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->nHeight);
// fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->GetHeight());
return(0);
}
@@ -1024,7 +1024,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_
if ( (pindex= mapBlockIndex[hashBlock]) != 0 )
{
*valuep = tx.vout[n].nValue;
*txheightp = pindex->nHeight;
*txheightp = pindex->GetHeight();
*txheighttimep = pindex->nTime;
if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 )
*tiptimep = (uint32_t)tipindex->nTime;
@@ -1059,7 +1059,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp)
if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 )
*kmdheightp = sp->CURRENT_HEIGHT;
else *kmdheightp = 0;
if ( (pindex= chainActive.LastTip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() )
if ( (pindex= chainActive.LastTip()) != 0 && pindex->GetHeight() >= (int32_t)komodo_longestchain() )
return(1);
else return(0);
}
@@ -1546,12 +1546,18 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
//printf("after nNonce: %s, height: %d\n", nonce.GetHex().c_str(), height);
//printf("POShash: %s\n\n", hash.GetHex().c_str());
if (newPOSActive && posHash != hash)
{
printf("blk hash: %s\nnonce: %s\ncorrect: %s\n", pblock->GetHash().GetHex().c_str(), pblock->nNonce.GetHex().c_str(), nonce.GetHex().c_str());
}
//if ((!newPOSActive || posHash == hash) && hash <= target)
if (hash <= target)
{
if ((mapBlockIndex.count(blkHash) == 0) ||
!(pastBlockIndex = mapBlockIndex[blkHash]) ||
(height - pastBlockIndex->nHeight) < VERUS_MIN_STAKEAGE)
(height - pastBlockIndex->GetHeight()) < VERUS_MIN_STAKEAGE)
{
fprintf(stderr,"ERROR: invalid PoS block %s - stake transaction too new\n",blkHash.ToString().c_str());
}
@@ -1660,7 +1666,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
return(0);
}
if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 )
height = pprev->nHeight + 1;
height = pprev->GetHeight() + 1;
if ( height == 0 )
return(0);
}
@@ -1800,21 +1806,21 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height)
*zfundsp = 0;
if ( (pindex= komodo_chainactive(height)) != 0 )
{
while ( pindex != 0 && pindex->nHeight > 0 )
while ( pindex != 0 && pindex->GetHeight() > 0 )
{
if ( pindex->newcoins == 0 && pindex->zfunds == 0 )
{
if ( komodo_blockload(block,pindex) == 0 )
pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block);
pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->GetHeight(),&block);
else
{
fprintf(stderr,"error loading block.%d\n",pindex->nHeight);
fprintf(stderr,"error loading block.%d\n",pindex->GetHeight());
return(0);
}
}
supply += pindex->newcoins;
zfunds += pindex->zfunds;
//printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds));
//printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->GetHeight(),dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds));
pindex = pindex->pprev;
}
}