|
|
@ -86,7 +86,7 @@ int32_t gettxout_scriptPubKey(int32_t height,uint8_t *scriptPubKey,int32_t maxsi |
|
|
|
{ |
|
|
|
if ( GetTransaction(txid,(CTransaction &)tx,hashBlock,false) == 0 ) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"ht.%d couldnt get txid.%s\n",height,txid.GetHex().c_str());
|
|
|
|
fprintf(stderr,"ht.%d couldnt get txid.%s\n",height,txid.GetHex().c_str()); |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
} |
|
|
@ -100,17 +100,18 @@ int32_t gettxout_scriptPubKey(int32_t height,uint8_t *scriptPubKey,int32_t maxsi |
|
|
|
{ |
|
|
|
const CWalletTx& wtx = it->second; |
|
|
|
tx = wtx.tx; |
|
|
|
//fprintf(stderr,"found tx in wallet\n");
|
|
|
|
fprintf(stderr,"found tx in wallet\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fprintf(stderr,"just before tx->vout\n"); |
|
|
|
if ( tx != 0 && n >= 0 && n <= (int32_t)tx->vout.size() ) // vout.size() seems off by 1
|
|
|
|
{ |
|
|
|
ptr = (uint8_t *)tx->vout[n].scriptPubKey.data(); |
|
|
|
m = tx->vout[n].scriptPubKey.size(); |
|
|
|
for (i=0; i<maxsize&&i<m; i++) |
|
|
|
scriptPubKey[i] = ptr[i]; |
|
|
|
//fprintf(stderr,"got scriptPubKey[%d] via rawtransaction ht.%d %s\n",m,height,txid.GetHex().c_str());
|
|
|
|
fprintf(stderr,"got scriptPubKey[%d] via rawtransaction ht.%d %s\n",m,height,txid.GetHex().c_str()); |
|
|
|
return(i); |
|
|
|
} |
|
|
|
else if ( tx != 0 ) |
|
|
@ -569,9 +570,9 @@ CBlockIndex *komodo_chainactive(int32_t height) |
|
|
|
{ |
|
|
|
if ( height <= tipindex->nHeight ) |
|
|
|
return(chainActive[height]); |
|
|
|
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight);
|
|
|
|
else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); |
|
|
|
} |
|
|
|
//fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height);
|
|
|
|
fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
@ -580,7 +581,7 @@ uint32_t komodo_heightstamp(int32_t height) |
|
|
|
CBlockIndex *ptr; |
|
|
|
if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) |
|
|
|
return(ptr->nTime); |
|
|
|
//else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height);
|
|
|
|
else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
@ -768,6 +769,7 @@ int32_t komodo_init() |
|
|
|
KOMODO_NEEDPUBKEYS = 1; |
|
|
|
KOMODO_TXINDEX = 0; |
|
|
|
} |
|
|
|
fprintf(stderr,"END INIT\n"); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
@ -817,6 +819,7 @@ uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth) |
|
|
|
|
|
|
|
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) |
|
|
|
{ |
|
|
|
fprintf(stderr,"komodo_notaries\n"); |
|
|
|
static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1; |
|
|
|
int32_t i; |
|
|
|
if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 ) |
|
|
@ -835,8 +838,8 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam |
|
|
|
did0 = 1; |
|
|
|
} |
|
|
|
memcpy(pubkeys,elected_pubkeys0,n0 * 33); |
|
|
|
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
|
|
|
//fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0);
|
|
|
|
if ( ASSETCHAINS_SYMBOL[0] != 0 ) |
|
|
|
fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0); |
|
|
|
return(n0); |
|
|
|
} |
|
|
|
else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 )
|
|
|
@ -854,6 +857,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam |
|
|
|
return(n1); |
|
|
|
} |
|
|
|
} |
|
|
|
fprintf(stderr,"komodo_notaries END\n"); |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
|
|
|
@ -871,6 +875,7 @@ void komodo_clearstate() |
|
|
|
|
|
|
|
void komodo_disconnect(CBlockIndex *pindex,CBlock *block) |
|
|
|
{ |
|
|
|
fprintf(stderr,"komodo_disconnect\n"); |
|
|
|
if ( (int32_t)pindex->nHeight <= NOTARIZED_HEIGHT ) |
|
|
|
{ |
|
|
|
fprintf(stderr,"komodo_disconnect unexpected reorg pindex->nHeight.%d vs %d\n",(int32_t)pindex->nHeight,NOTARIZED_HEIGHT); |
|
|
@ -988,6 +993,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n |
|
|
|
|
|
|
|
void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid,uint256 MoM,int32_t MoMdepth) |
|
|
|
{ |
|
|
|
fprintf(stderr,"komodo_notarized_update\n"); |
|
|
|
static int didinit; static uint256 zero; static FILE *fp; CBlockIndex *pindex; struct notarized_checkpoint *np,N; long fpos; |
|
|
|
if ( didinit == 0 ) |
|
|
|
{ |
|
|
@ -1043,7 +1049,7 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no |
|
|
|
fprintf(stderr,"komodo_notarized_update reject nHeight.%d notarized_height.%d:%d\n",nHeight,notarized_height,(int32_t)pindex->nHeight); |
|
|
|
return; |
|
|
|
} |
|
|
|
//fprintf(stderr,"komodo_notarized_update nHeight.%d notarized_height.%d prev.%d\n",nHeight,notarized_height,NPOINTS!=0?NPOINTS[NUM_NPOINTS-1].notarized_height:-1);
|
|
|
|
fprintf(stderr,"komodo_notarized_update nHeight.%d notarized_height.%d prev.%d\n",nHeight,notarized_height,NPOINTS!=0?NPOINTS[NUM_NPOINTS-1].notarized_height:-1); |
|
|
|
portable_mutex_lock(&komodo_mutex); |
|
|
|
NPOINTS = (struct notarized_checkpoint *)realloc(NPOINTS,(NUM_NPOINTS+1) * sizeof(*NPOINTS)); |
|
|
|
np = &NPOINTS[NUM_NPOINTS++]; |
|
|
@ -1065,10 +1071,13 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no |
|
|
|
} |
|
|
|
// add to stored notarizations
|
|
|
|
portable_mutex_unlock(&komodo_mutex); |
|
|
|
fprintf(stderr,"komodo_notarized_update END\n"); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) |
|
|
|
{ |
|
|
|
fprintf(stderr,"komodo_checkpoint\n"); |
|
|
|
|
|
|
|
int32_t notarized_height; uint256 zero,notarized_hash,notarized_desttxid; CBlockIndex *notary; CBlockIndex *pindex; |
|
|
|
memset(&zero,0,sizeof(zero)); |
|
|
|
//komodo_notarized_update(0,0,zero,zero,zero,0);
|
|
|
@ -1078,7 +1087,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has |
|
|
|
*notarized_heightp = notarized_height; |
|
|
|
if ( notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 ) |
|
|
|
{ |
|
|
|
//printf("nHeight.%d -> (%d %s)\n",pindex->nHeight,notarized_height,notarized_hash.ToString().c_str());
|
|
|
|
printf("nHeight.%d -> (%d %s)\n",pindex->nHeight,notarized_height,notarized_hash.ToString().c_str()); |
|
|
|
if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg
|
|
|
|
{ |
|
|
|
if ( nHeight < notarized_height ) |
|
|
@ -1094,11 +1103,14 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has |
|
|
|
} else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight); |
|
|
|
} else if ( notarized_height > 0 ) |
|
|
|
fprintf(stderr,"%s couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->nHeight); |
|
|
|
fprintf(stderr,"komodo_checkpoint END\n"); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
void komodo_voutupdate(int32_t txi,int32_t vout,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask) |
|
|
|
{ |
|
|
|
fprintf(stderr,"komodo_voutupdate\n"); |
|
|
|
|
|
|
|
static uint256 zero; static uint8_t crypto777[33]; |
|
|
|
int32_t MoMdepth,opretlen,len = 0; uint256 hash,desttxid,MoM; |
|
|
|
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) |
|
|
@ -1143,20 +1155,24 @@ void komodo_voutupdate(int32_t txi,int32_t vout,uint8_t *scriptbuf,int32_t scrip |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//fprintf(stderr,"VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,MoM.ToString().c_str(),MoMdepth);
|
|
|
|
fprintf(stderr,"VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,MoM.ToString().c_str(),MoMdepth); |
|
|
|
} |
|
|
|
} |
|
|
|
komodo_notarized_update(height,*notarizedheightp,hash,desttxid,MoM,MoMdepth); |
|
|
|
fprintf(stderr,"%s ht.%d NOTARIZED.%d %s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,hash.ToString().c_str(),"KMD",desttxid.ToString().c_str(),opretlen,len); |
|
|
|
} //else fprintf(stderr,"notarized.%d ht %d vs prev %d vs height.%d\n",notarized,*notarizedheightp,NOTARIZED_HEIGHT,height);
|
|
|
|
} else fprintf(stderr,"notarized.%d ht %d vs prev %d vs height.%d\n",notarized,*notarizedheightp,NOTARIZED_HEIGHT,height); |
|
|
|
} |
|
|
|
} |
|
|
|
fprintf(stderr,"komodo_voutupdate END\n"); |
|
|
|
} |
|
|
|
|
|
|
|
void komodo_connectblock(CBlockIndex *pindex,CBlock& block) |
|
|
|
{ |
|
|
|
static int32_t hwmheight; |
|
|
|
uint64_t signedmask; uint8_t scriptbuf[4096],pubkeys[64][33],scriptPubKey[35]; uint256 zero; int32_t i,j,k,numnotaries,notarized,scriptlen,numvalid,specialtx,notarizedheight,len,numvouts,numvins,height,txn_count; |
|
|
|
|
|
|
|
fprintf(stderr,"komodo_connectblock\n"); |
|
|
|
|
|
|
|
if ( KOMODO_NEEDPUBKEYS != 0 ) |
|
|
|
{ |
|
|
|
komodo_importpubkeys(); |
|
|
@ -1165,6 +1181,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) |
|
|
|
memset(&zero,0,sizeof(zero)); |
|
|
|
komodo_notarized_update(0,0,zero,zero,zero,0); |
|
|
|
numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime()); |
|
|
|
fprintf(stderr,"after komodo_notaries()\n"); |
|
|
|
|
|
|
|
if ( pindex->nHeight > hwmheight ) |
|
|
|
hwmheight = pindex->nHeight; |
|
|
|
else |
|
|
@ -1172,10 +1190,12 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) |
|
|
|
if ( pindex->nHeight != 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); |
|
|
|
} |
|
|
|
|
|
|
|
if ( pindex != 0 ) |
|
|
|
{ |
|
|
|
height = pindex->nHeight; |
|
|
|
txn_count = block.vtx.size(); |
|
|
|
fprintf(stderr, "txn_count=%d\n", txn_count); |
|
|
|
for (i=0; i<txn_count; i++) |
|
|
|
{ |
|
|
|
//txhash = block.vtx[i]->GetHash();
|
|
|
@ -1183,6 +1203,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) |
|
|
|
specialtx = notarizedheight = notarized = 0; |
|
|
|
signedmask = 0; |
|
|
|
numvins = block.vtx[i].vin.size(); |
|
|
|
fprintf(stderr, "tx=%d, numvouts=%d, numvins=%d\n", i, numvouts, numvins ); |
|
|
|
for (j=0; j<numvins; j++) |
|
|
|
{ |
|
|
|
if ( i == 0 && j == 0 ) |
|
|
@ -1195,17 +1216,17 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) |
|
|
|
signedmask |= (1LL << k); |
|
|
|
break; |
|
|
|
} |
|
|
|
} // else if ( block.vtx[i]->vin[j].prevout.hash != zero ) printf("%s cant get scriptPubKey for ht.%d txi.%d vin.%d\n",ASSETCHAINS_SYMBOL,height,i,j);
|
|
|
|
} else if ( block.vtx[i].vin[j].prevout.hash != zero ) printf("%s cant get scriptPubKey for ht.%d txi.%d vin.%d\n",ASSETCHAINS_SYMBOL,height,i,j); |
|
|
|
} |
|
|
|
numvalid = bitweight(signedmask); |
|
|
|
if ( numvalid >= KOMODO_MINRATIFY ) |
|
|
|
notarized = 1; |
|
|
|
//if ( NOTARY_PUBKEY33[0] != 0 )
|
|
|
|
// printf("(tx.%d: ",i);
|
|
|
|
if ( NOTARY_PUBKEY33[0] != 0 ) |
|
|
|
printf("(tx.%d: ",i); |
|
|
|
for (j=0; j<numvouts; j++) |
|
|
|
{ |
|
|
|
//if ( NOTARY_PUBKEY33[0] != 0 )
|
|
|
|
// printf("%.8f ",dstr(block.vtx[i]->vout[j].nValue));
|
|
|
|
if ( NOTARY_PUBKEY33[0] != 0 ) |
|
|
|
printf("%.8f ",dstr(block.vtx[i].vout[j].nValue)); |
|
|
|
len = block.vtx[i].vout[j].scriptPubKey.size(); |
|
|
|
if ( len >= (int32_t)sizeof(uint32_t) && len <= (int32_t)sizeof(scriptbuf) ) |
|
|
|
{ |
|
|
@ -1213,11 +1234,14 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) |
|
|
|
komodo_voutupdate(i,j,scriptbuf,len,height,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask); |
|
|
|
} |
|
|
|
} |
|
|
|
//if ( NOTARY_PUBKEY33[0] != 0 )
|
|
|
|
// printf(") ");
|
|
|
|
//if ( NOTARY_PUBKEY33[0] != 0 )
|
|
|
|
// printf("%s ht.%d\n",ASSETCHAINS_SYMBOL,height);
|
|
|
|
//printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx);
|
|
|
|
if ( NOTARY_PUBKEY33[0] != 0 ) |
|
|
|
printf(") "); |
|
|
|
if ( NOTARY_PUBKEY33[0] != 0 ) |
|
|
|
printf("%s ht.%d\n",ASSETCHAINS_SYMBOL,height); |
|
|
|
printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx); |
|
|
|
} |
|
|
|
fprintf(stderr,"komodo_connectblock: done processing txns\n"); |
|
|
|
} else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n"); |
|
|
|
|
|
|
|
fprintf(stderr,"komodo_connectblock END\n"); |
|
|
|
} |
|
|
|