Browse Source

try?

blackjok3r
blackjok3r 6 years ago
parent
commit
130d79208f
  1. 56
      iguana/dpow/dpow_fsm.c
  2. 32
      iguana/dpow/dpow_tx.c
  3. 27
      iguana/iguana_notary.c

56
iguana/dpow/dpow_fsm.c

@ -160,7 +160,7 @@ int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct
return(haveutxo);
}
uint32_t Numallocated;
//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,struct komodo_ccdataMoMoM
*mdata)
@ -264,7 +264,7 @@ void dpow_statemachinestart(void *ptr)
{
void **ptrs = ptr;
struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint;
int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,src_or_dest,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,MoM,merkleroot,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t MoMdepth,duration,minsigs,starttime,srctime;
int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,src_or_dest,numratified=0,kmdheight,myind = -1,blockindex=0; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,MoM,merkleroot,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t MoMdepth,duration,minsigs,starttime,srctime;
char *destlockunspent=0,*srclockunspent=0,*destunlockunspent=0,*srcunlockunspent=0;
memset(&zero,0,sizeof(zero));
MoM = zero;
@ -284,9 +284,7 @@ void dpow_statemachinestart(void *ptr)
if ( src == 0 || dest == 0 )
{
printf("null coin ptr? (%s %p or %s %p)\n",dp->symbol,src,dp->dest,dest);
bp->finished = 0xffffffff;
free(ptr);
return;
goto end2;
}
MoMdepth = 0;
memset(&MoM,0,sizeof(MoM));
@ -297,11 +295,12 @@ void dpow_statemachinestart(void *ptr)
MoM = dpow_calcMoM(&MoMdepth,myinfo,src,checkpoint.blockhash.height);
kmdheight = dest->longestchain;
}
if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 )
{
if ( (bp= dpow_heightfind(myinfo,dp, checkpoint.blockhash.height)) == 0 )
bp = calloc(1,sizeof(*bp));
blockindex = dpow_blockfind(myinfo,dp);
dp->blocks[blockindex] = bp;
//printf("allocate bp for %s ht.%d -> %s\n",src->symbol,checkpoint.blockhash.height,dest->symbol);
Numallocated++;
//Numallocated++;
bp->MoM = MoM;
bp->MoMdepth = MoMdepth;
bp->CCid = dp->fullCCid & 0xffff;
@ -321,11 +320,7 @@ void dpow_statemachinestart(void *ptr)
if ( numratified > 64 )
{
fprintf(stderr,"cant ratify more than 64 notaries ratified has %d\n",numratified);
bp->finished = 0xffffffff;
free(ptr);
free_json(ratified);
bp->finished = 0xffffffff;
return;
goto end2;
}
for (i=0; i<numratified; i++)
{
@ -368,7 +363,7 @@ void dpow_statemachinestart(void *ptr)
free_json(ratified);
}
bp->pendingbestk = bp->bestk = -1;
dp->blocks[checkpoint.blockhash.height] = bp;
//dp->blocks[checkpoint.blockhash.height] = bp;
dp->currentbp = bp;
bp->beacon = rand256(0);
vcalc_sha256(0,bp->commit.bytes,bp->beacon.bytes,sizeof(bp->beacon));
@ -384,9 +379,7 @@ void dpow_statemachinestart(void *ptr)
if ( dp->ratifying != 0 && bp->isratify == 0 )
{
printf("skip notarization ht.%d when ratifying\n",bp->height);
bp->finished = 0xffffffff;
free(ptr);
return;
goto end2;
}
dp->ratifying += bp->isratify;
@ -434,23 +427,16 @@ void dpow_statemachinestart(void *ptr)
for (i=0; i<33; i++)
printf("%02x",dp->minerkey33[i]);
printf(" statemachinestart this node %s %s is not official notary numnotaries.%d kmdht.%d bpht.%d\n",srcaddr,destaddr,bp->numnotaries,kmdheight,bp->height);
bp->finished = 0xffffffff;
free(ptr);
dp->ratifying -= bp->isratify;
bp->finished = 0xffffffff;
exit(-1);
return;
goto end2;
}
//printf("myind.%d\n",myind);
}
else
{
printf("statemachinestart no kmdheight.%d\n",kmdheight);
bp->finished = 0xffffffff;
free(ptr);
dp->ratifying -= bp->isratify;
bp->finished = 0xffffffff;
return;
goto end2;
}
bp->myind = myind;
printf("[%d] notarize %s->%s %s ht.%d minsigs.%d duration.%d start.%u MoM[%d] %s CCid.%u\n",bp->myind,dp->symbol,dp->dest,bits256_str(str,checkpoint.blockhash.hash),checkpoint.blockhash.height,minsigs,duration,checkpoint.timestamp,bp->MoMdepth,bits256_str(str2,bp->MoM),bp->CCid);
@ -463,9 +449,7 @@ void dpow_statemachinestart(void *ptr)
printf("%02x",bp->ratified_pubkeys[0][i]);
printf(" new, cant change notary0\n");
dp->ratifying -= bp->isratify;
bp->finished = 0xffffffff;
free(ptr);
return;
goto end2;
}
//printf(" myind.%d myaddr.(%s %s)\n",myind,srcaddr,destaddr);
if ( myind == 0 && bits256_nonz(destprevtxid0) != 0 && bits256_nonz(srcprevtxid0) != 0 && destprevvout0 >= 0 && srcprevvout0 >= 0 )
@ -539,8 +523,6 @@ void dpow_statemachinestart(void *ptr)
//printf("abort %s ht.%d due to new checkpoint.%d\n",dp->symbol,checkpoint.blockhash.height,dp->checkpoint.blockhash.height);
dp->ratifying -= bp->isratify;
goto end;
//free(ptr);
//return;
}
sleep(1);
}
@ -605,7 +587,7 @@ void dpow_statemachinestart(void *ptr)
if ( bp->state != 0xffffffff )
{
dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,0,bp->height,(void *)"ping",0);
dpow_nanomsg_update(myinfo);
//dpow_nanomsg_update(myinfo,bp);
}
else
{
@ -619,7 +601,7 @@ void dpow_statemachinestart(void *ptr)
}
sleep(30);
}
printf("[%d] END isratify.%d:%d bestk.%d %llx sigs.%llx state.%x machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx paxwdcrc.%x %p %p\n",Numallocated,bp->isratify,dp->ratifying,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->state,bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask,bp->paxwdcrc,src,dest);
printf("END isratify.%d:%d bestk.%d %llx sigs.%llx state.%x machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx paxwdcrc.%x %p %p\n",bp->isratify,dp->ratifying,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->state,bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask,bp->paxwdcrc,src,dest);
dp->lastrecvmask = bp->recvmask;
dp->ratifying -= bp->isratify;
// We need to wait for notarized confirm here. If the notarization is reorged for any reason we need to rebroadcast it,
@ -706,7 +688,7 @@ void dpow_statemachinestart(void *ptr)
dpow_sendrawtransaction(myinfo, bp->srccoin, srctx);
}
}
bp->state = 0xffffffff;
end:
// unlock the dest utxo on KMD.
if ( (strcmp("KMD",dest->symbol) == 0 ) && (ep->dest.prev_vout != -1) )
@ -722,7 +704,9 @@ end:
printf(">>>> UNLOCKED %s UTXO.(%s) vout.(%d)\n",src->symbol,bits256_str(str2,ep->src.prev_hash),ep->src.prev_vout);
}
// dp->blocks[bp->height] = 0;
bp->finished = 0xffffffff;
end2:
dp->blocks[blockindex] = 0;
bp->state = 0xffffffff;
free(bp);
free(ptr);
}

32
iguana/dpow/dpow_tx.c

@ -173,30 +173,24 @@ uint64_t dpow_maskmin(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp)
struct dpow_block *dpow_heightfind(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height)
{
int32_t r,h,incr = 100000; struct dpow_block *bp = 0;
if ( height > dp->maxblocks )
int32_t i; struct dpow_block *bp = 0;
for (i = 0; i < dp->maxblocks; i++)
{
if ( dp->maxblocks+incr < height+10000 )
incr = (height+10000) - dp->maxblocks;
dp->blocks = realloc(dp->blocks,sizeof(*dp->blocks) * (dp->maxblocks + incr));
memset(&dp->blocks[dp->maxblocks],0,sizeof(*dp->blocks) * incr);
dp->maxblocks += incr;
if ( height == dp->blocks[i]->height )
return(bp);
}
return(0);
}
if ( height < dp->maxblocks )
bp = dp->blocks!=0 ? dp->blocks[height] : 0;
if ( bp == 0 && height < DPOW_FIRSTRATIFY )
int32_t dpow_blockfind(struct supernet_info *myinfo,struct dpow_info *dp)
{
r = (rand() % DPOW_FIRSTRATIFY);
for (h=0; h<DPOW_FIRSTRATIFY; h++)
int32_t i; struct dpow_block *bp = 0;
for (i = 0; i < dp->maxblocks; i++)
{
height = (r + h) % DPOW_FIRSTRATIFY;
if ( (bp= dp->blocks[height]) != 0 )
return(bp);
}
if ( dp->blocks[i] == 0 )
return(i);
}
if ( bp != 0 && bp->state == 0xffffffff )
bp = 0;
return(bp);
return(0);
}
int32_t dpow_voutstandard(struct supernet_info *myinfo,struct dpow_block *bp,uint8_t *serialized,int32_t m,int32_t src_or_dest,uint8_t pubkeys[][33],int32_t numratified)

27
iguana/iguana_notary.c

@ -143,39 +143,18 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
dp->freq = 1;
if ( suppress == 0 && bits256_nonz(checkpoint.blockhash.hash) != 0 && (checkpoint.blockhash.height % dp->freq) == 0 )
{
if ( (0) && strcmp("KMD",dp->symbol) == 0 )
printf("%s/%s src ht.%d dest.%u nonz.%d %s minsigs.%d freq.%d\n",dp->symbol,dp->dest,checkpoint.blockhash.height,dp->destupdated,bits256_nonz(checkpoint.blockhash.hash),bits256_str(str,dp->last.blockhash.hash),dp->minsigs,dp->freq);
dpow_heightfind(myinfo,dp,checkpoint.blockhash.height + 1000);
//dpow_heightfind(myinfo,dp,checkpoint.blockhash.height + 1000);
dp->prevDESTHEIGHT = dp->DESTHEIGHT;
ptrs = calloc(1,sizeof(void *)*5 + sizeof(struct dpow_checkpoint) + sizeof(pthread_t));
ptrs[0] = (void *)myinfo;
ptrs[1] = (void *)dp;
ptrs[2] = (void *)(uint64_t)dp->minsigs;
//if ( strcmp(dp->dest,"KMD") != 0 )
ptrs[3] = (void *)DPOW_DURATION;
//else ptrs[3] = (void *)(DPOW_DURATION * 60); // essentially try forever for assetchains
ptrs[4] = 0;
memcpy(&ptrs[5],&checkpoint,sizeof(checkpoint));
dp->activehash = checkpoint.blockhash.hash;
ht = checkpoint.blockhash.height;
if ( OS_thread_create((void *)((uint64_t)&ptrs[5] + sizeof(struct dpow_checkpoint)),NULL,(void *)dpow_statemachinestart,(void *)ptrs) != 0 )
{
}
if ( ht > DPOW_MAXFREQ*5 )
{
for (i=ht-DPOW_MAXFREQ*5; i>ht-DPOW_MAXFREQ*100&&i>DPOW_MAXFREQ; i--)
{
if ( dp->blocks[i] != 0 && dp->blocks[i]->finished == 0xffffffff )
{
fprintf(stderr, "dpow free i.%i\n",i);
if ( dp->currentbp == dp->blocks[i] )
dp->currentbp = 0;
dp->blocks[i] = 0;
Numallocated--;
free(dp->blocks[i]);
}
}
}
OS_thread_create((void *)((uint64_t)&ptrs[5] + sizeof(struct dpow_checkpoint)),NULL,(void *)dpow_statemachinestart,(void *)ptrs)
}
}
@ -452,7 +431,7 @@ THREE_STRINGS_AND_DOUBLE(iguana,dpow,symbol,dest,pubkey,freq)
}
if ( dp->blocks == 0 )
{
dp->maxblocks = 10000;
dp->maxblocks = 100;
dp->blocks = calloc(dp->maxblocks,sizeof(*dp->blocks));
}
portable_mutex_init(&dp->paxmutex);

Loading…
Cancel
Save