Exemplo n.º 1
0
CMasternodeDB::ReadResult CMasternodeDB::Read(CMasternodeMan& mnodemanToLoad, bool fDryRun)
{
    int64_t nStart = GetTimeMillis();
    // open input file, and associate with CAutoFile
    FILE *file = fopen(pathMN.string().c_str(), "rb");
    CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
    if (filein.IsNull())
    {
        error("%s : Failed to open file %s", __func__, pathMN.string());
        return FileError;
    }

    // use file size to size memory buffer
    int fileSize = boost::filesystem::file_size(pathMN);
    int dataSize = fileSize - sizeof(uint256);
    // Don't try to resize to a negative number if file is small
    if (dataSize < 0)
        dataSize = 0;
    vector<unsigned char> vchData;
    vchData.resize(dataSize);
    uint256 hashIn;

    // read data and checksum from file
    try {
        filein.read((char *)&vchData[0], dataSize);
        filein >> hashIn;
    }
    catch (std::exception &e) {
        error("%s : Deserialize or I/O error - %s", __func__, e.what());
        return HashReadError;
    }
    filein.fclose();

    CDataStream ssMasternodes(vchData, SER_DISK, CLIENT_VERSION);

    // verify stored checksum matches input data
    uint256 hashTmp = Hash(ssMasternodes.begin(), ssMasternodes.end());
    if (hashIn != hashTmp)
    {
        error("%s : Checksum mismatch, data corrupted", __func__);
        return IncorrectHash;
    }

    unsigned char pchMsgTmp[4];
    std::string strMagicMessageTmp;
    try {
        // de-serialize file header (masternode cache file specific magic message) and ..

        ssMasternodes >> strMagicMessageTmp;

        // ... verify the message matches predefined one
        if (strMagicMessage != strMagicMessageTmp)
        {
            error("%s : Invalid masternode cache magic message", __func__);
            return IncorrectMagicMessage;
        }

        // de-serialize file header (network specific magic number) and ..
        ssMasternodes >> FLATDATA(pchMsgTmp);

        // ... verify the network matches ours
        if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
        {
            error("%s : Invalid network magic number", __func__);
            return IncorrectMagicNumber;
        }
        // de-serialize data into CMasternodeMan object
        ssMasternodes >> mnodemanToLoad;
    }
    catch (std::exception &e) {
        mnodemanToLoad.Clear();
        error("%s : Deserialize or I/O error - %s", __func__, e.what());
        return IncorrectFormat;
    }

    LogPrintf("Loaded info from mncache.dat  %dms\n", GetTimeMillis() - nStart);
    LogPrintf("  %s\n", mnodemanToLoad.ToString());
    if(!fDryRun) {
        LogPrintf("Masternode manager - cleaning....\n");
        mnodemanToLoad.CheckAndRemove(true);
        LogPrintf("Masternode manager - result:\n");
        LogPrintf("  %s\n", mnodemanToLoad.ToString());
    }

    return Ok;
}
Exemplo n.º 2
0
int ClientModel::getHashrate() const
{
    if (GetTimeMillis() - nHPSTimerStart > 8000)
        return (boost::int64_t)0;
    return (boost::int64_t)dHashesPerSec;
}
RPCMinerClient::RPCMinerClient():m_blockid(0),m_serverstatsurl(""),m_workrefreshms(4000),m_foundcount(0),m_hashraterefresh(30000),m_lasthashdisplay(0),m_done(true),m_running(false)
{
	m_startuptime=GetTimeMillis();
}
Exemplo n.º 4
0
void CUDARunner::FindBestConfiguration()
{
	unsigned long lowb=16;
	unsigned long highb=128;
	unsigned long lowt=16;
	unsigned long hight=256;
	unsigned long bestb=16;
	unsigned long bestt=16;
	int offset=0;
	void *ptr=0;
	int64 besttime=std::numeric_limits<int64>::max();

	if(m_requestedgrid>0 && m_requestedgrid<=65536)
	{
		lowb=m_requestedgrid;
		highb=m_requestedgrid;
	}

	if(m_requestedthreads>0 && m_requestedthreads<=65536)
	{
		lowt=m_requestedthreads;
		hight=m_requestedthreads;
	}

	for(int numb=lowb; numb<=highb; numb*=2)
	{
		for(int numt=lowt; numt<=hight; numt*=2)
		{
			if(AllocateResources(numb,numt)==true)
			{
				// clear out any existing error
				CUresult err=CUDA_SUCCESS;

				int64 st=GetTimeMillis();

				for(int it=0; it<128*256*2 && err==CUDA_SUCCESS; it+=(numb*numt))
				{

					cuMemcpyHtoD(m_devin,m_in,sizeof(cuda_in));

					offset=0;
					int loops=64;
					int bits=5;

					ptr=(void *)(size_t)m_devin;
					ALIGN_UP(offset, __alignof(ptr));
					cuParamSetv(m_function,offset,&ptr,sizeof(ptr));
					offset+=sizeof(ptr);

					ptr=(void *)(size_t)m_devout;
					ALIGN_UP(offset, __alignof(ptr));
					cuParamSetv(m_function,offset,&ptr,sizeof(ptr));
					offset+=sizeof(ptr);

					ALIGN_UP(offset, __alignof(loops));
					cuParamSeti(m_function,offset,loops);
					offset+=sizeof(loops);

					ALIGN_UP(offset, __alignof(bits));
					cuParamSeti(m_function,offset,bits);
					offset+=sizeof(bits);

					cuParamSetSize(m_function,offset);

					err=cuFuncSetBlockShape(m_function,numt,1,1);
					if(err!=CUDA_SUCCESS)
					{
						printf("cuFuncSetBlockShape error %d\n",err);
						continue;
					}

					err=cuLaunchGrid(m_function,numb,1);
					if(err!=CUDA_SUCCESS)
					{
						printf("cuLaunchGrid error %d\n",err);
						continue;
					}

					cuMemcpyDtoH(m_out,m_devout,numt*numb*sizeof(cuda_out));

					if(err!=CUDA_SUCCESS)
					{
						printf("CUDA error %d\n",err);
					}
				}

				int64 et=GetTimeMillis();

				printf("Finding best configuration step end (%d,%d) %"PRI64d"ms  prev best=%"PRI64d"ms\n",numb,numt,et-st,besttime);

				if((et-st)<besttime && err==CUDA_SUCCESS)
				{
					bestb=numb;
					bestt=numt;
					besttime=et-st;
				}
			}
		}
	}

	m_numb=bestb;
	m_numt=bestt;

	AllocateResources(m_numb,m_numt);

}
void RPCMinerClient::SendWorkRequest()
{
	json_spirit::Object obj;
	json_spirit::Array params;
	m_rpcreq.SetURL(m_url);
	m_rpcreq.SetUser(m_user);
	m_rpcreq.SetPassword(m_password);
	std::string res("");

	obj.push_back(json_spirit::Pair("method","getwork"));
	obj.push_back(json_spirit::Pair("params",params));
	obj.push_back(json_spirit::Pair("id",0));

	if(m_rpcreq.DoRequest(json_spirit::write(obj),res))
	{
		json_spirit::Value resobj;
		if(json_spirit::read(res,resobj))
		{
			if(resobj.type()==json_spirit::obj_type)
			{
				json_spirit::Value resval;
				resval=json_spirit::find_value(resobj.get_obj(),"result");

				if(resval.type()==json_spirit::obj_type)
				{
					uint256 target;
					std::vector<unsigned char> hash1;
					std::vector<unsigned char> block;
					std::vector<unsigned char> midstate;
					m_blockid++;
					
					json_spirit::Value val;

					val=json_spirit::find_value(resval.get_obj(),"hash1");
					if(val.type()==json_spirit::str_type)
					{
						Hex::Decode(val.get_str(),hash1);
					}
					val=json_spirit::find_value(resval.get_obj(),"data");
					if(val.type()==json_spirit::str_type)
					{
						Hex::Decode(val.get_str(),block);

						m_blocklookup[m_blockid].first=GetTimeMillis();
						m_blocklookup[m_blockid].second=block;

						if(block.size()>64)
						{
							block.erase(block.begin(),block.begin()+64);
						}
					}
					val=json_spirit::find_value(resval.get_obj(),"midstate");
					if(val.type()==json_spirit::str_type)
					{
						Hex::Decode(val.get_str(),midstate);
					}
					val=json_spirit::find_value(resval.get_obj(),"target");
					if(val.type()==json_spirit::str_type)
					{
						target.SetHex(val.get_str());
					}

					m_minerthreads.SetNextBlock(m_blockid,target,block,midstate,hash1);

					if(target!=m_lasttarget)
					{
						std::cout << "Target = " << Hex::Reverse(target.ToString()) << std::endl;
						m_lasttarget=target;
					}

				}
			}
		}
	}
	else
	{
		std::cout << "Could not retrieve work from RPC server." << std::endl;
		std::cout << "CURL return value = " << m_rpcreq.GetLastCurlReturn() << std::endl;
	}
}
void RPCMinerClient::Run(const std::string &url, const std::string &user, const std::string &password, const int threadcount)
{
	m_running=true;
	m_done=false;
	m_url=url;
	m_user=user;
	m_password=password;
	m_threadcount=threadcount;
	int64 lastrequestedwork=GetTimeMillis()-5000;
	int64 laststats=GetTimeMillis()-25000;
	m_lasttarget=0;
	m_lasthashdisplay=GetTimeMillis();
	int64 timenowmillis;
	static unsigned int counter=0u;

	std::cout << "Client will start " << m_threadcount << " miner threads" << std::endl;
	std::cout << "Work will be refreshed every " << m_workrefreshms << " ms" << std::endl;

	while(Done()==false)
	{
		if(m_minerthreads.RunningThreadCount()<m_threadcount)
		{
			m_minerthreads.Start(new threadtype);
		}

	/*	if(lastrequestedwork<=GetTimeMillis()-m_workrefreshms)
		{
			SendWorkRequest();
			lastrequestedwork=GetTimeMillis();
		}
	*/

		if(m_serverstatsurl!="" && laststats<=GetTimeMillis()-60000)
		{
			json_spirit::Object statsobj;
			if(GetServerStats(statsobj))
			{
				PrintServerStats(statsobj);
			}
			laststats=GetTimeMillis();
		}

		if(m_minerthreads.HaveFoundHash())
		{
			std::cout << GetTimeStr(time(0)) << " Found Hash!" << std::endl;
			RPCMinerThread::foundhash fhash;
			m_minerthreads.GetFoundHash(fhash);
			++counter;
			std::cout<<"Hashs found: "<<counter<<std::endl;
			SendFoundHash(fhash.m_blockid,fhash.m_nonce);
			SendWorkRequest();
			lastrequestedwork=GetTimeMillis();
		}
                CleanupOldBlocks();
		
                if(lastrequestedwork<=GetTimeMillis()-m_workrefreshms)
                {
                        SendWorkRequest();
                        lastrequestedwork=GetTimeMillis();
                }

		
		
		timenowmillis=GetTimeMillis();
		if(m_hashraterefresh>0 && (m_lasthashdisplay+m_hashraterefresh)<=timenowmillis)
		{
			int64 hr=GetHashRate(true);
			if(m_blocklookup.size()>0)
			{
				std::cout << hr << " khash/s" << std::endl;
			}
			else
			{
				if(m_startuptime+30000<timenowmillis)
				{
					std::cout << "No blocks are being hashed right now.  This can happen if the application is" << std::endl;
					std::cout << "still starting up, you supplied incorrect parameters, or there is a" << std::endl;
					std::cout << "communications error connecting to the RPC server." << std::endl;
					m_minerthreads.ClearWork();
				}
			}
			
		}

		Sleep(10);
	}

	m_running=false;

}
Exemplo n.º 7
0
unsigned int StartTimer () {
   return GetTimeMillis();
}
Exemplo n.º 8
0
void CUDARunner::FindBestConfiguration()
{
	unsigned long lowb=16;
	unsigned long highb=128;
	unsigned long lowt=16;
	unsigned long hight=256;
	unsigned long bestb=16;
	unsigned long bestt=16;
	int64 besttime=std::numeric_limits<int64>::max();

	if(m_requestedgrid>0 && m_requestedgrid<=65536)
	{
		lowb=m_requestedgrid;
		highb=m_requestedgrid;
	}

	if(m_requestedthreads>0 && m_requestedthreads<=65536)
	{
		lowt=m_requestedthreads;
		hight=m_requestedthreads;
	}

	for(int numb=lowb; numb<=highb; numb*=2)
	{
		for(int numt=lowt; numt<=hight; numt*=2)
		{
			AllocateResources(numb,numt);
			// clear out any existing error
			cudaError_t err=cudaGetLastError();
			err=cudaSuccess;

			int64 st=GetTimeMillis();

			for(int it=0; it<128*256*2 && err==0; it+=(numb*numt))
			{
				cutilSafeCall(cudaMemcpy(m_devin,m_in,sizeof(cuda_in),cudaMemcpyHostToDevice));

				cuda_process_helper(m_devin,m_devout,64,6,numb,numt);

				cutilSafeCall(cudaMemcpy(m_out,m_devout,numb*numt*sizeof(cuda_out),cudaMemcpyDeviceToHost));

				err=cudaGetLastError();
				if(err!=cudaSuccess)
				{
					printf("CUDA error %d\n",err);
				}
			}

			int64 et=GetTimeMillis();

			printf("Finding best configuration step end (%d,%d) %"PRI64d"ms  prev best=%"PRI64d"ms\n",numb,numt,et-st,besttime);

			if((et-st)<besttime && err==cudaSuccess)
			{
				bestb=numb;
				bestt=numt;
				besttime=et-st;
			}
		}
	}

	m_numb=bestb;
	m_numt=bestt;

	AllocateResources(m_numb,m_numt);

}
Exemplo n.º 9
0
int main(int argc, char ** argv)
{
  TsvReader myReader;
  
  /* Read the graph from a file */
  AdjacencyList * list;
  
  
  m_animation = Animation::Read("bin/animation/real.anim");
  
  
  
  if(pre_defined_graph)
  {
    std::cout << "Animation Read... Reading Graph" << std::endl;
    if( argc == 1 )
      list = myReader.readGraph("datasets/marvel_social_2.tsv");
    else
      list = myReader.readGraph(std::string(argv[1]));

    std::cout << "Graph Read... Converting Graph" << std::endl;

    /* Convert the graph */
    m_graph = GraphFactory::createGraph(list);
    std::cout << "Graph Converted... Initialising Layout" << std::endl;
  }
  else
  {
    bool m_blah = true;
    if(m_blah)
    {
      std::cout << "BLAH" << std::endl;
      list = myReader.readGraph("bin/animation/edges");
      std::cout << "BLAH" << std::endl;
      m_graph = GraphFactory::createGraph(list);
      std::cout << "BLAH" << std::endl;
    }
    else
    {
      m_graph = new Graph();
      m_graph->m_size = 100;
    }
    std::cout << "Animation Read... Initialising Layout" << std::endl;
  }
  
  m_state = GraphLayout::generateLayout(m_graph, 0.5f);
  std::cout << "Layout Initialised... Initialising OpenGL" << std::endl;
  
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);   // Set the initial Window's width and height
  glutInitWindowPosition(50, 50); // Position the initial Window's top-left corner
  glutCreateWindow("Meatballs, Spaghetti and Cheese Sauce");  // Create window with the given title
  glutDisplayFunc(Display); 
  glutReshapeFunc(Reshape);
  
  glEnable(GL_DEPTH_TEST);
  glClearColor(0.0, 0.0, 0.0, 1.0);
  Camera::get()->init();
  glPointSize(10.0f);
  
  
  glutCreateMenu(Menu);
  glutAddMenuEntry("Toggle Edges", 1);
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  /* */
  std::cout << "OpenGL Initialised... Starting Simulation" << std::endl;
  
  m_last_update = GetTimeMillis();
  
  glutMainLoop();
  
  return 0;
}