jl777 8 years ago
parent
commit
b6938a3807
  1. 55
      iguana/iguana_notary.c

55
iguana/iguana_notary.c

@ -90,15 +90,24 @@ int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *hei
return(opretlen); return(opretlen);
} }
int32_t dpow_rwutxobuf(int32_t rwflag,uint8_t *data,bits256 *hashmsg,bits256 *txid,int32_t *voutp,bits256 *commit) int32_t dpow_rwutxobuf(int32_t rwflag,uint8_t *data,bits256 *hashmsg,bits256 *txid,int32_t *voutp,bits256 *commit,uint8_t *senderpub)
{ {
int32_t len = 0; int32_t i,len = 0;
len += iguana_rwbignum(rwflag,&data[len],sizeof(*hashmsg),hashmsg->bytes); len += iguana_rwbignum(rwflag,&data[len],sizeof(*hashmsg),hashmsg->bytes);
len += iguana_rwbignum(rwflag,&data[len],sizeof(*txid),txid->bytes); len += iguana_rwbignum(rwflag,&data[len],sizeof(*txid),txid->bytes);
len += iguana_rwbignum(rwflag,&data[len],sizeof(*commit),commit->bytes); len += iguana_rwbignum(rwflag,&data[len],sizeof(*commit),commit->bytes);
if ( rwflag != 0 ) if ( rwflag != 0 )
{
data[len++] = *voutp; data[len++] = *voutp;
else *voutp = data[len++]; for (i=0; i<33; i++)
data[len++] = senderpub[i];
}
else
{
*voutp = data[len++];
for (i=0; i<33; i++)
senderpub[i] = data[len++];
}
return(len); return(len);
} }
@ -503,7 +512,7 @@ int32_t dpow_haveutxo(struct supernet_info *myinfo,struct iguana_info *coin,bits
return(haveutxo); return(haveutxo);
} }
int32_t dpow_message_utxo(bits256 *hashmsgp,bits256 *txidp,int32_t *voutp,bits256 *commitp,cJSON *json) int32_t dpow_message_utxo(uint8_t *senderpub,bits256 *hashmsgp,bits256 *txidp,int32_t *voutp,bits256 *commitp,cJSON *json)
{ {
cJSON *msgobj,*item; uint8_t key[BASILISK_KEYSIZE],data[512]; char *keystr,*hexstr,str[65],str2[65]; int32_t i,n,datalen,retval = -1; cJSON *msgobj,*item; uint8_t key[BASILISK_KEYSIZE],data[512]; char *keystr,*hexstr,str[65],str2[65]; int32_t i,n,datalen,retval = -1;
*voutp = -1; *voutp = -1;
@ -519,7 +528,7 @@ int32_t dpow_message_utxo(bits256 *hashmsgp,bits256 *txidp,int32_t *voutp,bits25
decode_hex(key,BASILISK_KEYSIZE,keystr); decode_hex(key,BASILISK_KEYSIZE,keystr);
datalen >>= 1; datalen >>= 1;
decode_hex(data,datalen,hexstr); decode_hex(data,datalen,hexstr);
retval = dpow_rwutxobuf(0,data,hashmsgp,txidp,voutp,commitp); retval = dpow_rwutxobuf(0,data,hashmsgp,txidp,voutp,commitp,senderpub);
printf("notary.%d hashmsg.(%s) txid.(%s) v%d\n",i,bits256_str(str,*hashmsgp),bits256_str(str2,*txidp),*voutp); printf("notary.%d hashmsg.(%s) txid.(%s) v%d\n",i,bits256_str(str,*hashmsgp),bits256_str(str2,*txidp),*voutp);
} }
} }
@ -774,43 +783,45 @@ int32_t dpow_mostsignedtx(struct supernet_info *myinfo,struct dpow_info *dp,stru
void dpow_txidupdate(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,uint64_t *recvmaskp,uint32_t channel,int32_t height,struct dpow_entry notaries[DPOW_MAXRELAYS],int32_t numnotaries,int32_t myind,bits256 hashmsg) void dpow_txidupdate(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,uint64_t *recvmaskp,uint32_t channel,int32_t height,struct dpow_entry notaries[DPOW_MAXRELAYS],int32_t numnotaries,int32_t myind,bits256 hashmsg)
{ {
int32_t i,j,k,m,vout; cJSON *item,*retarray; bits256 desthash,commit,srchash,checkmsg,txid; int32_t j,k,m,vout,flag; cJSON *item,*retarray; uint8_t senderpub[33]; bits256 desthash,commit,srchash,checkmsg,txid;
for (j=0; j<sizeof(srchash); j++) for (j=0; j<sizeof(srchash); j++)
srchash.bytes[j] = myinfo->DPOW.minerkey33[j+1]; desthash.bytes[j] = myinfo->DPOW.minerkey33[j+1];
for (i=0; i<numnotaries; i++)
{
//if ( (*recvmaskp & (1LL << i)) != 0 )
// continue;
for (j=0; j<sizeof(desthash); j++)
desthash.bytes[j] = notaries[i].pubkey[j+1];
if ( (retarray= basilisk_channelget(myinfo,srchash,desthash,channel,height,0)) != 0 ) if ( (retarray= basilisk_channelget(myinfo,srchash,desthash,channel,height,0)) != 0 )
{ {
//printf("TXIDUPDATE.(%s)\n",jprint(retarray,0)); //printf("TXIDUPDATE.(%s)\n",jprint(retarray,0));
if ( (m= cJSON_GetArraySize(retarray)) != 0 ) if ( (m= cJSON_GetArraySize(retarray)) != 0 )
{ {
for (k=0; k<m; k++) for (k=flag=0; k<m; k++)
{ {
item = jitem(retarray,k); item = jitem(retarray,k);
if ( dpow_message_utxo(&checkmsg,&txid,&vout,&commit,item) > 0 ) if ( dpow_message_utxo(senderpub,&checkmsg,&txid,&vout,&commit,item) > 0 )
{ {
if ( bits256_cmp(checkmsg,hashmsg) == 0 ) if ( bits256_cmp(checkmsg,hashmsg) == 0 )
{
for (j=0; j<numnotaries; j++)
{
if ( memcmp(notaries[j].pubkey,senderpub,33) == 0 )
{ {
if ( bits256_nonz(txid) != 0 ) if ( bits256_nonz(txid) != 0 )
{ {
notaries[i].prev_hash = txid; notaries[j].prev_hash = txid;
notaries[i].prev_vout = vout; notaries[j].prev_vout = vout;
notaries[i].commit = commit; notaries[j].commit = commit;
} }
notaries[i].height = height; notaries[j].height = height;
*recvmaskp |= (1LL << i); *recvmaskp |= (1LL << j);
flag++;
break; break;
} }
} }
if ( flag != 0 )
break;
} }
} }
free_json(retarray);
} }
} }
free_json(retarray);
}
} }
uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,uint32_t state,bits256 hashmsg,int32_t heightmsg,bits256 btctxid,struct dpow_entry notaries[DPOW_MAXRELAYS],int32_t numnotaries,int32_t myind,uint64_t *recvmaskp,bits256 *signedtxidp,char *signedtx,uint32_t timestamp,bits256 beacon) uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,uint32_t state,bits256 hashmsg,int32_t heightmsg,bits256 btctxid,struct dpow_entry notaries[DPOW_MAXRELAYS],int32_t numnotaries,int32_t myind,uint64_t *recvmaskp,bits256 *signedtxidp,char *signedtx,uint32_t timestamp,bits256 beacon)
@ -855,7 +866,7 @@ uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info
case 1: // wait for utxo, send utxo to all other nodes case 1: // wait for utxo, send utxo to all other nodes
if ( (haveutxo= dpow_haveutxo(myinfo,coin,&txid,&vout,coinaddr)) != 0 && vout >= 0 && vout < 0x100 ) if ( (haveutxo= dpow_haveutxo(myinfo,coin,&txid,&vout,coinaddr)) != 0 && vout >= 0 && vout < 0x100 )
{ {
len = dpow_rwutxobuf(1,data,&hashmsg,&txid,&vout,&commit); len = dpow_rwutxobuf(1,data,&hashmsg,&txid,&vout,&commit,myinfo->DPOW.minerkey33);
for (i=0; i<numnotaries; i++) for (i=0; i<numnotaries; i++)
{ {
//if ( i == myind ) //if ( i == myind )

Loading…
Cancel
Save