Merge remote-tracking branch 'origin/jl777' into snapshot
This commit is contained in:
@@ -11,6 +11,7 @@ using namespace std;
|
||||
* CChain implementation
|
||||
*/
|
||||
void CChain::SetTip(CBlockIndex *pindex) {
|
||||
lastTip = pindex;
|
||||
if (pindex == NULL) {
|
||||
vChain.clear();
|
||||
return;
|
||||
|
||||
@@ -416,6 +416,7 @@ public:
|
||||
class CChain {
|
||||
private:
|
||||
std::vector<CBlockIndex*> vChain;
|
||||
CBlockIndex *lastTip;
|
||||
|
||||
public:
|
||||
/** Returns the index entry for the genesis block of this chain, or NULL if none. */
|
||||
@@ -427,6 +428,11 @@ public:
|
||||
CBlockIndex *Tip() const {
|
||||
return vChain.size() > 0 ? vChain[vChain.size() - 1] : NULL;
|
||||
}
|
||||
|
||||
/** Returns the last tip of the chain, or NULL if none. */
|
||||
CBlockIndex *LastTip() const {
|
||||
return vChain.size() > 0 ? lastTip : NULL;
|
||||
}
|
||||
|
||||
/** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */
|
||||
CBlockIndex *operator[](int nHeight) const {
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
#define ZCASH_DEPRECATION_H
|
||||
|
||||
// Deprecation policy:
|
||||
// * Shut down 16 weeks' worth of blocks after the estimated release block height.
|
||||
// * A warning is shown during the 2 weeks' worth of blocks prior to shut down.
|
||||
static const int APPROX_RELEASE_HEIGHT = 800000;
|
||||
// * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height.
|
||||
// * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down.
|
||||
static const int WEEKS_UNTIL_DEPRECATION = 52;
|
||||
static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 24);
|
||||
static const int DEPRECATION_HEIGHT = 1400000;
|
||||
static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60);
|
||||
|
||||
// Number of blocks before deprecation to warn users
|
||||
static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months
|
||||
|
||||
@@ -823,7 +823,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
komodo_event_rewind(sp,symbol,pindex->nHeight);
|
||||
komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0);
|
||||
}
|
||||
komodo_currentheight_set(chainActive.Tip()->nHeight);
|
||||
komodo_currentheight_set(chainActive.LastTip()->nHeight);
|
||||
if ( pindex != 0 )
|
||||
{
|
||||
height = pindex->nHeight;
|
||||
@@ -907,7 +907,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
#else
|
||||
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
|
||||
#endif
|
||||
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.Tip()->GetBlockTime());
|
||||
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime());
|
||||
if ( 0 && i > 0 )
|
||||
{
|
||||
for (k=0; k<len; k++)
|
||||
|
||||
@@ -751,8 +751,8 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex)
|
||||
|
||||
uint32_t komodo_chainactive_timestamp()
|
||||
{
|
||||
if ( chainActive.Tip() != 0 )
|
||||
return((uint32_t)chainActive.Tip()->GetBlockTime());
|
||||
if ( chainActive.LastTip() != 0 )
|
||||
return((uint32_t)chainActive.LastTip()->GetBlockTime());
|
||||
else return(0);
|
||||
}
|
||||
|
||||
@@ -760,11 +760,11 @@ CBlockIndex *komodo_chainactive(int32_t height)
|
||||
{
|
||||
if ( chainActive.Tip() != 0 )
|
||||
{
|
||||
if ( height <= chainActive.Tip()->nHeight )
|
||||
if ( height <= chainActive.LastTip()->nHeight )
|
||||
return(chainActive[height]);
|
||||
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight);
|
||||
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->nHeight);
|
||||
}
|
||||
//fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height);
|
||||
//fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height);
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -994,7 +994,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in
|
||||
int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash)
|
||||
{
|
||||
int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex;
|
||||
if ( (pindex= chainActive.Tip()) == 0 )
|
||||
if ( (pindex= chainActive.LastTip()) == 0 )
|
||||
return(-1);
|
||||
notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid);
|
||||
*notarized_heightp = notarized_height;
|
||||
@@ -1036,7 +1036,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_
|
||||
*valuep = tx.vout[n].nValue;
|
||||
*txheightp = pindex->nHeight;
|
||||
*txheighttimep = pindex->nTime;
|
||||
if ( *tiptimep == 0 && (tipindex= chainActive.Tip()) != 0 )
|
||||
if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
*tiptimep = (uint32_t)tipindex->nTime;
|
||||
locktime = tx.nLockTime;
|
||||
//fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep);
|
||||
@@ -1069,7 +1069,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp)
|
||||
if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 )
|
||||
*kmdheightp = sp->CURRENT_HEIGHT;
|
||||
else *kmdheightp = 0;
|
||||
if ( (pindex= chainActive.Tip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() )
|
||||
if ( (pindex= chainActive.LastTip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() )
|
||||
return(1);
|
||||
else return(0);
|
||||
}
|
||||
@@ -1185,14 +1185,30 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout)
|
||||
{
|
||||
bits256 addrhash;
|
||||
vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address));
|
||||
memcpy(&hashbuf[100],&addrhash,sizeof(addrhash));
|
||||
memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid));
|
||||
memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout));
|
||||
vcalc_sha256(0,(uint8_t *)hashp,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout));
|
||||
return(addrhash.uints[0]);
|
||||
}
|
||||
|
||||
uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr)
|
||||
{
|
||||
bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage;
|
||||
txtime = komodo_txtime2(&value,txid,vout,address);
|
||||
if ( validateflag == 0 && blocktime < GetAdjustedTime() )
|
||||
blocktime = GetAdjustedTime();
|
||||
if ( blocktime < prevtime+3 )
|
||||
blocktime = prevtime+3;
|
||||
if ( validateflag == 0 )
|
||||
{
|
||||
//fprintf(stderr,"blocktime.%u -> ",blocktime);
|
||||
if ( blocktime < prevtime+3 )
|
||||
blocktime = prevtime+3;
|
||||
if ( blocktime < GetAdjustedTime()-60 )
|
||||
blocktime = GetAdjustedTime()+30;
|
||||
//fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime);
|
||||
}
|
||||
if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 )
|
||||
{
|
||||
//fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime);
|
||||
@@ -1212,8 +1228,10 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
|
||||
memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid));
|
||||
memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout));
|
||||
vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout));
|
||||
for (iter=0; iter<120; iter++)
|
||||
for (iter=0; iter<180; iter++)
|
||||
{
|
||||
if ( blocktime+iter+segid*2 < txtime+minage )
|
||||
continue;
|
||||
diff = (iter + blocktime - txtime - minage);
|
||||
if ( diff < 0 )
|
||||
diff = 60;
|
||||
@@ -1224,18 +1242,19 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
|
||||
}
|
||||
if ( iter > 0 )
|
||||
diff += segid*2;
|
||||
if ( blocktime+iter+segid*2 < txtime+minage )
|
||||
continue;
|
||||
coinage = (value * diff);
|
||||
if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 )
|
||||
coinage *= ((blocktime+iter+segid*2) - (prevtime+60));
|
||||
coinage256 = arith_uint256(coinage+1);
|
||||
hashval = ratio * (UintToArith256(hash) / coinage256);
|
||||
if ( nHeight >= 900 )
|
||||
if ( nHeight >= 900 && nHeight < 916 )
|
||||
hashval = (hashval / coinage256);
|
||||
if ( hashval <= bnTarget )
|
||||
{
|
||||
winner = 1;
|
||||
if ( validateflag == 0 )
|
||||
{
|
||||
//fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid);
|
||||
blocktime += iter;
|
||||
blocktime += segid * 2;
|
||||
}
|
||||
@@ -1395,10 +1414,11 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
|
||||
if ( prevtime != 0 )
|
||||
{
|
||||
if ( komodo_isPoS(pblock) != 0 )
|
||||
eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)"");
|
||||
eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)"");
|
||||
if ( eligible == 0 || eligible > pblock->nTime )
|
||||
{
|
||||
fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime));
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime));
|
||||
} else isPoS = 1;
|
||||
}
|
||||
if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx
|
||||
@@ -1537,7 +1557,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
|
||||
int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock)
|
||||
{
|
||||
int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0;
|
||||
CTxDestination address; int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0;
|
||||
n = pblock->vtx.size();
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
@@ -1562,10 +1582,17 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock)
|
||||
if ( (m= tx.vout.size()) > 0 )
|
||||
{
|
||||
for (j=0; j<m-1; j++)
|
||||
voutsum += tx.vout[j].nValue;
|
||||
{
|
||||
if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 )
|
||||
voutsum += tx.vout[j].nValue;
|
||||
else printf("skip %.8f -> %s\n",dstr(tx.vout[j].nValue),CBitcoinAddress(address).ToString().c_str());
|
||||
}
|
||||
script = (uint8_t *)tx.vout[j].scriptPubKey.data();
|
||||
if ( script == 0 || script[0] != 0x6a )
|
||||
voutsum += tx.vout[j].nValue;
|
||||
{
|
||||
if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 )
|
||||
voutsum += tx.vout[j].nValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
*zfundsp = zfunds;
|
||||
|
||||
@@ -1490,7 +1490,7 @@ void komodo_passport_iteration()
|
||||
komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime");
|
||||
if ( (fp= fopen(fname,"wb")) != 0 )
|
||||
{
|
||||
buf[0] = (uint32_t)chainActive.Tip()->nHeight;
|
||||
buf[0] = (uint32_t)chainActive.LastTip()->nHeight;
|
||||
buf[1] = (uint32_t)komodo_longestchain();
|
||||
if ( buf[0] != 0 && buf[0] == buf[1] )
|
||||
{
|
||||
|
||||
@@ -648,7 +648,7 @@ void jumblr_iteration()
|
||||
free(retstr);
|
||||
}
|
||||
}
|
||||
height = (int32_t)chainActive.Tip()->nHeight;
|
||||
height = (int32_t)chainActive.LastTip()->nHeight;
|
||||
if ( time(NULL) < lasttime+40 )
|
||||
return;
|
||||
lasttime = (uint32_t)time(NULL);
|
||||
|
||||
@@ -637,13 +637,13 @@ uint64_t komodo_paxpriceB(uint64_t seed,int32_t height,char *base,char *rel,uint
|
||||
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume)
|
||||
{
|
||||
int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0;
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight )
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && height > chainActive.LastTip()->nHeight )
|
||||
{
|
||||
if ( height < 100000000 )
|
||||
{
|
||||
static uint32_t counter;
|
||||
if ( counter++ < 3 )
|
||||
printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight);
|
||||
printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.LastTip()->nHeight);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
63
src/main.cpp
63
src/main.cpp
@@ -1277,7 +1277,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
}
|
||||
|
||||
auto verifier = libzcash::ProofVerifier::Strict();
|
||||
if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 )
|
||||
if ( komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 )
|
||||
{
|
||||
//fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n");
|
||||
return error("AcceptToMemoryPool: komodo_validate_interest failed");
|
||||
@@ -1407,7 +1407,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
// Bring the best block into scope
|
||||
view.GetBestBlock();
|
||||
|
||||
nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime);
|
||||
nValueIn = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime);
|
||||
if ( 0 && interest != 0 )
|
||||
fprintf(stderr,"add interest %.8f\n",(double)interest/COIN);
|
||||
// we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool
|
||||
@@ -1899,7 +1899,7 @@ void CheckForkWarningConditions()
|
||||
if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 288)
|
||||
pindexBestForkTip = NULL;
|
||||
|
||||
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6)))
|
||||
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.LastTip()->nChainWork + (GetBlockProof(*chainActive.LastTip()) * 6)))
|
||||
{
|
||||
if (!fLargeWorkForkFound && pindexBestForkBase)
|
||||
{
|
||||
@@ -1934,7 +1934,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip)
|
||||
AssertLockHeld(cs_main);
|
||||
// If we are on a fork that is sufficiently large, set a warning flag
|
||||
CBlockIndex* pfork = pindexNewForkTip;
|
||||
CBlockIndex* plonger = chainActive.Tip();
|
||||
CBlockIndex* plonger = chainActive.LastTip();
|
||||
while (pfork && pfork != plonger)
|
||||
{
|
||||
while (plonger && plonger->nHeight > pfork->nHeight)
|
||||
@@ -1991,7 +1991,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
|
||||
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight,
|
||||
log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S",
|
||||
pindexNew->GetBlockTime()));
|
||||
CBlockIndex *tip = chainActive.Tip();
|
||||
CBlockIndex *tip = chainActive.LastTip();
|
||||
assert (tip);
|
||||
LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", __func__,
|
||||
tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0),
|
||||
@@ -2119,14 +2119,14 @@ namespace Consensus {
|
||||
// Check for negative or overflow input values
|
||||
nValueIn += coins->vout[prevout.n].nValue;
|
||||
#ifdef KOMODO_ENABLE_INTEREST
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 )
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 )
|
||||
{
|
||||
if ( coins->vout[prevout.n].nValue >= 10*COIN )
|
||||
{
|
||||
int64_t interest; int32_t txheight; uint32_t locktime;
|
||||
if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue,(int32_t)nSpendHeight-1)) != 0 )
|
||||
{
|
||||
//fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime);
|
||||
//fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.LastTip()->nTime);
|
||||
nValueIn += interest;
|
||||
}
|
||||
}
|
||||
@@ -2876,7 +2876,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||
|
||||
if (!tx.IsCoinBase())
|
||||
{
|
||||
nFees += view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut();
|
||||
nFees += view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime) - tx.GetValueOut();
|
||||
sum += interest;
|
||||
|
||||
std::vector<CScriptCheck> vChecks;
|
||||
@@ -3203,10 +3203,19 @@ void static UpdateTip(CBlockIndex *pindexNew) {
|
||||
nTimeBestReceived = GetTime();
|
||||
mempool.AddTransactionsUpdated(1);
|
||||
KOMODO_NEWBLOCKS++;
|
||||
double progress;
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 ) {
|
||||
progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip());
|
||||
} else {
|
||||
int32_t longestchain = komodo_longestchain();
|
||||
progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0;
|
||||
}
|
||||
|
||||
LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__,
|
||||
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx,
|
||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
|
||||
Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
|
||||
chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(),
|
||||
log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.LastTip()->nChainTx,
|
||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress,
|
||||
pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
|
||||
|
||||
cvBlockChange.notify_all();
|
||||
|
||||
@@ -3454,7 +3463,7 @@ static void PruneBlockIndexCandidates() {
|
||||
// Note that we can't delete the current block itself, as we may need to return to it later in case a
|
||||
// reorganization to a better block fails.
|
||||
std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexCandidates.begin();
|
||||
while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) {
|
||||
while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.LastTip())) {
|
||||
setBlockIndexCandidates.erase(it++);
|
||||
}
|
||||
// Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates.
|
||||
@@ -3506,8 +3515,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
|
||||
if ( KOMODO_REWIND != 0 )
|
||||
{
|
||||
CBlockIndex *tipindex;
|
||||
fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.Tip()->nHeight,KOMODO_REWIND);
|
||||
while ( KOMODO_REWIND > 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->nHeight > KOMODO_REWIND )
|
||||
fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.LastTip()->nHeight,KOMODO_REWIND);
|
||||
while ( KOMODO_REWIND > 0 && (tipindex= chainActive.LastTip()) != 0 && tipindex->nHeight > KOMODO_REWIND )
|
||||
{
|
||||
fBlocksDisconnected = true;
|
||||
fprintf(stderr,"%d ",(int32_t)tipindex->nHeight);
|
||||
@@ -3921,9 +3930,9 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,
|
||||
for (i=31; i>=0; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- CheckBlockHeader\n");
|
||||
if ( chainActive.Tip() != 0 )
|
||||
if ( chainActive.LastTip() != 0 )
|
||||
{
|
||||
hash = chainActive.Tip()->GetBlockHash();
|
||||
hash = chainActive.LastTip()->GetBlockHash();
|
||||
for (i=31; i>=0; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- chainTip\n");
|
||||
@@ -4102,7 +4111,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
|
||||
// Don't accept any forks from the main chain prior to last checkpoint
|
||||
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints());
|
||||
int32_t notarized_height;
|
||||
if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 )
|
||||
if ( nHeight == 1 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight > 1 )
|
||||
{
|
||||
CBlockIndex *heightblock = chainActive[nHeight];
|
||||
if ( heightblock != 0 && heightblock->GetBlockHash() == hash )
|
||||
@@ -4439,8 +4448,8 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
|
||||
auto verifier = libzcash::ProofVerifier::Disabled();
|
||||
hash = pblock->GetHash();
|
||||
|
||||
if ( chainActive.Tip() != 0 )
|
||||
komodo_currentheight_set(chainActive.Tip()->nHeight);
|
||||
if ( chainActive.LastTip() != 0 )
|
||||
komodo_currentheight_set(chainActive.LastTip()->nHeight);
|
||||
checked = CheckBlock(&futureblock,height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
@@ -4858,11 +4867,21 @@ bool static LoadBlockIndexDB()
|
||||
it->second->hashAnchorEnd = pcoinsTip->GetBestAnchor();
|
||||
|
||||
PruneBlockIndexCandidates();
|
||||
|
||||
double progress;
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 ) {
|
||||
progress = Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip());
|
||||
} else {
|
||||
int32_t longestchain = komodo_longestchain();
|
||||
// TODO: komodo_longestchain does not have the data it needs at the time LoadBlockIndexDB
|
||||
// runs, which makes it return 0, so we guess 50% for now
|
||||
progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 0.5;
|
||||
}
|
||||
|
||||
LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__,
|
||||
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(),
|
||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
|
||||
Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()));
|
||||
chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(),
|
||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()),
|
||||
progress);
|
||||
|
||||
EnforceNodeDeprecation(chainActive.Height(), true);
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ int printStats(bool mining)
|
||||
{
|
||||
LOCK2(cs_main, cs_vNodes);
|
||||
height = chainActive.Height();
|
||||
tipmediantime = chainActive.Tip()->GetMedianTimePast();
|
||||
tipmediantime = chainActive.LastTip()->GetMedianTimePast();
|
||||
connections = vNodes.size();
|
||||
netsolps = GetNetworkHashPS(120, -1);
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
|
||||
{
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||
CBlockIndex* pindexPrev = chainActive.LastTip();
|
||||
const int nHeight = pindexPrev->nHeight + 1;
|
||||
uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus());
|
||||
pblock->nTime = GetAdjustedTime();
|
||||
@@ -334,7 +334,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
//fprintf(stderr,"dont have inputs\n");
|
||||
continue;
|
||||
}
|
||||
CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut();
|
||||
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut();
|
||||
|
||||
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||
@@ -400,14 +400,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 )
|
||||
{
|
||||
CAmount txfees = 0;
|
||||
if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-57 )
|
||||
return(0);
|
||||
//if ( (int32_t)chainActive.LastTip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 )
|
||||
// return(0);
|
||||
pblock->vtx.push_back(txStaked);
|
||||
pblocktemplate->vTxFees.push_back(txfees);
|
||||
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked));
|
||||
nFees += txfees;
|
||||
pblock->nTime = blocktime;
|
||||
//printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->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");
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if ( ASSETCHAINS_STAKED == 0 )
|
||||
{
|
||||
CValidationState state;
|
||||
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false))
|
||||
@@ -640,19 +640,19 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
#endif // ENABLE_WALLET
|
||||
{
|
||||
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.LastTip()->nHeight+1);
|
||||
|
||||
// Found a solution
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
|
||||
if (pblock->hashPrevBlock != chainActive.LastTip()->GetBlockHash())
|
||||
{
|
||||
uint256 hash; int32_t i;
|
||||
hash = pblock->hashPrevBlock;
|
||||
for (i=31; i>=0; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- prev (stale)\n");
|
||||
hash = chainActive.Tip()->GetBlockHash();
|
||||
hash = chainActive.LastTip()->GetBlockHash();
|
||||
for (i=31; i>=0; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- chainTip (stale)\n");
|
||||
@@ -680,7 +680,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
|
||||
// Process this block the same as if we had received it from another node
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(1,chainActive.Tip()->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");
|
||||
|
||||
TrackMinedBlock(pblock->GetHash());
|
||||
@@ -718,13 +718,13 @@ void static BitcoinMiner()
|
||||
unsigned int n = chainparams.EquihashN();
|
||||
unsigned int k = chainparams.EquihashK();
|
||||
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
|
||||
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 &&
|
||||
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.LastTip()->nHeight != 235300 &&
|
||||
{
|
||||
sleep(1);
|
||||
if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 )
|
||||
break;
|
||||
}
|
||||
komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime());
|
||||
komodo_chosennotary(¬aryid,chainActive.LastTip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime());
|
||||
if ( notaryid != My_notaryid )
|
||||
My_notaryid = notaryid;
|
||||
std::string solver;
|
||||
@@ -750,9 +750,9 @@ void static BitcoinMiner()
|
||||
fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str());
|
||||
while (true)
|
||||
{
|
||||
if (chainparams.MiningRequiresPeers()) //chainActive.Tip()->nHeight != 235300 &&
|
||||
if (chainparams.MiningRequiresPeers()) //chainActive.LastTip()->nHeight != 235300 &&
|
||||
{
|
||||
//if ( ASSETCHAINS_SEED != 0 && chainActive.Tip()->nHeight < 100 )
|
||||
//if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->nHeight < 100 )
|
||||
// break;
|
||||
// Busy-wait for the network to come online so we don't waste time mining
|
||||
// on an obsolete chain. In regtest mode we expect to fly solo.
|
||||
@@ -776,7 +776,7 @@ void static BitcoinMiner()
|
||||
// Create new block
|
||||
//
|
||||
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||
CBlockIndex* pindexPrev = chainActive.LastTip();
|
||||
if ( Mining_height != pindexPrev->nHeight+1 )
|
||||
{
|
||||
Mining_height = pindexPrev->nHeight+1;
|
||||
@@ -832,8 +832,9 @@ void static BitcoinMiner()
|
||||
// Search
|
||||
//
|
||||
uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime();
|
||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
||||
savebits = pblock->nBits;
|
||||
HASHTarget = arith_uint256().SetCompact(pblock->nBits);
|
||||
HASHTarget = arith_uint256().SetCompact(savebits);
|
||||
roundrobin_delay = ROUNDROBIN_DELAY;
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 )
|
||||
{
|
||||
@@ -951,8 +952,8 @@ void static BitcoinMiner()
|
||||
fprintf(stderr," POW\n");*/
|
||||
if ( h > hashTarget )
|
||||
{
|
||||
if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 )
|
||||
sleep(1);
|
||||
//if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 )
|
||||
// sleep(1);
|
||||
return false;
|
||||
}
|
||||
if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() )
|
||||
@@ -961,7 +962,7 @@ void static BitcoinMiner()
|
||||
while ( GetAdjustedTime() < B.nTime-2 )
|
||||
{
|
||||
sleep(1);
|
||||
if ( chainActive.Tip()->nHeight >= Mining_height )
|
||||
if ( chainActive.LastTip()->nHeight >= Mining_height )
|
||||
{
|
||||
fprintf(stderr,"new block arrived\n");
|
||||
return(false);
|
||||
@@ -980,19 +981,18 @@ void static BitcoinMiner()
|
||||
else
|
||||
{
|
||||
while ( B.nTime-57 > GetAdjustedTime() )
|
||||
sleep(1);
|
||||
/*if ( Mining_height < 6000 )
|
||||
{
|
||||
while ( B.nTime > GetAdjustedTime() )
|
||||
sleep(1);
|
||||
}*/
|
||||
sleep(1);
|
||||
if ( chainActive.LastTip()->nHeight >= Mining_height )
|
||||
return(false);
|
||||
}
|
||||
uint256 tmp = B.GetHash();
|
||||
int32_t z; for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]);
|
||||
fprintf(stderr," mined %s block %d!\n",ASSETCHAINS_SYMBOL,Mining_height);
|
||||
}
|
||||
CValidationState state;
|
||||
if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false))
|
||||
if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false))
|
||||
{
|
||||
h = UintToArith256(B.GetHash());
|
||||
for (z=31; z>=0; z--)
|
||||
@@ -1112,7 +1112,7 @@ void static BitcoinMiner()
|
||||
fprintf(stderr,"timeout, break\n");
|
||||
break;
|
||||
}
|
||||
if ( pindexPrev != chainActive.Tip() )
|
||||
if ( pindexPrev != chainActive.LastTip() )
|
||||
{
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"Tip advanced, break\n");
|
||||
|
||||
@@ -530,7 +530,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
// serialize data
|
||||
// use exact same output as mentioned in Bip64
|
||||
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs;
|
||||
ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs;
|
||||
string ssGetUTXOResponseString = ssGetUTXOResponse.str();
|
||||
|
||||
req->WriteHeader("Content-Type", "application/octet-stream");
|
||||
@@ -540,7 +540,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
|
||||
case RF_HEX: {
|
||||
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs;
|
||||
ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs;
|
||||
string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n";
|
||||
|
||||
req->WriteHeader("Content-Type", "text/plain");
|
||||
@@ -554,7 +554,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
// pack in some essentials
|
||||
// use more or less the same output as mentioned in Bip64
|
||||
objGetUTXOResponse.push_back(Pair("chainHeight", chainActive.Height()));
|
||||
objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.Tip()->GetBlockHash().GetHex()));
|
||||
objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.LastTip()->GetBlockHash().GetHex()));
|
||||
objGetUTXOResponse.push_back(Pair("bitmap", bitmapStringRepresentation));
|
||||
|
||||
UniValue utxos(UniValue::VARR);
|
||||
|
||||
@@ -38,10 +38,10 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul
|
||||
// minimum difficulty = 1.0.
|
||||
if (blockindex == NULL)
|
||||
{
|
||||
if (chainActive.Tip() == NULL)
|
||||
if (chainActive.LastTip() == NULL)
|
||||
return 1.0;
|
||||
else
|
||||
blockindex = chainActive.Tip();
|
||||
blockindex = chainActive.LastTip();
|
||||
}
|
||||
|
||||
uint32_t bits;
|
||||
@@ -326,7 +326,7 @@ UniValue getbestblockhash(const UniValue& params, bool fHelp)
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
return chainActive.Tip()->GetBlockHash().GetHex();
|
||||
return chainActive.LastTip()->GetBlockHash().GetHex();
|
||||
}
|
||||
|
||||
UniValue getdifficulty(const UniValue& params, bool fHelp)
|
||||
@@ -803,13 +803,13 @@ UniValue kvsearch(const UniValue& params, bool fHelp)
|
||||
if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 )
|
||||
{
|
||||
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
|
||||
ret.push_back(Pair("currentheight", (int64_t)chainActive.Tip()->nHeight));
|
||||
ret.push_back(Pair("currentheight", (int64_t)chainActive.LastTip()->nHeight));
|
||||
ret.push_back(Pair("key",params[0].get_str()));
|
||||
ret.push_back(Pair("keylen",keylen));
|
||||
if ( keylen < sizeof(key) )
|
||||
{
|
||||
memcpy(key,params[0].get_str().c_str(),keylen);
|
||||
if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 )
|
||||
if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&flags,&height,value,key,keylen)) >= 0 )
|
||||
{
|
||||
std::string val; char *valuestr;
|
||||
val.resize(valuesize);
|
||||
@@ -837,7 +837,7 @@ UniValue minerids(const UniValue& params, bool fHelp)
|
||||
LOCK(cs_main);
|
||||
int32_t height = atoi(params[0].get_str().c_str());
|
||||
if ( height <= 0 )
|
||||
height = chainActive.Tip()->nHeight;
|
||||
height = chainActive.LastTip()->nHeight;
|
||||
else
|
||||
{
|
||||
CBlockIndex *pblockindex = chainActive[height];
|
||||
@@ -899,8 +899,8 @@ UniValue notaries(const UniValue& params, bool fHelp)
|
||||
else timestamp = (uint32_t)time(NULL);
|
||||
if ( height < 0 )
|
||||
{
|
||||
height = chainActive.Tip()->nHeight;
|
||||
timestamp = chainActive.Tip()->GetBlockTime();
|
||||
height = chainActive.LastTip()->nHeight;
|
||||
timestamp = chainActive.LastTip()->GetBlockTime();
|
||||
}
|
||||
else if ( params.size() < 2 )
|
||||
{
|
||||
@@ -988,7 +988,7 @@ UniValue paxprice(const UniValue& params, bool fHelp)
|
||||
std::string rel = params[1].get_str();
|
||||
int32_t height;
|
||||
if ( params.size() == 2 )
|
||||
height = chainActive.Tip()->nHeight;
|
||||
height = chainActive.LastTip()->nHeight;
|
||||
else height = atoi(params[2].get_str().c_str());
|
||||
//if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 )
|
||||
basevolume = 100000;
|
||||
@@ -1280,10 +1280,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("chain", Params().NetworkIDString()));
|
||||
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
||||
obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
|
||||
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
|
||||
obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex()));
|
||||
obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty()));
|
||||
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
|
||||
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
|
||||
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip())));
|
||||
obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex()));
|
||||
obj.push_back(Pair("pruned", fPruneMode));
|
||||
|
||||
ZCIncrementalMerkleTree tree;
|
||||
@@ -1294,7 +1294,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("commitments", tree.size()));
|
||||
#endif
|
||||
|
||||
CBlockIndex* tip = chainActive.Tip();
|
||||
CBlockIndex* tip = chainActive.LastTip();
|
||||
UniValue valuePools(UniValue::VARR);
|
||||
valuePools.push_back(ValuePoolDesc("sprout", tip->nChainSproutValue, boost::none));
|
||||
obj.push_back(Pair("valuePools", valuePools));
|
||||
@@ -1319,7 +1319,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
|
||||
if (fPruneMode)
|
||||
{
|
||||
CBlockIndex *block = chainActive.Tip();
|
||||
CBlockIndex *block = chainActive.LastTip();
|
||||
while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA))
|
||||
block = block->pprev;
|
||||
|
||||
@@ -1394,7 +1394,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
|
||||
}
|
||||
|
||||
// Always report the currently active tip.
|
||||
setTips.insert(chainActive.Tip());
|
||||
setTips.insert(chainActive.LastTip());
|
||||
|
||||
/* Construct the output array. */
|
||||
UniValue res(UniValue::VARR); const CBlockIndex *forked;
|
||||
|
||||
@@ -39,7 +39,7 @@ using namespace std;
|
||||
* If 'height' is nonnegative, compute the estimate at the time when a given block was found.
|
||||
*/
|
||||
int64_t GetNetworkHashPS(int lookup, int height) {
|
||||
CBlockIndex *pb = chainActive.Tip();
|
||||
CBlockIndex *pb = chainActive.LastTip();
|
||||
|
||||
if (height >= 0 && height < chainActive.Height())
|
||||
pb = chainActive[height];
|
||||
@@ -224,7 +224,7 @@ UniValue generate(const UniValue& params, bool fHelp)
|
||||
CBlock *pblock = &pblocktemplate->block;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
|
||||
IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce);
|
||||
}
|
||||
|
||||
// Hash state
|
||||
@@ -268,7 +268,7 @@ UniValue generate(const UniValue& params, bool fHelp)
|
||||
}
|
||||
endloop:
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||
if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
|
||||
++nHeight;
|
||||
blockHashes.push_back(pblock->GetHash().GetHex());
|
||||
@@ -550,7 +550,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
return "duplicate-inconclusive";
|
||||
}
|
||||
|
||||
CBlockIndex* const pindexPrev = chainActive.Tip();
|
||||
CBlockIndex* const pindexPrev = chainActive.LastTip();
|
||||
// TestBlockValidity only supports blocks built on the current Tip
|
||||
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
|
||||
return "inconclusive-not-best-prevblk";
|
||||
@@ -589,7 +589,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
else
|
||||
{
|
||||
// NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier
|
||||
hashWatchedChain = chainActive.Tip()->GetBlockHash();
|
||||
hashWatchedChain = chainActive.LastTip()->GetBlockHash();
|
||||
nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
checktxtime = boost::get_system_time() + boost::posix_time::minutes(1);
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(csBestBlock);
|
||||
while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning())
|
||||
while (chainActive.LastTip()->GetBlockHash() == hashWatchedChain && IsRPCRunning())
|
||||
{
|
||||
if (!cvBlockChange.timed_wait(lock, checktxtime))
|
||||
{
|
||||
@@ -621,7 +621,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
static CBlockIndex* pindexPrev;
|
||||
static int64_t nStart;
|
||||
static CBlockTemplate* pblocktemplate;
|
||||
if (pindexPrev != chainActive.Tip() ||
|
||||
if (pindexPrev != chainActive.LastTip() ||
|
||||
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5))
|
||||
{
|
||||
// Clear pindexPrev so future calls make a new block, despite any failures from here on
|
||||
@@ -629,7 +629,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
|
||||
// Store the pindexBest used before CreateNewBlockWithKey, to avoid races
|
||||
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
CBlockIndex* pindexPrevNew = chainActive.Tip();
|
||||
CBlockIndex* pindexPrevNew = chainActive.LastTip();
|
||||
nStart = GetTime();
|
||||
|
||||
// Create new block
|
||||
@@ -640,7 +640,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
CReserveKey reservekey(pwalletMain);
|
||||
pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1,KOMODO_MAXGPUCOUNT);
|
||||
pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.LastTip()->nHeight+1,KOMODO_MAXGPUCOUNT);
|
||||
#else
|
||||
pblocktemplate = CreateNewBlockWithKey();
|
||||
#endif
|
||||
@@ -693,7 +693,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
// Correct this if GetBlockTemplate changes the order
|
||||
// entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue));
|
||||
//}
|
||||
CAmount nReward = GetBlockSubsidy(chainActive.Tip()->nHeight+1, Params().GetConsensus());
|
||||
CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->nHeight+1, Params().GetConsensus());
|
||||
entry.push_back(Pair("coinbasevalue", nReward));
|
||||
entry.push_back(Pair("required", true));
|
||||
txCoinbase = entry;
|
||||
@@ -726,7 +726,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
result.push_back(Pair("coinbaseaux", aux));
|
||||
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
|
||||
}
|
||||
result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
|
||||
result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
|
||||
result.push_back(Pair("target", hashTarget.GetHex()));
|
||||
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
|
||||
result.push_back(Pair("mutable", aMutable));
|
||||
@@ -809,7 +809,7 @@ UniValue submitblock(const UniValue& params, bool fHelp)
|
||||
CValidationState state;
|
||||
submitblock_StateCatcher sc(block.GetHash());
|
||||
RegisterValidationInterface(&sc);
|
||||
bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL);
|
||||
bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, &block, true, NULL);
|
||||
UnregisterValidationInterface(&sc);
|
||||
if (fBlockPresent)
|
||||
{
|
||||
|
||||
@@ -133,8 +133,8 @@ UniValue getinfo(const UniValue& params, bool fHelp)
|
||||
//fprintf(stderr,"after longestchain %u\n",(uint32_t)time(NULL));
|
||||
obj.push_back(Pair("longestchain", longestchain));
|
||||
obj.push_back(Pair("timeoffset", GetTimeOffset()));
|
||||
if ( chainActive.Tip() != 0 )
|
||||
obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime));
|
||||
if ( chainActive.LastTip() != 0 )
|
||||
obj.push_back(Pair("tiptime", (int)chainActive.LastTip()->nTime));
|
||||
obj.push_back(Pair("connections", (int)vNodes.size()));
|
||||
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string())));
|
||||
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
||||
@@ -152,7 +152,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||
{
|
||||
char pubkeystr[65]; int32_t notaryid;
|
||||
if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight,komodo_chainactive_timestamp())) >= 0 )
|
||||
if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->nHeight,komodo_chainactive_timestamp())) >= 0 )
|
||||
{
|
||||
obj.push_back(Pair("notaryid", notaryid));
|
||||
obj.push_back(Pair("pubkey", pubkeystr));
|
||||
@@ -826,7 +826,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
|
||||
result.push_back(Pair("utxos", utxos));
|
||||
|
||||
LOCK(cs_main);
|
||||
result.push_back(Pair("hash", chainActive.Tip()->GetBlockHash().GetHex()));
|
||||
result.push_back(Pair("hash", chainActive.LastTip()->GetBlockHash().GetHex()));
|
||||
result.push_back(Pair("height", (int)chainActive.Height()));
|
||||
return result;
|
||||
} else {
|
||||
|
||||
@@ -179,7 +179,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
|
||||
const CTxOut& txout = tx.vout[i];
|
||||
UniValue out(UniValue::VOBJ);
|
||||
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
|
||||
if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 )
|
||||
if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
{
|
||||
int64_t interest; int32_t txheight; uint32_t locktime;
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->nHeight);
|
||||
|
||||
@@ -437,7 +437,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight)
|
||||
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++)
|
||||
{
|
||||
const CTransaction& tx = it->GetTx();
|
||||
tipindex = chainActive.Tip();
|
||||
tipindex = chainActive.LastTip();
|
||||
if (IsExpiredTx(tx, nBlockHeight) || (ASSETCHAINS_SYMBOL[0] == 0 && tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,0)) < 0)
|
||||
{
|
||||
transactionsToRemove.push_back(tx);
|
||||
|
||||
@@ -278,7 +278,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys
|
||||
if (!file.is_open())
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
|
||||
|
||||
int64_t nTimeBegin = chainActive.Tip()->GetBlockTime();
|
||||
int64_t nTimeBegin = chainActive.LastTip()->GetBlockTime();
|
||||
|
||||
bool fGood = true;
|
||||
|
||||
@@ -364,7 +364,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys
|
||||
file.close();
|
||||
pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI
|
||||
|
||||
CBlockIndex *pindex = chainActive.Tip();
|
||||
CBlockIndex *pindex = chainActive.LastTip();
|
||||
while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200)
|
||||
pindex = pindex->pprev;
|
||||
|
||||
@@ -509,8 +509,8 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys)
|
||||
// produce output
|
||||
file << strprintf("# Wallet dump created by Komodo %s (%s)\n", CLIENT_BUILD, CLIENT_DATE);
|
||||
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
|
||||
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
|
||||
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
|
||||
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.LastTip()->GetBlockHash().ToString());
|
||||
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.LastTip()->GetBlockTime()));
|
||||
file << "\n";
|
||||
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
|
||||
const CKeyID &keyid = it->second;
|
||||
|
||||
@@ -574,7 +574,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp)
|
||||
valuesize = (int32_t)strlen(params[1].get_str().c_str());
|
||||
}
|
||||
memcpy(keyvalue,key,keylen);
|
||||
if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
|
||||
if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
|
||||
{
|
||||
if ( (tmpflags & KOMODO_KVPROTECTED) != 0 )
|
||||
{
|
||||
@@ -599,7 +599,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp)
|
||||
// printf("%02x",((uint8_t *)&sig)[i]);
|
||||
//printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize);
|
||||
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
|
||||
height = chainActive.Tip()->nHeight;
|
||||
height = chainActive.LastTip()->nHeight;
|
||||
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
|
||||
ret.push_back(Pair("owner",refpubkey.GetHex()));
|
||||
ret.push_back(Pair("height", (int64_t)height));
|
||||
@@ -671,7 +671,7 @@ UniValue paxdeposit(const UniValue& params, bool fHelp)
|
||||
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
|
||||
std::string base = params[2].get_str();
|
||||
std::string dest;
|
||||
height = chainActive.Tip()->nHeight;
|
||||
height = chainActive.LastTip()->nHeight;
|
||||
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis )
|
||||
{
|
||||
fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis);
|
||||
@@ -2713,13 +2713,13 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
|
||||
CBlockIndex *tipindex,*pindex = it->second;
|
||||
uint64_t interest; uint32_t locktime; int32_t txheight;
|
||||
if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 )
|
||||
if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
{
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
|
||||
//interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime);
|
||||
entry.push_back(Pair("interest",ValueFromAmount(interest)));
|
||||
}
|
||||
//fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight);
|
||||
//fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight);
|
||||
}
|
||||
entry.push_back(Pair("confirmations",out.nDepth));
|
||||
entry.push_back(Pair("spendable", out.fSpendable));
|
||||
@@ -2746,7 +2746,7 @@ uint64_t komodo_interestsum()
|
||||
{
|
||||
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
|
||||
CBlockIndex *tipindex,*pindex = it->second;
|
||||
if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 )
|
||||
if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
{
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
|
||||
//interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime);
|
||||
@@ -4513,6 +4513,8 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp)
|
||||
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
||||
extern std::string NOTARY_PUBKEY;
|
||||
uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr);
|
||||
int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout);
|
||||
int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n);
|
||||
|
||||
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33)
|
||||
{
|
||||
@@ -4590,10 +4592,96 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33)
|
||||
return(siglen);
|
||||
}
|
||||
|
||||
struct komodo_staking
|
||||
{
|
||||
char address[64];
|
||||
uint256 txid;
|
||||
arith_uint256 hashval;
|
||||
uint64_t nValue;
|
||||
uint32_t segid32,txtime;
|
||||
int32_t vout;
|
||||
CScript scriptPubKey;
|
||||
};
|
||||
|
||||
struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,CScript pk)
|
||||
{
|
||||
uint256 hash; uint32_t segid32; struct komodo_staking *kp;
|
||||
segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout);
|
||||
if ( *numkp >= *maxkp )
|
||||
{
|
||||
*maxkp += 1000;
|
||||
array = (struct komodo_staking *)realloc(array,sizeof(*array) * (*maxkp));
|
||||
}
|
||||
kp = &array[(*numkp)++];
|
||||
memset(kp,0,sizeof(*kp));
|
||||
strcpy(kp->address,address);
|
||||
kp->txid = txid;
|
||||
kp->vout = vout;
|
||||
kp->hashval = UintToArith256(hash);
|
||||
kp->txtime = txtime;
|
||||
kp->segid32 = segid32;
|
||||
kp->nValue = nValue;
|
||||
kp->scriptPubKey = pk;
|
||||
return(array);
|
||||
}
|
||||
|
||||
arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uint32_t blocktime,int32_t iter,int32_t minage,int32_t segid,int32_t nHeight,uint32_t prevtime)
|
||||
{
|
||||
int32_t diff; uint64_t coinage; arith_uint256 coinage256,hashval;
|
||||
diff = (iter + blocktime - kp->txtime - minage);
|
||||
if ( diff < 0 )
|
||||
diff = 60;
|
||||
else if ( diff > 3600*24*30 )
|
||||
diff = 3600*24*30;
|
||||
if ( iter > 0 )
|
||||
diff += segid*2;
|
||||
coinage = ((uint64_t)kp->nValue/COIN * diff);
|
||||
if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 )
|
||||
coinage *= ((blocktime+iter+segid*2) - (prevtime+60));
|
||||
coinage256 = arith_uint256(coinage+1);
|
||||
hashval = ratio * (kp->hashval / coinage256);
|
||||
if ( nHeight >= 900 && nHeight < 916 )
|
||||
hashval = (hashval / coinage256);
|
||||
return(hashval);
|
||||
}
|
||||
|
||||
uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage,uint8_t *hashbuf)
|
||||
{
|
||||
int32_t maxiters = 180; uint256 hash;
|
||||
int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256;
|
||||
komodo_stakehash(&hash,kp->address,hashbuf,kp->txid,kp->vout);
|
||||
kp->hashval = UintToArith256(hash);
|
||||
segid = ((nHeight + kp->segid32) & 0x3f);
|
||||
hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime);
|
||||
//for (int i=32; i>=0; i--)
|
||||
// fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]);
|
||||
//fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime);
|
||||
if ( hashval <= bnTarget )
|
||||
{
|
||||
for (iter=0; iter<maxiters; iter++)
|
||||
{
|
||||
if ( blocktime+iter+segid*2 < kp->txtime+minage )
|
||||
continue;
|
||||
hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime);
|
||||
if ( hashval <= bnTarget )
|
||||
{
|
||||
//fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid);
|
||||
blocktime += iter;
|
||||
blocktime += segid * 2;
|
||||
return(blocktime);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig)
|
||||
{
|
||||
set<CBitcoinAddress> setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector<COutput> vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow;
|
||||
static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime;
|
||||
set<CBitcoinAddress> setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector<COutput> vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock;
|
||||
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
||||
mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||
ratio = (mindiff / bnTarget);
|
||||
assert(pwalletMain != NULL);
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
*utxovaluep = 0;
|
||||
@@ -4601,64 +4689,109 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
memset(utxovoutp,0,sizeof(*utxovoutp));
|
||||
memset(utxosig,0,72);
|
||||
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
|
||||
BOOST_FOREACH(const COutput& out, vecOutputs)
|
||||
if ( (tipindex= chainActive.Tip()) == 0 )
|
||||
return(0);
|
||||
nHeight = tipindex->nHeight + 1;
|
||||
if ( (minage= nHeight*3) > 6000 ) // about 100 blocks
|
||||
minage = 6000;
|
||||
komodo_segids(hashbuf,nHeight-101,100);
|
||||
if ( *blocktimep > tipindex->nTime+60 )
|
||||
*blocktimep = tipindex->nTime+60;
|
||||
//fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight);
|
||||
if ( time(NULL) > lasttime+600 )
|
||||
{
|
||||
if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth )
|
||||
if ( array != 0 )
|
||||
{
|
||||
//fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth);
|
||||
continue;
|
||||
free(array);
|
||||
array = 0;
|
||||
maxkp = numkp = 0;
|
||||
lasttime = 0;
|
||||
}
|
||||
if ( setAddress.size() )
|
||||
BOOST_FOREACH(const COutput& out, vecOutputs)
|
||||
{
|
||||
CTxDestination address;
|
||||
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
|
||||
if ( (tipindex= chainActive.Tip()) == 0 || tipindex->nHeight+1 > nHeight )
|
||||
{
|
||||
fprintf(stderr,"komodo_staked ExtractDestination error\n");
|
||||
fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter);
|
||||
return(0);
|
||||
}
|
||||
counter++;
|
||||
if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth )
|
||||
{
|
||||
//fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth);
|
||||
continue;
|
||||
}
|
||||
if (!setAddress.count(address))
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
if ( nValue < COIN || !out.fSpendable )
|
||||
continue;
|
||||
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
||||
if ( ExtractDestination(pk,address) != 0 )
|
||||
{
|
||||
fprintf(stderr,"komodo_staked setAddress.count error\n");
|
||||
if ( IsMine(*pwalletMain,address) == 0 )
|
||||
continue;
|
||||
if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 )
|
||||
{
|
||||
array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
lasttime = (uint32_t)time(NULL);
|
||||
//fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp);
|
||||
}
|
||||
block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57;
|
||||
for (i=winners=0; i<numkp; i++)
|
||||
{
|
||||
if ( (tipindex= chainActive.Tip()) == 0 || tipindex->nHeight+1 > nHeight )
|
||||
{
|
||||
fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter);
|
||||
return(0);
|
||||
}
|
||||
kp = &array[i];
|
||||
if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 )
|
||||
continue;
|
||||
eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address);
|
||||
//fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible);
|
||||
if ( eligible > 0 )
|
||||
{
|
||||
besttime = m = 0;
|
||||
if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) )
|
||||
{
|
||||
while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) )
|
||||
{
|
||||
besttime = eligible;
|
||||
eligible--;
|
||||
if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier
|
||||
break;
|
||||
m++;
|
||||
//fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible);
|
||||
continue;
|
||||
}
|
||||
if ( IsMine(*pwalletMain, address) == 0 )
|
||||
continue;
|
||||
}
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
if ( nValue < COIN || !out.fSpendable )
|
||||
continue;
|
||||
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
||||
//entry.push_back(Pair("generated", out.tx->IsCoinBase()));
|
||||
CTxDestination address;
|
||||
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
|
||||
{
|
||||
//entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
||||
//if (pwalletMain->mapAddressBook.count(address))
|
||||
// entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
|
||||
}
|
||||
//BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
|
||||
CBlockIndex *tipindex;
|
||||
if ( (tipindex= chainActive.Tip()) != 0 )
|
||||
{
|
||||
eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str());
|
||||
if ( eligible > 0 )
|
||||
eligible = besttime;
|
||||
winners++;
|
||||
//fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible);
|
||||
if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) )
|
||||
{
|
||||
if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) )
|
||||
{
|
||||
//fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible);
|
||||
}
|
||||
else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) )
|
||||
{
|
||||
earliest = eligible;
|
||||
best_scriptPubKey = out.tx->vout[out.i].scriptPubKey;
|
||||
*utxovaluep = (uint64_t)nValue;
|
||||
decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str());
|
||||
*utxovoutp = out.i;
|
||||
*txtimep = (uint32_t)out.tx->nLockTime;
|
||||
//fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep);
|
||||
}
|
||||
} //else fprintf(stderr,"utxo not eligible\n");
|
||||
} //else fprintf(stderr,"no tipindex\n");
|
||||
earliest = eligible;
|
||||
best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey;
|
||||
*utxovaluep = (uint64_t)kp->nValue;
|
||||
//decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str());
|
||||
decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str());
|
||||
*utxovoutp = kp->vout;
|
||||
*txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime;
|
||||
fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winners.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners);
|
||||
}
|
||||
} //else fprintf(stderr,"utxo not eligible\n");
|
||||
} //else fprintf(stderr,"no tipindex\n");
|
||||
if ( numkp < 10000 && array != 0 )
|
||||
{
|
||||
free(array);
|
||||
array = 0;
|
||||
maxkp = numkp = 0;
|
||||
lasttime = 0;
|
||||
}
|
||||
if ( earliest != 0 )
|
||||
{
|
||||
@@ -4691,6 +4824,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
*blocktimep = earliest;
|
||||
}
|
||||
} //else fprintf(stderr,"no earliest utxo for staking\n");
|
||||
//fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners);
|
||||
return(siglen);
|
||||
}
|
||||
|
||||
|
||||
@@ -1819,7 +1819,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
|
||||
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
|
||||
double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false);
|
||||
double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false);
|
||||
double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip(), false);
|
||||
while (pindex)
|
||||
{
|
||||
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
||||
@@ -1885,6 +1885,11 @@ void CWallet::ReacceptWalletTransactions()
|
||||
|
||||
bool CWalletTx::RelayWalletTransaction()
|
||||
{
|
||||
if ( pwallet == 0 )
|
||||
{
|
||||
fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n");
|
||||
return(false);
|
||||
}
|
||||
assert(pwallet->GetBroadcastTransactions());
|
||||
if (!IsCoinBase())
|
||||
{
|
||||
@@ -2112,7 +2117,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
|
||||
// Don't rebroadcast if newer than nTime:
|
||||
if (wtx.nTimeReceived > nTime)
|
||||
continue;
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
//if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
{
|
||||
if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME )
|
||||
{
|
||||
@@ -2124,9 +2129,12 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
|
||||
}
|
||||
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
|
||||
{
|
||||
CWalletTx& wtx = *item.second;
|
||||
if (wtx.RelayWalletTransaction())
|
||||
result.push_back(wtx.GetHash());
|
||||
if ( item.second != 0 )
|
||||
{
|
||||
CWalletTx &wtx = *item.second;
|
||||
if (wtx.RelayWalletTransaction())
|
||||
result.push_back(wtx.GetHash());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -2299,20 +2307,20 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
|
||||
if ( KOMODO_EXCHANGEWALLET == 0 )
|
||||
{
|
||||
uint32_t locktime; int32_t txheight; CBlockIndex *tipindex;
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 )
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 )
|
||||
{
|
||||
if ( pcoin->vout[i].nValue >= 10*COIN )
|
||||
{
|
||||
if ( (tipindex= chainActive.Tip()) != 0 )
|
||||
if ( (tipindex= chainActive.LastTip()) != 0 )
|
||||
{
|
||||
komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue,(int32_t)tipindex->nHeight);
|
||||
interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime);
|
||||
} else interest = 0;
|
||||
//interest = komodo_interestnew(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime);
|
||||
//interest = komodo_interestnew(chainActive.LastTip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.LastTip()->nTime);
|
||||
if ( interest != 0 )
|
||||
{
|
||||
//printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u/%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,txheight,locktime,pcoin->nLockTime,tipindex->nTime);
|
||||
//fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime);
|
||||
//fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.LastTip()->nHeight+1,pcoin->nLockTime,chainActive.LastTip()->nTime);
|
||||
//ptr = (uint64_t *)&pcoin->vout[i].nValue;
|
||||
//(*ptr) += interest;
|
||||
ptr = (uint64_t *)&pcoin->vout[i].interest;
|
||||
@@ -2687,7 +2695,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
|
||||
int nextBlockHeight = chainActive.Height() + 1;
|
||||
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(
|
||||
Params().GetConsensus(), nextBlockHeight);
|
||||
txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now
|
||||
txNew.nLockTime = (uint32_t)chainActive.LastTip()->nTime + 1; // set to a time close to now
|
||||
|
||||
// Activates after Overwinter network upgrade
|
||||
// Set nExpiryHeight to expiryDelta (default 20) blocks past current block height
|
||||
|
||||
Reference in New Issue
Block a user