jl777 8 years ago
parent
commit
87bf35e727
  1. 1
      datachain/datachain.c
  2. 6
      iguana/dPoW.h
  3. 81
      iguana/dpow/dpow_network.c
  4. 16
      iguana/dpow/dpow_tx.c
  5. 2
      iguana/main.c

1
datachain/datachain.c

@ -320,6 +320,7 @@ void datachain_update_spend(struct supernet_info *myinfo,int32_t ordered,struct
int64_t datachain_update(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t value,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen,bits256 txid,int32_t vout) int64_t datachain_update(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t value,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen,bits256 txid,int32_t vout)
{ {
return(0);
if ( memcmp(rmd160,CRYPTO777_RMD160,20) == 0 ) if ( memcmp(rmd160,CRYPTO777_RMD160,20) == 0 )
{ {
crypto777_payment += value; crypto777_payment += value;

6
iguana/dPoW.h

@ -66,7 +66,7 @@ struct dpow_entry
int32_t height; int32_t height;
uint16_t ratifysrcvout,ratifydestvout; uint16_t ratifysrcvout,ratifydestvout;
int8_t bestk,ratifybestk; int8_t bestk,ratifybestk;
uint8_t pubkey[33],ratifysigs[2][DPOW_MAXRELAYS][76],ratifysiglens[2][DPOW_MAXRELAYS]; uint8_t pubkey[33],ratifysigs[2][76],ratifysiglens[2];
struct dpow_coinentry src,dest; struct dpow_coinentry src,dest;
}; };
@ -97,13 +97,13 @@ struct dpow_block
bits256 hashmsg,desttxid,srctxid,beacon,commit; bits256 hashmsg,desttxid,srctxid,beacon,commit;
struct iguana_info *srccoin,*destcoin; char *opret_symbol; struct iguana_info *srccoin,*destcoin; char *opret_symbol;
uint64_t destsigsmasks[DPOW_MAXRELAYS],srcsigsmasks[DPOW_MAXRELAYS]; uint64_t destsigsmasks[DPOW_MAXRELAYS],srcsigsmasks[DPOW_MAXRELAYS];
uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2][DPOW_MAXRELAYS]; uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2];
struct dpow_entry notaries[DPOW_MAXRELAYS]; struct dpow_entry notaries[DPOW_MAXRELAYS];
uint32_t state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2]; uint32_t state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2];
int32_t height,numnotaries,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS]; int32_t height,numnotaries,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS];
int8_t bestk,ratifybestk,pendingbestk,pendingratifybestk; int8_t bestk,ratifybestk,pendingbestk,pendingratifybestk;
cJSON *ratified; cJSON *ratified;
uint8_t myind,ratified_pubkeys[DPOW_MAXRELAYS][33],ratifysigs[2][DPOW_MAXRELAYS][76],ratifysiglens[2][DPOW_MAXRELAYS]; uint8_t myind,ratified_pubkeys[DPOW_MAXRELAYS][33],ratifysigs[2][76],ratifysiglens[2];
char handles[DPOW_MAXRELAYS][32]; char handles[DPOW_MAXRELAYS][32];
char signedtx[32768];//,rawtx[32768]; char signedtx[32768];//,rawtx[32768];
}; };

81
iguana/dpow/dpow_network.c

@ -152,19 +152,15 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr
np->srcvout = bp->notaries[bp->myind].ratifysrcvout; np->srcvout = bp->notaries[bp->myind].ratifysrcvout;
np->destutxo = bp->notaries[bp->myind].ratifydestutxo; np->destutxo = bp->notaries[bp->myind].ratifydestutxo;
np->destvout = bp->notaries[bp->myind].ratifydestvout; np->destvout = bp->notaries[bp->myind].ratifydestvout;
np->bestmask = bp->ratifybestmask;
np->recvmask = bp->ratifyrecvmask; np->recvmask = bp->ratifyrecvmask;
if ( (np->bestmask= bp->pendingratifybestmask) == 0 )
{
np->bestmask = bp->ratifybestmask;
np->bestk = bp->ratifybestk;
} else np->bestk = bp->pendingratifybestk;
//printf("send ratify best.(%d %llx) siglens.(%d %d)\n", bp->ratifybestk,(long long)bp->ratifybestmask,bp->ratifysiglens[0],bp->ratifysiglens[1]); //printf("send ratify best.(%d %llx) siglens.(%d %d)\n", bp->ratifybestk,(long long)bp->ratifybestmask,bp->ratifysiglens[0],bp->ratifysiglens[1]);
if ( np->bestk >= 0 ) if ( (np->bestk= bp->ratifybestk) >= 0 )
{ {
for (i=0; i<2; i++) for (i=0; i<2; i++)
{ {
if ( (np->siglens[i]= bp->ratifysiglens[i][np->bestk]) > 0 ) if ( (np->siglens[i]= bp->ratifysiglens[i]) > 0 )
memcpy(np->sigs[i],bp->ratifysigs[i][np->bestk],np->siglens[i]); memcpy(np->sigs[i],bp->ratifysigs[i],np->siglens[i]);
} }
} }
} }
@ -188,7 +184,7 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr
void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][76]) void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][76])
{ {
int32_t i,matchbestk,ratifybestk,best,bestmatches = 0,matches = 0; uint64_t ratifybestmask,matchbestmask; int32_t i,bestmatches = 0,matches = 0;
//char str[65],str2[65]; //char str[65],str2[65];
//printf("senderind.%d num.%d %s %s\n",senderind,bp->numnotaries,bits256_str(str,srcutxo),bits256_str(str2,destutxo)); //printf("senderind.%d num.%d %s %s\n",senderind,bp->numnotaries,bits256_str(str,srcutxo),bits256_str(str2,destutxo));
if ( bp->isratify != 0 && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 ) if ( bp->isratify != 0 && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
@ -203,12 +199,12 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct
{ {
for (i=0; i<2; i++) for (i=0; i<2; i++)
{ {
if ( (bp->notaries[senderind].ratifysiglens[i][bestk]= siglens[i]) != 0 ) if ( (bp->notaries[senderind].ratifysiglens[i]= siglens[i]) != 0 )
{ {
memcpy(bp->notaries[senderind].ratifysigs[i][bestk],sigs[i],siglens[i]); memcpy(bp->notaries[senderind].ratifysigs[i],sigs[i],siglens[i]);
if ( bp->notaries[senderind].bestmask == bestmask ) if ( bestk == bp->pendingratifybestk && bestmask == bp->pendingratifybestmask )
bp->ratifysigmasks[i][bestk] |= (1LL << senderind); bp->ratifysigmasks[i] |= (1LL << senderind);
else bp->ratifysigmasks[i][bestk] &= ~(1LL << senderind); else bp->ratifysigmasks[i] &= ~(1LL << senderind);
} }
} }
} }
@ -218,60 +214,42 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct
bp->notaries[bp->myind].ratifybestk = bp->ratifybestk; bp->notaries[bp->myind].ratifybestk = bp->ratifybestk;
bp->notaries[bp->myind].ratifybestmask = bp->ratifybestmask; bp->notaries[bp->myind].ratifybestmask = bp->ratifybestmask;
bp->notaries[bp->myind].ratifyrecvmask = bp->ratifyrecvmask; bp->notaries[bp->myind].ratifyrecvmask = bp->ratifyrecvmask;
best = 0;
ratifybestk = bp->ratifybestk;
ratifybestmask = bp->ratifybestmask;
if ( bp->ratifybestk >= 0 ) if ( bp->ratifybestk >= 0 )
{ {
matchbestk = -1;
matchbestmask = 0;
for (i=0; i<bp->numnotaries; i++) for (i=0; i<bp->numnotaries; i++)
{ {
if ( bp->ratifybestk >= 0 && bp->notaries[i].ratifybestk == bp->ratifybestk && bp->notaries[i].ratifybestmask == bp->ratifybestmask ) if ( bp->ratifybestk >= 0 && bp->notaries[i].ratifybestk == bp->ratifybestk && bp->notaries[i].ratifybestmask == bp->ratifybestmask )
{ {
if ( matches++ < bp->minsigs ) matches++;
{
matchbestmask = (1LL << i);
if ( matches == bp->minsigs )
matchbestk = i;
}
if ( ((1LL << i) & bp->ratifybestmask) != 0 ) if ( ((1LL << i) & bp->ratifybestmask) != 0 )
bestmatches++; bestmatches++;
} }
} }
best = bestmatches; if ( bestmatches >= bp->minsigs )
if ( (bp->require0 == 0 || (bestmatches & 1) != 0) && matchbestk >= i && bestmatches < bp->minsigs && matches >= bp->minsigs )
{
printf("bestmatches.%d (%d %llx) switch to matchmask (%d %llx)\n",bestmatches,ratifybestk,(long long)ratifybestmask,matchbestk,(long long)matchbestmask);
ratifybestk = matchbestk;
ratifybestmask = matchbestmask;
best = matches;
}
if ( best >= bp->minsigs )
{ {
if ( bp->pendingratifybestk != ratifybestk || bp->pendingratifybestmask != ratifybestmask ) if ( bp->pendingratifybestk != bp->ratifybestk || bp->pendingratifybestmask != bp->ratifybestmask )
{ {
printf("new PENDING RATIFY BESTK (%d %llx)\n",ratifybestk,(long long)ratifybestmask); printf("new PENDING RATIFY BESTK (%d %llx)\n",bp->ratifybestk,(long long)bp->ratifybestmask);
bp->pendingratifybestk = ratifybestk; bp->pendingratifybestk = bp->ratifybestk;
bp->pendingratifybestmask = ratifybestmask; bp->pendingratifybestmask = bp->ratifybestmask;
dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,ratifybestk,ratifybestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,1); dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->ratifybestk,bp->ratifybestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,1);
} }
if ( (bp->ratifysigmasks[1][ratifybestk] & ratifybestmask) == ratifybestmask ) // have all sigs if ( bp->ratifysigmasks[1] == bp->pendingratifybestmask ) // have all sigs
{ {
if ( bp->state < 1000 ) if ( bp->state < 1000 )
{ {
dpow_sigscheck(myinfo,dp,bp,bp->myind,1,ratifybestk,ratifybestmask,bp->ratified_pubkeys,bp->numratified); dpow_sigscheck(myinfo,dp,bp,bp->myind,1,bp->pendingratifybestk,bp->pendingratifybestmask,bp->ratified_pubkeys,bp->numratified);
} }
if ( (bp->ratifysigmasks[0][ratifybestk] & ratifybestmask) == ratifybestmask ) // have all sigs if ( bp->ratifysigmasks[0] == bp->pendingratifybestmask ) // have all sigs
{ {
if ( bp->state != 0xffffffff ) if ( bp->state != 0xffffffff )
dpow_sigscheck(myinfo,dp,bp,bp->myind,0,ratifybestk,ratifybestmask,bp->ratified_pubkeys,bp->numratified); dpow_sigscheck(myinfo,dp,bp,bp->myind,0,bp->pendingratifybestk,bp->pendingratifybestmask,bp->ratified_pubkeys,bp->numratified);
} //else printf("ratify srcmask.%llx != bestmask.%llx\n",(long long)bp->ratifysigmasks[0],(long long)bp->bestmask); } //else printf("ratify srcmask.%llx != bestmask.%llx\n",(long long)bp->ratifysigmasks[0],(long long)bp->bestmask);
} //else printf("ratify destmask.%llx != bestmask.%llx\n",(long long)bp->ratifysigmasks[1],(long long)bp->bestmask); } //else printf("ratify destmask.%llx != bestmask.%llx\n",(long long)bp->ratifysigmasks[1],(long long)bp->bestmask);
} }
} }
if ( (rand() % 100) == 0 ) if ( (rand() % 100) == 0 )
printf("[%d] numips.%d %s RATIFY.%d matches.%d bestmatches.%d -> %d bestk.%d %llx recv.%llx sigmasks.(%llx %llx)\n",bp->myind,dp->numipbits,dp->symbol,bp->minsigs,matches,bestmatches,best,ratifybestk,(long long)ratifybestmask,(long long)bp->ratifyrecvmask,(long long)(bestk>=0?bp->ratifysigmasks[1][bestk]:0),(long long)(bestk>=0?bp->ratifysigmasks[0][bestk]:0)); printf("[%d] numips.%d %s RATIFY.%d matches.%d bestmatches.%d bestk.%d %llx recv.%llx sigmasks.(%llx %llx)\n",bp->myind,dp->numipbits,dp->symbol,bp->minsigs,matches,bestmatches,bp->ratifybestk,(long long)bp->ratifybestmask,(long long)bp->ratifyrecvmask,(long long)bp->ratifysigmasks[1],(long long)bp->ratifysigmasks[0]);
} }
} }
@ -328,11 +306,11 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
bp->pendingbestmask = bp->bestmask; bp->pendingbestmask = bp->bestmask;
dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->bestk,bp->bestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,0); dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->bestk,bp->bestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,0);
} }
if ( (bp->destsigsmasks[bp->bestk] & bp->bestmask) == bp->bestmask ) // have all sigs if ( bp->destsigsmasks[bp->bestk] == bp->bestmask ) // have all sigs
{ {
if ( bp->state < 1000 ) if ( bp->state < 1000 )
dpow_sigscheck(myinfo,dp,bp,bp->myind,1,bp->bestk,bp->bestmask,0,0); dpow_sigscheck(myinfo,dp,bp,bp->myind,1,bp->bestk,bp->bestmask,0,0);
if ( (bp->srcsigsmasks[bp->bestk] & bp->bestmask) == bp->bestmask ) // have all sigs if ( bp->srcsigsmasks[bp->bestk] == bp->bestmask ) // have all sigs
{ {
if ( bp->state != 0xffffffff ) if ( bp->state != 0xffffffff )
dpow_sigscheck(myinfo,dp,bp,bp->myind,0,bp->bestk,bp->bestmask,0,0); dpow_sigscheck(myinfo,dp,bp,bp->myind,0,bp->bestk,bp->bestmask,0,0);
@ -682,17 +660,6 @@ uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp,int32_t *shor
#define MAX_CURRENCIES 32 #define MAX_CURRENCIES 32
extern char CURRENCIES[][8]; extern char CURRENCIES[][8];
void komodo_fiatports()
{
int32_t i,shortflag; uint16_t port; uint32_t magic;
for (i=0; i<MAX_CURRENCIES; i++)
{
port = komodo_port(CURRENCIES[i],10,&magic,&shortflag);
printf("(%s %d) ",CURRENCIES[i],port);
}
printf("fiat ports\n");
}
void komodo_assetcoins() void komodo_assetcoins()
{ {
uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *userhome,char *coindir,char *confname); uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *userhome,char *coindir,char *confname);

16
iguana/dpow/dpow_tx.c

@ -254,8 +254,8 @@ bits256 dpow_notarytx(char *signedtx,int32_t *numsigsp,int32_t isPoS,struct dpow
} }
if ( bestk >= 0 ) if ( bestk >= 0 )
{ {
siglen = bp->notaries[k].ratifysiglens[src_or_dest][bestk]; siglen = bp->notaries[k].ratifysiglens[src_or_dest];
sig = bp->notaries[k].ratifysigs[src_or_dest][bestk]; sig = bp->notaries[k].ratifysigs[src_or_dest];
} }
//char str[65]; printf("j.%d k.%d m.%d vin.(%s) v%d siglen.%d\n",j,k,m,bits256_str(str,txid),vout,siglen); //char str[65]; printf("j.%d k.%d m.%d vin.(%s) v%d siglen.%d\n",j,k,m,bits256_str(str,txid),vout,siglen);
} }
@ -443,12 +443,12 @@ int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struc
item = jitem(vin,j); item = jitem(vin,j);
if ( (sobj= jobj(item,"scriptSig")) != 0 && (sigstr= jstr(sobj,"hex")) != 0 && strlen(sigstr) > 32 ) if ( (sobj= jobj(item,"scriptSig")) != 0 && (sigstr= jstr(sobj,"hex")) != 0 && strlen(sigstr) > 32 )
{ {
bp->ratifysiglens[src_or_dest][bestk] = (int32_t)strlen(sigstr) >> 1; bp->ratifysiglens[src_or_dest] = (int32_t)strlen(sigstr) >> 1;
decode_hex(bp->ratifysigs[src_or_dest][bestk],bp->ratifysiglens[src_or_dest][bestk],sigstr); decode_hex(bp->ratifysigs[src_or_dest],bp->ratifysiglens[src_or_dest],sigstr);
bp->notaries[bp->myind].ratifysiglens[src_or_dest][bestk] = bp->ratifysiglens[src_or_dest][bestk]; bp->notaries[bp->myind].ratifysiglens[src_or_dest] = bp->ratifysiglens[src_or_dest];
memcpy(bp->notaries[bp->myind].ratifysigs[src_or_dest][bestk],bp->ratifysigs[src_or_dest][bestk],bp->ratifysiglens[src_or_dest][bestk]); memcpy(bp->notaries[bp->myind].ratifysigs[src_or_dest],bp->ratifysigs[src_or_dest],bp->ratifysiglens[src_or_dest]);
bp->ratifysigmasks[src_or_dest][bestk] |= (1LL << bp->myind); bp->ratifysigmasks[src_or_dest] |= (1LL << bp->myind);
printf("RATIFYSIG[%d] <- set notaryid.%d siglen.%d\n",src_or_dest,bp->myind,bp->ratifysiglens[src_or_dest][bestk]); printf("RATIFYSIG[%d] <- set notaryid.%d siglen.%d\n",src_or_dest,bp->myind,bp->ratifysiglens[src_or_dest]);
break; break;
} }
} }

2
iguana/main.c

@ -1671,8 +1671,6 @@ void iguana_main(void *arg)
} }
} }
} }
void komodo_fiatports();
komodo_fiatports();
iguana_launchdaemons(myinfo); iguana_launchdaemons(myinfo);
} }

Loading…
Cancel
Save