diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index 9f6a35966..2f2b702f4 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -26,6 +26,7 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee); std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data); // CCcustom +UniValue OracleDataSample(uint256 reforacletxid,uint256 txid); UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num); UniValue OracleInfo(uint256 origtxid); UniValue OraclesList(); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 193f66a1a..bdd01ccfa 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -638,11 +638,7 @@ bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransactio int32_t GetLatestTimestamp(int32_t height) { - uint256 blockHash; CBlock block; CBlockIndex* pindex; - - blockHash = chainActive[height]->GetBlockHash(); - pindex = mapBlockIndex[blockHash]; - return(pindex->nTime); + return(komodo_heightstamp(height)); } bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) @@ -1059,6 +1055,38 @@ UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatl return(obj); } +UniValue OracleDataSample(uint256 reforacletxid,uint256 txid) +{ + UniValue result(UniValue::VOBJ); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; std::string error; + CPubKey pk; std::string name,description,format; int32_t numvouts; std::vector data; char str[67], *formatstr = 0; + + result.push_back(Pair("result","success")); + if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 ) + { + if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) + { + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 ) + { + if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) + { + if ( (formatstr= (char *)format.c_str()) == 0 ) + formatstr = (char *)""; + result.push_back(Pair("txid",uint256_str(str,txid))); + result.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size()))); + return(result); + } + else error="invalid data tx"; + } + else error="cannot find data txid"; + } + else error="invalid oracles txid"; + } + else error="cannot find oracles txid"; + result.push_back(Pair("result","error")); + result.push_back(Pair("error",error)); + return(result); +} + UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num) { UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 txid,hashBlock,btxid,oracletxid; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ecf5237e6..1bf8dfbeb 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1692,7 +1692,7 @@ int8_t equihash_params_possible(uint64_t n, uint64_t k) void komodo_args(char *argv0) { - std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512]; + std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512] = {0}; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_STAKED_NOTARY = GetArg("-stakednotary", -1); memset(ccenables,0,sizeof(ccenables)); @@ -1717,15 +1717,17 @@ void komodo_args(char *argv0) // I think on season change should reccomend notaries to use -notary to avoid needing this. int32_t kmd_season = getacseason(time(NULL)); for (i=0; i<64; i++) - if ( strcmp(NOTARY_PUBKEY.c_str(),notaries_elected[kmd_season][NUM_KMD_NOTARIES][1]) == 0 ) + { + if ( strcmp(NOTARY_PUBKEY.c_str(),notaries_elected[kmd_season-1][i][1]) == 0 ) { IS_KOMODO_NOTARY = 1; KOMODO_MININGTHREADS = 1; mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); IS_STAKED_NOTARY = -1; - fprintf(stderr,"running as notary.%d %s\n",i,notaries_elected[kmd_season][NUM_KMD_NOTARIES][0]); + fprintf(stderr,"running as notary.%d %s\n",i,notaries_elected[kmd_season-1][i][0]); break; } + } } } if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) { @@ -1767,7 +1769,7 @@ void komodo_args(char *argv0) { int32_t ecode = ccEnablesHeight[i]; int32_t ht = ccEnablesHeight[i+1]; - if ( ecode > 256 ) + if ( ecode > 255 || ecode < 0 ) fprintf(stderr, "ac_ccactivateht: invalid evalcode.%i must be between 0 and 256.\n", ecode); else if ( ht > 0 ) { diff --git a/src/main.cpp b/src/main.cpp index 30783e2ab..e01cba61f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,10 +147,28 @@ namespace { struct CBlockIndexWorkComparator { - bool operator()(CBlockIndex *pa, CBlockIndex *pb) const { + bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const { // First sort by most total work, ... - if (pa->chainPower > pb->chainPower) return false; - if (pa->chainPower < pb->chainPower) return true; + + if (ASSETCHAINS_LWMAPOS) { + + /* Decker: + + seems we had CChainPower classes compare here from Verus, it's slow, bcz of hard + arith_uint256 math in bool operator<(const CChainPower &p1, const CChainPower &p2), + this slows down setBlockIndexCandidates.insert operations in LoadBlockIndexDB(), + so, for faster block index db loading we will use check from Verus only for LWMAPOS + enabled chains. + */ + + if (pa->chainPower > pb->chainPower) return false; + if (pa->chainPower < pb->chainPower) return true; + } + else + { + if (pa->chainPower.chainWork > pb->chainPower.chainWork) return false; + if (pa->chainPower.chainWork < pb->chainPower.chainWork) return true; + } // ... then by earliest time received, ... if (pa->nSequenceId < pb->nSequenceId) return false; @@ -173,8 +191,10 @@ namespace { * as good as our current tip or better. Entries may be failed, though, and pruning nodes may be * missing the data for the block. */ + + //set> setBlockIndexCandidates; set setBlockIndexCandidates; - + /** Number of nodes with fSyncStarted. */ int nSyncStarted = 0; diff --git a/src/miner.cpp b/src/miner.cpp index 9976909fa..e4e907447 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -222,9 +222,13 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 boost::optional cheatSpend; uint256 cbHash; - + + boost::this_thread::interruption_point(); // exit thread before entering locks. + CBlockIndex* pindexPrev = 0; { + // this should stop create block ever exiting until it has returned something. + boost::this_thread::disable_interruption(); ENTER_CRITICAL_SECTION(cs_main); ENTER_CRITICAL_SECTION(mempool.cs); pindexPrev = chainActive.LastTip(); @@ -815,7 +819,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 LEAVE_CRITICAL_SECTION(cs_main); LEAVE_CRITICAL_SECTION(mempool.cs); } - throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); + //throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); // crashes the node, moved to GetBlockTemplate and issue return. + return(0); } //fprintf(stderr,"valid\n"); } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 53a744497..4814d34dd 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -745,7 +745,8 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) #endif ENTER_CRITICAL_SECTION(cs_main); if (!pblocktemplate) - throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking"); + throw std::runtime_error("CreateNewBlock(): create block failed"); + //throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking"); // Need to update only after we know CreateNewBlockWithKey succeeded pindexPrev = pindexPrevNew; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5d7fd6d74..75360fd35 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -460,6 +460,7 @@ static const CRPCCommand vRPCCommands[] = { "oracles", "oraclesregister", &oraclesregister, true }, { "oracles", "oraclessubscribe", &oraclessubscribe, true }, { "oracles", "oraclesdata", &oraclesdata, true }, + { "oracles", "oraclessample", &oraclessample, true }, { "oracles", "oraclessamples", &oraclessamples, true }, // Prices diff --git a/src/rpc/server.h b/src/rpc/server.h index 27e7288cd..d447d2472 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -271,6 +271,7 @@ extern UniValue oraclesfund(const UniValue& params, bool fHelp); extern UniValue oraclesregister(const UniValue& params, bool fHelp); extern UniValue oraclessubscribe(const UniValue& params, bool fHelp); extern UniValue oraclesdata(const UniValue& params, bool fHelp); +extern UniValue oraclessample(const UniValue& params, bool fHelp); extern UniValue oraclessamples(const UniValue& params, bool fHelp); extern UniValue pricesaddress(const UniValue& params, bool fHelp); extern UniValue priceslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bf861662f..6a47e71a0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5564,6 +5564,8 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) UniValue cclib(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; char *method,*jsonstr=0; uint8_t evalcode = EVAL_FIRSTUSER; + std::string vobjJsonSerialized; + if ( fHelp || params.size() > 3 ) throw runtime_error("cclib method [evalcode] [JSON params]\n"); if ( ASSETCHAINS_CCLIB.size() == 0 ) @@ -5583,7 +5585,12 @@ UniValue cclib(const UniValue& params, bool fHelp) } if ( params.size() == 3 ) { - jsonstr = (char *)params[2].get_str().c_str(); + if (params[2].getType() == UniValue::VOBJ) { + vobjJsonSerialized = params[2].write(0, 0); + jsonstr = (char *)vobjJsonSerialized.c_str(); + } + else // VSTR assumed + jsonstr = (char *)params[2].get_str().c_str(); //fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),jsonstr); } } @@ -6830,6 +6837,20 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) return(result); } +UniValue oraclessample(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 oracletxid,txid; int32_t num; char *batonaddr; + if ( fHelp || params.size() != 2 ) + throw runtime_error("oraclessample oracletxid txid\n"); + if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + oracletxid = Parseuint256((char *)params[0].get_str().c_str()); + txid = Parseuint256((char *)params[1].get_str().c_str()); + return(OracleDataSample(oracletxid,txid)); +} + UniValue oraclessamples(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 txid; int32_t num; char *batonaddr;