jl777 8 years ago
parent
commit
0731d72eca
  1. 6
      iguana/dPoW.h
  2. 3
      iguana/dpow/dpow_fsm.c
  3. 11
      iguana/dpow/dpow_network.c
  4. 26
      iguana/dpow/dpow_tx.c
  5. 2
      iguana/iguana_notary.c

6
iguana/dPoW.h

@ -22,7 +22,7 @@
#define DPOW_MINSIGS 7
#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
#define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries)
#define DPOW_VERSION 0x0556
#define DPOW_VERSION 0x0577
#define DPOW_UTXOSIZE 10000
#define DPOW_MINOUTPUT 6000
#define DPOW_DURATION 300
@ -62,7 +62,7 @@ struct dpow_utxoentry
struct dpow_entry
{
bits256 commit,beacon;
uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask;
uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask,bestmask;
int32_t height;
int8_t bestk;
uint8_t pubkey[33];
@ -99,7 +99,7 @@ struct dpow_block
uint64_t recvmask,bestmask;
struct dpow_entry notaries[DPOW_MAXRELAYS];
uint32_t state,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2];
int32_t height,numnotaries,completed,minsigs,duration,numratified,isratify,require0;
int32_t height,numnotaries,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS];
int8_t bestk;
cJSON *ratified;
uint8_t ratified_pubkeys[DPOW_MAXRELAYS][33]; char handles[DPOW_MAXRELAYS][32];

3
iguana/dpow/dpow_fsm.c

@ -111,7 +111,7 @@ void dpow_sync(struct supernet_info *myinfo,int32_t forceflag,struct dpow_info *
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,lastk,mask,myind,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL,src_or_dest);
}
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen)
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint8_t nn_senderind,int8_t nn_bestk,uint64_t nn_bestmask,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen)
{
bits256 txid,commit,srchash,hashmsg; struct dpow_block *bp = 0; uint32_t flag = 0; int32_t src_or_dest,senderind,i,iter,rlen,myind = -1; char str[65],str2[65]; struct dpow_sigentry dsig; struct dpow_entry *ep; struct dpow_coinentry *cp; struct dpow_utxoentry U; struct iguana_info *coin;
if ( (bp= dpow_heightfind(myinfo,dp,height)) == 0 )
@ -126,6 +126,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint3
printf("couldnt find myind height.%d | this means your pubkey for this node is not registered and needs to be ratified by majority vote of all notaries\n",height);
return(-1);
}
dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask);
for (i=0; i<32; i++)
srchash.bytes[i] = dp->minerkey33[i+1];
if ( channel == DPOW_ENTRIESCHANNEL )

11
iguana/dpow/dpow_network.c

@ -19,9 +19,11 @@
struct dpow_nanomsghdr
{
bits256 srchash,desthash;
uint64_t bestmask;
uint32_t channel,height,size,datalen,crc32,numipbits,ipbits[64];
char symbol[16];
uint8_t version0,version1,packet[];
int8_t bestk;
uint8_t senderind,version0,version1,packet[];
} PACKED;
char *nanomsg_tcpname(char *str,char *ipaddr)
@ -124,6 +126,9 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
size = (int32_t)(sizeof(*np) + datalen);
np = calloc(1,size); // endian dependent!
np->numipbits = myinfo->numdpowipbits;
np->bestk = bp->bestk;
np->bestmask = bp->bestmask;
np->senderind = bp->myind;
memcpy(np->ipbits,myinfo->dpowipbits,myinfo->numdpowipbits * sizeof(*myinfo->dpowipbits));
//printf("dpow_send.(%d) size.%d numipbits.%d\n",datalen,size,np->numipbits);
np->size = size;
@ -201,10 +206,10 @@ void dpow_nanomsg_update(struct supernet_info *myinfo)
//char str[65]; printf("%s RECV ht.%d ch.%08x (%d) crc32.%08x:%08x datalen.%d:%d firstz.%d\n",bits256_str(str,np->srchash),np->height,np->channel,size,np->crc32,crc32,np->datalen,(int32_t)(size - sizeof(*np)),firstz);
if ( i == myinfo->numdpows )
printf("received nnpacket for (%s)\n",np->symbol);
else if ( dpow_datahandler(myinfo,dp,np->channel,np->height,np->packet,np->datalen) >= 0 )
else if ( dpow_datahandler(myinfo,dp,np->senderind,np->bestk,np->bestmask,np->channel,np->height,np->packet,np->datalen) >= 0 )
dp->crcs[firstz] = crc32;
}
} else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np));
} //else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np));
}
if ( np != 0 )
nn_freemsg(np);

26
iguana/dpow/dpow_tx.c

@ -13,6 +13,26 @@
* *
******************************************************************************/
void dpow_bestmask_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t nn_senderind,int8_t nn_bestk,uint64_t nn_bestmask)
{
if ( nn_senderind < 0 || nn_senderind >= bp->numnotaries )
return;
bp->notaries[nn_senderind].bestk = nn_bestk;
bp->notaries[nn_senderind].bestmask = nn_bestmask;
if ( bp->bestk >= 0 )
{
if ( nn_bestk < 0 )
bp->scores[nn_senderind] -= 10;
else if ( nn_bestk != bp->bestk )
bp->scores[nn_senderind]--;
else if ( nn_bestmask != bp->bestmask )
bp->scores[nn_senderind]--;
else if ( bp->scores[nn_senderind] < 1 )
bp->scores[nn_senderind] = 1;
else bp->scores[nn_senderind]++;
}
}
uint64_t dpow_lastk_mask(struct dpow_block *bp,int8_t *lastkp)
{
int32_t j,m,k; uint64_t mask = bp->require0;
@ -20,7 +40,9 @@ uint64_t dpow_lastk_mask(struct dpow_block *bp,int8_t *lastkp)
m = bp->require0;
for (j=0; j<bp->numnotaries; j++)
{
k = DPOW_MODIND(bp,j);//((bp->height % bp->numnotaries) + j) % bp->numnotaries;
k = DPOW_MODIND(bp,j);
if ( (bp->require0 == 0 || k != 0) && bp->scores[k] < -100 )
continue;
if ( bits256_nonz(bp->notaries[k].src.prev_hash) != 0 && bits256_nonz(bp->notaries[k].dest.prev_hash) != 0 )
{
bp->recvmask |= (1LL << k);
@ -54,6 +76,8 @@ uint64_t dpow_maskmin(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp)
for (j=0; j<bp->numnotaries; j++)
{
k = DPOW_MODIND(bp,j);
if ( (bp->require0 == 0 || k != 0) && bp->scores[k] < -100 )
continue;
if ( bits256_nonz(bp->notaries[k].src.prev_hash) != 0 && bits256_nonz(bp->notaries[k].dest.prev_hash) != 0 )
{
mask |= (1LL << k);

2
iguana/iguana_notary.c

@ -22,7 +22,7 @@
#include "iguana777.h"
#include "notaries.h"
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen);
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint8_t nn_senderind,int8_t bestk,uint64_t bestmask,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen);
#include "dpow/dpow_network.c"
#include "dpow/dpow_rpc.c"

Loading…
Cancel
Save