Test
This commit is contained in:
@@ -876,7 +876,8 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t bloc
|
||||
fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]);
|
||||
if ( height > 807000 )
|
||||
return(-2);
|
||||
} else return(1);
|
||||
}
|
||||
return(1);
|
||||
} else return(0);
|
||||
}
|
||||
else
|
||||
|
||||
467
src/miner.cpp
467
src/miner.cpp
@@ -207,12 +207,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
const CTransaction& tx = mi->GetTx();
|
||||
|
||||
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
||||
? nMedianTimePast
|
||||
: pblock->GetBlockTime();
|
||||
? nMedianTimePast
|
||||
: pblock->GetBlockTime();
|
||||
|
||||
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
|
||||
continue;
|
||||
if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 )
|
||||
if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 )
|
||||
{
|
||||
fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n");
|
||||
continue;
|
||||
@@ -401,16 +401,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked));
|
||||
nFees += txfees;
|
||||
pblock->nTime = blocktime;
|
||||
if ( GetAdjustedTime()+30 < pblock->nTime )
|
||||
if ( GetAdjustedTime() < pblock->nTime )
|
||||
{
|
||||
//printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime()));
|
||||
/*while ( GetAdjustedTime()+30 < pblock->nTime )
|
||||
printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime()));
|
||||
while ( GetAdjustedTime()+30 < pblock->nTime )
|
||||
{
|
||||
sleep(30);
|
||||
fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime()));
|
||||
}*/
|
||||
//fprintf(stderr,"finished waiting\n");
|
||||
sleep(30);
|
||||
}
|
||||
fprintf(stderr,"finished waiting\n");
|
||||
//sleep(pblock->nTime - GetAdjustedTime());
|
||||
}
|
||||
|
||||
} else fprintf(stderr,"no utxos eligible for staking\n");
|
||||
@@ -430,28 +430,28 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
|
||||
/*if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
{
|
||||
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
||||
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
|
||||
{
|
||||
if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed
|
||||
{
|
||||
txNew.vout.resize(2);
|
||||
txNew.vout[1].scriptPubKey.resize(opretlen);
|
||||
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
||||
for (i=0; i<opretlen; i++)
|
||||
ptr[i] = opret[i];
|
||||
txNew.vout[1].nValue = 0;
|
||||
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
||||
} //else printf("null opretlen for prices\n");
|
||||
}
|
||||
}
|
||||
else if ( komodo_is_issuer() != 0 )
|
||||
{
|
||||
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
|
||||
if ( txNew.vout.size() > 1 )
|
||||
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
|
||||
}*/
|
||||
{
|
||||
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
||||
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
|
||||
{
|
||||
if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed
|
||||
{
|
||||
txNew.vout.resize(2);
|
||||
txNew.vout[1].scriptPubKey.resize(opretlen);
|
||||
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
||||
for (i=0; i<opretlen; i++)
|
||||
ptr[i] = opret[i];
|
||||
txNew.vout[1].nValue = 0;
|
||||
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
||||
} //else printf("null opretlen for prices\n");
|
||||
}
|
||||
}
|
||||
else if ( komodo_is_issuer() != 0 )
|
||||
{
|
||||
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
|
||||
if ( txNew.vout.size() > 1 )
|
||||
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
|
||||
}*/
|
||||
|
||||
pblock->vtx[0] = txNew;
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 )
|
||||
@@ -484,6 +484,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
||||
}
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 )
|
||||
pblock->nTime = pindexPrev->nTime + 60;
|
||||
pblock->nSolution.clear();
|
||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||
|
||||
@@ -492,7 +494,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
{
|
||||
static uint32_t counter;
|
||||
//if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
|
||||
fprintf(stderr,"warning: miner testblockvalidity failed\n");
|
||||
fprintf(stderr,"warning: miner testblockvalidity failed\n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
@@ -501,47 +503,47 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
}
|
||||
|
||||
/*
|
||||
#ifdef ENABLE_WALLET
|
||||
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
||||
#else
|
||||
boost::optional<CScript> GetMinerScriptPubKey()
|
||||
#endif
|
||||
{
|
||||
CKeyID keyID;
|
||||
CBitcoinAddress addr;
|
||||
if (addr.SetString(GetArg("-mineraddress", ""))) {
|
||||
addr.GetKeyID(keyID);
|
||||
} else {
|
||||
#ifdef ENABLE_WALLET
|
||||
CPubKey pubkey;
|
||||
if (!reservekey.GetReservedKey(pubkey)) {
|
||||
return boost::optional<CScript>();
|
||||
}
|
||||
keyID = pubkey.GetID();
|
||||
#else
|
||||
return boost::optional<CScript>();
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
||||
#else
|
||||
boost::optional<CScript> GetMinerScriptPubKey()
|
||||
#endif
|
||||
{
|
||||
CKeyID keyID;
|
||||
CBitcoinAddress addr;
|
||||
if (addr.SetString(GetArg("-mineraddress", ""))) {
|
||||
addr.GetKeyID(keyID);
|
||||
} else {
|
||||
#ifdef ENABLE_WALLET
|
||||
CPubKey pubkey;
|
||||
if (!reservekey.GetReservedKey(pubkey)) {
|
||||
return boost::optional<CScript>();
|
||||
}
|
||||
keyID = pubkey.GetID();
|
||||
#else
|
||||
return boost::optional<CScript>();
|
||||
#endif
|
||||
}
|
||||
|
||||
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
return scriptPubKey;
|
||||
}
|
||||
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
return scriptPubKey;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||
{
|
||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey(reservekey);
|
||||
#else
|
||||
CBlockTemplate* CreateNewBlockWithKey()
|
||||
{
|
||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
||||
#endif
|
||||
#ifdef ENABLE_WALLET
|
||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||
{
|
||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey(reservekey);
|
||||
#else
|
||||
CBlockTemplate* CreateNewBlockWithKey()
|
||||
{
|
||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
||||
#endif
|
||||
|
||||
if (!scriptPubKey) {
|
||||
return NULL;
|
||||
}
|
||||
return CreateNewBlock(*scriptPubKey);
|
||||
}*/
|
||||
if (!scriptPubKey) {
|
||||
return NULL;
|
||||
}
|
||||
return CreateNewBlock(*scriptPubKey);
|
||||
}*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -657,7 +659,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
}
|
||||
|
||||
int32_t komodo_baseid(char *origbase);
|
||||
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height);
|
||||
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t *blocktimes,int32_t *nonzpkeysp,int32_t height);
|
||||
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc);
|
||||
int32_t FOUND_BLOCK,KOMODO_MAYBEMINED;
|
||||
extern int32_t KOMODO_LASTMINED;
|
||||
@@ -692,12 +694,11 @@ void static BitcoinMiner()
|
||||
if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 )
|
||||
break;
|
||||
}
|
||||
//sleep(60);
|
||||
komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime());
|
||||
|
||||
std::string solver;
|
||||
//if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
solver = "tromp";
|
||||
solver = "tromp";
|
||||
//else solver = "default";
|
||||
assert(solver == "tromp" || solver == "default");
|
||||
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
||||
@@ -706,11 +707,11 @@ void static BitcoinMiner()
|
||||
std::mutex m_cs;
|
||||
bool cancelSolver = false;
|
||||
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
||||
[&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = true;
|
||||
}
|
||||
);
|
||||
[&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = true;
|
||||
}
|
||||
);
|
||||
miningTimer.start();
|
||||
|
||||
try {
|
||||
@@ -741,10 +742,10 @@ void static BitcoinMiner()
|
||||
miningTimer.start();
|
||||
}
|
||||
/*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT )
|
||||
{
|
||||
fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight);
|
||||
sleep(3);
|
||||
}*/
|
||||
{
|
||||
fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight);
|
||||
sleep(3);
|
||||
}*/
|
||||
//
|
||||
// Create new block
|
||||
//
|
||||
@@ -877,11 +878,11 @@ void static BitcoinMiner()
|
||||
while (true)
|
||||
{
|
||||
/*if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt
|
||||
{
|
||||
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
||||
sleep(10);
|
||||
break;
|
||||
}*/
|
||||
{
|
||||
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
||||
sleep(10);
|
||||
break;
|
||||
}*/
|
||||
// Hash state
|
||||
KOMODO_CHOSEN_ONE = 0;
|
||||
crypto_generichash_blake2b_state state;
|
||||
@@ -902,11 +903,11 @@ void static BitcoinMiner()
|
||||
//fprintf(stderr,"running solver\n");
|
||||
std::function<bool(std::vector<unsigned char>)> validBlock =
|
||||
#ifdef ENABLE_WALLET
|
||||
[&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
|
||||
[&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
|
||||
#else
|
||||
[&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams]
|
||||
[&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams]
|
||||
#endif
|
||||
(std::vector<unsigned char> soln) {
|
||||
(std::vector<unsigned char> soln) {
|
||||
// Write the solution to the hash and compute the result.
|
||||
LogPrint("pow", "- Checking solution against target\n");
|
||||
pblock->nSolution = soln;
|
||||
@@ -962,178 +963,178 @@ void static BitcoinMiner()
|
||||
#ifdef ENABLE_WALLET
|
||||
if (ProcessBlockFound(pblock, *pwallet, reservekey)) {
|
||||
#else
|
||||
if (ProcessBlockFound(pblock)) {
|
||||
if (ProcessBlockFound(pblock)) {
|
||||
#endif
|
||||
// Ignore chain updates caused by us
|
||||
// Ignore chain updates caused by us
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = false;
|
||||
}
|
||||
KOMODO_CHOSEN_ONE = 0;
|
||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||
// In regression test mode, stop mining after a block is found.
|
||||
if (chainparams.MineBlocksOnDemand()) {
|
||||
// Increment here because throwing skips the call below
|
||||
ehSolverRuns.increment();
|
||||
throw boost::thread_interrupted();
|
||||
}
|
||||
//if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
|
||||
// sleep(1800);
|
||||
return true;
|
||||
};
|
||||
std::function<bool(EhSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) {
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = false;
|
||||
}
|
||||
KOMODO_CHOSEN_ONE = 0;
|
||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||
// In regression test mode, stop mining after a block is found.
|
||||
if (chainparams.MineBlocksOnDemand()) {
|
||||
// Increment here because throwing skips the call below
|
||||
ehSolverRuns.increment();
|
||||
throw boost::thread_interrupted();
|
||||
}
|
||||
//if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
|
||||
// sleep(1800);
|
||||
return true;
|
||||
};
|
||||
std::function<bool(EhSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) {
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
return cancelSolver;
|
||||
};
|
||||
return cancelSolver;
|
||||
};
|
||||
|
||||
// TODO: factor this out into a function with the same API for each solver.
|
||||
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
||||
// Create solver and initialize it.
|
||||
equi eq(1);
|
||||
eq.setstate(&curr_state);
|
||||
// TODO: factor this out into a function with the same API for each solver.
|
||||
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
||||
// Create solver and initialize it.
|
||||
equi eq(1);
|
||||
eq.setstate(&curr_state);
|
||||
|
||||
// Initialization done, start algo driver.
|
||||
eq.digit0(0);
|
||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||
eq.showbsizes(0);
|
||||
for (u32 r = 1; r < WK; r++) {
|
||||
(r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0);
|
||||
// Initialization done, start algo driver.
|
||||
eq.digit0(0);
|
||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||
eq.showbsizes(r);
|
||||
}
|
||||
eq.digitK(0);
|
||||
ehSolverRuns.increment();
|
||||
|
||||
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||
for (size_t s = 0; s < eq.nsols; s++) {
|
||||
LogPrint("pow", "Checking solution %d\n", s+1);
|
||||
std::vector<eh_index> index_vector(PROOFSIZE);
|
||||
for (size_t i = 0; i < PROOFSIZE; i++) {
|
||||
index_vector[i] = eq.sols[s][i];
|
||||
eq.showbsizes(0);
|
||||
for (u32 r = 1; r < WK; r++) {
|
||||
(r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0);
|
||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||
eq.showbsizes(r);
|
||||
}
|
||||
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
||||
|
||||
if (validBlock(sol_char)) {
|
||||
// If we find a POW solution, do not try other solutions
|
||||
// because they become invalid as we created a new block in blockchain.
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
// If we find a valid block, we rebuild
|
||||
bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
|
||||
eq.digitK(0);
|
||||
ehSolverRuns.increment();
|
||||
if (found) {
|
||||
int32_t i; uint256 hash = pblock->GetHash();
|
||||
for (i=0; i<32; i++)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
||||
FOUND_BLOCK = 1;
|
||||
KOMODO_MAYBEMINED = Mining_height;
|
||||
|
||||
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||
for (size_t s = 0; s < eq.nsols; s++) {
|
||||
LogPrint("pow", "Checking solution %d\n", s+1);
|
||||
std::vector<eh_index> index_vector(PROOFSIZE);
|
||||
for (size_t i = 0; i < PROOFSIZE; i++) {
|
||||
index_vector[i] = eq.sols[s][i];
|
||||
}
|
||||
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
||||
|
||||
if (validBlock(sol_char)) {
|
||||
// If we find a POW solution, do not try other solutions
|
||||
// because they become invalid as we created a new block in blockchain.
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
// If we find a valid block, we rebuild
|
||||
bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
|
||||
ehSolverRuns.increment();
|
||||
if (found) {
|
||||
int32_t i; uint256 hash = pblock->GetHash();
|
||||
for (i=0; i<32; i++)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
||||
FOUND_BLOCK = 1;
|
||||
KOMODO_MAYBEMINED = Mining_height;
|
||||
break;
|
||||
}
|
||||
} catch (EhSolverCancelledException&) {
|
||||
LogPrint("pow", "Equihash solver cancelled\n");
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for stop or if block needs to be rebuilt
|
||||
boost::this_thread::interruption_point();
|
||||
// Regtest mode doesn't require peers
|
||||
if ( FOUND_BLOCK != 0 )
|
||||
{
|
||||
FOUND_BLOCK = 0;
|
||||
fprintf(stderr,"FOUND_BLOCK!\n");
|
||||
//sleep(2000);
|
||||
}
|
||||
if (vNodes.empty() && chainparams.MiningRequiresPeers())
|
||||
{
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
{
|
||||
fprintf(stderr,"no nodes, break\n");
|
||||
break;
|
||||
}
|
||||
} catch (EhSolverCancelledException&) {
|
||||
LogPrint("pow", "Equihash solver cancelled\n");
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for stop or if block needs to be rebuilt
|
||||
boost::this_thread::interruption_point();
|
||||
// Regtest mode doesn't require peers
|
||||
if ( FOUND_BLOCK != 0 )
|
||||
{
|
||||
FOUND_BLOCK = 0;
|
||||
fprintf(stderr,"FOUND_BLOCK!\n");
|
||||
//sleep(2000);
|
||||
}
|
||||
if (vNodes.empty() && chainparams.MiningRequiresPeers())
|
||||
{
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
||||
{
|
||||
fprintf(stderr,"no nodes, break\n");
|
||||
//if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"0xffff, break\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
||||
{
|
||||
//if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"0xffff, break\n");
|
||||
break;
|
||||
}
|
||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
||||
{
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"timeout, break\n");
|
||||
break;
|
||||
}
|
||||
if ( pindexPrev != chainActive.Tip() )
|
||||
{
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"Tip advanced, break\n");
|
||||
break;
|
||||
}
|
||||
// Update nNonce and nTime
|
||||
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
||||
pblock->nBits = savebits;
|
||||
if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
|
||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
||||
{
|
||||
// Changing pblock->nTime can change work required on testnet:
|
||||
HASHTarget.SetCompact(pblock->nBits);
|
||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
||||
{
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"timeout, break\n");
|
||||
break;
|
||||
}
|
||||
if ( pindexPrev != chainActive.Tip() )
|
||||
{
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"Tip advanced, break\n");
|
||||
break;
|
||||
}
|
||||
// Update nNonce and nTime
|
||||
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
||||
pblock->nBits = savebits;
|
||||
if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
|
||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
||||
{
|
||||
// Changing pblock->nTime can change work required on testnet:
|
||||
HASHTarget.SetCompact(pblock->nBits);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const boost::thread_interrupted&)
|
||||
{
|
||||
catch (const boost::thread_interrupted&)
|
||||
{
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
LogPrintf("KomodoMiner terminated\n");
|
||||
throw;
|
||||
}
|
||||
catch (const std::runtime_error &e)
|
||||
{
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
LogPrintf("KomodoMiner runtime error: %s\n", e.what());
|
||||
return;
|
||||
}
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
LogPrintf("KomodoMiner terminated\n");
|
||||
throw;
|
||||
}
|
||||
catch (const std::runtime_error &e)
|
||||
{
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
LogPrintf("KomodoMiner runtime error: %s\n", e.what());
|
||||
return;
|
||||
}
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
||||
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
||||
#else
|
||||
void GenerateBitcoins(bool fGenerate, int nThreads)
|
||||
void GenerateBitcoins(bool fGenerate, int nThreads)
|
||||
#endif
|
||||
{
|
||||
static boost::thread_group* minerThreads = NULL;
|
||||
|
||||
if (nThreads < 0)
|
||||
nThreads = GetNumCores();
|
||||
|
||||
if (minerThreads != NULL)
|
||||
{
|
||||
minerThreads->interrupt_all();
|
||||
delete minerThreads;
|
||||
minerThreads = NULL;
|
||||
}
|
||||
static boost::thread_group* minerThreads = NULL;
|
||||
|
||||
if (nThreads == 0 || !fGenerate)
|
||||
return;
|
||||
if (nThreads < 0)
|
||||
nThreads = GetNumCores();
|
||||
|
||||
minerThreads = new boost::thread_group();
|
||||
for (int i = 0; i < nThreads; i++) {
|
||||
if (minerThreads != NULL)
|
||||
{
|
||||
minerThreads->interrupt_all();
|
||||
delete minerThreads;
|
||||
minerThreads = NULL;
|
||||
}
|
||||
|
||||
if (nThreads == 0 || !fGenerate)
|
||||
return;
|
||||
|
||||
minerThreads = new boost::thread_group();
|
||||
for (int i = 0; i < nThreads; i++) {
|
||||
#ifdef ENABLE_WALLET
|
||||
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
|
||||
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
|
||||
#else
|
||||
minerThreads->create_thread(&BitcoinMiner);
|
||||
minerThreads->create_thread(&BitcoinMiner);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ENABLE_MINING
|
||||
|
||||
Reference in New Issue
Block a user