jl777 9 years ago
parent
commit
f8b1cc0343
  1. 2
      iguana/dPoW.h
  2. 38
      iguana/dpow/dpow_fsm.c
  3. 8
      iguana/dpow/dpow_network.c
  4. 16
      iguana/dpow/dpow_tx.c

2
iguana/dPoW.h

@ -53,7 +53,7 @@ struct dpow_utxoentry
struct dpow_entry struct dpow_entry
{ {
bits256 commit,beacon; bits256 commit,beacon;
uint64_t masks[DPOW_MAXRELAYS],recvmask,othermask; uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask;
int32_t height; int32_t height;
int8_t bestk; int8_t bestk;
uint8_t pubkey[33]; uint8_t pubkey[33];

38
iguana/dpow/dpow_fsm.c

@ -74,7 +74,7 @@ void dpow_utxosync(struct supernet_info *myinfo,struct dpow_block *bp,uint64_t r
if ( ((1LL << myind) & recvmask) == 0 ) if ( ((1LL << myind) & recvmask) == 0 )
{ {
i = myind; i = myind;
printf("utxosync bp->%llx != %llx, myind.%d\n",(long long)bp->recvmask,(long long)recvmask,myind); //printf("utxosync bp->%llx != %llx, myind.%d\n",(long long)bp->recvmask,(long long)recvmask,myind);
} }
else else
{ {
@ -85,7 +85,7 @@ void dpow_utxosync(struct supernet_info *myinfo,struct dpow_block *bp,uint64_t r
if ( ((1LL << i) & bp->recvmask) != 0 && ((1LL << i) & recvmask) == 0 ) if ( ((1LL << i) & bp->recvmask) != 0 && ((1LL << i) & recvmask) == 0 )
break; break;
} }
printf("utxosync bp->%llx != %llx, random pick.%d\n",(long long)bp->recvmask,(long long)recvmask,i); //printf("utxosync bp->%llx != %llx, random pick.%d\n",(long long)bp->recvmask,(long long)recvmask,i);
} }
memset(&U,0,sizeof(U)); memset(&U,0,sizeof(U));
dpow_entry2utxo(&U,bp,&bp->notaries[i]); dpow_entry2utxo(&U,bp,&bp->notaries[i]);
@ -157,7 +157,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t
{ {
if ( ep->masks[dsig.lastk] == 0 ) if ( ep->masks[dsig.lastk] == 0 )
{ {
ep->masks[dsig.lastk] = dsig.mask; ep->masks[src_or_dest][dsig.lastk] = dsig.mask;
cp->siglens[dsig.lastk] = dsig.siglen; cp->siglens[dsig.lastk] = dsig.siglen;
memcpy(cp->sigs[dsig.lastk],dsig.sig,dsig.siglen); memcpy(cp->sigs[dsig.lastk],dsig.sig,dsig.siglen);
ep->beacon = dsig.beacon; ep->beacon = dsig.beacon;
@ -204,7 +204,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t
{ {
printf("verify (%s) it is properly signed! set ht.%d signedtxid to %s\n",coin->symbol,height,bits256_str(str,txid)); printf("verify (%s) it is properly signed! set ht.%d signedtxid to %s\n",coin->symbol,height,bits256_str(str,txid));
bp->signedtxid = txid; bp->signedtxid = txid;
bp->state = 0xffffffff; bp->state = src_or_dest != 0 ? 1000 : 0xffffffff;
} }
else else
{ {
@ -217,10 +217,13 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t
return(0); return(0);
} }
int32_t dpow_update(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t utxochannel,uint32_t sigchannel,uint32_t txidchannel,bits256 srchash,int32_t myind,int32_t src_or_dest) int32_t dpow_update(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t txidchannel,bits256 srchash,int32_t myind)
{ {
struct dpow_entry *ep; int32_t i,k,len,sendutxo = 1; uint8_t data[sizeof(struct dpow_entry)+2]; struct dpow_utxoentry U; struct dpow_entry *ep; int32_t i,k,len,src_or_dest,sendutxo = 1; uint8_t data[sizeof(struct dpow_entry)+2]; struct dpow_utxoentry U;
ep = &bp->notaries[myind]; ep = &bp->notaries[myind];
if ( bp->state < 1000 )
{
src_or_dest = 1;
if ( (bp->bestk= dpow_bestk(bp,&bp->bestmask)) >= 0 ) if ( (bp->bestk= dpow_bestk(bp,&bp->bestmask)) >= 0 )
{ {
sendutxo = 0; sendutxo = 0;
@ -236,8 +239,8 @@ int32_t dpow_update(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t
break; break;
} }
} }
if ( ep->masks[bp->bestk] == 0 ) if ( ep->masks[src_or_dest][bp->bestk] == 0 )
dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,sigchannel,src_or_dest); dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,DPOW_SIGBTCCHANNEL,src_or_dest);
//else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel); //else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel);
} }
if ( sendutxo != 0 ) if ( sendutxo != 0 )
@ -245,12 +248,17 @@ int32_t dpow_update(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t
memset(&U,0,sizeof(U)); memset(&U,0,sizeof(U));
dpow_entry2utxo(&U,bp,&bp->notaries[myind]); dpow_entry2utxo(&U,bp,&bp->notaries[myind]);
if ( (len= dpow_rwutxobuf(1,data,&U,bp)) > 0 ) if ( (len= dpow_rwutxobuf(1,data,&U,bp)) > 0 )
dpow_send(myinfo,bp,srchash,bp->hashmsg,utxochannel,bp->height,data,len,bp->utxocrcs); dpow_send(myinfo,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,data,len,bp->utxocrcs);
} }
if ( bp->state != 0xffffffff ) if ( ep->masks[src_or_dest][bp->bestk] == 0 )
dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,"",DPOW_SIGBTCCHANNEL,src_or_dest);
//else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel);
}
else if ( bp->state != 0xffffffff )
{ {
if ( ep->masks[bp->bestk] == 0 ) src_or_dest = 0;
dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,sigchannel,src_or_dest); if ( ep->masks[src_or_dest][bp->bestk] == 0 )
dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,DPOW_SIGCHANNEL,src_or_dest);
//else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel); //else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel);
} }
return(bp->state); return(bp->state);
@ -278,11 +286,9 @@ uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info
} }
bitcoin_address(coinaddr,coin->chain->pubtype,myinfo->DPOW.minerkey33,33); bitcoin_address(coinaddr,coin->chain->pubtype,myinfo->DPOW.minerkey33,33);
if ( bits256_nonz(bp->hashmsg) == 0 ) if ( bits256_nonz(bp->hashmsg) == 0 )
return(0xffffffff); return(0);
for (j=0; j<sizeof(srchash); j++) for (j=0; j<sizeof(srchash); j++)
srchash.bytes[j] = myinfo->DPOW.minerkey33[j+1]; srchash.bytes[j] = myinfo->DPOW.minerkey33[j+1];
if ( bits256_nonz(bp->signedtxid) != 0 )
bp->state = 0xffffffff;
bp->bestk = dpow_bestk(bp,&bp->bestmask); bp->bestk = dpow_bestk(bp,&bp->bestmask);
if ( (rand() % 10) == 0 ) if ( (rand() % 10) == 0 )
printf("[%d] %s ht.%d FSM.%d %s BTC.%d masks.%llx best.(%d %llx) sigsmask.%llx\n",myind,coin->symbol,bp->height,bp->state,coinaddr,bits256_nonz(bp->desttxid)==0,(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,(long long)bp->destsigsmasks[bp->bestk]); printf("[%d] %s ht.%d FSM.%d %s BTC.%d masks.%llx best.(%d %llx) sigsmask.%llx\n",myind,coin->symbol,bp->height,bp->state,coinaddr,bits256_nonz(bp->desttxid)==0,(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,(long long)bp->destsigsmasks[bp->bestk]);
@ -293,7 +299,7 @@ uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info
} }
else else
{ {
dpow_update(myinfo,bp,channel,sigchannel,txidchannel,srchash,myind,src_or_dest); dpow_update(myinfo,bp,txidchannel,srchash,myind);
if ( bits256_nonz(bp->signedtxid) != 0 ) if ( bits256_nonz(bp->signedtxid) != 0 )
bp->state = 0xffffffff; bp->state = 0xffffffff;
} }

8
iguana/dpow/dpow_network.c

@ -164,14 +164,14 @@ int32_t dpow_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen)
return(opretlen + offset); return(opretlen + offset);
} }
int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *heightmsgp,bits256 *btctxid,char *src) int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *heightmsgp,bits256 *desttxid,char *src,bits256 *beaconp)
{ {
int32_t i,opretlen = 0; int32_t i,opretlen = 0;
opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*hashmsg),hashmsg->bytes); opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*hashmsg),hashmsg->bytes);
opretlen += iguana_rwnum(rwflag,&opret[opretlen],sizeof(*heightmsgp),(uint32_t *)heightmsgp); opretlen += iguana_rwnum(rwflag,&opret[opretlen],sizeof(*heightmsgp),(uint32_t *)heightmsgp);
if ( bits256_nonz(*btctxid) != 0 ) if ( bits256_nonz(*desttxid) != 0 )
{ {
opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*btctxid),btctxid->bytes); opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*desttxid),desttxid->bytes);
if ( rwflag != 0 ) if ( rwflag != 0 )
{ {
for (i=0; src[i]!=0; i++) for (i=0; src[i]!=0; i++)
@ -185,7 +185,7 @@ int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *hei
src[i] = 0; src[i] = 0;
opretlen++; opretlen++;
} }
} } else opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*beaconp),beaconp->bytes);
return(opretlen); return(opretlen);
} }

16
iguana/dpow/dpow_tx.c

@ -121,7 +121,7 @@ bits256 dpow_notarytx(char *signedtx,int32_t *numsigsp,int32_t isPoS,struct dpow
serialized[len++] = CHECKSIG; serialized[len++] = CHECKSIG;
satoshis = 0; satoshis = 0;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis); len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,&bp->desttxid,src); opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,&bp->desttxid,src,&bp->beacon);
opretlen = dpow_opreturnscript(data,opret,opretlen); opretlen = dpow_opreturnscript(data,opret,opretlen);
if ( opretlen < 0xfd ) if ( opretlen < 0xfd )
serialized[len++] = opretlen; serialized[len++] = opretlen;
@ -198,13 +198,13 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct iguana_info *coin,struct
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 )
{ {
printf("height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bp->height,bp->height%bp->numnotaries,j,myind,jprint(item,0),j); printf("%s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",(src_or_dest != 0) ? bp->srccoin->symbol : bp->destcoin->symbol,bp->height,bp->height%bp->numnotaries,j,myind,jprint(item,0),j);
cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1; cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1;
if ( src_or_dest != 0 ) if ( src_or_dest != 0 )
bp->destsigsmasks[bestk] |= (1LL << myind); bp->destsigsmasks[bestk] |= (1LL << myind);
else bp->srcsigsmasks[bestk] |= (1LL << myind); else bp->srcsigsmasks[bestk] |= (1LL << myind);
decode_hex(cp->sigs[bestk],cp->siglens[bestk],sigstr); decode_hex(cp->sigs[bestk],cp->siglens[bestk],sigstr);
ep->masks[bestk] = bestmask; ep->masks[src_or_dest][bestk] = bestmask;
ep->beacon = bp->beacon; ep->beacon = bp->beacon;
dpow_sigsend(myinfo,bp,myind,bestk,bestmask,srchash,sigchannel); dpow_sigsend(myinfo,bp,myind,bestk,bestmask,srchash,sigchannel);
retval = 0; retval = 0;
@ -260,7 +260,7 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t
bits256 txid,srchash,zero; struct iguana_info *coin; int32_t j,len,numsigs; char *retstr=0,str[65],str2[65]; uint8_t txdata[32768]; bits256 txid,srchash,zero; struct iguana_info *coin; int32_t j,len,numsigs; char *retstr=0,str[65],str2[65]; uint8_t txdata[32768];
coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin; coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
printf("sigscheck myind.%d src_dest.%d state.%x\n",myind,src_or_dest,bp->state); //printf("sigscheck myind.%d src_dest.%d state.%x\n",myind,src_or_dest,bp->state);
if ( bp->state != 0xffffffff && coin != 0 ) if ( bp->state != 0xffffffff && coin != 0 )
{ {
bp->signedtxid = dpow_notarytx(bp->signedtx,&numsigs,coin->chain->isPoS,bp,bp->bestk,bp->bestmask,bp->opret_symbol,1,src_or_dest); bp->signedtxid = dpow_notarytx(bp->signedtx,&numsigs,coin->chain->isPoS,bp,bp->bestk,bp->bestmask,bp->opret_symbol,1,src_or_dest);
@ -276,13 +276,19 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t
decode_hex(txid.bytes,sizeof(txid),retstr); decode_hex(txid.bytes,sizeof(txid),retstr);
if ( bits256_cmp(txid,bp->signedtxid) == 0 ) if ( bits256_cmp(txid,bp->signedtxid) == 0 )
{ {
if ( src_or_dest != 0 )
{
bp->desttxid = txid;
dpow_signedtxgen(myinfo,bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->srccoin->symbol,DPOW_SIGCHANNEL,0);
}
else bp->srctxid = txid;
len = (int32_t)strlen(bp->signedtx) >> 1; len = (int32_t)strlen(bp->signedtx) >> 1;
decode_hex(txdata+32,len,bp->signedtx); decode_hex(txdata+32,len,bp->signedtx);
for (j=0; j<sizeof(srchash); j++) for (j=0; j<sizeof(srchash); j++)
txdata[j] = txid.bytes[j]; txdata[j] = txid.bytes[j];
dpow_send(myinfo,bp,txid,bp->hashmsg,(channel == DPOW_SIGBTCCHANNEL) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32,bp->txidcrcs); dpow_send(myinfo,bp,txid,bp->hashmsg,(channel == DPOW_SIGBTCCHANNEL) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32,bp->txidcrcs);
printf("complete statemachine.%s ht.%d\n",coin->symbol,bp->height); printf("complete statemachine.%s ht.%d\n",coin->symbol,bp->height);
bp->state = 0xffffffff; bp->state = src_or_dest != 0 ? 1000 : 0xffffffff;
} else printf("sendtxid mismatch got %s instead of %s\n",bits256_str(str,txid),bits256_str(str2,bp->signedtxid)); } else printf("sendtxid mismatch got %s instead of %s\n",bits256_str(str,txid),bits256_str(str2,bp->signedtxid));
} }
free(retstr); free(retstr);

Loading…
Cancel
Save