From 0c537c1178b910769b526f7a4ececbe2137428df Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Aug 2018 02:51:10 -1100 Subject: [PATCH 1/4] +print --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 563277f4b..eb9f4766c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1611,7 +1611,7 @@ int32_t LP_tradecommand(int32_t from_mpnet,void *ctx,char *myipaddr,int32_t pubs if ( i == sizeof(rqs)/sizeof(*rqs) ) i = (rand() % (sizeof(rqs)/sizeof(*rqs))); rqs[i] = rq; -//printf("CONNECTED.(%s)\n",jprint(argjson,0)); +printf("CONNECTED.(%s)\n",jprint(argjson,0)); if ( (proof= jarray(&num,argjson,"proof")) != 0 && num > 0 ) Q.othercredits = LP_instantdex_proofcheck(Q.srccoin,Q.coinaddr,proof,num); if ( Qtrades == 0 ) @@ -1665,7 +1665,7 @@ int32_t LP_tradecommand(int32_t from_mpnet,void *ctx,char *myipaddr,int32_t pubs if ( i == sizeof(rqs)/sizeof(*rqs) ) i = (rand() % (sizeof(rqs)/sizeof(*rqs))); rqs[i] = rq; - //printf("CONNECT.(%s)\n",jprint(argjson,0)); + printf("CONNECT.(%s)\n",jprint(argjson,0)); if ( (proof= jarray(&num,argjson,"proof")) != 0 && num > 0 ) Q.othercredits = LP_instantdex_proofcheck(Q.destcoin,Q.destaddr,proof,num); if ( Qtrades == 0 ) From 3379129399677e10f0d0e2f5de72229605400e0c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 18 Sep 2018 17:54:47 +0800 Subject: [PATCH 2/4] Lock UTXO code added for testing --- iguana/dpow/dpow_fsm.c | 38 +++++++++++++++++++++++++++++++++++++- iguana/dpow/dpow_rpc.c | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index c531c27a7..308e57cd3 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/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<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,20 @@ 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 regardless if it was locked or not it does not matter. + 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, if it was locked or not it does not matter. + 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); } - diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index edcd687d3..447de82bc 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -236,7 +236,7 @@ bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *c } else { - + } if ( bits256_nonz(blockhash) != 0 ) { @@ -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; @@ -399,7 +429,7 @@ cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits2 int32_t dpow_is015(char *symbol) { - if ( strcmp("CHIPS",symbol) == 0 || strcmp("GAME",symbol) == 0 ) //strcmp("BTC",symbol) == 0 || + if ( strcmp("CHIPS",symbol) == 0 || strcmp("GAME",symbol) == 0 ) //strcmp("BTC",symbol) == 0 || return(1); else return(0); } @@ -1254,7 +1284,7 @@ void dpow_issuer_voutupdate(struct dpow_info *dp,char *symbol,int32_t isspecial, printf(" opret[%c] fiatoshis %.8f vs check %.8f\n",script[0],dstr(fiatoshis),dstr(checktoshis)); if ( seed == 0 || fiatoshis < checktoshis ) { - + }*/ } } @@ -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); } - From daa2549ab5e5e8055dd80e9e81426ad94333744c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 18 Sep 2018 18:24:42 +0800 Subject: [PATCH 3/4] fix unlock on utxo not locked, CHIPS got really angry --- iguana/dpow/dpow_fsm.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 308e57cd3..5b6734ff0 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -618,18 +618,24 @@ 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 regardless if it was locked or not it does not matter. - 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, if it was locked or not it does not matter. - 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); + // 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; From 0e3d6913b23d11500507792876eeb70785e6a03e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 18 Sep 2018 18:42:50 +0800 Subject: [PATCH 4/4] Add purge of lockunspent on m_notary_run --- iguana/m_notary_run | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/m_notary_run b/iguana/m_notary_run index fde6f4db9..b554ffa4e 100755 --- a/iguana/m_notary_run +++ b/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