give this a go
This commit is contained in:
@@ -169,7 +169,7 @@ try_again:
|
|||||||
curl_handle = curl_easy_init();
|
curl_handle = curl_easy_init();
|
||||||
init_string(&s);
|
init_string(&s);
|
||||||
headers = curl_slist_append(0,"Expect:");
|
headers = curl_slist_append(0,"Expect:");
|
||||||
|
|
||||||
curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )");
|
curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )");
|
||||||
curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers);
|
||||||
curl_easy_setopt(curl_handle,CURLOPT_URL, url);
|
curl_easy_setopt(curl_handle,CURLOPT_URL, url);
|
||||||
@@ -198,7 +198,7 @@ try_again:
|
|||||||
bracket0 = (char *)"[";
|
bracket0 = (char *)"[";
|
||||||
bracket1 = (char *)"]";
|
bracket1 = (char *)"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
databuf = (char *)malloc(256 + strlen(command) + strlen(params));
|
databuf = (char *)malloc(256 + strlen(command) + strlen(params));
|
||||||
sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1);
|
sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1);
|
||||||
//printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf);
|
//printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf);
|
||||||
@@ -238,7 +238,7 @@ try_again:
|
|||||||
free(s.ptr);
|
free(s.ptr);
|
||||||
sleep((1<<numretries));
|
sleep((1<<numretries));
|
||||||
goto try_again;
|
goto try_again;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -524,7 +524,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t
|
|||||||
}
|
}
|
||||||
return(hash);
|
return(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 _komodo_getblockhash(int32_t height);*/
|
uint256 _komodo_getblockhash(int32_t height);*/
|
||||||
|
|
||||||
uint64_t komodo_seed(int32_t height)
|
uint64_t komodo_seed(int32_t height)
|
||||||
@@ -1099,31 +1099,39 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
komodo_checkPOW (fast) is called early in the process and should only refer to data immediately available. it is a filter to prevent bad blocks from going into the local DB. The more blocks we can filter out at this stage, the less junk in the local DB that will just get purged later on.
|
komodo_checkPOW (fast) is called early in the process and should only refer to data immediately available. it is a filter to prevent bad blocks from going into the local DB. The more blocks we can filter out at this stage, the less junk in the local DB that will just get purged later on.
|
||||||
|
|
||||||
komodo_checkPOW (slow) is called right before connecting blocks so all prior blocks can be assumed to be there and all checks must pass
|
komodo_checkPOW (slow) is called right before connecting blocks so all prior blocks can be assumed to be there and all checks must pass
|
||||||
|
|
||||||
commission must be in coinbase.vout[1] and must be >= 10000 sats
|
commission must be in coinbase.vout[1] and must be >= 10000 sats
|
||||||
PoS stake must be without txfee and in the last tx in the block at vout[0]
|
PoS stake must be without txfee and in the last tx in the block at vout[0]
|
||||||
*/
|
*/
|
||||||
|
extern int32_t ASSETCHAINS_STREAM;
|
||||||
|
|
||||||
uint64_t komodo_commission(const CBlock *pblock)
|
uint64_t komodo_commission(const CBlock *pblock)
|
||||||
{
|
{
|
||||||
int32_t i,j,n=0,txn_count; uint64_t commission,total = 0;
|
if ( ASSETCHAINS_STREAM == 0 )
|
||||||
txn_count = pblock->vtx.size();
|
|
||||||
for (i=0; i<txn_count; i++)
|
|
||||||
{
|
{
|
||||||
n = pblock->vtx[i].vout.size();
|
int32_t i,j,n=0,txn_count; uint64_t commission,total = 0;
|
||||||
for (j=0; j<n; j++)
|
txn_count = pblock->vtx.size();
|
||||||
{
|
for (i=0; i<txn_count; i++)
|
||||||
//fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j);
|
{
|
||||||
if ( i != 0 || j != 1 )
|
n = pblock->vtx[i].vout.size();
|
||||||
total += pblock->vtx[i].vout[j].nValue;
|
for (j=0; j<n; j++)
|
||||||
}
|
{
|
||||||
|
//fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j);
|
||||||
|
if ( i != 0 || j != 1 )
|
||||||
|
total += pblock->vtx[i].vout[j].nValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN));
|
||||||
|
commission = ((total * ASSETCHAINS_COMMISSION) / COIN);
|
||||||
|
if ( commission < 10000 )
|
||||||
|
commission = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commission = 10000;
|
||||||
}
|
}
|
||||||
//fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN));
|
|
||||||
commission = ((total * ASSETCHAINS_COMMISSION) / COIN);
|
|
||||||
if ( commission < 10000 )
|
|
||||||
commission = 0;
|
|
||||||
return(commission);
|
return(commission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34];
|
|||||||
#define _COINBASE_MATURITY 100
|
#define _COINBASE_MATURITY 100
|
||||||
int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
|
int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
|
||||||
|
|
||||||
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1;
|
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1;
|
||||||
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
|
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
|
||||||
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
|
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
|
||||||
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
|
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
|
||||||
|
|||||||
@@ -1561,6 +1561,7 @@ void komodo_args(char *argv0)
|
|||||||
ASSETCHAINS_DECAY = GetArg("-ac_decay",0);
|
ASSETCHAINS_DECAY = GetArg("-ac_decay",0);
|
||||||
ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0);
|
ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0);
|
||||||
ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey","");
|
ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey","");
|
||||||
|
ASSETCHAINS_STREAM = GetArg("-ac_stream",0);
|
||||||
if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
|
if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
|
||||||
ASSETCHAINS_STAKED = 100;
|
ASSETCHAINS_STAKED = 100;
|
||||||
if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 )
|
if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 )
|
||||||
@@ -1589,7 +1590,10 @@ void komodo_args(char *argv0)
|
|||||||
{
|
{
|
||||||
ASSETCHAINS_COMMISSION = 0;
|
ASSETCHAINS_COMMISSION = 0;
|
||||||
printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n");
|
printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n");
|
||||||
}
|
} else if ( ASSETCHAINS_STREAM != 0) {
|
||||||
|
ASSETCHAINS_STREAM = 0;
|
||||||
|
printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! This parameter has been ignored! \n");
|
||||||
|
}
|
||||||
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 )
|
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]);
|
fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]);
|
||||||
|
|||||||
16
src/main.cpp
16
src/main.cpp
@@ -1866,6 +1866,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW)
|
|||||||
//uint64_t komodo_moneysupply(int32_t height);
|
//uint64_t komodo_moneysupply(int32_t height);
|
||||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||||
extern uint32_t ASSETCHAINS_MAGIC;
|
extern uint32_t ASSETCHAINS_MAGIC;
|
||||||
|
extern int32_t ASSETCHAINS_STREAM;
|
||||||
extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY;
|
extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY;
|
||||||
extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
|
extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
|
||||||
|
|
||||||
@@ -1895,7 +1896,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
|
|||||||
{
|
{
|
||||||
if ( ASSETCHAINS_REWARD == 0 )
|
if ( ASSETCHAINS_REWARD == 0 )
|
||||||
return(10000);
|
return(10000);
|
||||||
else if ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY )
|
else if ( ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY )|| ASSETCHAINS_STREAM != 0)
|
||||||
return(0);
|
return(0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2961,6 +2962,19 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
if (!view.HaveJoinSplitRequirements(tx))
|
if (!view.HaveJoinSplitRequirements(tx))
|
||||||
return state.DoS(100, error("ConnectBlock(): JoinSplit requirements not met"),
|
return state.DoS(100, error("ConnectBlock(): JoinSplit requirements not met"),
|
||||||
REJECT_INVALID, "bad-txns-joinsplit-requirements-not-met");
|
REJECT_INVALID, "bad-txns-joinsplit-requirements-not-met");
|
||||||
|
|
||||||
|
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
|
{
|
||||||
|
if ( ASSETCHAINS_STREAM != 0 )
|
||||||
|
{
|
||||||
|
if ( block.vtx.size() == 1 && block.vtx[0].vout.size() == 2 && pindex->nHeight > ASSETCHAINS_MINHEIGHT)
|
||||||
|
{
|
||||||
|
return state.DoS(100, error("ConnectBlock(): There are no TX in this block, it is invalid!"),
|
||||||
|
REJECT_INVALID, "bad-block-no-transactions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fAddressIndex || fSpentIndex)
|
if (fAddressIndex || fSpentIndex)
|
||||||
{
|
{
|
||||||
for (size_t j = 0; j < tx.vin.size(); j++) {
|
for (size_t j = 0; j < tx.vin.size(); j++) {
|
||||||
|
|||||||
117
src/miner.cpp
117
src/miner.cpp
@@ -64,7 +64,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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -78,10 +78,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)
|
||||||
@@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
|
|||||||
|
|
||||||
#include "komodo_defs.h"
|
#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 uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED;
|
||||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||||
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY;
|
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
|
// -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;
|
||||||
CBlockIndex* pindexPrev = 0;
|
CBlockIndex* pindexPrev = 0;
|
||||||
@@ -174,12 +174,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
||||||
CCoinsViewCache view(pcoinsTip);
|
CCoinsViewCache view(pcoinsTip);
|
||||||
uint32_t expired; uint64_t commission;
|
uint32_t expired; uint64_t commission;
|
||||||
|
|
||||||
// Priority order to process transactions
|
// Priority order to process transactions
|
||||||
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());
|
||||||
@@ -187,11 +187,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
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))
|
||||||
{
|
{
|
||||||
//fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",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;
|
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;
|
||||||
@@ -274,27 +274,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
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-512) // room for extra autotx
|
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);
|
//fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)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)
|
||||||
@@ -329,14 +329,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
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))
|
||||||
{
|
{
|
||||||
//fprintf(stderr,"dont have inputs\n");
|
//fprintf(stderr,"dont have inputs\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut();
|
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->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)
|
||||||
{
|
{
|
||||||
@@ -354,7 +354,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
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);
|
||||||
@@ -363,12 +363,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
++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))
|
||||||
{
|
{
|
||||||
@@ -386,7 +386,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nLastBlockTx = nBlockTx;
|
nLastBlockTx = nBlockTx;
|
||||||
nLastBlockSize = nBlockSize;
|
nLastBlockSize = nBlockSize;
|
||||||
blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
||||||
@@ -411,7 +411,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)));
|
//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");
|
} else return(0); //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);
|
||||||
@@ -426,9 +426,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
// 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;
|
||||||
|
|
||||||
pblock->vtx[0] = txNew;
|
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;
|
int32_t i; uint8_t *ptr;
|
||||||
txNew.vout.resize(2);
|
txNew.vout.resize(2);
|
||||||
@@ -449,7 +449,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
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();
|
||||||
@@ -527,7 +527,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
|
|
||||||
return pblocktemplate.release();
|
return pblocktemplate.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
||||||
@@ -550,11 +550,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
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)
|
||||||
{
|
{
|
||||||
@@ -564,7 +564,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
{
|
{
|
||||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!scriptPubKey) {
|
if (!scriptPubKey) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -592,7 +592,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();
|
||||||
}
|
}
|
||||||
@@ -606,7 +606,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
|||||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount)
|
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount)
|
||||||
{
|
{
|
||||||
CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i;
|
CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i;
|
||||||
if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
|
if ( (nHeight == 1 || ASSETCHAINS_STREAM != 0 ) && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
|
||||||
{
|
{
|
||||||
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
|
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
|
||||||
}
|
}
|
||||||
@@ -615,7 +615,6 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in
|
|||||||
//fprintf(stderr,"use notary pubkey\n");
|
//fprintf(stderr,"use notary pubkey\n");
|
||||||
scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
|
scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (!reservekey.GetReservedKey(pubkey))
|
if (!reservekey.GetReservedKey(pubkey))
|
||||||
{
|
{
|
||||||
@@ -661,7 +660,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.LastTip()->nHeight+1);
|
LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->nHeight+1);
|
||||||
|
|
||||||
// Found a solution
|
// Found a solution
|
||||||
{
|
{
|
||||||
//LOCK(cs_main);
|
//LOCK(cs_main);
|
||||||
@@ -676,11 +675,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 )
|
||||||
@@ -704,7 +703,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
|||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
|
if (!ProcessNewBlock(1,chainActive.LastTip()->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());
|
||||||
komodo_broadcast(pblock,16);
|
komodo_broadcast(pblock,16);
|
||||||
return true;
|
return true;
|
||||||
@@ -728,15 +727,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,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
|
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
|
||||||
@@ -767,7 +766,7 @@ void static BitcoinMiner()
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
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());
|
||||||
@@ -790,7 +789,7 @@ void static BitcoinMiner()
|
|||||||
break;
|
break;
|
||||||
MilliSleep(15000);
|
MilliSleep(15000);
|
||||||
//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();
|
||||||
@@ -1054,13 +1053,13 @@ void static BitcoinMiner()
|
|||||||
std::lock_guard<std::mutex> lock{m_cs};
|
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.
|
// TODO: factor this out into a function with the same API for each solver.
|
||||||
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
||||||
// Create solver and initialize it.
|
// Create solver and initialize it.
|
||||||
equi eq(1);
|
equi eq(1);
|
||||||
eq.setstate(&curr_state);
|
eq.setstate(&curr_state);
|
||||||
|
|
||||||
// Initialization done, start algo driver.
|
// Initialization done, start algo driver.
|
||||||
eq.digit0(0);
|
eq.digit0(0);
|
||||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||||
@@ -1072,7 +1071,7 @@ void static BitcoinMiner()
|
|||||||
}
|
}
|
||||||
eq.digitK(0);
|
eq.digitK(0);
|
||||||
ehSolverRuns.increment();
|
ehSolverRuns.increment();
|
||||||
|
|
||||||
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||||
for (size_t s = 0; s < eq.nsols; s++) {
|
for (size_t s = 0; s < eq.nsols; s++) {
|
||||||
LogPrint("pow", "Checking solution %d\n", s+1);
|
LogPrint("pow", "Checking solution %d\n", s+1);
|
||||||
@@ -1081,7 +1080,7 @@ void static BitcoinMiner()
|
|||||||
index_vector[i] = eq.sols[s][i];
|
index_vector[i] = eq.sols[s][i];
|
||||||
}
|
}
|
||||||
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
||||||
|
|
||||||
if (validBlock(sol_char)) {
|
if (validBlock(sol_char)) {
|
||||||
// If we find a POW solution, do not try other solutions
|
// If we find a POW solution, do not try other solutions
|
||||||
// because they become invalid as we created a new block in blockchain.
|
// because they become invalid as we created a new block in blockchain.
|
||||||
@@ -1108,7 +1107,7 @@ void static BitcoinMiner()
|
|||||||
cancelSolver = false;
|
cancelSolver = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for stop or if block needs to be rebuilt
|
// Check for stop or if block needs to be rebuilt
|
||||||
boost::this_thread::interruption_point();
|
boost::this_thread::interruption_point();
|
||||||
// Regtest mode doesn't require peers
|
// Regtest mode doesn't require peers
|
||||||
@@ -1178,7 +1177,7 @@ void static BitcoinMiner()
|
|||||||
miningTimer.stop();
|
miningTimer.stop();
|
||||||
c.disconnect();
|
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
|
||||||
@@ -1186,10 +1185,10 @@ void static BitcoinMiner()
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
static boost::thread_group* minerThreads = NULL;
|
static boost::thread_group* minerThreads = NULL;
|
||||||
|
|
||||||
if (nThreads < 0)
|
if (nThreads < 0)
|
||||||
nThreads = GetNumCores();
|
nThreads = GetNumCores();
|
||||||
|
|
||||||
if (minerThreads != NULL)
|
if (minerThreads != NULL)
|
||||||
{
|
{
|
||||||
minerThreads->interrupt_all();
|
minerThreads->interrupt_all();
|
||||||
@@ -1201,7 +1200,7 @@ void static BitcoinMiner()
|
|||||||
nThreads = 1;
|
nThreads = 1;
|
||||||
if (nThreads == 0 || !fGenerate)
|
if (nThreads == 0 || !fGenerate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
minerThreads = new boost::thread_group();
|
minerThreads = new boost::thread_group();
|
||||||
for (int i = 0; i < nThreads; i++) {
|
for (int i = 0; i < nThreads; i++) {
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
@@ -1211,5 +1210,5 @@ void static BitcoinMiner()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_MINING
|
#endif // ENABLE_MINING
|
||||||
|
|||||||
48
src/pow.cpp
48
src/pow.cpp
@@ -20,31 +20,39 @@
|
|||||||
#include "librustzcash.h"
|
#include "librustzcash.h"
|
||||||
#endif // ENABLE_RUST
|
#endif // ENABLE_RUST
|
||||||
uint32_t komodo_chainactive_timestamp();
|
uint32_t komodo_chainactive_timestamp();
|
||||||
|
extern int32_t ASSETCHAINS_STREAM;
|
||||||
|
|
||||||
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
|
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
|
||||||
{
|
{
|
||||||
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
|
if ( ASSETCHAINS_STREAM == 0)
|
||||||
// Genesis block
|
{
|
||||||
if (pindexLast == NULL )
|
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
|
||||||
return nProofOfWorkLimit;
|
// Genesis block
|
||||||
|
if (pindexLast == NULL )
|
||||||
|
return nProofOfWorkLimit;
|
||||||
|
|
||||||
// Find the first block in the averaging interval
|
// Find the first block in the averaging interval
|
||||||
const CBlockIndex* pindexFirst = pindexLast;
|
const CBlockIndex* pindexFirst = pindexLast;
|
||||||
arith_uint256 bnTot {0};
|
arith_uint256 bnTot {0};
|
||||||
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) {
|
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) {
|
||||||
arith_uint256 bnTmp;
|
arith_uint256 bnTmp;
|
||||||
bnTmp.SetCompact(pindexFirst->nBits);
|
bnTmp.SetCompact(pindexFirst->nBits);
|
||||||
bnTot += bnTmp;
|
bnTot += bnTmp;
|
||||||
pindexFirst = pindexFirst->pprev;
|
pindexFirst = pindexFirst->pprev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check we have enough blocks
|
||||||
|
if (pindexFirst == NULL)
|
||||||
|
return nProofOfWorkLimit;
|
||||||
|
|
||||||
|
arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow};
|
||||||
|
|
||||||
|
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 537857807;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check we have enough blocks
|
|
||||||
if (pindexFirst == NULL)
|
|
||||||
return nProofOfWorkLimit;
|
|
||||||
|
|
||||||
arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow};
|
|
||||||
|
|
||||||
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
||||||
|
|||||||
Reference in New Issue
Block a user