From fc537a2231884ed4f9ece79e5dfd64762b976582 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 02:47:56 -1100 Subject: [PATCH 01/28] +prints --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f3b714eaa..7e900bd3b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7091,7 +7091,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); //if ( KOMODO_NSPV != 0 ) //if ( strCommand != "version" && strCommand != "verack" ) - // fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); + fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); @@ -7287,7 +7287,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (pfrom->nVersion < chainparams.GetConsensus().vUpgrades[ CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion) { - LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion); + LogPrintf("peer=%d using obsolete version %i vs %d; disconnecting\n", pfrom->id, pfrom->nVersion,(int32_t)chainparams.GetConsensus())].nProtocolVersion); pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", chainparams.GetConsensus().vUpgrades[ From 8738d15aa00a3089a763190b44d4c3fb69d69386 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 02:56:15 -1100 Subject: [PATCH 02/28] Syntax --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7e900bd3b..43dbc4550 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7287,7 +7287,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (pfrom->nVersion < chainparams.GetConsensus().vUpgrades[ CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion) { - LogPrintf("peer=%d using obsolete version %i vs %d; disconnecting\n", pfrom->id, pfrom->nVersion,(int32_t)chainparams.GetConsensus())].nProtocolVersion); + LogPrintf("peer=%d using obsolete version %i vs %d; disconnecting\n", pfrom->id, pfrom->nVersion,(int32_t)chainparams.GetConsensus().vUpgrades[ + CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion); pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", chainparams.GetConsensus().vUpgrades[ From 2bae0f02263833b4b63d69f6522c732829d2bccf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 05:25:26 -1100 Subject: [PATCH 03/28] +print --- src/komodo_nSPV_fullnode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index b5eba8ed3..2d7c138da 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -513,14 +513,14 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->prevtimes[ind] = 0; if ( request[0] == NSPV_INFO ) // info { - //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); + fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; if ( len == 1+sizeof(reqheight) ) iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); else reqheight = 0; - //fprintf(stderr,"request height.%d\n",reqheight); + fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) { From 995687de260fc5022cde8c0b1f9571f5bb2e250e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 05:30:36 -1100 Subject: [PATCH 04/28] +print --- src/komodo_nSPV_fullnode.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 2d7c138da..c8b9d90dd 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -529,6 +529,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req //fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { + fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } From 59d4e939bdde89d031bc12283516fdfc3679a06e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 05:40:31 -1100 Subject: [PATCH 05/28] +prints --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 43dbc4550..f6fc6d55f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7090,8 +7090,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, const CChainParams& chainparams = Params(); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); //if ( KOMODO_NSPV != 0 ) - //if ( strCommand != "version" && strCommand != "verack" ) - fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); + if ( strCommand != "version" && strCommand != "verack" && strCommand != "ping" && strCommand != "pong" ) + fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), vRecv.size(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); @@ -7464,6 +7464,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } else if (strCommand == "getnSPV") { + fprintf(stderr,"got getnSPV\n"); std::vector payload; vRecv >> payload; komodo_nSPVreq(pfrom,payload); From 9e55b41979287c2989a436a800f610cda23dd0b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 05:51:56 -1100 Subject: [PATCH 06/28] -print --- src/komodo_nSPV_fullnode.h | 6 +++--- src/main.cpp | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index c8b9d90dd..ec682fea0 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -513,14 +513,14 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->prevtimes[ind] = 0; if ( request[0] == NSPV_INFO ) // info { - fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); + //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; if ( len == 1+sizeof(reqheight) ) iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); else reqheight = 0; - fprintf(stderr,"request height.%d\n",reqheight); + //fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) { @@ -529,7 +529,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req //fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { - fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); + //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } diff --git a/src/main.cpp b/src/main.cpp index f6fc6d55f..6333d18a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7090,8 +7090,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, const CChainParams& chainparams = Params(); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); //if ( KOMODO_NSPV != 0 ) - if ( strCommand != "version" && strCommand != "verack" && strCommand != "ping" && strCommand != "pong" ) - fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), vRecv.size(), (int32_t)pfrom->GetId()); + //if ( strCommand != "version" && strCommand != "verack" ) + fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)vRecv.size(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); @@ -7464,7 +7464,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } else if (strCommand == "getnSPV") { - fprintf(stderr,"got getnSPV\n"); std::vector payload; vRecv >> payload; komodo_nSPVreq(pfrom,payload); From 3ba7d72856759347b2aa5c02ba5f2e0a360ee9ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 06:02:31 -1100 Subject: [PATCH 07/28] -msg print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6333d18a1..d41d50a13 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7091,7 +7091,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); //if ( KOMODO_NSPV != 0 ) //if ( strCommand != "version" && strCommand != "verack" ) - fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)vRecv.size(), (int32_t)pfrom->GetId()); + // fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)vRecv.size(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); From e1bdd3bb1411643534223b6254117e908160641b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 07:55:16 -1100 Subject: [PATCH 08/28] Fix mempool son --- 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 f8dae10bf..22f25fe05 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -442,7 +442,7 @@ UniValue NSPV_mempoolresp_json(struct NSPV_mempoolresp *ptr) UniValue result(UniValue::VOBJ),array(UniValue::VARR); int32_t i; result.push_back(Pair("result","success")); for (i=0; inumtxids; i++) - array.push_back(Pair("txid",ptr->txids[i].GetHex().c_str())); + array.push_back(ptr->txids[i].GetHex().c_str()); result.push_back(Pair("txids",array)); result.push_back(Pair("address",ptr->coinaddr)); result.push_back(Pair("isCC",ptr->CCflag)); From 4a1afec4e9ba758f7cc214d7d7676f9c6d5b7c18 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 08:01:07 -1100 Subject: [PATCH 09/28] Fix nexttxlen --- 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 22f25fe05..c8a86196d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -476,7 +476,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("prevtxlen",(int64_t)ptr->prevtxlen)); result.push_back(Pair("nexttxid",ptr->nexttxid.GetHex())); result.push_back(Pair("nexttxidht",(int64_t)ptr->nexttxidht)); - result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); + result.push_back(Pair("nexttxlen",(int64_t)ptr->nexttxlen)); 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)); From b52b4b7685e9b04a3398da77c8a210bccaa361b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jul 2019 22:34:09 -1100 Subject: [PATCH 10/28] Prevent nspv cli when nSPV=0 --- src/wallet/rpcdump.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 395612a3d..c734eb0d9 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -992,6 +992,8 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp) int32_t reqht = 0; if ( fHelp || params.size() > 1 ) throw runtime_error("nspv_getinfo [hdrheight]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 1 ) reqht = atoi((char *)params[0].get_str().c_str()); return(NSPV_getinfo_req(reqht)); @@ -1001,6 +1003,8 @@ UniValue nspv_logout(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 0 ) throw runtime_error("nspv_logout\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_logout()); } @@ -1008,6 +1012,8 @@ UniValue nspv_login(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_login wif\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_login((char *)params[0].get_str().c_str())); } @@ -1016,6 +1022,8 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) int32_t skipcount = 0,CCflag = 0; if ( fHelp || params.size() > 3 ) throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) @@ -1039,6 +1047,8 @@ UniValue nspv_mempool(const UniValue& params, bool fHelp) memset(&txid,0,sizeof(txid)); if ( fHelp || params.size() > 5 ) throw runtime_error("nspv_mempool func(0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool) address isCC [txid vout]]]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); funcid = atoi((char *)params[0].get_str().c_str()); coinaddr = (char *)params[1].get_str().c_str(); CCflag = atoi((char *)params[2].get_str().c_str()); @@ -1057,6 +1067,8 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) int32_t skipcount = 0,CCflag = 0; if ( fHelp || params.size() > 3 ) throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) @@ -1080,6 +1092,8 @@ UniValue nspv_spentinfo(const UniValue& params, bool fHelp) uint256 txid; int32_t vout; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_spentinfo txid vout\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); vout = atoi((char *)params[1].get_str().c_str()); return(NSPV_spentinfo(txid,vout)); @@ -1090,6 +1104,8 @@ UniValue nspv_notarizations(const UniValue& params, bool fHelp) int32_t height; if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_notarizations height\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); height = atoi((char *)params[0].get_str().c_str()); return(NSPV_notarizations(height)); } @@ -1099,6 +1115,8 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp) int32_t prevheight,nextheight; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_hdrsproof prevheight nextheight\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); prevheight = atoi((char *)params[0].get_str().c_str()); nextheight = atoi((char *)params[1].get_str().c_str()); return(NSPV_hdrsproof(prevheight,nextheight)); @@ -1109,6 +1127,8 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) uint256 txid; int32_t height; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_txproof txid height\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); return(NSPV_txproof(0,txid,height)); @@ -1118,7 +1138,9 @@ UniValue nspv_spend(const UniValue& params, bool fHelp) { uint64_t satoshis; if ( fHelp || params.size() != 2 ) - throw runtime_error("nspv_spend destaddr amount\n"); + throw runtime_error("nspv_spend address amount\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( NSPV_address.size() == 0 ) throw runtime_error("to nspv_send you need an active nspv_login\n"); satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049; @@ -1132,5 +1154,7 @@ UniValue nspv_broadcast(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_broadcast hex\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_broadcast((char *)params[0].get_str().c_str())); } From f97a4a3caf54f291be38cdebc2cbe205bffd2e09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 00:05:08 -1100 Subject: [PATCH 11/28] +print --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 27f03a5be..51deb18be 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -286,7 +286,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); - //fprintf(stderr,"hdr rwlen.%d\n",len); +fprintf(stderr,"hdr rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ec682fea0..ecd8dde44 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -520,16 +520,16 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( len == 1+sizeof(reqheight) ) iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); else reqheight = 0; - //fprintf(stderr,"request height.%d\n",reqheight); + fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_INFORESP; - //fprintf(stderr,"slen.%d\n",slen); + fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { - //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); + fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } From 8ba800d6780f556bfdbeb4aa1ce3536b63101cf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 00:20:07 -1100 Subject: [PATCH 12/28] extern int32_t KOMODO_NSPV; --- src/wallet/rpcdump.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index c734eb0d9..d8bed23dd 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -972,6 +972,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) return EncodeViewingKey(vk); } +extern int32_t KOMODO_NSPV; UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); From 79e273d2db4d5576f993fda18c0f766477f76f0c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 00:26:23 -1100 Subject: [PATCH 13/28] +print --- src/komodo_nSPV_fullnode.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ecd8dde44..88a1a123d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -519,7 +519,11 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req struct NSPV_inforesp I; if ( len == 1+sizeof(reqheight) ) iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); - else reqheight = 0; + else + { + fprintf(stderr,"request len %d\n",len); + reqheight = 0; + } fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) From b69c24da55424a6f5047e3bc68798eb3564f94c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 00:56:25 -1100 Subject: [PATCH 14/28] -print --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 51deb18be..c7b0c3741 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -286,7 +286,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); -fprintf(stderr,"hdr rwlen.%d\n",len); +//fprintf(stderr,"hdr rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 88a1a123d..ec682fea0 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -519,21 +519,17 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req struct NSPV_inforesp I; if ( len == 1+sizeof(reqheight) ) iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); - else - { - fprintf(stderr,"request len %d\n",len); - reqheight = 0; - } - fprintf(stderr,"request height.%d\n",reqheight); + else reqheight = 0; + //fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_INFORESP; - fprintf(stderr,"slen.%d\n",slen); + //fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { - fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); + //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } From ffad20360ddd5d71b0ec56f583806a359712be23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 01:28:54 -1100 Subject: [PATCH 15/28] +prints --- src/komodo_nSPV_fullnode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ec682fea0..9e78717fe 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -702,7 +702,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwnum(0,&request[1+sizeof(height)],sizeof(vout),&vout); iguana_rwbignum(0,&request[1+sizeof(height)+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); - //fprintf(stderr,"got txid %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); + fprintf(stderr,"got txid %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { @@ -715,7 +715,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } NSPV_txproof_purge(&P); } - } + } else fprintf(stderr,"txproof reqlen.%d\n",len); } } else if ( request[0] == NSPV_SPENTINFO ) From 276ebfe547295540c922ca6911741c6998aa096c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 01:33:11 -1100 Subject: [PATCH 16/28] Test --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c7b0c3741..8c18e3ff2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -305,6 +305,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); +fprintf(stderr,"len %d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9e78717fe..072d1ab94 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -706,10 +706,12 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { + fprintf(stderr,"slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) { + fprintf(stderr,"send response\n"); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } From 981e6eac0b5e2e05fa71d39ab8f30794154e20b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 01:38:36 -1100 Subject: [PATCH 17/28] Test --- src/komodo_nSPV_fullnode.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 072d1ab94..a886ee950 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -363,7 +363,10 @@ uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint2 *txlenp = 0; { if (!GetTransaction(txid, tx, hashBlock, false)) + { + fprintf(stderr,"error getting transaction %s\n",txid.GetHex().c_str()); return(0); + } string strHex = EncodeHexTx(tx); *txlenp = (int32_t)strHex.size() >> 1; if ( *txlenp > 0 ) @@ -716,7 +719,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->prevtimes[ind] = timestamp; } NSPV_txproof_purge(&P); - } + } else fprintf(stderr,"gettxproof error.%d\n",slen); } else fprintf(stderr,"txproof reqlen.%d\n",len); } } From d7de64a99855ee87502ae4d7ecf3b812723ecf7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 01:46:08 -1100 Subject: [PATCH 18/28] +/- 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 a886ee950..ff8807875 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -364,7 +364,7 @@ uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint2 { if (!GetTransaction(txid, tx, hashBlock, false)) { - fprintf(stderr,"error getting transaction %s\n",txid.GetHex().c_str()); + //fprintf(stderr,"error getting transaction %s\n",txid.GetHex().c_str()); return(0); } string strHex = EncodeHexTx(tx); @@ -428,13 +428,13 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 ssMB << mb; std::vector proof(ssMB.begin(), ssMB.end()); ptr->txprooflen = (int32_t)proof.size(); - //fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); + fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); if ( ptr->txprooflen > 0 ) { ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); memcpy(ptr->txproof,&proof[0],ptr->txprooflen); } - //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); + fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); } } ptr->unspentvalue = CCgettxout(txid,vout,1,1); @@ -709,12 +709,12 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { - fprintf(stderr,"slen.%d\n",slen); + //fprintf(stderr,"slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) { - fprintf(stderr,"send response\n"); + //fprintf(stderr,"send response\n"); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } From 8a4001f6ed7d5e80007765f481bcc0a7b549632a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 01:52:33 -1100 Subject: [PATCH 19/28] Ignore txproofless cache entry if height is specified --- src/komodo_nSPV_fullnode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ff8807875..9dab5b147 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -428,13 +428,13 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 ssMB << mb; std::vector proof(ssMB.begin(), ssMB.end()); ptr->txprooflen = (int32_t)proof.size(); - fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); + //fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); if ( ptr->txprooflen > 0 ) { ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); memcpy(ptr->txproof,&proof[0],ptr->txprooflen); } - fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); + //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); } } ptr->unspentvalue = CCgettxout(txid,vout,1,1); @@ -705,7 +705,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwnum(0,&request[1+sizeof(height)],sizeof(vout),&vout); iguana_rwbignum(0,&request[1+sizeof(height)+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); - fprintf(stderr,"got txid %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); + //fprintf(stderr,"got txid %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { From 5333c9223761413cbb37156f276a98cf74eae911 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jul 2019 03:16:11 -1100 Subject: [PATCH 20/28] Fix i == to i = --- src/komodo_nSPV_superlite.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index c8a86196d..58d4700a1 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -59,7 +59,7 @@ struct NSPV_ntzsresp *NSPV_ntzsresp_add(struct NSPV_ntzsresp *ptr) if ( NSPV_ntzsresp_cache[i].reqheight == 0 ) break; if ( i == sizeof(NSPV_ntzsresp_cache)/sizeof(*NSPV_ntzsresp_cache) ) - i == (rand() % (sizeof(NSPV_ntzsresp_cache)/sizeof(*NSPV_ntzsresp_cache))); + i = (rand() % (sizeof(NSPV_ntzsresp_cache)/sizeof(*NSPV_ntzsresp_cache))); NSPV_ntzsresp_purge(&NSPV_ntzsresp_cache[i]); NSPV_ntzsresp_copy(&NSPV_ntzsresp_cache[i],ptr); fprintf(stderr,"ADD CACHE ntzsresp req.%d\n",ptr->reqheight); @@ -98,7 +98,7 @@ struct NSPV_txproof *NSPV_txproof_add(struct NSPV_txproof *ptr) if ( NSPV_txproof_cache[i].txlen == 0 ) break; if ( i == sizeof(NSPV_txproof_cache)/sizeof(*NSPV_txproof_cache) ) - i == (rand() % (sizeof(NSPV_txproof_cache)/sizeof(*NSPV_txproof_cache))); + i = (rand() % (sizeof(NSPV_txproof_cache)/sizeof(*NSPV_txproof_cache))); NSPV_txproof_purge(&NSPV_txproof_cache[i]); NSPV_txproof_copy(&NSPV_txproof_cache[i],ptr); fprintf(stderr,"ADD CACHE txproof %s\n",ptr->txid.GetHex().c_str()); @@ -121,7 +121,7 @@ struct NSPV_ntzsproofresp *NSPV_ntzsproof_add(struct NSPV_ntzsproofresp *ptr) if ( NSPV_ntzsproofresp_cache[i].common.hdrs == 0 ) break; if ( i == sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache) ) - i == (rand() % (sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache))); + i = (rand() % (sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache))); NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresp_cache[i]); NSPV_ntzsproofresp_copy(&NSPV_ntzsproofresp_cache[i],ptr); fprintf(stderr,"ADD CACHE ntzsproof %s %s\n",ptr->prevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); @@ -656,8 +656,11 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout) { - UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0; + UniValue result(UniValue::VOBJ); uint8_t msg[512]; char zeroes[64]; int32_t i,iter,slen,len = 0; NSPV_mempoolresp_purge(&NSPV_mempoolresult); + memset(zeroes,0,sizeof(zeroes)); + if ( coinaddr == 0 ) + coinaddr = zeroes; if ( coinaddr[0] != 0 && bitcoin_base58decode(msg,coinaddr) != 25 ) { result.push_back(Pair("result","error")); From 987fc332e003891ead9a3089f8ef671f02777adf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jul 2019 09:29:30 -1100 Subject: [PATCH 21/28] Various bug fixes found during libnspv --- src/komodo_nSPV_superlite.h | 32 ++++++++++++++++---------------- src/komodo_nSPV_wallet.h | 24 +++++++++++++++++------- src/komodo_notary.h | 4 ++-- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 58d4700a1..e9c0c20b6 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -544,11 +544,11 @@ UniValue NSPV_login(char *wifstr) UniValue NSPV_getinfo_req(int32_t reqht) { - uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_inforesp I; + uint8_t msg[512]; int32_t i,iter,len = 0; struct NSPV_inforesp I; NSPV_inforesp_purge(&NSPV_inforesult); msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); - for (iter=0; iter<3; iter++); + for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); @@ -601,7 +601,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); - for (iter=0; iter<3; iter++); + for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag && skipcount == NSPV_txidsresult.skipcount ) return(NSPV_txidsresp_json(&NSPV_txidsresult)); if ( skipcount < 0 ) @@ -638,7 +638,7 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) msg[len++] = (CCflag != 0); len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); //fprintf(stderr,"skipcount.%d\n",skipcount); - for (iter=0; iter<3; iter++); + for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; iprevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); @@ -771,7 +771,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<3; iter++) if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i proof; + struct NSPV_txproof *ptr; int32_t i,offset,retval = -1; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; //fprintf(stderr,"NSPV_gettx %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); if ( (ptr= NSPV_txproof_find(txid)) == 0 ) { @@ -78,7 +78,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int retval = -2001; else if ( skipvalidation == 0 && ptr->unspentvalue <= 0 ) retval = -2002; - else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) + else if ( ASSETCHAINS_SYMBOL[0] == 0 && tiptime != 0 ) { rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); if ( rewards != extradata ) @@ -117,11 +117,12 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int { std::vector txids; uint256 proofroot; proofroot = BitcoinGetProofMerkleRoot(proof,txids); - if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) + if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot || txids[0] != txid ) { + fprintf(stderr,"txid.%s vs txids[0] %s\n",txid.GetHex().c_str(),txids[0].GetHex().c_str()); fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",(int32_t)proof.size(),proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); retval = -2003; - } + } else retval = 0; } } else retval = -2005; } else retval = -2004; @@ -242,7 +243,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,branchid) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - //fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); } //else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); @@ -321,12 +322,21 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a len >>= 1; data.resize(len); decode_hex(&data[0],len,destaddr); - scriptPubKey = CScript() << data << OP_CHECKCRYPTOCONDITION; + if ( data[len-1] == OP_CHECKCRYPTOCONDITION ) + { + data.resize(--len); + scriptPubKey = CScript() << data << OP_CHECKCRYPTOCONDITION; + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","only CC hex allowed for now")); + return(result); } } else { result.push_back(Pair("result","error")); - result.push_back(Pair("error","invalid destaddr")); + result.push_back(Pair("error","invalid destaddr/CCvout hex")); return(result); } } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 028bc4dc2..caa99bdcd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -73,7 +73,7 @@ int32_t getkmdseason(int32_t height) return(i+1); } return(0); -}; +} int32_t getacseason(uint32_t timestamp) { @@ -85,7 +85,7 @@ int32_t getacseason(uint32_t timestamp) return(i+1); } return(0); -}; +} int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { From c9a8402f308e75ba8c6eee1052699a71df19c576 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jul 2019 10:04:11 -1100 Subject: [PATCH 22/28] Faster --- src/komodo_nSPV_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 4cf4d93eb..e4a08a125 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -18,7 +18,7 @@ #define KOMODO_NSPV_DEFSH #define NSPV_POLLITERS 100 -#define NSPV_POLLMICROS 50000 +#define NSPV_POLLMICROS 10000 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 #define NSPV_BRANCHID 0x76b809bb From 587a4a6b91ea0e568608add463008c1f2562389c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jul 2019 23:52:29 -1100 Subject: [PATCH 23/28] +print --- src/komodo_nSPV.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8c18e3ff2..d53798176 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -494,6 +494,7 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t continue; char coinaddr[64]; Getscriptaddress(coinaddr,scriptPubKeys[j]); NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j],nTime); // sets SIG_TXHASH + fprintf(stderr,"%s ",SIG_TXHASH.GetHex().c_str()); if ( (retval= pubkeys[j].Verify(SIG_TXHASH,vData[0])) != 0 ) { fprintf(stderr,"(vini.%d %s.%d) ",vini,coinaddr,retval); @@ -501,7 +502,7 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t break; } } - fprintf(stderr," verified %llx\n",(long long)mask); + fprintf(stderr," vini.%d verified %llx\n",vini,(long long)mask); } } return(bitweight(mask)); From 40413281f45d17a726d0f66ab67f2c81bec6b900 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Jul 2019 00:01:42 -1100 Subject: [PATCH 24/28] -print --- src/komodo_nSPV.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d53798176..5143154dc 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -494,15 +494,15 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t continue; char coinaddr[64]; Getscriptaddress(coinaddr,scriptPubKeys[j]); NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j],nTime); // sets SIG_TXHASH - fprintf(stderr,"%s ",SIG_TXHASH.GetHex().c_str()); + //fprintf(stderr,"%s ",SIG_TXHASH.GetHex().c_str()); if ( (retval= pubkeys[j].Verify(SIG_TXHASH,vData[0])) != 0 ) { - fprintf(stderr,"(vini.%d %s.%d) ",vini,coinaddr,retval); + //fprintf(stderr,"(vini.%d %s.%d) ",vini,coinaddr,retval); mask |= (1LL << j); break; } } - fprintf(stderr," vini.%d verified %llx\n",vini,(long long)mask); + //fprintf(stderr," vini.%d verified %llx\n",vini,(long long)mask); } } return(bitweight(mask)); @@ -573,7 +573,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * { fprintf(stderr,"numsigs.%d error\n",numsigs); return(-3); - } + } else fprintf(stderr,"numsigs.%d validated\n",numsigs); return(0); } else From 0ce3df8627abfc7e104a843fc4317939937bf8cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Jul 2019 00:18:37 -1100 Subject: [PATCH 25/28] -print --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 5143154dc..9fe49f9e0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -573,7 +573,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * { fprintf(stderr,"numsigs.%d error\n",numsigs); return(-3); - } else fprintf(stderr,"numsigs.%d validated\n",numsigs); + } return(0); } else From db4721816c34dea5b86b92b83f871d62b4c4b365 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Jul 2019 05:30:04 -1100 Subject: [PATCH 26/28] Have full node txproof return height if not set --- src/komodo_nSPV_fullnode.h | 54 ++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9dab5b147..2700f293b 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -408,34 +408,42 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 return(-1); ptr->txid = txid; ptr->vout = vout; - ptr->height = height; - if ( height != 0 && (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) + if ( height != 0 ) { - BOOST_FOREACH(const CTransaction&tx, block.vtx) + ptr->height = height; + if ((pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) { - if ( tx.GetHash() == txid ) + BOOST_FOREACH(const CTransaction&tx, block.vtx) { - flag = 1; - break; + if ( tx.GetHash() == txid ) + { + flag = 1; + break; + } + } + if ( flag != 0 ) + { + set setTxids; + CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); + setTxids.insert(txid); + CMerkleBlock mb(block, setTxids); + ssMB << mb; + std::vector proof(ssMB.begin(), ssMB.end()); + ptr->txprooflen = (int32_t)proof.size(); + //fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); + if ( ptr->txprooflen > 0 ) + { + ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); + memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + } + //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); } } - if ( flag != 0 ) - { - set setTxids; - CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); - setTxids.insert(txid); - CMerkleBlock mb(block, setTxids); - ssMB << mb; - std::vector proof(ssMB.begin(), ssMB.end()); - ptr->txprooflen = (int32_t)proof.size(); - //fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); - if ( ptr->txprooflen > 0 ) - { - ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); - memcpy(ptr->txproof,&proof[0],ptr->txprooflen); - } - //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); - } + } + else + { + if ( GetTransaction(args->txid,tx,hashBlock,false) != 0 ) + ptr->height = komodo_blockheight(hashBlock); } ptr->unspentvalue = CCgettxout(txid,vout,1,1); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); From e87602ffc613d9bbf7add8ca3d58ce4bd012fb04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Jul 2019 05:32:52 -1100 Subject: [PATCH 27/28] Syntax --- src/komodo_nSPV_fullnode.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 2700f293b..d35c6e9ad 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -408,7 +408,9 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 return(-1); ptr->txid = txid; ptr->vout = vout; - if ( height != 0 ) + if ( height == 0 ) + ptr->height = komodo_blockheight(hashBlock); + else { ptr->height = height; if ((pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) @@ -440,11 +442,6 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 } } } - else - { - if ( GetTransaction(args->txid,tx,hashBlock,false) != 0 ) - ptr->height = komodo_blockheight(hashBlock); - } ptr->unspentvalue = CCgettxout(txid,vout,1,1); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); } From 69ca7f11f4f58ea74ff345e1e7427a8ef4187ee5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Jul 2019 07:16:51 -1100 Subject: [PATCH 28/28] *retvalp = skipvalidation != 0 ? 0 : -1; --- src/komodo_nSPV_wallet.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 128bdd233..d7714f15e 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -60,7 +60,9 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) 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) { - struct NSPV_txproof *ptr; int32_t i,offset,retval = -1; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; + struct NSPV_txproof *ptr; int32_t i,offset,retval; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; + retval = skipvalidation != 0 ? 0 : -1; + //fprintf(stderr,"NSPV_gettx %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); if ( (ptr= NSPV_txproof_find(txid)) == 0 ) {