// FIXME algo is only needed here for a minimum work block. // if all algos are treated the same with the same minimum limit... bool CheckProofOfWork(uint256 hash, unsigned int nBits, int algo) { bool fNegative; bool fOverflow; uint256 bnTarget; if (Params().SkipProofOfWorkCheck() || hash == Params().HashAirdropBlock()) return true; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); // Check range if (fNegative || bnTarget == 0 || fOverflow || bnTarget > Params().ProofOfWorkLimit(algo)) { LogPrintf("CheckProofOfWork: \n"); LogPrintf(" hash = %s\n", hash.GetHex()); LogPrintf(" bnTaget = %s\n", bnTarget.GetHex()); LogPrintf(" Params().ProofOfWorkLimit(%s) = %s\n", GetAlgoName(algo), Params().ProofOfWorkLimit(algo).GetHex()); return error("CheckProofOfWork(algo=%d) : nBits below minimum work", algo); } // Check proof of work matches claimed amount if (hash > bnTarget) return error("CheckProofOfWork(algo=%s) : hash doesn't match nBits", GetAlgoName(algo)); return true; }
void MediPixAlgo::PreInitMPXAlgo(){ //////////////////////////////////////////////////////////////////////////////////////////////////// // Deal with the extended mask here if (m_inputExtendedMask) { // In this case the code will produce the extended mask // If not filename given if( m_extendedMaskFile == TString("") ) { TString oname = TString(GetOutputBaseName().c_str()); oname += "_ExtendedMask.txt"; m_extendedMaskFile = oname; } Log << MSG::INFO << "Attempting to load extended mask file : " << m_extendedMaskFile << endreq; infile_extendedmask = new ifstream(m_extendedMaskFile.Data()); if( ! infile_extendedmask->good() ) { Log << MSG::ERROR << "Coudn't load extended mask file : " << m_extendedMaskFile << ", giving up." << endreq; exit(1); } LoadExtendedMask(); DumpExtendedMask(); Log << MSG::INFO << "Extended mask successfully loaded. " << GetAlgoName() << " will use it." << endreq; } }
void RunSimulation(boost::function<double(const CBlockIndex*)>* hashRate, int startHeight, int iterations) { CBlockIndex* tip = NULL; double rate[5]; for(int i=0; i<5; i++) rate[i]=hashRate[i](tip); SimulationSetup(tip, rate, startHeight); printf("begin simulation:\n"); for(int it=0; it<iterations; it++) { for(int i=0; i<5; i++) rate[i]=hashRate[i](tip); SimulateNextBlock(tip, rate); double diffsum=0; for(int i=0; i<5; i++) diffsum+=BitsToDifficulty(GetNextWorkRequired(tip, NULL, i)); printf("height %d algo %7s time %3d diff %8.3f, avg next diff %7.3f\n", tip->nHeight, GetAlgoName(GetAlgo(tip->nVersion)).c_str(), tip->nTime - tip->pprev->nTime, BitsToDifficulty(tip->nBits), diffsum/5); } }
void MediPixAlgo::TouchConfiguraton(string type, string val, string varname, string algo) { MPXDefs::SpecialObjs typeFetch; if(type == "int") typeFetch = MPXDefs::CONF_INT; else if(type == "float") typeFetch = MPXDefs::CONF_FLOAT; else if(type == "double") typeFetch = MPXDefs::CONF_DOUBLE; else if(type == "bool") typeFetch = MPXDefs::CONF_BOOL; std::vector<CandidateContainer *> conf = GetObjectsSpecialWithAuthor(typeFetch, GetAlgoName()); std::vector<CandidateContainer *>::iterator itr = conf.begin(); if(type == "int"){ for( ; itr != conf.end() ; itr++){ ConfigurationValue<Int_t> * p = (ConfigurationValue<Int_t> *)(*itr); if(p->GetConfigName() == varname && algoName == algo){ Log << MSG::ALWAYS << " found " << p->GetConfigName() << " | setting value to " << val << endreq; p->SetConfigValue( atoi(val.c_str()) ); } } } else if(type == "float"){ for( ; itr != conf.end() ; itr++){ ConfigurationValue<Float_t> * p = (ConfigurationValue<Float_t> *)(*itr); if(p->GetConfigName() == varname && algoName == algo){ Log << MSG::ALWAYS << " found " << p->GetConfigName() << " | setting value to " << val << endreq; p->SetConfigValue( atof(val.c_str()) ); } } } else if(type == "double"){ for( ; itr != conf.end() ; itr++){ ConfigurationValue<Double_t> * p = (ConfigurationValue<Double_t> *)(*itr); if(p->GetConfigName() == varname && algoName == algo){ Log << MSG::ALWAYS << " found " << p->GetConfigName() << " | setting value to " << val << endreq; p->SetConfigValue( atof(val.c_str()) ); } } } else if(type == "bool"){ for( ; itr != conf.end() ; itr++){ ConfigurationValue<Bool_t> * p = (ConfigurationValue<Bool_t> *)(*itr); if(p->GetConfigName() == varname && algoName == algo){ Log << MSG::ALWAYS << " found " << p->GetConfigName() << " | setting value to " << val << endreq; p->SetConfigValue( atof(val.c_str()) ); } } } }
static UniValue getmininginfo(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 0) throw std::runtime_error( "getmininginfo\n" "\nReturns a json object containing mining-related information." "\nResult:\n" "{\n" " \"blocks\": nnn, (numeric) The current block\n" " \"currentblockweight\": nnn, (numeric) The last block weight\n" " \"currentblocktx\": nnn, (numeric) The last block transaction\n" " \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n" " \"networkhashps\": nnn, (numeric) The network hashes per second\n" " \"pooledtx\": n (numeric) The size of the mempool\n" " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" " \"warnings\": \"...\" (string) any network and blockchain warnings\n" "}\n" "\nExamples:\n" + HelpExampleCli("getmininginfo", "") + HelpExampleRpc("getmininginfo", "") ); LOCK(cs_main); UniValue obj(UniValue::VOBJ); obj.pushKV("blocks", (int)chainActive.Height()); obj.pushKV("currentblockweight", (uint64_t)nLastBlockWeight); obj.pushKV("pow_algo_id", miningAlgo); obj.pushKV("pow_algo", GetAlgoName(miningAlgo)); obj.pushKV("difficulty", (double)GetDifficulty(NULL, miningAlgo)); obj.pushKV("difficulty_sha256d", (double)GetDifficulty(NULL, ALGO_SHA256D)); obj.pushKV("difficulty_scrypt", (double)GetDifficulty(NULL, ALGO_SCRYPT)); obj.pushKV("difficulty_groestl", (double)GetDifficulty(NULL, ALGO_GROESTL)); obj.pushKV("difficulty_skein", (double)GetDifficulty(NULL, ALGO_SKEIN)); obj.pushKV("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_QUBIT)); //obj.push_back(Pair("difficulty_EQUIHASH", (double)GetDifficulty(NULL, ALGO_EQUIHASH))); //obj.push_back(Pair("difficulty_ETHASH", (double)GetDifficulty(NULL, ALGO_ETHASH))); obj.pushKV("errors", GetWarnings("statusbar")); //obj.push_back(Pair("networkhashps", getnetworkhashps(request))); obj.pushKV("pooledtx", (uint64_t)mempool.size()); obj.pushKV("chain", Params().NetworkIDString()); if (IsDeprecatedRPCEnabled("getmininginfo")) { obj.pushKV("errors", GetWarnings("statusbar")); } else { obj.pushKV("warnings", GetWarnings("statusbar")); } return obj; }
void UpdateStatusLines() { std::string rule = currlayer->algo->getrule(); status1 = "Pattern="; if (currlayer->dirty) { // display asterisk to indicate pattern has been modified status1 += "*"; } status1 += currlayer->currname; status1 += widescreen ? large_algo_prefix : small_algo_prefix; status1 += GetAlgoName(currlayer->algtype); status1 += widescreen ? large_rule_prefix : small_rule_prefix; status1 += rule; // show rule name if one exists and is not same as rule // (best NOT to remove any suffix like ":T100,200" in case we allow // users to name "B3/S23:T100,200" as "Life on torus") std::string rulename = GetRuleName(rule); if (!rulename.empty() && rulename != rule) { status1 += " ["; status1 += rulename; status1 += "]"; } char scalestr[32]; int mag = currlayer->view->getmag(); if (mag < 0) { sprintf(scalestr, "2^%d:1", -mag); } else { sprintf(scalestr, "1:%d", 1 << mag); } char stepstr[32]; if (currlayer->currexpo < 0) { // show delay in secs sprintf(stepstr, "Delay=%gs", (double)GetCurrentDelay() / 1000.0); } else { sprintf(stepstr, "Step=%d^%d", currlayer->currbase, currlayer->currexpo); } status2 = widescreen ? large_gen_prefix : small_gen_prefix; if (nopattupdate) { status2 += "0"; } else { status2 += Stringify(currlayer->algo->getGeneration()); } status2 += widescreen ? large_pop_prefix : small_pop_prefix; if (nopattupdate) { status2 += "0"; } else { bigint popcount = currlayer->algo->getPopulation(); if (popcount.sign() < 0) { // getPopulation returns -1 if it can't be calculated status2 += "?"; } else { status2 += Stringify(popcount); } } status2 += widescreen ? large_scale_prefix : small_scale_prefix; status2 += scalestr; status2 += widescreen ? large_step_prefix : small_step_prefix; status2 += stepstr; status2 += widescreen ? large_xy_prefix : small_xy_prefix; #ifdef WEB_GUI // in web app we show the cursor's current cell location, // or nothing if the cursor is outside the viewport (ie. showxy is false) if (showxy) { bigint xo, yo; bigint xpos = currx; xpos -= currlayer->originx; bigint ypos = curry; ypos -= currlayer->originy; if (mathcoords) { // Y values increase upwards bigint temp = 0; temp -= ypos; ypos = temp; } status2 += Stringify(xpos); status2 += " "; status2 += Stringify(ypos); } #else // in iOS and Android apps we show location of the cell in middle of viewport status2 += Stringify(currlayer->view->x); status2 += " "; status2 += Stringify(currlayer->view->y); #endif }