jl777 8 years ago
parent
commit
eda20dc579
  1. 1
      iguana/dPoW.h
  2. 14
      iguana/dpow/dpow_fsm.c
  3. 4
      iguana/dpow/dpow_tx.c
  4. 4
      iguana/iguana_notary.c

1
iguana/dPoW.h

@ -16,6 +16,7 @@
#ifndef INCLUDE_DPOW_H
#define INCLUDE_DPOW_H
#define DPOW_MAXBLOCKS 10000000
#define DPOW_CHECKPOINTFREQ 10
#define DPOW_MINSIGS 7
#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)

14
iguana/dpow/dpow_fsm.c

@ -235,6 +235,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t
{
bp->desttxid = txid;
bp->state = 1000;
myinfo->DPOW.destupdated = 0;
dpow_signedtxgen(myinfo,bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGCHANNEL,0);
//dpow_sigscheck(myinfo,bp,DPOW_SIGCHANNEL,myind,0);
}
@ -381,14 +382,13 @@ void dpow_statemachinestart(void *ptr)
{
void **ptrs = ptr;
struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint;
int32_t i,n,numratified,myind = -1; cJSON *ratified,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime = (uint32_t)time(NULL);
int32_t i,n,numratified,myind = -1; cJSON *ratified,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime;
memset(&zero,0,sizeof(zero));
myinfo = ptrs[0];
dp = ptrs[1];
minsigs = (uint32_t)(long)ptrs[2];
duration = (uint32_t)(long)ptrs[3];
jsonstr = ptrs[4];
dp->destupdated = 0; // prevent another state machine till next BTC block
memcpy(&checkpoint,&ptrs[5],sizeof(checkpoint));
printf("statemachinestart %s->%s %s ht.%d minsigs.%d duration.%d\n",dp->symbol,dp->dest,bits256_str(str,checkpoint.blockhash.hash),checkpoint.blockhash.height,minsigs,duration);
src = iguana_coinfind(dp->symbol);
@ -482,6 +482,16 @@ void dpow_statemachinestart(void *ptr)
bp->height = checkpoint.blockhash.height;
bp->timestamp = checkpoint.timestamp;
bp->hashmsg = checkpoint.blockhash.hash;
while ( dp->destupdated == 0 )
{
if ( checkpoint.blockhash.height != 0 && dp->checkpoint.blockhash.height > checkpoint.blockhash.height )
{
printf("abort ht.%d due to new checkpoint.%d\n",checkpoint.blockhash.height,dp->checkpoint.blockhash.height);
return;
}
sleep(1);
}
starttime = (uint32_t)time(NULL);
printf("DPOW statemachine checkpoint.%d %s\n",checkpoint.blockhash.height,bits256_str(str,checkpoint.blockhash.hash));
for (i=0; i<sizeof(srchash); i++)
srchash.bytes[i] = myinfo->DPOW.minerkey33[i+1];

4
iguana/dpow/dpow_tx.c

@ -66,7 +66,9 @@ uint64_t dpow_maskmin(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp)
struct dpow_block *dpow_heightfind(struct supernet_info *myinfo,int32_t height)
{
return(myinfo->DPOW.blocks!=0?myinfo->DPOW.blocks[height]:0);
if ( height < DPOW_MAXBLOCKS )
return(myinfo->DPOW.blocks!=0?myinfo->DPOW.blocks[height]:0);
else return(0);
}
int32_t dpow_voutratify(struct dpow_block *bp,uint8_t *serialized,int32_t m,uint8_t pubkeys[][33],int32_t numratified)

4
iguana/iguana_notary.c

@ -68,7 +68,7 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
checkpoint = dp->srcfifo[dp->srcconfirms];
printf("%s srcupdate ht.%d destupdated.%u nonz.%d %s\n",dp->symbol,height,dp->destupdated,bits256_nonz(checkpoint.blockhash.hash),bits256_str(str,dp->last.blockhash.hash));
dpow_fifoupdate(myinfo,dp->srcfifo,dp->last);
if ( dp->destupdated != 0 && bits256_nonz(checkpoint.blockhash.hash) != 0 && (checkpoint.blockhash.height % DPOW_CHECKPOINTFREQ) == 0 )
if ( bits256_nonz(checkpoint.blockhash.hash) != 0 && (checkpoint.blockhash.height % DPOW_CHECKPOINTFREQ) == 0 )
{
ptrs = calloc(1,sizeof(void *)*5 + sizeof(struct dpow_checkpoint));
ptrs[0] = (void *)myinfo;
@ -225,7 +225,7 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey)
if ( myinfo->DPOW.srcconfirms > DPOW_FIFOSIZE )
myinfo->DPOW.srcconfirms = DPOW_FIFOSIZE;
if ( myinfo->DPOW.blocks == 0 )
myinfo->DPOW.blocks = calloc(1000000,sizeof(*myinfo->DPOW.blocks));
myinfo->DPOW.blocks = calloc(DPOW_MAXBLOCKS,sizeof(*myinfo->DPOW.blocks));
return(clonestr("{\"result\":\"success\"}"));
}

Loading…
Cancel
Save