Browse Source

MoMoM code complete

jl777
jl777 7 years ago
parent
commit
2be7001a60
  1. 10
      iguana/dPoW.h
  2. 62
      iguana/dpow/dpow_fsm.c
  3. 18
      iguana/dpow/dpow_rpc.c
  4. 24
      iguana/dpow/dpow_tx.c
  5. 12
      iguana/iguana_notary.c
  6. 2
      includes/iguana_structs.h

10
iguana/dPoW.h

@ -141,6 +141,16 @@ struct dpow_info
uint32_t ipbits[128],numipbits;
struct dpow_block **blocks;
};
struct komodo_ccdatapair { int32_t notarization_height; uint32_t MoMoMoffset; };
struct komodo_ccdataMoMoM
{
bits256 MoMoM;
int32_t kmdstarti,kmdendi,MoMoMdepth,numpairs,len;
struct komodo_ccdatapair *pairs;
};
uint64_t dpow_notarybestk(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp);
int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp,bits256 MoM,uint32_t MoMdepth);
void dex_updateclient(struct supernet_info *myinfo);

62
iguana/dpow/dpow_fsm.c

@ -162,7 +162,8 @@ int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct
uint32_t Numallocated;
int32_t dpow_opreturn_parsesrc(bits256 *blockhashp,int32_t *heightp,bits256 *txidp,char *symbol,bits256 *MoMp,uint32_t *MoMdepthp,uint8_t *opret,int32_t opretlen)
int32_t dpow_opreturn_parsesrc(bits256 *blockhashp,int32_t *heightp,bits256 *txidp,char *symbol,bits256 *MoMp,uint32_t *MoMdepthp,uint8_t *opret,int32_t opretlen,struct komodo_ccdataMoMoM
*mdata)
{
int32_t i,c,len,offset = 0; uint8_t op;
symbol[0] = 0;
@ -171,6 +172,7 @@ int32_t dpow_opreturn_parsesrc(bits256 *blockhashp,int32_t *heightp,bits256 *txi
memset(txidp->bytes,0,sizeof(*txidp));
memset(MoMp->bytes,0,sizeof(*MoMp));
memset(MoMdepthp,0,sizeof(*MoMdepthp));
memset(mdata,0,sizeof(*mdata));
if ( opret[offset++] == 0x6a )
{
if ( (op= opret[offset++]) < 0x4c )
@ -198,16 +200,37 @@ int32_t dpow_opreturn_parsesrc(bits256 *blockhashp,int32_t *heightp,bits256 *txi
}
if ( offset+sizeof(bits256)+sizeof(uint32_t) <= opretlen )
{
uint32_t CCid,k;
offset += iguana_rwbignum(0,&opret[offset],sizeof(*MoMp),MoMp->bytes);
offset += iguana_rwnum(0,&opret[offset],sizeof(*MoMdepthp),(uint32_t *)MoMdepthp);
// MoMoM, depth, numpairs, (notarization ht, MoMoM offset)
if ( offset+52 <= opretlen )
{
offset += iguana_rwnum(0,&opret[offset],sizeof(CCid),(uint8_t *)&CCid);
offset += iguana_rwnum(0,&opret[offset],sizeof(uint32_t),(uint8_t *)&mdata->kmdstarti);
offset += iguana_rwnum(0,&opret[offset],sizeof(uint32_t),(uint8_t *)&mdata->kmdendi);
offset += iguana_rwbignum(0,&opret[offset],sizeof(mdata->MoMoM),(uint8_t *)&mdata->MoMoM);
offset += iguana_rwnum(0,&opret[offset],sizeof(uint32_t),(uint8_t *)&mdata->MoMoMdepth);
offset += iguana_rwnum(0,&opret[offset],sizeof(uint32_t),(uint8_t *)&mdata->numpairs);
mdata->len += sizeof(mdata->MoMoM) + sizeof(uint32_t)*4;
if ( offset+mdata->numpairs*8 == opretlen )
{
mdata->pairs = (struct komodo_ccdatapair *)calloc(mdata->numpairs,sizeof(*mdata->pairs));
for (k=0; k<mdata->numpairs; k++)
{
offset += iguana_rwnum(0,&opret[offset],sizeof(int32_t),(uint8_t *)&mdata->pairs[k].notarization_height);
offset += iguana_rwnum(0,&opret[offset],sizeof(uint32_t),(uint8_t *)&mdata->pairs[k].MoMoMoffset);
mdata->len += sizeof(uint32_t) * 2;
}
} else if ( mdata->numpairs > 0 )
printf("offset.%d + %d*8 != opretlen.%d\n",offset,mdata->numpairs,opretlen);
}
}
///printf("offset.%d vs len.%d\n",offset,len);
return(len);
}
return(-1);
}
int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t height)
int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t height,struct komodo_ccdataMoMoM *mdata)
{
cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[256]; bits256 spenttxid; uint64_t notarymask=0; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0;
if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 )
@ -269,12 +292,25 @@ int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supe
{
len >>= 1;
decode_hex(script,len,hexstr);
if ( dpow_opreturn_parsesrc(&blockhash,nothtp,&txid,symbol,&MoM,&MoMdepth,script,len) > 0 )
if ( dpow_opreturn_parsesrc(&blockhash,nothtp,&txid,symbol,&MoM,&MoMdepth,script,len,mdata) > 0 && strcmp(symbol,coin->symbol) == 0 )
{
if ( Notaries_port != DPOW_SOCKPORT )
// if ( Notaries_port != DPOW_SOCKPORT ) // keep going till valid MoM found, useful for new chains without any MoM
{
if ( bits256_nonz(MoM) == 0 || MoMdepth == 0 || *nothtp >= height || *nothtp < 0 )
{
*nothtp = 0;
}
}
if ( mdata->pairs != 0 && mdata->numpairs > 0 )
{
for (j=0; j<mdata->numpairs; j++)
{
if ( mdata->pairs[j].notarization_height > coin->MoMoMheight )
{
coin->MoMoMheight = mdata->pairs[j].notarization_height;
printf("set %s MoMoMheight <- %d\n",coin->symbol,coin->MoMoMheight);
}
}
}
//printf("%s.%d notarizationht.%d %s -> %s MoM.%s [%d]\n",symbol,height,*nothtp,bits256_str(str,blockhash),bits256_str(str2,txid),bits256_str(str3,MoM),MoMdepth);
}
@ -291,17 +327,18 @@ int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supe
return(hasnotarization);
}
int32_t dpow_hasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson,int32_t ht)
int32_t dpow_hasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson,int32_t ht,struct komodo_ccdataMoMoM *mdata)
{
int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray;
*nothtp = 0;
*signedmaskp = 0;
memset(mdata,0,sizeof(*mdata));
if ( (txarray= jarray(&n,blockjson,"tx")) != 0 )
{
for (i=0; i<n; i++)
{
txid = jbits256i(txarray,i);
hasnotarization += dpow_txhasnotarization(signedmaskp,nothtp,myinfo,coin,txid,ht);
hasnotarization += dpow_txhasnotarization(signedmaskp,nothtp,myinfo,coin,txid,ht,mdata);
}
}
return(hasnotarization);
@ -309,7 +346,7 @@ int32_t dpow_hasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supern
bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct iguana_info *coin,int32_t height)
{
bits256 MoM,blockhash,merkle,*merkles; cJSON *blockjson; uint64_t signedmask; int32_t breakht=0,notht=0,ht,maxdepth = 1440,MoMdepth = 0;
struct komodo_ccdataMoMoM mdata; bits256 MoM,blockhash,merkle,*merkles; cJSON *blockjson; uint64_t signedmask; int32_t breakht=0,notht=0,ht,maxdepth = 1440,MoMdepth = 0;
memset(MoM.bytes,0,sizeof(MoM));
blockhash = dpow_getblockhash(myinfo,coin,height);
//printf("start MoM calc %s height.%d\n",coin->symbol,height);
@ -328,10 +365,9 @@ bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct igu
blockhash = dpow_getblockhash(myinfo,coin,ht);
if ( (blockjson= dpow_getblock(myinfo,coin,blockhash)) != 0 )
{
if ( breakht == 0 && dpow_hasnotarization(&signedmask,&notht,myinfo,coin,blockjson,ht) > 0 )
if ( breakht == 0 && dpow_hasnotarization(&signedmask,&notht,myinfo,coin,blockjson,ht,&mdata) > 0 )
{
breakht = notht;
//free_json(blockjson);
printf("%s has notarization at %d for breakht.%d\n",coin->symbol,ht,notht);
}
merkle = jbits256(blockjson,"merkleroot");
@ -342,6 +378,8 @@ bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct igu
{
printf("%s MoMdepth.%d ht.%d from height.%d, null merkleroot\n",coin->symbol,MoMdepth,ht,height);
MoMdepth = 0;
if ( mdata.pairs != 0 )
free(mdata.pairs);
break;
}
}
@ -349,6 +387,8 @@ bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct igu
{
printf("%s MoMdepth.%d ht.%d from height.%d, no blockhash\n",coin->symbol,MoMdepth,ht,height);
MoMdepth = 0;
if ( mdata.pairs != 0 )
free(mdata.pairs);
break;
}
ht = height - MoMdepth;

18
iguana/dpow/dpow_rpc.c

@ -226,6 +226,24 @@ bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *c
return(blockhash);
}
cJSON *dpow_MoMoMdata(struct iguana_info *coin,char *symbol,int32_t kmdheight)
{
char buf[128],*retstr=0; cJSON *retjson = 0; struct iguana_info *src;
if ( coin->FULLNODE < 0 && strcmp(coin->symbol,"KMD") == 0 && (src= iguana_coinfind(symbol)) != 0 )
{
sprintf(buf,"[\"%s\", %d, %d]",symbol,kmdheight,src->MoMoMheight);
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"MoMoMdata",buf)) != 0 )
{
retjson = cJSON_Parse(retstr);
printf("MoMoM.(%s %d %d) -> %s\n",symbol,kmdheight,src->MoMoMheight,retstr);
free(retstr);
}
usleep(10000);
}
return(retjson);
}
int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp,bits256 MoM,uint32_t MoMdepth)
{
struct iguana_info *coin; char *retstr,*hexstr; cJSON *retjson; int32_t n=0; uint32_t paxwdcrc;

24
iguana/dpow/dpow_tx.c

@ -226,17 +226,23 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in
}
printf("numvouts.%d len.%d RATIFY vouts\n",numvouts,len);
}
/*if ( 0 && (src_or_dest == 0 || strcmp(bp->destcoin->symbol,"BTC") != 0) && (n= dpow_paxpending(extras,&paxwdcrc,bp->MoM,bp->MoMdepth)) > 0 )
{
for (i=0; i<n; i++)
printf("%02x",extras[i]);
printf(" <- withdraw.%d %08x\n",n,paxwdcrc);
}
else*/ if ( bp->MoMdepth > 0 && (strcmp(bp->destcoin->symbol,"KMD") == 0 || strcmp(bp->srccoin->symbol,"KMD") == 0) )
if ( bp->MoMdepth > 0 && (strcmp(bp->destcoin->symbol,"KMD") == 0 || strcmp(bp->srccoin->symbol,"KMD") == 0) )
{
cJSON *retjson; char *hexstr; int32_t hexlen; struct iguana_info *kmdcoin = 0;
n = dpow_paxpending(extras,&paxwdcrc,bp->MoM,bp->MoMdepth);
//n += iguana_rwbignum(1,&extras[n],sizeof(bp->MoM),bp->MoM.bytes);
//n += iguana_rwnum(1,&extras[n],sizeof(bp->MoMdepth),(uint32_t *)&bp->MoMdepth);
if ( src_or_dest == 0 && strcmp(bp->destcoin->symbol,"KMD") == 0 )
{
kmdcoin = bp->destcoin;
if ( kmdcoin->lastbestheight > 10 && (retjson= dpow_MoMoMdata(kmdcoin,bp->srccoin->symbol,kmdcoin->lastbestheight-10)) != 0 )
{
if ( (hexstr= jstr(retjson,"data")) != 0 && (hexlen= (int32_t)strlen(hexstr)) > 0 && n+hexlen/2 <= sizeof(extras) )
{
hexlen >>= 1;
decode_hex(&extras[n],hexlen,hexstr), n += hexlen;
}
free_json(retjson);
}
}
}
satoshis = 0;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);

12
iguana/iguana_notary.c

@ -60,7 +60,7 @@ void dpow_checkpointset(struct supernet_info *myinfo,struct dpow_checkpoint *che
void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height,bits256 hash,uint32_t timestamp,uint32_t blocktime)
{
void **ptrs; char str[65]; cJSON *blockjson; struct iguana_info *coin; struct dpow_checkpoint checkpoint; int32_t freq,minsigs,i,ht,notht; uint64_t signedmask; struct dpow_block *bp;
struct komodo_ccdataMoMoM mdata; void **ptrs; char str[65]; cJSON *blockjson; struct iguana_info *coin; struct dpow_checkpoint checkpoint; int32_t freq,minsigs,i,ht,notht; uint64_t signedmask; struct dpow_block *bp;
dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime);
checkpoint = dp->srcfifo[dp->srcconfirms];
if ( strcmp("BTC",dp->dest) == 0 )
@ -88,8 +88,10 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
if ( (blockjson= dpow_getblock(myinfo,coin,hash)) != 0 )
{
height = jint(blockjson,"height");
if ( dpow_hasnotarization(&signedmask,&notht,myinfo,coin,blockjson,height) <= 0 )
if ( dpow_hasnotarization(&signedmask,&notht,myinfo,coin,blockjson,height,&mdata) <= 0 )
{
if ( mdata.pairs != 0 )
free(mdata.pairs);
blocktime = juint(blockjson,"time");
free_json(blockjson);
if ( height > 0 && blocktime > 0 )
@ -579,7 +581,7 @@ void iguana_notarystats(int32_t totals[64],int32_t dispflag)
STRING_AND_TWOINTS(dpow,notarizations,symbol,height,numblocks)
{
int32_t i,j,ht,maxheight,notht,masksums[64]; uint64_t signedmask; cJSON *retjson,*blockjson,*item,*array; bits256 blockhash;
struct komodo_ccdataMoMoM mdata; int32_t i,j,ht,maxheight,notht,masksums[64]; uint64_t signedmask; cJSON *retjson,*blockjson,*item,*array; bits256 blockhash;
memset(masksums,0,sizeof(masksums));
ht = height;
if ( (coin= iguana_coinfind(symbol)) != 0 )
@ -597,8 +599,10 @@ STRING_AND_TWOINTS(dpow,notarizations,symbol,height,numblocks)
blockhash = dpow_getblockhash(myinfo,coin,ht);
if ( (blockjson= dpow_getblock(myinfo,coin,blockhash)) != 0 )
{
if ( dpow_hasnotarization(&signedmask,&notht,myinfo,coin,blockjson,ht) > 0 )
if ( dpow_hasnotarization(&signedmask,&notht,myinfo,coin,blockjson,ht,&mdata) > 0 )
{
if ( mdata.pairs != 0 )
free(mdata.pairs);
for (j=0; j<64; j++)
if ( ((1LL << j) & signedmask) != 0 )
masksums[j]++;

2
includes/iguana_structs.h

@ -499,7 +499,7 @@ struct iguana_info
uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100];
uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime;
int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles;
int32_t MAXPEERS,MAXPENDINGREQUESTS,MAXBUNDLES,MAXSTUCKTIME,active,closestbundle,numemitted,lastsweep,numemit,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,FULLNODE,VALIDATENODE,origbalanceswritten,balanceswritten,lastRTheight,RTdatabad;
int32_t MoMoMheight,MAXPEERS,MAXPENDINGREQUESTS,MAXBUNDLES,MAXSTUCKTIME,active,closestbundle,numemitted,lastsweep,numemit,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,FULLNODE,VALIDATENODE,origbalanceswritten,balanceswritten,lastRTheight,RTdatabad;
bits256 balancehash,allbundles;
uint32_t lastsync,parsetime,numiAddrs,lastpossible,bundlescount,savedblocks,backlog,spendvectorsaved,laststats,lastinv2,symbolcrc,spendvalidated; char VALIDATEDIR[512];
int32_t longestchain,badlongestchain,longestchain_strange,RTramchain_busy,emitbusy,stuckiters,virtualchain,RTheight,RTreset_needed;

Loading…
Cancel
Save