From a6df99fc9c34e56e6ac10faf049e915cb8602579 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 22:08:32 +0300 Subject: [PATCH 1/6] Getchaintips error checks --- src/rpcblockchain.cpp | 58 +++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e4574860c..d4f65f940 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1055,7 +1055,9 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.insert(item.second); BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { - const CBlockIndex* pprev = item.second->pprev; + const CBlockIndex* pprev=0; + if ( item.second != 0 ) + pprev = item.second->pprev; if (pprev) setTips.erase(pprev); } @@ -1064,38 +1066,40 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.insert(chainActive.Tip()); /* Construct the output array. */ - UniValue res(UniValue::VARR); + UniValue res(UniValue::VARR); CBlockIndex *forked; BOOST_FOREACH(const CBlockIndex* block, setTips) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("height", block->nHeight)); obj.push_back(Pair("hash", block->phashBlock->GetHex())); - - const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight; - obj.push_back(Pair("branchlen", branchLen)); - - string status; - if (chainActive.Contains(block)) { - // This block is part of the currently active chain. - status = "active"; - } else if (block->nStatus & BLOCK_FAILED_MASK) { - // This block or one of its ancestors is invalid. - status = "invalid"; - } else if (block->nChainTx == 0) { - // This block cannot be connected because full block data for it or one of its parents is missing. - status = "headers-only"; - } else if (block->IsValid(BLOCK_VALID_SCRIPTS)) { - // This block is fully validated, but no longer part of the active chain. It was probably the active block once, but was reorganized. - status = "valid-fork"; - } else if (block->IsValid(BLOCK_VALID_TREE)) { - // The headers for this block are valid, but it has not been validated. It was probably never part of the most-work chain. - status = "valid-headers"; - } else { - // No clue. - status = "unknown"; + forked = chainActive.FindFork(block); + if ( forked != 0 ) + { + const int branchLen = block->nHeight - forked->nHeight; + obj.push_back(Pair("branchlen", branchLen)); + + string status; + if (chainActive.Contains(block)) { + // This block is part of the currently active chain. + status = "active"; + } else if (block->nStatus & BLOCK_FAILED_MASK) { + // This block or one of its ancestors is invalid. + status = "invalid"; + } else if (block->nChainTx == 0) { + // This block cannot be connected because full block data for it or one of its parents is missing. + status = "headers-only"; + } else if (block->IsValid(BLOCK_VALID_SCRIPTS)) { + // This block is fully validated, but no longer part of the active chain. It was probably the active block once, but was reorganized. + status = "valid-fork"; + } else if (block->IsValid(BLOCK_VALID_TREE)) { + // The headers for this block are valid, but it has not been validated. It was probably never part of the most-work chain. + status = "valid-headers"; + } else { + // No clue. + status = "unknown"; + } + obj.push_back(Pair("status", status)); } - obj.push_back(Pair("status", status)); - res.push_back(obj); } From 40daca68fd0b292ad6c8f9edef3f5130e2ea973e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 22:25:48 +0300 Subject: [PATCH 2/6] Test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d4f65f940..d5b822da9 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1066,7 +1066,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.insert(chainActive.Tip()); /* Construct the output array. */ - UniValue res(UniValue::VARR); CBlockIndex *forked; + UniValue res(UniValue::VARR); const CBlockIndex *forked; BOOST_FOREACH(const CBlockIndex* block, setTips) { UniValue obj(UniValue::VOBJ); From c608f584cc4527b5642b4fc21f590e7208b88cec Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 1 Oct 2017 19:32:58 +0300 Subject: [PATCH 3/6] Test --- src/httprpc.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 2a465ee54..abff68868 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -102,7 +102,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &) return false; } - if (!RPCAuthorized(authHeader.second)) { + if ( (0) && !RPCAuthorized(authHeader.second)) { LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", req->GetPeer().ToString()); /* Deter brute-forcing @@ -126,6 +126,15 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &) // singleton request if (valRequest.isObject()) { jreq.parse(valRequest); + + if (!RPCAuthorized(authHeader.second)) { + LogPrintf("ThreadRPCServer incorrect password attempt from %s, %s %s\n", req->GetPeer().ToString(),jreq.strMethod.ToString(), jreq.params.ToString()); + MilliSleep(250); + + req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA); + req->WriteReply(HTTP_UNAUTHORIZED); + return false; + } UniValue result = tableRPC.execute(jreq.strMethod, jreq.params); From 578a9891dc5c5c347cbf002b446c152f1a62b3af Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 1 Oct 2017 19:42:04 +0300 Subject: [PATCH 4/6] Test --- src/httprpc.cpp | 4 ++-- src/komodo_bitcoind.h | 1 + src/komodo_utils.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/httprpc.cpp b/src/httprpc.cpp index abff68868..d6b317537 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -102,7 +102,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &) return false; } - if ( (0) && !RPCAuthorized(authHeader.second)) { + if (!RPCAuthorized(authHeader.second)) { LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", req->GetPeer().ToString()); /* Deter brute-forcing @@ -128,7 +128,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &) jreq.parse(valRequest); if (!RPCAuthorized(authHeader.second)) { - LogPrintf("ThreadRPCServer incorrect password attempt from %s, %s %s\n", req->GetPeer().ToString(),jreq.strMethod.ToString(), jreq.params.ToString()); + LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", req->GetPeer().ToString()); MilliSleep(250); req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c581a676f..5000603d9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -340,6 +340,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); //printf("postdata.(%s) USERPASS.(%s)\n",postdata,KMDUSERPASS); + LogPrintf("komodo_issuemethod userpass.(%s) %s %s port.%u\n",userpass,method,params,port); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4afc572f6..28e91b540 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1510,6 +1510,7 @@ void komodo_args() extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); COINBASE_MATURITY = 1; + LogPrintf("ASSETCHAINS_PORT %s %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); } ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); From 20d00c7773966f251727cbc2d847d767f68bb532 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 1 Oct 2017 19:48:08 +0300 Subject: [PATCH 5/6] Test --- src/komodo_bitcoind.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5000603d9..ae942c855 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -354,7 +354,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig *kmdnotarized_heightp = 0; if ( strcmp(dest,"KMD") == 0 ) { - port = BITCOIND_PORT; + port = 7771; userpass = KMDUSERPASS; } else if ( strcmp(dest,"BTC") == 0 ) @@ -432,8 +432,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) - jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,BITCOIND_PORT); - //else jsonstr = _dex_getrawtransaction(); + jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); else return(0); // need universal way to issue DEX* API, since notaries mine most blocks, this ok } else if ( strcmp(dest,"BTC") == 0 ) From 3ddca65d5223909c12cf4c3d2e3c30bd6bab1fbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 1 Oct 2017 19:56:43 +0300 Subject: [PATCH 6/6] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ae942c855..4c68b886d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -340,7 +340,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); //printf("postdata.(%s) USERPASS.(%s)\n",postdata,KMDUSERPASS); - LogPrintf("komodo_issuemethod userpass.(%s) %s %s port.%u\n",userpass,method,params,port); + //LogPrintf("komodo_issuemethod userpass.(%s) %s %s port.%u\n",userpass,method,params,port); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); }