Browse Source

Merge pull request #964 from blackjok3rtt/beta

Lock unspent testing. PR for discussion and improvement before merging in.
patch-5
jl777 6 years ago
committed by GitHub
parent
commit
afef6945b8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      iguana/dpow/dpow_fsm.c
  2. 31
      iguana/dpow/dpow_rpc.c
  3. 2
      iguana/m_notary_run

44
iguana/dpow/dpow_fsm.c

@ -265,6 +265,7 @@ void dpow_statemachinestart(void *ptr)
void **ptrs = ptr;
struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint;
int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,src_or_dest,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,MoM,merkleroot,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t MoMdepth,duration,minsigs,starttime,srctime;
char *destlockunspent,*srclockunspent,*destunlockunspent,*srcunlockunspent;
memset(&zero,0,sizeof(zero));
MoM = zero;
srcprevtxid0 = destprevtxid0 = zero;
@ -501,6 +502,29 @@ void dpow_statemachinestart(void *ptr)
bp->desttxid = bp->notaries[myind].src.prev_hash;
dpow_signedtxgen(myinfo,dp,src,bp,bp->myind,1LL<<bp->myind,bp->myind,DPOW_SIGCHANNEL,0,0);
}*/
if (strcmp("KMD",dest->symbol) == 0 )
{
// lock the dest utxo if destination coin is KMD.
destlockunspent = dpow_lockunspent(myinfo,bp->destcoin,destaddr,bits256_str(str2,ep->dest.prev_hash),ep->dest.prev_vout);
if (strncmp(destlockunspent,"true", 4) == 0 )
printf(">>>> LOCKED %s UTXO.(%s) vout.(%d)\n",dest->symbol,bits256_str(str2,ep->dest.prev_hash),ep->dest.prev_vout);
else
printf("<<<< FAILED TO LOCK %s UTXO.(%s) vout.(%d)\n",dest->symbol,bits256_str(str2,ep->dest.prev_hash),ep->dest.prev_vout);
free(destlockunspent);
}
if ( strcmp("BTC",dest->symbol) == 0 )
{
// lock the src coin selected utxo if the source coin is KMD.
srclockunspent = dpow_lockunspent(myinfo,bp->srccoin,srcaddr,bits256_str(str2,ep->src.prev_hash),ep->src.prev_vout);
if (strncmp(srclockunspent,"true", 4) == 0 )
printf(">>>> LOCKED %s UTXO.(%s) vout.(%d\n",src->symbol,bits256_str(str2,ep->src.prev_hash),ep->src.prev_vout);
else
printf("<<<< FAILED TO LOCK %s UTXO.(%s) vout.(%d)\n",src->symbol,bits256_str(str2,ep->src.prev_hash),ep->src.prev_vout);
free(srclockunspent);
}
bp->recvmask |= (1LL << myind);
bp->notaries[myind].othermask |= (1LL << myind);
dp->checkpoint = checkpoint;
@ -594,8 +618,26 @@ void dpow_statemachinestart(void *ptr)
printf("[%d] END isratify.%d:%d bestk.%d %llx sigs.%llx state.%x machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx paxwdcrc.%x %p %p\n",Numallocated,bp->isratify,dp->ratifying,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->state,bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask,bp->paxwdcrc,src,dest);
dp->lastrecvmask = bp->recvmask;
dp->ratifying -= bp->isratify;
// unlock the dest utxo on KMD.
if (strcmp("KMD",dest->symbol) == 0 )
{
destunlockunspent = dpow_unlockunspent(myinfo,bp->destcoin,destaddr,bits256_str(str2,ep->dest.prev_hash),ep->dest.prev_vout);
if (strncmp(destunlockunspent,"true", 4) == 0 )
printf(">>>>UNLOCKED %s UTXO.(%s) vout.(%d)\n",dest->symbol,bits256_str(str2,ep->dest.prev_hash),ep->dest.prev_vout);
free(destunlockunspent);
}
// unlock the src selected utxo on KMD, as those are the only ones we LOCK, and CHIPS does not like the lockunspent call.
if ( strcmp("BTC",dest->symbol) == 0 )
{
srcunlockunspent = dpow_unlockunspent(myinfo,bp->srccoin,srcaddr,bits256_str(str2,ep->src.prev_hash),ep->src.prev_vout);
if (strncmp(srcunlockunspent,"true", 4) == 0 )
printf(">>>>UNLOCKED %s UTXO.(%s) vout.(%d)\n",src->symbol,bits256_str(str2,ep->src.prev_hash),ep->src.prev_vout);
free(srcunlockunspent);
}
// dp->blocks[bp->height] = 0;
bp->state = 0xffffffff;
free(ptr);
}

31
iguana/dpow/dpow_rpc.c

@ -370,6 +370,36 @@ bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin,
return(blockhash);
}
char *dpow_lockunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,char *txid,int32_t vout)
{
char buf[128],*retstr;
if ( coin->FULLNODE < 0 )
{
sprintf(buf,"false, [{\"txid\":\"%s\",\"vout\":%d}]", txid, vout);
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"lockunspent",buf)) != 0 )
{
//printf("RESULT.(%s)\n",retstr);
return(retstr);
} else printf("%s null retstr from (%s)n",coin->symbol,buf);
}
return(0);
}
char *dpow_unlockunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,char *txid,int32_t vout)
{
char buf[128],*retstr;
if ( coin->FULLNODE < 0 )
{
sprintf(buf,"true, [{\"txid\":\"%s\",\"vout\":%d}]", txid, vout);
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"lockunspent",buf)) != 0 )
{
//printf("RESULT.(%s)\n",retstr);
return(retstr);
} else printf("%s null retstr from (%s)n",coin->symbol,buf);
}
return(0);
}
cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash)
{
char buf[128],str[65],*retstr=0; cJSON *json = 0;
@ -1424,4 +1454,3 @@ int32_t dpow_issuer_iteration(struct dpow_info *dp,struct iguana_info *coin,int3
//printf("[%s -> %s] %s ht.%d current.%d\n",dp->symbol,dp->dest,coin->symbol,height,currentheight);
return(height);
}

2
iguana/m_notary_run

@ -1,4 +1,6 @@
#!/bin/bash
# Unlock all lockunspents to make sure we can access all our utxo!
komodo-cli lockunspent true `komodo-cli listlockunspent | jq -c .`
cd secp256k1; ./m_unix; cd ..
cd ../crypto777; ./m_LP; cd ../iguana

Loading…
Cancel
Save