From c1bbe1421c53d66a300fcab857c4fd7488c232cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 00:45:22 -1100 Subject: [PATCH 01/15] Fullnode shouldn't issue getnSPV calls --- 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 75fffb761..2563f1253 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -155,6 +155,8 @@ UniValue NSPV_logout() void komodo_nSPV(CNode *pto) // polling loop from SendMessages { uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); + if ( KOMODO_NSPV == 0 ) + return; if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) NSPV_logout(); if ( (pto->nServices & NODE_NSPV) == 0 ) From c45bb97ce8c66de49c3d4cde459a5c0b827b3406 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 00:53:56 -1100 Subject: [PATCH 02/15] -fullnode doing nSPV client --- 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 2563f1253..6ab42b272 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -102,6 +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 ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); @@ -155,8 +157,6 @@ UniValue NSPV_logout() void komodo_nSPV(CNode *pto) // polling loop from SendMessages { uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); - if ( KOMODO_NSPV == 0 ) - return; if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) NSPV_logout(); if ( (pto->nServices & NODE_NSPV) == 0 ) From c34dd538bb3f31319ffe51a7257cc51e005c3a58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 00:54:31 -1100 Subject: [PATCH 03/15] Test --- 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 6ab42b272..005193681 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 fc3c50c02e8e3dd2f9ab2380873f64e2e3f7cae8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:00:39 -1100 Subject: [PATCH 04/15] No services bug? --- src/net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index 0586d7124..56de05b83 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -458,7 +458,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -//fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); +fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); } From ec24982ff6ff4403ed86745d2367f90ac622bc77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:02:35 -1100 Subject: [PATCH 05/15] +print --- src/komodo_nSPV_superlite.h | 4 ++-- src/net.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 005193681..6ab42b272 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)); diff --git a/src/net.cpp b/src/net.cpp index 56de05b83..3bd9e4b19 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -458,7 +458,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); +fprintf(stderr,"KOMODO_NSPV.%d PUSH services.%llx\n",KOMODO_NSPV,(long long)nLocalServices); } From 94a1656ed280c452d257a8f9cdf9d111165363c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:04:43 -1100 Subject: [PATCH 06/15] Extern --- src/net.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 3bd9e4b19..0c5612bb1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -444,6 +444,8 @@ void CNode::CloseSocketDisconnect() vRecvMsg.clear(); } +extern int32_t KOMODO_NSPV; + void CNode::PushVersion() { int nBestHeight = g_signals.GetHeight().get_value_or(0); From bab3e6a1b800bffc4d070d9296830f7270a50fc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:07:27 -1100 Subject: [PATCH 07/15] +print --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 339f4e790..ac5b8b48b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7245,6 +7245,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if ( KOMODO_NSPV != 0 ) { + fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pform->nServices,pfrom->id); if ( (pfrom->nServices & NODE_NSPV) == 0 ) { //fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); From 794839f38e9d9097cf3f4743042a9518de2fb93d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:09:06 -1100 Subject: [PATCH 08/15] From --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ac5b8b48b..2ef31147e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7245,7 +7245,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if ( KOMODO_NSPV != 0 ) { - fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pform->nServices,pfrom->id); + fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pfrom->nServices,pfrom->id); if ( (pfrom->nServices & NODE_NSPV) == 0 ) { //fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); From d7abeff40cfef8a45a5e12280d4b719818fa58e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:12:51 -1100 Subject: [PATCH 09/15] Test --- src/init.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 738d94377..4adde6681 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1147,9 +1147,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Option to startup with mocktime set (used for regression testing): SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op - if (GetBoolArg("-peerbloomfilters", true)) - nLocalServices |= NODE_BLOOM; - + if ( KOMODO_NSPV == 0 ) + { + if (GetBoolArg("-peerbloomfilters", true)) + nLocalServices |= NODE_BLOOM; + } nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); #ifdef ENABLE_MINING From 70e6b596fe4e946058ce2bd49e2214fc4ee4c55d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:16:44 -1100 Subject: [PATCH 10/15] +print --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 6ab42b272..56157e32d 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)); @@ -131,7 +131,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - //fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); From f89ebce1e7b47cb74d5b4875f8d6fe22efc6bd56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:22:41 -1100 Subject: [PATCH 11/15] -print --- src/komodo_nSPV_superlite.h | 3 ++- src/net.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 56157e32d..9a30ddc44 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -131,7 +131,8 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + if ( KOMODO_NSPV == 0 ) + fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); diff --git a/src/net.cpp b/src/net.cpp index 0c5612bb1..23d20e4c0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -460,7 +460,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -fprintf(stderr,"KOMODO_NSPV.%d PUSH services.%llx\n",KOMODO_NSPV,(long long)nLocalServices); +//fprintf(stderr,"KOMODO_NSPV.%d PUSH services.%llx\n",KOMODO_NSPV,(long long)nLocalServices); } From 53728f1bb503e9d06435b0ab34af4853f9ba95df Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:26:35 -1100 Subject: [PATCH 12/15] -print --- src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2ef31147e..b4ecc6922 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7245,10 +7245,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if ( KOMODO_NSPV != 0 ) { - fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pfrom->nServices,pfrom->id); if ( (pfrom->nServices & NODE_NSPV) == 0 ) { - //fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); + // fprintf(stderr,"invalid nServices.%llx nSPV peer.%d\n",(long long)pfrom->nServices,pfrom->id); pfrom->fDisconnect = true; return false; } From ecc5aebc444b57bf64d5d9df6e84fd00168dee8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:52:25 -1100 Subject: [PATCH 13/15] Disp relay tx --- 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 cdfb0f57e..436095945 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -214,7 +214,10 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int if ( myAddtomempool(tx) != 0 ) ptr->retcode = 1; else ptr->retcode = 0; - //fprintf(stderr,"relay transaction %s retcode.%d\n",ptr->txid.GetHex().c_str(),ptr->retcode); + int32_t i; + for (i=0; itxid.GetHex().c_str(),ptr->retcode); RelayTransaction(tx); } else ptr->retcode = -1; return(sizeof(*ptr)); From 9a3cf79c3760fb3ff8a70f7f29340bba520345ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 02:00:15 -1100 Subject: [PATCH 14/15] Test --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 16 +++++++++------- src/net.cpp | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d4a4fd90f..e0a003fcd 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -23,6 +23,7 @@ // CC signing // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) +// bug: under load, fullnode was returning all 0 nServices #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 436095945..948846fe5 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -210,15 +210,17 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int { LOCK(cs_main); ptr->txid = tx.GetHash(); - fprintf(stderr,"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; - else ptr->retcode = 0; - int32_t i; - for (i=0; itxid.GetHex().c_str(),ptr->retcode); - RelayTransaction(tx); + RelayTransaction(tx); + } else ptr->retcode = -3; + } else ptr->retcode = -1; return(sizeof(*ptr)); } diff --git a/src/net.cpp b/src/net.cpp index 23d20e4c0..02cddd3e2 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1843,7 +1843,7 @@ bool StopNode() for (int i=0; ipost(); - if (fAddressesInitialized) + if (KOMODO_NSPV == 0 && fAddressesInitialized) { DumpAddresses(); fAddressesInitialized = false; From 7e47549603bc04ded54228c56a590cb8ccb7c730 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 02:04:54 -1100 Subject: [PATCH 15/15] Fix signing legacy check --- src/komodo_nSPV_wallet.h | 2 +- src/main.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index e0a477ed3..6cf2e82c6 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -132,7 +132,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C fprintf(stderr,"%02x",((uint8_t *)&scriptPubKey)[i]); fprintf(stderr," scriptPubKey\n"); } - if ( nTime < KOMODO_SAPLING_ACTIVATION ) + if ( nTime != 0 && nTime < KOMODO_SAPLING_ACTIVATION ) { fprintf(stderr,"use legacy sig validation\n"); branchid = 0; diff --git a/src/main.cpp b/src/main.cpp index b4ecc6922..a8ff33c2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3974,7 +3974,8 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) { void FlushStateToDisk() { CValidationState state; - FlushStateToDisk(state, FLUSH_STATE_ALWAYS); + if ( KOMODO_NSPV == 0 ) + FlushStateToDisk(state, FLUSH_STATE_ALWAYS); } void PruneAndFlush() {