@@ -1416,6 +1416,29 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256
|
||||
return(addrhash.uints[0]);
|
||||
}
|
||||
|
||||
arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime)
|
||||
{
|
||||
arith_uint256 origtarget,easy; int32_t diff; int64_t mult; bool fNegative,fOverflow; CBlockIndex *tipindex;
|
||||
if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 )
|
||||
{
|
||||
diff = (nTime - tipindex->GetMedianTimePast());
|
||||
if ( diff > 20 * ASSETCHAINS_BLOCKTIME )
|
||||
{
|
||||
mult = diff - 19 * ASSETCHAINS_BLOCKTIME;
|
||||
mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 3;
|
||||
origtarget = bnTarget;
|
||||
bnTarget = bnTarget * arith_uint256(mult * mult);
|
||||
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||
if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow
|
||||
{
|
||||
bnTarget = easy;
|
||||
fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult);
|
||||
} else fprintf(stderr,"miner elapsed %d, adjust by factor of %lld\n",diff,(long long)mult);
|
||||
}
|
||||
} //else fprintf(stderr,"cant find height.%d\n",height);
|
||||
return(bnTarget);
|
||||
}
|
||||
|
||||
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc)
|
||||
{
|
||||
int32_t oldflag = 0,dispflag = 0;
|
||||
@@ -2260,6 +2283,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
if ( height == 0 )
|
||||
return(0);
|
||||
}
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW != 0 )
|
||||
bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime);
|
||||
if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget )
|
||||
{
|
||||
// if proof of stake is active, check if this is a valid PoS block before we fail
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#ifndef KOMODO_DEFS_H
|
||||
#define KOMODO_DEFS_H
|
||||
#include "arith_uint256.h"
|
||||
|
||||
#include "komodo_nk.h"
|
||||
|
||||
#define KOMODO_EARLYTXID_HEIGHT 100
|
||||
@@ -261,7 +263,7 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] =
|
||||
//#define PRICES_DAYWINDOW (7)
|
||||
//#endif
|
||||
|
||||
extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC;
|
||||
extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC,ASSETCHAINS_ADAPTIVEPOW;
|
||||
int32_t MAX_BLOCK_SIZE(int32_t height);
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||
@@ -337,6 +339,7 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
|
||||
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
|
||||
int32_t komodo_currentheight();
|
||||
int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height);
|
||||
arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime);
|
||||
|
||||
uint256 Parseuint256(const char *hexstr);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ uint256 KOMODO_EARLYTXID;
|
||||
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY,KOMODO_NSPV;
|
||||
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
|
||||
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB;
|
||||
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA;
|
||||
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA,ASSETCHAINS_ADAPTIVEPOW;
|
||||
bool VERUS_MINTBLOCKS;
|
||||
std::vector<uint8_t> Mineropret;
|
||||
std::vector<std::string> vWhiteListAddress;
|
||||
|
||||
@@ -587,8 +587,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0;
|
||||
//fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str());
|
||||
if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount )
|
||||
return(NSPV_utxosresp_json(&NSPV_utxosresult));
|
||||
//if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount && filter == NSPV_utxosresult.filter )
|
||||
// return(NSPV_utxosresp_json(&NSPV_utxosresult));
|
||||
if ( skipcount < 0 )
|
||||
skipcount = 0;
|
||||
NSPV_utxosresp_purge(&NSPV_utxosresult);
|
||||
|
||||
@@ -1879,6 +1879,7 @@ void komodo_args(char *argv0)
|
||||
ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0);
|
||||
ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0);
|
||||
ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0);
|
||||
ASSETCHAINS_ADAPTIVEPOW = GetArg("-ac_adaptivepow",0);
|
||||
//fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET);
|
||||
if ( ASSETCHAINS_CBOPRET != 0 )
|
||||
{
|
||||
@@ -2065,7 +2066,7 @@ void komodo_args(char *argv0)
|
||||
fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n");
|
||||
StartShutdown();
|
||||
}
|
||||
if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0)
|
||||
if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 )
|
||||
{
|
||||
fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size());
|
||||
extraptr = extrabuf;
|
||||
@@ -2214,6 +2215,8 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen);
|
||||
{
|
||||
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBMATURITY),(void *)&ASSETCHAINS_CBMATURITY);
|
||||
}
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW != 0 )
|
||||
extraptr[extralen++] = ASSETCHAINS_ADAPTIVEPOW;
|
||||
}
|
||||
|
||||
addn = GetArg("-seednode","");
|
||||
|
||||
@@ -1447,7 +1447,9 @@ void static BitcoinMiner_noeq()
|
||||
HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||
LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED);
|
||||
}
|
||||
|
||||
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 )
|
||||
HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime);
|
||||
|
||||
while (true)
|
||||
{
|
||||
arith_uint256 arNonce = UintToArith256(pblock->nNonce);
|
||||
@@ -1480,7 +1482,9 @@ void static BitcoinMiner_noeq()
|
||||
}
|
||||
else if ( ASSETCHAINS_STAKED == 100 && Mining_height > 100 )
|
||||
hashTarget = HASHTarget;
|
||||
|
||||
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 )
|
||||
hashTarget = HASHTarget_POW;
|
||||
|
||||
// for speed check NONCEMASK at a time
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
@@ -1816,6 +1820,8 @@ void static BitcoinMiner()
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED);
|
||||
}
|
||||
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 )
|
||||
HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime);
|
||||
gotinvalid = 0;
|
||||
while (true)
|
||||
{
|
||||
@@ -1843,6 +1849,8 @@ void static BitcoinMiner()
|
||||
arith_uint256 hashTarget;
|
||||
if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 )
|
||||
hashTarget = HASHTarget_POW;
|
||||
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 )
|
||||
hashTarget = HASHTarget_POW;
|
||||
else hashTarget = HASHTarget;
|
||||
std::function<bool(std::vector<unsigned char>)> validBlock =
|
||||
#ifdef ENABLE_WALLET
|
||||
@@ -2032,6 +2040,8 @@ void static BitcoinMiner()
|
||||
// Update nNonce and nTime
|
||||
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
||||
pblock->nBits = savebits;
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW != 0 )
|
||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||
/*if ( NOTARY_PUBKEY33[0] == 0 )
|
||||
{
|
||||
int32_t percPoS;
|
||||
|
||||
@@ -453,6 +453,8 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t
|
||||
arith_uint256 bnMaxPoSdiff;
|
||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||
}
|
||||
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 )
|
||||
bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime);
|
||||
// Check proof of work matches claimed amount
|
||||
if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user