Merge branch 'dev' into jl777
This commit is contained in:
@@ -528,8 +528,8 @@ wallet_utility_LDADD = \
|
|||||||
$(CRYPTO_LIBS) \
|
$(CRYPTO_LIBS) \
|
||||||
$(LIBZCASH) \
|
$(LIBZCASH) \
|
||||||
$(LIBSNARK) \
|
$(LIBSNARK) \
|
||||||
$(LIBZCASH_LIBS)\
|
$(LIBZCASH_LIBS)\
|
||||||
$(LIBCRYPTOCONDITIONS)
|
$(LIBCRYPTOCONDITIONS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# zcash-tx binary #
|
# zcash-tx binary #
|
||||||
|
|||||||
@@ -679,7 +679,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata);
|
//komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata);
|
||||||
//printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth);
|
//printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth);
|
||||||
}
|
}
|
||||||
if ( MoMoMdata.pairs != 0 )
|
if ( MoMoMdata.pairs != 0 )
|
||||||
@@ -687,8 +687,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
|||||||
memset(&ccdata,0,sizeof(ccdata));
|
memset(&ccdata,0,sizeof(ccdata));
|
||||||
memset(&MoMoMdata,0,sizeof(MoMoMdata));
|
memset(&MoMoMdata,0,sizeof(MoMoMdata));
|
||||||
}
|
}
|
||||||
else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 )
|
//else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 )
|
||||||
komodo_rwccdata((char *)"KMD",1,&ccdata,0);
|
// komodo_rwccdata((char *)"KMD",1,&ccdata,0);
|
||||||
if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
|
if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
|
||||||
{
|
{
|
||||||
sp->NOTARIZED_HEIGHT = *notarizedheightp;
|
sp->NOTARIZED_HEIGHT = *notarizedheightp;
|
||||||
|
|||||||
578
src/miner.cpp
578
src/miner.cpp
@@ -63,7 +63,7 @@ public:
|
|||||||
set<uint256> setDependsOn;
|
set<uint256> setDependsOn;
|
||||||
CFeeRate feeRate;
|
CFeeRate feeRate;
|
||||||
double dPriority;
|
double dPriority;
|
||||||
|
|
||||||
COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0)
|
COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -77,10 +77,10 @@ typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority;
|
|||||||
class TxPriorityCompare
|
class TxPriorityCompare
|
||||||
{
|
{
|
||||||
bool byFee;
|
bool byFee;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TxPriorityCompare(bool _byFee) : byFee(_byFee) { }
|
TxPriorityCompare(bool _byFee) : byFee(_byFee) { }
|
||||||
|
|
||||||
bool operator()(const TxPriority& a, const TxPriority& b)
|
bool operator()(const TxPriority& a, const TxPriority& b)
|
||||||
{
|
{
|
||||||
if (byFee)
|
if (byFee)
|
||||||
@@ -159,30 +159,30 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
// -blockversion=N to test forking scenarios
|
// -blockversion=N to test forking scenarios
|
||||||
if (Params().MineBlocksOnDemand())
|
if (Params().MineBlocksOnDemand())
|
||||||
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
|
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
|
||||||
|
|
||||||
// Add dummy coinbase tx as first transaction
|
// Add dummy coinbase tx as first transaction
|
||||||
pblock->vtx.push_back(CTransaction());
|
pblock->vtx.push_back(CTransaction());
|
||||||
pblocktemplate->vTxFees.push_back(-1); // updated at end
|
pblocktemplate->vTxFees.push_back(-1); // updated at end
|
||||||
pblocktemplate->vTxSigOps.push_back(-1); // updated at end
|
pblocktemplate->vTxSigOps.push_back(-1); // updated at end
|
||||||
|
|
||||||
// Largest block you're willing to create:
|
// Largest block you're willing to create:
|
||||||
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
|
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
|
||||||
// Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
|
// 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));
|
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,
|
// How much of the block should be dedicated to high-priority transactions,
|
||||||
// included regardless of the fees they pay
|
// included regardless of the fees they pay
|
||||||
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
|
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
|
||||||
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
|
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
|
||||||
|
|
||||||
// Minimum block size you want to create; block will be filled with free transactions
|
// 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:
|
// until there are no more or the block reaches this size:
|
||||||
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
|
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
|
||||||
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
|
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
|
||||||
|
|
||||||
// Collect memory pool transactions into the block
|
// Collect memory pool transactions into the block
|
||||||
CAmount nFees = 0;
|
CAmount nFees = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
LOCK2(cs_main, mempool.cs);
|
LOCK2(cs_main, mempool.cs);
|
||||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||||
@@ -197,7 +197,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
list<COrphan> vOrphan; // list memory doesn't move
|
list<COrphan> vOrphan; // list memory doesn't move
|
||||||
map<uint256, vector<COrphan*> > mapDependers;
|
map<uint256, vector<COrphan*> > mapDependers;
|
||||||
bool fPrintPriority = GetBoolArg("-printpriority", false);
|
bool fPrintPriority = GetBoolArg("-printpriority", false);
|
||||||
|
|
||||||
// This vector will be sorted into a priority queue:
|
// This vector will be sorted into a priority queue:
|
||||||
vector<TxPriority> vecPriority;
|
vector<TxPriority> vecPriority;
|
||||||
vecPriority.reserve(mempool.mapTx.size());
|
vecPriority.reserve(mempool.mapTx.size());
|
||||||
@@ -205,11 +205,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
mi != mempool.mapTx.end(); ++mi)
|
mi != mempool.mapTx.end(); ++mi)
|
||||||
{
|
{
|
||||||
const CTransaction& tx = mi->GetTx();
|
const CTransaction& tx = mi->GetTx();
|
||||||
|
|
||||||
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
||||||
? nMedianTimePast
|
? nMedianTimePast
|
||||||
: pblock->GetBlockTime();
|
: pblock->GetBlockTime();
|
||||||
|
|
||||||
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
|
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
|
||||||
continue;
|
continue;
|
||||||
if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 )
|
if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 )
|
||||||
@@ -238,7 +238,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
vOrphan.pop_back();
|
vOrphan.pop_back();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has to wait for dependencies
|
// Has to wait for dependencies
|
||||||
if (!porphan)
|
if (!porphan)
|
||||||
{
|
{
|
||||||
@@ -253,27 +253,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
}
|
}
|
||||||
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
|
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
|
||||||
assert(coins);
|
assert(coins);
|
||||||
|
|
||||||
CAmount nValueIn = coins->vout[txin.prevout.n].nValue;
|
CAmount nValueIn = coins->vout[txin.prevout.n].nValue;
|
||||||
nTotalIn += nValueIn;
|
nTotalIn += nValueIn;
|
||||||
|
|
||||||
int nConf = nHeight - coins->nHeight;
|
int nConf = nHeight - coins->nHeight;
|
||||||
|
|
||||||
dPriority += (double)nValueIn * nConf;
|
dPriority += (double)nValueIn * nConf;
|
||||||
}
|
}
|
||||||
nTotalIn += tx.GetJoinSplitValueIn();
|
nTotalIn += tx.GetJoinSplitValueIn();
|
||||||
|
|
||||||
if (fMissingInputs) continue;
|
if (fMissingInputs) continue;
|
||||||
|
|
||||||
// Priority is sum(valuein * age) / modified_txsize
|
// Priority is sum(valuein * age) / modified_txsize
|
||||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
dPriority = tx.ComputePriority(dPriority, nTxSize);
|
dPriority = tx.ComputePriority(dPriority, nTxSize);
|
||||||
|
|
||||||
uint256 hash = tx.GetHash();
|
uint256 hash = tx.GetHash();
|
||||||
mempool.ApplyDeltas(hash, dPriority, nTotalIn);
|
mempool.ApplyDeltas(hash, dPriority, nTotalIn);
|
||||||
|
|
||||||
CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
|
CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
|
||||||
|
|
||||||
if (porphan)
|
if (porphan)
|
||||||
{
|
{
|
||||||
porphan->dPriority = dPriority;
|
porphan->dPriority = dPriority;
|
||||||
@@ -282,37 +282,37 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
else
|
else
|
||||||
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
|
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect transactions into block
|
// Collect transactions into block
|
||||||
uint64_t nBlockSize = 1000;
|
uint64_t nBlockSize = 1000;
|
||||||
uint64_t nBlockTx = 0;
|
uint64_t nBlockTx = 0;
|
||||||
int64_t interest;
|
int64_t interest;
|
||||||
int nBlockSigOps = 100;
|
int nBlockSigOps = 100;
|
||||||
bool fSortedByFee = (nBlockPrioritySize <= 0);
|
bool fSortedByFee = (nBlockPrioritySize <= 0);
|
||||||
|
|
||||||
TxPriorityCompare comparer(fSortedByFee);
|
TxPriorityCompare comparer(fSortedByFee);
|
||||||
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||||
|
|
||||||
while (!vecPriority.empty())
|
while (!vecPriority.empty())
|
||||||
{
|
{
|
||||||
// Take highest priority transaction off the priority queue:
|
// Take highest priority transaction off the priority queue:
|
||||||
double dPriority = vecPriority.front().get<0>();
|
double dPriority = vecPriority.front().get<0>();
|
||||||
CFeeRate feeRate = vecPriority.front().get<1>();
|
CFeeRate feeRate = vecPriority.front().get<1>();
|
||||||
const CTransaction& tx = *(vecPriority.front().get<2>());
|
const CTransaction& tx = *(vecPriority.front().get<2>());
|
||||||
|
|
||||||
std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||||
vecPriority.pop_back();
|
vecPriority.pop_back();
|
||||||
|
|
||||||
// Size limits
|
// Size limits
|
||||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
if (nBlockSize + nTxSize >= nBlockMaxSize)
|
if (nBlockSize + nTxSize >= nBlockMaxSize)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Legacy limits on sigOps:
|
// Legacy limits on sigOps:
|
||||||
unsigned int nTxSigOps = GetLegacySigOpCount(tx);
|
unsigned int nTxSigOps = GetLegacySigOpCount(tx);
|
||||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Skip free transactions if we're past the minimum block size:
|
// Skip free transactions if we're past the minimum block size:
|
||||||
const uint256& hash = tx.GetHash();
|
const uint256& hash = tx.GetHash();
|
||||||
double dPriorityDelta = 0;
|
double dPriorityDelta = 0;
|
||||||
@@ -320,7 +320,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
|
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
|
||||||
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
|
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Prioritise by fee once past the priority size or we run out of high-priority
|
// Prioritise by fee once past the priority size or we run out of high-priority
|
||||||
// transactions:
|
// transactions:
|
||||||
if (!fSortedByFee &&
|
if (!fSortedByFee &&
|
||||||
@@ -330,16 +330,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
comparer = TxPriorityCompare(fSortedByFee);
|
comparer = TxPriorityCompare(fSortedByFee);
|
||||||
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!view.HaveInputs(tx))
|
if (!view.HaveInputs(tx))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut();
|
CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut();
|
||||||
|
|
||||||
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
||||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Note that flags: we don't want to set mempool/IsStandard()
|
// Note that flags: we don't want to set mempool/IsStandard()
|
||||||
// policy here, but we still have to ensure that the block we
|
// policy here, but we still have to ensure that the block we
|
||||||
// create only contains transactions that are valid in new blocks.
|
// create only contains transactions that are valid in new blocks.
|
||||||
@@ -347,9 +347,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
PrecomputedTransactionData txdata(tx);
|
PrecomputedTransactionData txdata(tx);
|
||||||
if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId))
|
if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
UpdateCoins(tx, view, nHeight);
|
UpdateCoins(tx, view, nHeight);
|
||||||
|
|
||||||
// Added
|
// Added
|
||||||
pblock->vtx.push_back(tx);
|
pblock->vtx.push_back(tx);
|
||||||
pblocktemplate->vTxFees.push_back(nTxFees);
|
pblocktemplate->vTxFees.push_back(nTxFees);
|
||||||
@@ -358,12 +358,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
++nBlockTx;
|
++nBlockTx;
|
||||||
nBlockSigOps += nTxSigOps;
|
nBlockSigOps += nTxSigOps;
|
||||||
nFees += nTxFees;
|
nFees += nTxFees;
|
||||||
|
|
||||||
if (fPrintPriority)
|
if (fPrintPriority)
|
||||||
{
|
{
|
||||||
LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString());
|
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
|
// Add transactions that depend on this one to the priority queue
|
||||||
if (mapDependers.count(hash))
|
if (mapDependers.count(hash))
|
||||||
{
|
{
|
||||||
@@ -381,7 +381,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nLastBlockTx = nBlockTx;
|
nLastBlockTx = nBlockTx;
|
||||||
nLastBlockSize = nBlockSize;
|
nLastBlockSize = nBlockSize;
|
||||||
blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
||||||
@@ -412,10 +412,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
fprintf(stderr,"finished waiting\n");
|
fprintf(stderr,"finished waiting\n");
|
||||||
//sleep(pblock->nTime - GetAdjustedTime());
|
//sleep(pblock->nTime - GetAdjustedTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else fprintf(stderr,"no utxos eligible for staking\n");
|
} else fprintf(stderr,"no utxos eligible for staking\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create coinbase tx
|
// Create coinbase tx
|
||||||
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight);
|
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight);
|
||||||
txNew.vin.resize(1);
|
txNew.vin.resize(1);
|
||||||
@@ -428,30 +428,30 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
// Add fees
|
// Add fees
|
||||||
txNew.vout[0].nValue += nFees;
|
txNew.vout[0].nValue += nFees;
|
||||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||||
|
|
||||||
/*if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
/*if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
{
|
{
|
||||||
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
||||||
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
|
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
|
if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed
|
||||||
{
|
{
|
||||||
txNew.vout.resize(2);
|
txNew.vout.resize(2);
|
||||||
txNew.vout[1].scriptPubKey.resize(opretlen);
|
txNew.vout[1].scriptPubKey.resize(opretlen);
|
||||||
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
||||||
for (i=0; i<opretlen; i++)
|
for (i=0; i<opretlen; i++)
|
||||||
ptr[i] = opret[i];
|
ptr[i] = opret[i];
|
||||||
txNew.vout[1].nValue = 0;
|
txNew.vout[1].nValue = 0;
|
||||||
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
||||||
} //else printf("null opretlen for prices\n");
|
} //else printf("null opretlen for prices\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( komodo_is_issuer() != 0 )
|
else if ( komodo_is_issuer() != 0 )
|
||||||
{
|
{
|
||||||
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
|
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
|
||||||
if ( txNew.vout.size() > 1 )
|
if ( txNew.vout.size() > 1 )
|
||||||
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
|
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
pblock->vtx[0] = txNew;
|
pblock->vtx[0] = txNew;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 )
|
||||||
@@ -475,7 +475,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
nonce <<= 32;
|
nonce <<= 32;
|
||||||
nonce >>= 16;
|
nonce >>= 16;
|
||||||
pblock->nNonce = ArithToUint256(nonce);
|
pblock->nNonce = ArithToUint256(nonce);
|
||||||
|
|
||||||
// Fill in header
|
// Fill in header
|
||||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
||||||
pblock->hashReserved = uint256();
|
pblock->hashReserved = uint256();
|
||||||
@@ -493,7 +493,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
}
|
}
|
||||||
pblock->nSolution.clear();
|
pblock->nSolution.clear();
|
||||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false))
|
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false))
|
||||||
{
|
{
|
||||||
@@ -503,52 +503,52 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pblocktemplate.release();
|
return pblocktemplate.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
||||||
#else
|
#else
|
||||||
boost::optional<CScript> GetMinerScriptPubKey()
|
boost::optional<CScript> GetMinerScriptPubKey()
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
CKeyID keyID;
|
CKeyID keyID;
|
||||||
CBitcoinAddress addr;
|
CBitcoinAddress addr;
|
||||||
if (addr.SetString(GetArg("-mineraddress", ""))) {
|
if (addr.SetString(GetArg("-mineraddress", ""))) {
|
||||||
addr.GetKeyID(keyID);
|
addr.GetKeyID(keyID);
|
||||||
} else {
|
} else {
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
CPubKey pubkey;
|
CPubKey pubkey;
|
||||||
if (!reservekey.GetReservedKey(pubkey)) {
|
if (!reservekey.GetReservedKey(pubkey)) {
|
||||||
return boost::optional<CScript>();
|
return boost::optional<CScript>();
|
||||||
}
|
}
|
||||||
keyID = pubkey.GetID();
|
keyID = pubkey.GetID();
|
||||||
#else
|
#else
|
||||||
return boost::optional<CScript>();
|
return boost::optional<CScript>();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||||
return scriptPubKey;
|
return scriptPubKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||||
{
|
{
|
||||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey(reservekey);
|
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey(reservekey);
|
||||||
#else
|
#else
|
||||||
CBlockTemplate* CreateNewBlockWithKey()
|
CBlockTemplate* CreateNewBlockWithKey()
|
||||||
{
|
{
|
||||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!scriptPubKey) {
|
if (!scriptPubKey) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return CreateNewBlock(*scriptPubKey);
|
return CreateNewBlock(*scriptPubKey);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -571,7 +571,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
|||||||
CMutableTransaction txCoinbase(pblock->vtx[0]);
|
CMutableTransaction txCoinbase(pblock->vtx[0]);
|
||||||
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
|
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
|
||||||
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
||||||
|
|
||||||
pblock->vtx[0] = txCoinbase;
|
pblock->vtx[0] = txCoinbase;
|
||||||
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
|
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
|
||||||
}
|
}
|
||||||
@@ -616,7 +616,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
|||||||
{
|
{
|
||||||
LogPrintf("%s\n", pblock->ToString());
|
LogPrintf("%s\n", pblock->ToString());
|
||||||
LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.Tip()->nHeight+1);
|
LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.Tip()->nHeight+1);
|
||||||
|
|
||||||
// Found a solution
|
// Found a solution
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
@@ -631,11 +631,11 @@ static bool ProcessBlockFound(CBlock* pblock)
|
|||||||
for (i=31; i>=0; i--)
|
for (i=31; i>=0; i--)
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||||
fprintf(stderr," <- chainTip (stale)\n");
|
fprintf(stderr," <- chainTip (stale)\n");
|
||||||
|
|
||||||
return error("KomodoMiner: generated block is stale");
|
return error("KomodoMiner: generated block is stale");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
// Remove key from key pool
|
// Remove key from key pool
|
||||||
if ( IS_KOMODO_NOTARY == 0 )
|
if ( IS_KOMODO_NOTARY == 0 )
|
||||||
@@ -652,14 +652,14 @@ static bool ProcessBlockFound(CBlock* pblock)
|
|||||||
wallet.mapRequestCount[pblock->GetHash()] = 0;
|
wallet.mapRequestCount[pblock->GetHash()] = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Process this block the same as if we had received it from another node
|
// Process this block the same as if we had received it from another node
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL))
|
if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||||
return error("KomodoMiner: ProcessNewBlock, block not accepted");
|
return error("KomodoMiner: ProcessNewBlock, block not accepted");
|
||||||
|
|
||||||
TrackMinedBlock(pblock->GetHash());
|
TrackMinedBlock(pblock->GetHash());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,15 +681,15 @@ void static BitcoinMiner()
|
|||||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||||
RenameThread("komodo-miner");
|
RenameThread("komodo-miner");
|
||||||
const CChainParams& chainparams = Params();
|
const CChainParams& chainparams = Params();
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
// Each thread has its own key
|
// Each thread has its own key
|
||||||
CReserveKey reservekey(pwallet);
|
CReserveKey reservekey(pwallet);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Each thread has its own counter
|
// Each thread has its own counter
|
||||||
unsigned int nExtraNonce = 0;
|
unsigned int nExtraNonce = 0;
|
||||||
|
|
||||||
unsigned int n = chainparams.EquihashN();
|
unsigned int n = chainparams.EquihashN();
|
||||||
unsigned int k = chainparams.EquihashK();
|
unsigned int k = chainparams.EquihashK();
|
||||||
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,notaryid = -1;
|
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,notaryid = -1;
|
||||||
@@ -700,10 +700,10 @@ void static BitcoinMiner()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime());
|
komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime());
|
||||||
|
|
||||||
std::string solver;
|
std::string solver;
|
||||||
//if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 )
|
//if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
solver = "tromp";
|
solver = "tromp";
|
||||||
//else solver = "default";
|
//else solver = "default";
|
||||||
assert(solver == "tromp" || solver == "default");
|
assert(solver == "tromp" || solver == "default");
|
||||||
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
||||||
@@ -712,13 +712,13 @@ void static BitcoinMiner()
|
|||||||
std::mutex m_cs;
|
std::mutex m_cs;
|
||||||
bool cancelSolver = false;
|
bool cancelSolver = false;
|
||||||
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
||||||
[&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
|
[&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
|
||||||
std::lock_guard<std::mutex> lock{m_cs};
|
std::lock_guard<std::mutex> lock{m_cs};
|
||||||
cancelSolver = true;
|
cancelSolver = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
miningTimer.start();
|
miningTimer.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str());
|
fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str());
|
||||||
@@ -741,16 +741,16 @@ void static BitcoinMiner()
|
|||||||
break;
|
break;
|
||||||
MilliSleep(5000);
|
MilliSleep(5000);
|
||||||
//fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload());
|
//fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload());
|
||||||
|
|
||||||
} while (true);
|
} while (true);
|
||||||
//fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL);
|
//fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL);
|
||||||
miningTimer.start();
|
miningTimer.start();
|
||||||
}
|
}
|
||||||
/*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT )
|
/*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);
|
fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight);
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}*/
|
}*/
|
||||||
//
|
//
|
||||||
// Create new block
|
// Create new block
|
||||||
//
|
//
|
||||||
@@ -883,11 +883,11 @@ void static BitcoinMiner()
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
/*if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt
|
/*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);
|
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
||||||
sleep(10);
|
sleep(10);
|
||||||
break;
|
break;
|
||||||
}*/
|
}*/
|
||||||
// Hash state
|
// Hash state
|
||||||
KOMODO_CHOSEN_ONE = 0;
|
KOMODO_CHOSEN_ONE = 0;
|
||||||
crypto_generichash_blake2b_state state;
|
crypto_generichash_blake2b_state state;
|
||||||
@@ -908,11 +908,11 @@ void static BitcoinMiner()
|
|||||||
//fprintf(stderr,"running solver\n");
|
//fprintf(stderr,"running solver\n");
|
||||||
std::function<bool(std::vector<unsigned char>)> validBlock =
|
std::function<bool(std::vector<unsigned char>)> validBlock =
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
[&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
|
[&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
|
||||||
#else
|
#else
|
||||||
[&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams]
|
[&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams]
|
||||||
#endif
|
#endif
|
||||||
(std::vector<unsigned char> soln) {
|
(std::vector<unsigned char> soln) {
|
||||||
// Write the solution to the hash and compute the result.
|
// Write the solution to the hash and compute the result.
|
||||||
LogPrint("pow", "- Checking solution against target\n");
|
LogPrint("pow", "- Checking solution against target\n");
|
||||||
pblock->nSolution = soln;
|
pblock->nSolution = soln;
|
||||||
@@ -968,178 +968,178 @@ void static BitcoinMiner()
|
|||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
if (ProcessBlockFound(pblock, *pwallet, reservekey)) {
|
if (ProcessBlockFound(pblock, *pwallet, reservekey)) {
|
||||||
#else
|
#else
|
||||||
if (ProcessBlockFound(pblock)) {
|
if (ProcessBlockFound(pblock)) {
|
||||||
#endif
|
#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};
|
std::lock_guard<std::mutex> lock{m_cs};
|
||||||
cancelSolver = false;
|
return cancelSolver;
|
||||||
}
|
};
|
||||||
KOMODO_CHOSEN_ONE = 0;
|
|
||||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
// TODO: factor this out into a function with the same API for each solver.
|
||||||
// In regression test mode, stop mining after a block is found.
|
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
||||||
if (chainparams.MineBlocksOnDemand()) {
|
// Create solver and initialize it.
|
||||||
// Increment here because throwing skips the call below
|
equi eq(1);
|
||||||
ehSolverRuns.increment();
|
eq.setstate(&curr_state);
|
||||||
throw boost::thread_interrupted();
|
|
||||||
}
|
// Initialization done, start algo driver.
|
||||||
//if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
|
eq.digit0(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;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||||
eq.showbsizes(r);
|
eq.showbsizes(0);
|
||||||
}
|
for (u32 r = 1; r < WK; r++) {
|
||||||
eq.digitK(0);
|
(r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0);
|
||||||
ehSolverRuns.increment();
|
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||||
|
eq.showbsizes(r);
|
||||||
// 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);
|
eq.digitK(0);
|
||||||
|
|
||||||
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();
|
ehSolverRuns.increment();
|
||||||
if (found) {
|
|
||||||
int32_t i; uint256 hash = pblock->GetHash();
|
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||||
for (i=0; i<32; i++)
|
for (size_t s = 0; s < eq.nsols; s++) {
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
LogPrint("pow", "Checking solution %d\n", s+1);
|
||||||
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
std::vector<eh_index> index_vector(PROOFSIZE);
|
||||||
FOUND_BLOCK = 1;
|
for (size_t i = 0; i < PROOFSIZE; i++) {
|
||||||
KOMODO_MAYBEMINED = Mining_height;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
} catch (EhSolverCancelledException&) {
|
|
||||||
LogPrint("pow", "Equihash solver cancelled\n");
|
|
||||||
std::lock_guard<std::mutex> lock{m_cs};
|
|
||||||
cancelSolver = false;
|
|
||||||
}
|
}
|
||||||
}
|
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
||||||
|
|
||||||
// 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");
|
//if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
|
fprintf(stderr,"0xffff, break\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
||||||
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
{
|
||||||
{
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
//if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
fprintf(stderr,"timeout, break\n");
|
||||||
fprintf(stderr,"0xffff, break\n");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
if ( pindexPrev != chainActive.Tip() )
|
||||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
{
|
||||||
{
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
fprintf(stderr,"Tip advanced, break\n");
|
||||||
fprintf(stderr,"timeout, break\n");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
// Update nNonce and nTime
|
||||||
if ( pindexPrev != chainActive.Tip() )
|
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
||||||
{
|
pblock->nBits = savebits;
|
||||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
|
||||||
fprintf(stderr,"Tip advanced, break\n");
|
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||||
break;
|
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
||||||
}
|
{
|
||||||
// Update nNonce and nTime
|
// Changing pblock->nTime can change work required on testnet:
|
||||||
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
HASHTarget.SetCompact(pblock->nBits);
|
||||||
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();
|
miningTimer.stop();
|
||||||
c.disconnect();
|
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
|
#ifdef ENABLE_WALLET
|
||||||
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
||||||
#else
|
#else
|
||||||
void GenerateBitcoins(bool fGenerate, int nThreads)
|
void GenerateBitcoins(bool fGenerate, int nThreads)
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
static boost::thread_group* minerThreads = NULL;
|
|
||||||
|
|
||||||
if (nThreads < 0)
|
|
||||||
nThreads = GetNumCores();
|
|
||||||
|
|
||||||
if (minerThreads != NULL)
|
|
||||||
{
|
{
|
||||||
minerThreads->interrupt_all();
|
static boost::thread_group* minerThreads = NULL;
|
||||||
delete minerThreads;
|
|
||||||
minerThreads = NULL;
|
if (nThreads < 0)
|
||||||
}
|
nThreads = GetNumCores();
|
||||||
|
|
||||||
if (nThreads == 0 || !fGenerate)
|
if (minerThreads != NULL)
|
||||||
return;
|
{
|
||||||
|
minerThreads->interrupt_all();
|
||||||
minerThreads = new boost::thread_group();
|
delete minerThreads;
|
||||||
for (int i = 0; i < nThreads; i++) {
|
minerThreads = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nThreads == 0 || !fGenerate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
minerThreads = new boost::thread_group();
|
||||||
|
for (int i = 0; i < nThreads; i++) {
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
|
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
|
||||||
#else
|
#else
|
||||||
minerThreads->create_thread(&BitcoinMiner);
|
minerThreads->create_thread(&BitcoinMiner);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ENABLE_MINING
|
#endif // ENABLE_MINING
|
||||||
|
|||||||
13
src/pow.cpp
13
src/pow.cpp
@@ -192,7 +192,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
|
|||||||
return true;
|
return true;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 )
|
||||||
{
|
{
|
||||||
if ( 1 && height > 792000 )
|
if ( 0 && height > 792000 )
|
||||||
{
|
{
|
||||||
for (i=31; i>=0; i--)
|
for (i=31; i>=0; i--)
|
||||||
printf("%02x",((uint8_t *)&hash)[i]);
|
printf("%02x",((uint8_t *)&hash)[i]);
|
||||||
@@ -214,14 +214,15 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*for (i=31; i>=0; i--)
|
/*for (i=31; i>=0; i--)
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||||
fprintf(stderr," hash vs ");
|
fprintf(stderr," hash vs ");
|
||||||
for (i=31; i>=0; i--)
|
for (i=31; i>=0; i--)
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
|
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
|
||||||
fprintf(stderr," height.%d notaryid.%d PoW valid\n",height,notaryid);*/
|
fprintf(stderr," height.%d notaryid.%d PoW valid\n",height,notaryid);*/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
arith_uint256 GetBlockProof(const CBlockIndex& block)
|
arith_uint256 GetBlockProof(const CBlockIndex& block)
|
||||||
{
|
{
|
||||||
arith_uint256 bnTarget;
|
arith_uint256 bnTarget;
|
||||||
|
|||||||
Reference in New Issue
Block a user