Merge branch 'libscottFIX' into fixgettransactioncrash
This commit is contained in:
159
src/miner.cpp
159
src/miner.cpp
@@ -64,7 +64,7 @@ public:
|
||||
set<uint256> setDependsOn;
|
||||
CFeeRate feeRate;
|
||||
double dPriority;
|
||||
|
||||
|
||||
COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0)
|
||||
{
|
||||
}
|
||||
@@ -78,10 +78,10 @@ typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority;
|
||||
class TxPriorityCompare
|
||||
{
|
||||
bool byFee;
|
||||
|
||||
|
||||
public:
|
||||
TxPriorityCompare(bool _byFee) : byFee(_byFee) { }
|
||||
|
||||
|
||||
bool operator()(const TxPriority& a, const TxPriority& b)
|
||||
{
|
||||
if (byFee)
|
||||
@@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
|
||||
|
||||
#include "komodo_defs.h"
|
||||
|
||||
extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE;
|
||||
extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE;
|
||||
extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED;
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY;
|
||||
@@ -141,27 +141,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
// -blockversion=N to test forking scenarios
|
||||
if (Params().MineBlocksOnDemand())
|
||||
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
|
||||
|
||||
|
||||
// Add dummy coinbase tx as first transaction
|
||||
pblock->vtx.push_back(CTransaction());
|
||||
pblocktemplate->vTxFees.push_back(-1); // updated at end
|
||||
pblocktemplate->vTxSigOps.push_back(-1); // updated at end
|
||||
|
||||
|
||||
// Largest block you're willing to create:
|
||||
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
|
||||
// Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
|
||||
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize));
|
||||
|
||||
|
||||
// How much of the block should be dedicated to high-priority transactions,
|
||||
// included regardless of the fees they pay
|
||||
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
|
||||
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
|
||||
|
||||
|
||||
// Minimum block size you want to create; block will be filled with free transactions
|
||||
// until there are no more or the block reaches this size:
|
||||
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
|
||||
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
|
||||
|
||||
|
||||
// Collect memory pool transactions into the block
|
||||
CAmount nFees = 0;
|
||||
CBlockIndex* pindexPrev = 0;
|
||||
@@ -174,12 +174,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
||||
CCoinsViewCache view(pcoinsTip);
|
||||
uint32_t expired; uint64_t commission;
|
||||
|
||||
|
||||
// Priority order to process transactions
|
||||
list<COrphan> vOrphan; // list memory doesn't move
|
||||
map<uint256, vector<COrphan*> > mapDependers;
|
||||
bool fPrintPriority = GetBoolArg("-printpriority", false);
|
||||
|
||||
|
||||
// This vector will be sorted into a priority queue:
|
||||
vector<TxPriority> vecPriority;
|
||||
vecPriority.reserve(mempool.mapTx.size());
|
||||
@@ -187,11 +187,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
mi != mempool.mapTx.end(); ++mi)
|
||||
{
|
||||
const CTransaction& tx = mi->GetTx();
|
||||
|
||||
|
||||
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
||||
? nMedianTimePast
|
||||
: pblock->GetBlockTime();
|
||||
|
||||
|
||||
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
|
||||
{
|
||||
//fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight));
|
||||
@@ -256,16 +256,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
}
|
||||
|
||||
if (fMissingInputs) continue;
|
||||
|
||||
|
||||
// Priority is sum(valuein * age) / modified_txsize
|
||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||
dPriority = tx.ComputePriority(dPriority, nTxSize);
|
||||
|
||||
|
||||
uint256 hash = tx.GetHash();
|
||||
mempool.ApplyDeltas(hash, dPriority, nTotalIn);
|
||||
|
||||
|
||||
CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
|
||||
|
||||
|
||||
if (porphan)
|
||||
{
|
||||
porphan->dPriority = dPriority;
|
||||
@@ -274,27 +274,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
else
|
||||
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
|
||||
}
|
||||
|
||||
|
||||
// Collect transactions into block
|
||||
uint64_t nBlockSize = 1000;
|
||||
uint64_t nBlockTx = 0;
|
||||
int64_t interest;
|
||||
int nBlockSigOps = 100;
|
||||
bool fSortedByFee = (nBlockPrioritySize <= 0);
|
||||
|
||||
|
||||
TxPriorityCompare comparer(fSortedByFee);
|
||||
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||
|
||||
|
||||
while (!vecPriority.empty())
|
||||
{
|
||||
// Take highest priority transaction off the priority queue:
|
||||
double dPriority = vecPriority.front().get<0>();
|
||||
CFeeRate feeRate = vecPriority.front().get<1>();
|
||||
const CTransaction& tx = *(vecPriority.front().get<2>());
|
||||
|
||||
|
||||
std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||
vecPriority.pop_back();
|
||||
|
||||
|
||||
// Size limits
|
||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||
if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx
|
||||
@@ -302,7 +302,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
//fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Legacy limits on sigOps:
|
||||
unsigned int nTxSigOps = GetLegacySigOpCount(tx);
|
||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||
@@ -329,7 +329,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
comparer = TxPriorityCompare(fSortedByFee);
|
||||
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||
}
|
||||
|
||||
|
||||
if (!view.HaveInputs(tx))
|
||||
{
|
||||
//fprintf(stderr,"dont have inputs\n");
|
||||
@@ -345,7 +345,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
}
|
||||
}
|
||||
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut();
|
||||
|
||||
|
||||
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||
{
|
||||
@@ -363,7 +363,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
continue;
|
||||
}
|
||||
UpdateCoins(tx, view, nHeight);
|
||||
|
||||
|
||||
// Added
|
||||
pblock->vtx.push_back(tx);
|
||||
pblocktemplate->vTxFees.push_back(nTxFees);
|
||||
@@ -372,12 +372,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
++nBlockTx;
|
||||
nBlockSigOps += nTxSigOps;
|
||||
nFees += nTxFees;
|
||||
|
||||
|
||||
if (fPrintPriority)
|
||||
{
|
||||
LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString());
|
||||
}
|
||||
|
||||
|
||||
// Add transactions that depend on this one to the priority queue
|
||||
if (mapDependers.count(hash))
|
||||
{
|
||||
@@ -395,7 +395,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nLastBlockTx = nBlockTx;
|
||||
nLastBlockSize = nBlockSize;
|
||||
blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
||||
@@ -420,7 +420,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
//printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13)));
|
||||
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
|
||||
}
|
||||
|
||||
|
||||
// Create coinbase tx
|
||||
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight);
|
||||
txNew.vin.resize(1);
|
||||
@@ -435,9 +435,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
// Add fees
|
||||
txNew.vout[0].nValue += nFees;
|
||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
|
||||
|
||||
pblock->vtx[0] = txNew;
|
||||
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 )
|
||||
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 )
|
||||
{
|
||||
int32_t i; uint8_t *ptr;
|
||||
txNew.vout.resize(2);
|
||||
@@ -448,7 +448,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
for (i=0; i<33; i++)
|
||||
ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i];
|
||||
ptr[34] = OP_CHECKSIG;
|
||||
//printf("autocreate commision vout\n");
|
||||
//printf("autocreate commission vout\n");
|
||||
pblock->vtx[0] = txNew;
|
||||
}
|
||||
pblocktemplate->vTxFees[0] = -nFees;
|
||||
@@ -458,7 +458,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
nonce <<= 32;
|
||||
nonce >>= 16;
|
||||
pblock->nNonce = ArithToUint256(nonce);
|
||||
|
||||
|
||||
// Fill in header
|
||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
||||
pblock->hashReserved = uint256();
|
||||
@@ -502,6 +502,26 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_SYMBOL[0] != 0 && nHeight > 128 )
|
||||
{
|
||||
CMutableTransaction txStream = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
|
||||
if ( komodo_notaryvin(txStream,ASSETCHAINS_OVERRIDE_PUBKEY33) > 0 )
|
||||
{
|
||||
CAmount txfees = 10000;
|
||||
pblock->vtx.push_back(txStream);
|
||||
pblocktemplate->vTxFees.push_back(txfees);
|
||||
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStream));
|
||||
nFees += txfees;
|
||||
pblocktemplate->vTxFees[0] = -nFees;
|
||||
//*(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees;
|
||||
//fprintf(stderr,"added notaryvin\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"error adding streamer vin, the chain broke! \n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) )
|
||||
{
|
||||
CValidationState state;
|
||||
@@ -536,7 +556,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
|
||||
return pblocktemplate.release();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#ifdef ENABLE_WALLET
|
||||
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
||||
@@ -559,11 +579,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
return boost::optional<CScript>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
return scriptPubKey;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||
{
|
||||
@@ -573,7 +593,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
{
|
||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
||||
#endif
|
||||
|
||||
|
||||
if (!scriptPubKey) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -601,7 +621,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
||||
CMutableTransaction txCoinbase(pblock->vtx[0]);
|
||||
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
|
||||
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
||||
|
||||
|
||||
pblock->vtx[0] = txCoinbase;
|
||||
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
|
||||
}
|
||||
@@ -619,12 +639,18 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in
|
||||
{
|
||||
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
|
||||
}
|
||||
else if ( ASSETCHAINS_STREAM != 0 )
|
||||
{
|
||||
if ( nHeight < 128 )
|
||||
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
|
||||
else
|
||||
scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG;
|
||||
}
|
||||
else if ( USE_EXTERNAL_PUBKEY != 0 )
|
||||
{
|
||||
//fprintf(stderr,"use notary pubkey\n");
|
||||
scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
if (!reservekey.GetReservedKey(pubkey))
|
||||
{
|
||||
@@ -670,7 +696,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
{
|
||||
LogPrintf("%s\n", pblock->ToString());
|
||||
LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->nHeight+1);
|
||||
|
||||
|
||||
// Found a solution
|
||||
{
|
||||
//LOCK(cs_main);
|
||||
@@ -685,11 +711,11 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
for (i=31; i>=0; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- chainTip (stale)\n");
|
||||
|
||||
|
||||
return error("KomodoMiner: generated block is stale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
// Remove key from key pool
|
||||
if ( IS_KOMODO_NOTARY == 0 )
|
||||
@@ -713,7 +739,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||
return error("KomodoMiner: ProcessNewBlock, block not accepted");
|
||||
|
||||
|
||||
TrackMinedBlock(pblock->GetHash());
|
||||
komodo_broadcast(pblock,16);
|
||||
return true;
|
||||
@@ -737,15 +763,15 @@ void static BitcoinMiner()
|
||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||
RenameThread("komodo-miner");
|
||||
const CChainParams& chainparams = Params();
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
// Each thread has its own key
|
||||
CReserveKey reservekey(pwallet);
|
||||
#endif
|
||||
|
||||
|
||||
// Each thread has its own counter
|
||||
unsigned int nExtraNonce = 0;
|
||||
|
||||
|
||||
unsigned int n = chainparams.EquihashN();
|
||||
unsigned int k = chainparams.EquihashK();
|
||||
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
|
||||
@@ -776,7 +802,7 @@ void static BitcoinMiner()
|
||||
}
|
||||
);
|
||||
miningTimer.start();
|
||||
|
||||
|
||||
try {
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str());
|
||||
@@ -799,7 +825,7 @@ void static BitcoinMiner()
|
||||
break;
|
||||
MilliSleep(15000);
|
||||
//fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload());
|
||||
|
||||
|
||||
} while (true);
|
||||
//fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL);
|
||||
miningTimer.start();
|
||||
@@ -849,14 +875,19 @@ void static BitcoinMiner()
|
||||
{
|
||||
if ( ASSETCHAINS_REWARD == 0 )
|
||||
{
|
||||
if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
int minvoutsize = 1;
|
||||
int minvtxsize = 1;
|
||||
if ( ASSETCHAINS_STREAM != 0 )
|
||||
minvoutsize = 2;
|
||||
minvtxsize = 2;
|
||||
if ( pblock->vtx.size() == minvtxsize && pblock->vtx[0].vout.size() == minvoutsize && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
{
|
||||
static uint32_t counter;
|
||||
if ( counter++ < 10 )
|
||||
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
||||
sleep(10);
|
||||
continue;
|
||||
} else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
|
||||
} else fprintf(stderr,"%s tx.%d vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx.size(),(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
|
||||
}
|
||||
}
|
||||
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
|
||||
@@ -935,13 +966,13 @@ void static BitcoinMiner()
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
if ( KOMODO_INSYNC == 0 )
|
||||
/*if ( KOMODO_INSYNC == 0 && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
{
|
||||
fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height);
|
||||
if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN )
|
||||
KOMODO_INSYNC = 1;
|
||||
sleep(3);
|
||||
}
|
||||
} */
|
||||
// Hash state
|
||||
KOMODO_CHOSEN_ONE = 0;
|
||||
crypto_generichash_blake2b_state state;
|
||||
@@ -1063,13 +1094,13 @@ void static BitcoinMiner()
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
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);
|
||||
|
||||
|
||||
// Initialization done, start algo driver.
|
||||
eq.digit0(0);
|
||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||
@@ -1081,7 +1112,7 @@ void static BitcoinMiner()
|
||||
}
|
||||
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);
|
||||
@@ -1090,7 +1121,7 @@ void static BitcoinMiner()
|
||||
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.
|
||||
@@ -1117,7 +1148,7 @@ void static BitcoinMiner()
|
||||
cancelSolver = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check for stop or if block needs to be rebuilt
|
||||
boost::this_thread::interruption_point();
|
||||
// Regtest mode doesn't require peers
|
||||
@@ -1187,7 +1218,7 @@ void static BitcoinMiner()
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
||||
#else
|
||||
@@ -1195,10 +1226,10 @@ void static BitcoinMiner()
|
||||
#endif
|
||||
{
|
||||
static boost::thread_group* minerThreads = NULL;
|
||||
|
||||
|
||||
if (nThreads < 0)
|
||||
nThreads = GetNumCores();
|
||||
|
||||
|
||||
if (minerThreads != NULL)
|
||||
{
|
||||
minerThreads->interrupt_all();
|
||||
@@ -1210,7 +1241,7 @@ void static BitcoinMiner()
|
||||
nThreads = 1;
|
||||
if (nThreads == 0 || !fGenerate)
|
||||
return;
|
||||
|
||||
|
||||
minerThreads = new boost::thread_group();
|
||||
for (int i = 0; i < nThreads; i++) {
|
||||
#ifdef ENABLE_WALLET
|
||||
@@ -1220,5 +1251,5 @@ void static BitcoinMiner()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // ENABLE_MINING
|
||||
|
||||
Reference in New Issue
Block a user