From c792649129e3a1a4f774fbe23f27f8b0f40c0bc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 02:10:58 -1100 Subject: [PATCH 01/17] -print --- src/komodo_nSPV_fullnode.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 948846fe5..0d540e06d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -210,14 +210,14 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int { LOCK(cs_main); ptr->txid = tx.GetHash(); - fprintf(stderr,"try to addmempool transaction %s\n",ptr->txid.GetHex().c_str()); + //fprintf(stderr,"try to addmempool transaction %s\n",ptr->txid.GetHex().c_str()); if ( myAddtomempool(tx) != 0 ) { - int32_t i; - for (i=0; itxid.GetHex().c_str(),ptr->retcode); ptr->retcode = 1; + //int32_t i; + //for (i=0; itxid.GetHex().c_str(),ptr->retcode); RelayTransaction(tx); } else ptr->retcode = -3; From 6862fbcd1d0fc6c53eb64ef99d91d281a179b741 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 05:54:49 -1100 Subject: [PATCH 02/17] More patience --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e0a003fcd..e9253a167 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -28,8 +28,8 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_POLLITERS 10 -#define NSPV_POLLMICROS 100777 +#define NSPV_POLLITERS 15 +#define NSPV_POLLMICROS 100000 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 #define NSPV_BRANCHID 0x76b809bb From a79d415babffb0154fbe03828a331a31c20a6da9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 05:56:03 -1100 Subject: [PATCH 03/17] Prevent getnSPV from full nodes --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 9a30ddc44..66e921f4d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -102,8 +102,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); - //if ( KOMODO_NSPV == 0 ) - // return(0); + if ( KOMODO_NSPV == 0 ) + return(0); if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); From 177902aa8aa21b866229b759697234a3a2fff7fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:32:46 -1100 Subject: [PATCH 04/17] Validate KMD rewards --- src/komodo_nSPV.h | 4 ++-- src/komodo_nSPV_superlite.h | 16 +++++++++++++--- src/komodo_nSPV_wallet.h | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e9253a167..2d50dec26 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -51,7 +51,7 @@ #define NSPV_BROADCAST 0x0c #define NSPV_BROADCASTRESP 0x0d -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx); +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime); extern uint256 SIG_TXHASH; uint32_t NSPV_blocktime(int32_t hdrheight); @@ -475,7 +475,7 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) for (i=0; i response) // received a r NSPV_inforesult = I; } else if ( NSPV_inforesult.height > I.height ) + { NSPV_lastinfo = timestamp - ASSETCHAINS_BLOCKTIME/4; + // need to validate new header to make sure it is valid mainchain + if ( NSPV_inforesult.height == NSPV_inforesult.hdrheight ) + NSPV_tiptime = NSPV_inforesult.hdr.nTime; + } break; case NSPV_UTXOSRESP: NSPV_utxosresp_purge(&NSPV_utxosresult); @@ -604,9 +609,9 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(0); } -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx) +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime) { - int32_t i,offset,retval = 0; std::vector proof; + int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; for (i=0; i<3; i++) { NSPV_txproof(vout,txid,height); @@ -623,6 +628,11 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int retval = -2000; else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 ) retval = -2001; + else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) + { + rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); + fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); + } else if ( skipvalidation == 0 ) { if ( NSPV_txproofresult.txprooflen > 0 ) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 6cf2e82c6..c38b29598 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -170,7 +170,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); + validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { From ee266ad84f2b8210e40df0101545d6dca8bd7158 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:34:59 -1100 Subject: [PATCH 05/17] H --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b81250424..5e8821712 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -63,7 +63,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r NSPV_lastinfo = timestamp - ASSETCHAINS_BLOCKTIME/4; // need to validate new header to make sure it is valid mainchain if ( NSPV_inforesult.height == NSPV_inforesult.hdrheight ) - NSPV_tiptime = NSPV_inforesult.hdr.nTime; + NSPV_tiptime = NSPV_inforesult.H.nTime; } break; case NSPV_UTXOSRESP: From 8ef296a93e9c590b09d43efc43879f7ddfbad751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:47:52 -1100 Subject: [PATCH 06/17] Da --- src/komodo_nSPV_superlite.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5e8821712..302928b3f 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -27,7 +27,7 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); uint32_t NSPV_lastinfo,NSPV_logintime,NSPV_tiptime; CKey NSPV_key; -char NSPV_wifstr[64],NSPV_pubkeystr[67]; +char NSPV_wifstr[64],NSPV_pubkeystr[67],NSPV_lastpeer[128]; std::string NSPV_address; struct NSPV_inforesp NSPV_inforesult; struct NSPV_utxosresp NSPV_utxosresult; @@ -43,6 +43,7 @@ struct NSPV_broadcastresp NSPV_broadcastresult; void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { struct NSPV_inforesp I; int32_t len; uint32_t timestamp = (uint32_t)time(NULL); + strncpy(NSPV_lastpeer,pfrom->addr.ToString().c_str(),sizeof(NSPV_lastpeer)-1); if ( (len= response.size()) > 0 ) { switch ( response[0] ) @@ -191,6 +192,7 @@ UniValue NSPV_txproof_json(struct NSPV_txproof *ptr) result.push_back(Pair("height",(int64_t)ptr->height)); result.push_back(Pair("txlen",(int64_t)ptr->txlen)); result.push_back(Pair("txprooflen",(int64_t)ptr->txprooflen)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -205,6 +207,7 @@ UniValue NSPV_spentinfo_json(struct NSPV_spentinfo *ptr) result.push_back(Pair("spentvini",(int64_t)ptr->spentvini)); result.push_back(Pair("spenttxlen",(int64_t)ptr->spent.txlen)); result.push_back(Pair("spenttxprooflen",(int64_t)ptr->spent.txprooflen)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -258,6 +261,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); result.push_back(Pair("header",NSPV_header_json(&ptr->H,ptr->hdrheight))); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -290,6 +294,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) result.push_back(Pair("balance",(double)ptr->total/COIN)); if ( ASSETCHAINS_SYMBOL[0] == 0 ) result.push_back(Pair("interest",(double)ptr->interest/COIN)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -299,6 +304,7 @@ UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) result.push_back(Pair("result","success")); result.push_back(Pair("prev",NSPV_ntz_json(&ptr->prevntz))); result.push_back(Pair("next",NSPV_ntz_json(&ptr->nextntz))); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -316,6 +322,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -332,8 +339,10 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) case 0: result.push_back(Pair("type","broadcast")); break; case -1: result.push_back(Pair("type","decode error")); break; case -2: result.push_back(Pair("type","timeout")); break; + case -2: result.push_back(Pair("type","error adding to mempool")); break; default: result.push_back(Pair("type","unknown")); break; } + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -396,15 +405,19 @@ UniValue NSPV_getinfo_req(int32_t reqht) uint32_t NSPV_blocktime(int32_t hdrheight) { + uint32_t timestamp; struct NSPV_inforesp old = NSPV_inforesult; if ( hdrheight > 0 ) { NSPV_getinfo_req(hdrheight); if ( NSPV_inforesult.hdrheight == hdrheight ) { - fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); - return(NSPV_inforesult.H.nTime); + timestamp = NSPV_inforesult.H.nTime; + NSPV_inforesult = old; + fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,timestamp); + return(timestamp); } } + NSPV_inforesult = old; return(0); } From ff60331104dfbba158474300830d808fc3af6d6f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:49:01 -1100 Subject: [PATCH 07/17] -3 --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 302928b3f..10c6c16b2 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -339,7 +339,7 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) case 0: result.push_back(Pair("type","broadcast")); break; case -1: result.push_back(Pair("type","decode error")); break; case -2: result.push_back(Pair("type","timeout")); break; - case -2: result.push_back(Pair("type","error adding to mempool")); break; + case -3: result.push_back(Pair("type","error adding to mempool")); break; default: result.push_back(Pair("type","unknown")); break; } result.push_back(Pair("lastpeer",NSPV_lastpeer)); From e6b1b310e9d8073642277a73a28052ee5b67c91b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:16:31 -1100 Subject: [PATCH 08/17] Fix control flow --- src/komodo_nSPV_superlite.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 10c6c16b2..38522d74d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -646,7 +646,8 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); } - else if ( skipvalidation == 0 ) + + if ( skipvalidation == 0 ) { if ( NSPV_txproofresult.txprooflen > 0 ) { From d8b568683c8f19446c073f7fffac10315b586a41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:26:27 -1100 Subject: [PATCH 09/17] Display rewards vs validated --- src/komodo_nSPV.h | 6 +++--- src/komodo_nSPV_superlite.h | 8 ++++++-- src/komodo_nSPV_wallet.h | 14 ++++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2d50dec26..2aec951ba 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -51,7 +51,7 @@ #define NSPV_BROADCAST 0x0c #define NSPV_BROADCASTRESP 0x0d -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime); +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); extern uint256 SIG_TXHASH; uint32_t NSPV_blocktime(int32_t hdrheight); @@ -471,11 +471,11 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t */ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint8_t *script; CTransaction vintx; int32_t i,j,utxovout,scriptlen,numsigs = 0; + uint8_t *script; CTransaction vintx; int64_t rewardsum = 0; int32_t i,j,utxovout,scriptlen,numsigs = 0; for (i=0; i proof; for (i=0; i<3; i++) @@ -644,7 +644,11 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) { rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); - fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); + if ( rewards != extradata ) + { + fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); + } + rewardsum += rewards; } if ( skipvalidation == 0 ) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c38b29598..afe162880 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -146,7 +146,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C return(false); } -std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) +std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcodes,CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) { CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n,validation; n = mtx.vout.size(); @@ -158,6 +158,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf totalinputs += used[i].satoshis; interest += used[i].extradata; } + interestsum = interest; if ( (totalinputs+interest) >= totaloutputs+2*txfee ) { change = (totalinputs+interest) - (totaloutputs+txfee); @@ -170,7 +171,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime); + validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime,rewardsum); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { @@ -244,7 +245,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); - std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; + std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; int64_t rewardsum=0,interestsum=0; mtx.fOverwintered = true; mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; @@ -264,7 +265,12 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","wif expired")); return(result); } - hex = NSPV_signtx(retcodes,mtx,txfee,opret,used); + hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); + if ( interestsum != 0 || rewardsum != 0 ) + { + result.push_back(Pair("rewards",dstr(interestsum))); + result.push_back(Pair("validated",dstr(rewardsum))); + } if ( hex.size() > 0 ) { if ( DecodeHexTx(tx,hex) != 0 ) From b46416b3123fa83eadb5ce5d0e3940211a96cecc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:32:59 -1100 Subject: [PATCH 10/17] Test --- src/komodo_nSPV_superlite.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index df29e8635..ed3325ade 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -592,33 +592,36 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) { int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) - return(-1); - else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) + { + fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",,ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); return(-2); - else if ( tx.GetHash() != ptr->nexttxid ) + } + else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) return(-3); - else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) + else if ( tx.GetHash() != ptr->nexttxid ) return(-4); - else if ( height != ptr->common.nextht ) + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) return(-5); - else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + else if ( height != ptr->common.nextht ) return(-6); + else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + return(-7); for (i=ptr->common.numhdrs-1; i>0; i--) { blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) - return(-i-12); + return(-i-13); } if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-7); - else if ( tx.GetHash() != ptr->prevtxid ) return(-8); - else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) + else if ( tx.GetHash() != ptr->prevtxid ) return(-9); - else if ( height != ptr->common.prevht ) + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) return(-10); - else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + else if ( height != ptr->common.prevht ) return(-11); + else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + return(-12); return(0); } @@ -668,7 +671,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int } if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { - fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); + fprintf(stderr,">>>>> gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { From 24f54ef1b6da1a203c524928bf011bd4f2c53de4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:40:19 -1100 Subject: [PATCH 11/17] Test --- src/komodo_nSPV_superlite.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ed3325ade..f2613def0 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -661,6 +661,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int proof.resize(NSPV_txproofresult.txprooflen); memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); } + fprintf(stderr,"call NSPV_notarizations\n"); NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) { @@ -675,6 +676,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { + fprintf(stderr,"call NSPV_txidhdrsproof\n"); NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { From 47a1d5cbf6edf9354220660123c2511c004e4a3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:42:12 -1100 Subject: [PATCH 12/17] -,, --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index f2613def0..91c55bbd4 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -593,7 +593,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) { - fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",,ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); + fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); return(-2); } else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) From 5178ec0d6305c8417ff217e0c1eecd808686bb9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:48:22 -1100 Subject: [PATCH 13/17] 5 seconds --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 91c55bbd4..1e5efd049 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -481,7 +481,7 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); - for (iter=0; iter<3; iter++); + for (iter=0; iter<5; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Tue, 9 Jul 2019 23:21:38 -1100 Subject: [PATCH 14/17] +print --- src/komodo_nSPV_superlite.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 1e5efd049..b3e584979 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -323,6 +323,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); + fprintf(stderr,"ntzs_proof %s\n",result); return(result); } @@ -481,7 +482,7 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); - for (iter=0; iter<5; iter++); + for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Tue, 9 Jul 2019 23:23:08 -1100 Subject: [PATCH 15/17] .txid.GetHex().c_str() --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b3e584979..626008694 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -677,7 +677,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { - fprintf(stderr,"call NSPV_txidhdrsproof\n"); + fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { From 90be0e94e6d26ceb158027de95ea45301068cdcd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 23:29:02 -1100 Subject: [PATCH 16/17] Pause --- src/komodo_nSPV_superlite.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 626008694..e4c7c3446 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -323,7 +323,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); - fprintf(stderr,"ntzs_proof %s\n",result); + fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str,ptr->common.prevht,ptr->nexttxid.GetHex().c_str,ptr->common.nextht); return(result); } @@ -679,6 +679,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int { fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); + usleep(10000); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { std::vector txids; uint256 proofroot; From 1089c2528203257d7a58c09b11d94c8ae3c5cc60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 23:31:25 -1100 Subject: [PATCH 17/17] () --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index e4c7c3446..f8dd7c9af 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -113,7 +113,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); - LOCK(cs_vNodes); + //LOCK(cs_vNodes); n = 0; BOOST_FOREACH(CNode *ptr,vNodes) { @@ -323,7 +323,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); - fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str,ptr->common.prevht,ptr->nexttxid.GetHex().c_str,ptr->common.nextht); + fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); return(result); }