Merge branch 'FSM' of https://github.com/jl777/komodo into jl777-FSM

merge
This commit is contained in:
blackjok3r
2018-11-29 23:22:32 +08:00
566 changed files with 42751 additions and 10240 deletions

View File

@@ -511,7 +511,7 @@ int32_t komodo_validate_chain(uint256 srchash,int32_t notarized_height)
static int32_t last_rewind; int32_t rewindtarget; CBlockIndex *pindex; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
return(0);
if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != notarized_height) )
if ( IsInitialBlockDownload() == 0 && ((pindex= komodo_getblockindex(srchash)) == 0 || pindex->GetHeight() != notarized_height) )
{
if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < notarized_height )
rewindtarget = sp->NOTARIZED_HEIGHT - 1;
@@ -807,7 +807,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash;
int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
memset(&zero,0,sizeof(zero));
komodo_init(pindex->nHeight);
komodo_init(pindex->GetHeight());
KOMODO_INITDONE = (uint32_t)time(NULL);
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
{
@@ -837,25 +837,25 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
lastStakedEra = staked_era;
}
numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime());
numnotaries = komodo_notaries(pubkeys,pindex->GetHeight(),pindex->GetBlockTime());
calc_rmd160_sha256(rmd160,pubkeys[0],33);
if ( pindex->nHeight > hwmheight )
hwmheight = pindex->nHeight;
if ( pindex->GetHeight() > hwmheight )
hwmheight = pindex->GetHeight();
else
{
if ( pindex->nHeight != hwmheight )
if ( pindex->GetHeight() != hwmheight )
{
printf("%s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight);
komodo_purge_ccdata((int32_t)pindex->nHeight);
hwmheight = pindex->nHeight;
printf("%s hwmheight.%d vs pindex->GetHeight().%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->GetHeight(),(uint32_t)pindex->nTime,hwmheight-pindex->GetHeight());
komodo_purge_ccdata((int32_t)pindex->GetHeight());
hwmheight = pindex->GetHeight();
}
komodo_event_rewind(sp,symbol,pindex->nHeight);
komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0);
komodo_event_rewind(sp,symbol,pindex->GetHeight());
komodo_stateupdate(pindex->GetHeight(),0,0,0,zero,0,0,0,0,-pindex->GetHeight(),pindex->nTime,0,0,0,0,zero,0);
}
komodo_currentheight_set(chainActive.LastTip()->nHeight);
komodo_currentheight_set(chainActive.LastTip()->GetHeight());
if ( pindex != 0 )
{
height = pindex->nHeight;
height = pindex->GetHeight();
txn_count = block.vtx.size();
for (i=0; i<txn_count; i++)
{
@@ -918,7 +918,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
{
/*if ( i == 0 && j == 0 )
{
uint8_t *script = (uint8_t *)block.vtx[0].vout[numvouts-1].scriptPubKey.data();
uint8_t *script = (uint8_t *)&block.vtx[0].vout[numvouts-1].scriptPubKey[0];
if ( numvouts <= 2 || script[0] != 0x6a )
{
if ( numvouts == 2 && block.vtx[0].vout[1].nValue != 0 )
@@ -935,11 +935,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
{
#ifdef KOMODO_ZCASH
memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
#else
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
#endif
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime());
if ( 0 && i > 0 )
{
@@ -969,11 +965,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
{
#ifdef KOMODO_ZCASH
memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
#else
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
#endif
if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
{
memcpy(pubkeys[numvalid++],scriptbuf+1,33);
@@ -994,11 +986,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height);
if ( pindex->nHeight == hwmheight )
if ( pindex->GetHeight() == hwmheight )
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0);
} else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n");
//KOMODO_INITDONE = (uint32_t)time(NULL);
//fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight);
//fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->GetHeight());
}