Changes for most chain power rule
This commit is contained in:
@@ -385,19 +385,19 @@ int64_t CCduration(int32_t &numblocks,uint256 txid)
|
||||
fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid));
|
||||
return(0);
|
||||
}
|
||||
else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->nHeight) <= 0 )
|
||||
else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->GetHeight()) <= 0 )
|
||||
{
|
||||
fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid));
|
||||
return(0);
|
||||
}
|
||||
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight )
|
||||
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->GetHeight() <= txheight )
|
||||
{
|
||||
fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight);
|
||||
fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->GetHeight());
|
||||
return(0);
|
||||
}
|
||||
numblocks = (pindex->nHeight - txheight);
|
||||
numblocks = (pindex->GetHeight() - txheight);
|
||||
duration = (pindex->nTime - txtime);
|
||||
fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->nHeight,txheight);
|
||||
fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->GetHeight(),txheight);
|
||||
return(duration);
|
||||
}
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ bool Eval::DisputePayout(AppVM &vm, std::vector<uint8_t> params, const CTransact
|
||||
if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock))
|
||||
return Error("couldnt-get-parent");
|
||||
|
||||
if (GetCurrentHeight() < sessionBlock.nHeight + waitBlocks)
|
||||
if (GetCurrentHeight() < sessionBlock.GetHeight() + waitBlocks)
|
||||
return Invalid("dispute-too-soon"); // Not yet
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ bool Eval::DisputePayout(AppVM &vm, std::vector<uint8_t> params, const CTransact
|
||||
if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock))
|
||||
return Error("couldnt-get-parent");
|
||||
|
||||
if (GetCurrentHeight() < sessionBlock.nHeight + waitBlocks)
|
||||
if (GetCurrentHeight() < sessionBlock.GetHeight() + waitBlocks)
|
||||
return Invalid("dispute-too-soon"); // Not yet
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data)
|
||||
CTransaction notarisationTx;
|
||||
CBlockIndex block;
|
||||
if (!GetTxConfirmed(notaryHash, notarisationTx, block)) return false;
|
||||
if (!CheckNotaryInputs(notarisationTx, block.nHeight, block.nTime)) return false;
|
||||
if (!CheckNotaryInputs(notarisationTx, block.GetHeight(), block.nTime)) return false;
|
||||
if (!ParseNotarisationOpReturn(notarisationTx, data)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ void CChain::SetTip(CBlockIndex *pindex) {
|
||||
vChain.clear();
|
||||
return;
|
||||
}
|
||||
vChain.resize(pindex->nHeight + 1);
|
||||
while (pindex && vChain[pindex->nHeight] != pindex) {
|
||||
vChain[pindex->nHeight] = pindex;
|
||||
vChain.resize(pindex->GetHeight() + 1);
|
||||
while (pindex && vChain[pindex->GetHeight()] != pindex) {
|
||||
vChain[pindex->GetHeight()] = pindex;
|
||||
pindex = pindex->pprev;
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,10 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
|
||||
while (pindex) {
|
||||
vHave.push_back(pindex->GetBlockHash());
|
||||
// Stop when we have added the genesis block.
|
||||
if (pindex->nHeight == 0)
|
||||
if (pindex->GetHeight() == 0)
|
||||
break;
|
||||
// Exponentially larger steps back, plus the genesis block.
|
||||
int nHeight = std::max(pindex->nHeight - nStep, 0);
|
||||
int nHeight = std::max(pindex->GetHeight() - nStep, 0);
|
||||
if (Contains(pindex)) {
|
||||
// Use O(1) CChain index if possible.
|
||||
pindex = (*this)[nHeight];
|
||||
@@ -54,13 +54,63 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
|
||||
const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
|
||||
if ( pindex == 0 )
|
||||
return(0);
|
||||
if (pindex->nHeight > Height())
|
||||
if (pindex->GetHeight() > Height())
|
||||
pindex = pindex->GetAncestor(Height());
|
||||
while (pindex && !Contains(pindex))
|
||||
pindex = pindex->pprev;
|
||||
return pindex;
|
||||
}
|
||||
|
||||
CChainPower::CChainPower(CBlockIndex *pblockIndex)
|
||||
{
|
||||
nHeight = pblockIndex->GetHeight();
|
||||
chainStake = arith_uint256(0);
|
||||
chainWork = arith_uint256(0);
|
||||
}
|
||||
|
||||
CChainPower::CChainPower(CBlockIndex *pblockIndex, const arith_uint256 &stake, const arith_uint256 &work)
|
||||
{
|
||||
nHeight = pblockIndex->GetHeight();
|
||||
chainStake = stake;
|
||||
chainWork = work;
|
||||
}
|
||||
|
||||
bool operator==(const CChainPower &p1, const CChainPower &p2)
|
||||
{
|
||||
arith_uint256 bigZero = arith_uint256(0);
|
||||
arith_uint256 workDivisor = p1.chainWork > p2.chainWork ? p1.chainWork : (p2.chainWork != bigZero ? p2.chainWork : 1);
|
||||
arith_uint256 stakeDivisor = p1.chainStake > p2.chainStake ? p1.chainStake : (p2.chainStake != bigZero ? p2.chainStake : 1);
|
||||
|
||||
// use up 16 bits for precision
|
||||
return ((p1.chainWork << 16) / workDivisor + (p1.chainStake << 16) / stakeDivisor) ==
|
||||
((p2.chainWork << 16) / workDivisor + (p2.chainStake << 16) / stakeDivisor);
|
||||
}
|
||||
|
||||
bool operator<(const CChainPower &p1, const CChainPower &p2)
|
||||
{
|
||||
arith_uint256 bigZero = arith_uint256(0);
|
||||
arith_uint256 workDivisor = p1.chainWork > p2.chainWork ? p1.chainWork : (p2.chainWork != bigZero ? p2.chainWork : 1);
|
||||
arith_uint256 stakeDivisor = p1.chainStake > p2.chainStake ? p1.chainStake : (p2.chainStake != bigZero ? p2.chainStake : 1);
|
||||
|
||||
// use up 16 bits for precision
|
||||
return ((p1.chainWork << 16) / workDivisor + (p1.chainStake << 16) / stakeDivisor) <
|
||||
((p2.chainWork << 16) / workDivisor + (p2.chainStake << 16) / stakeDivisor);
|
||||
}
|
||||
|
||||
bool operator<=(const CChainPower &p1, const CChainPower &p2)
|
||||
{
|
||||
arith_uint256 bigZero = arith_uint256(0);
|
||||
arith_uint256 workDivisor = p1.chainWork > p2.chainWork ? p1.chainWork : (p2.chainWork != bigZero ? p2.chainWork : 1);
|
||||
arith_uint256 stakeDivisor = p1.chainStake > p2.chainStake ? p1.chainStake : (p2.chainStake != bigZero ? p2.chainStake : 1);
|
||||
|
||||
// use up 16 bits for precision
|
||||
return ((p1.chainWork << 16) / workDivisor + (p1.chainStake << 16) / stakeDivisor) <=
|
||||
((p2.chainWork << 16) / workDivisor + (p2.chainStake << 16) / stakeDivisor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** Turn the lowest '1' bit in the binary representation of a number into a '0'. */
|
||||
int static inline InvertLowestOne(int n) { return n & (n - 1); }
|
||||
|
||||
@@ -77,11 +127,11 @@ int static inline GetSkipHeight(int height) {
|
||||
|
||||
CBlockIndex* CBlockIndex::GetAncestor(int height)
|
||||
{
|
||||
if (height > nHeight || height < 0)
|
||||
if (height > GetHeight() || height < 0)
|
||||
return NULL;
|
||||
|
||||
CBlockIndex* pindexWalk = this;
|
||||
int heightWalk = nHeight;
|
||||
int heightWalk = GetHeight();
|
||||
while ( heightWalk > height && pindexWalk != 0 )
|
||||
{
|
||||
int heightSkip = GetSkipHeight(heightWalk);
|
||||
@@ -110,5 +160,5 @@ const CBlockIndex* CBlockIndex::GetAncestor(int height) const
|
||||
void CBlockIndex::BuildSkip()
|
||||
{
|
||||
if (pprev)
|
||||
pskip = pprev->GetAncestor(GetSkipHeight(nHeight));
|
||||
pskip = pprev->GetAncestor(GetSkipHeight(GetHeight()));
|
||||
}
|
||||
|
||||
128
src/chain.h
128
src/chain.h
@@ -6,6 +6,8 @@
|
||||
#ifndef BITCOIN_CHAIN_H
|
||||
#define BITCOIN_CHAIN_H
|
||||
|
||||
class CChainPower;
|
||||
|
||||
#include "arith_uint256.h"
|
||||
#include "primitives/block.h"
|
||||
#include "pow.h"
|
||||
@@ -103,6 +105,101 @@ enum BlockStatus: uint32_t {
|
||||
//! Blocks with this validity are assumed to satisfy all consensus rules.
|
||||
static const BlockStatus BLOCK_VALID_CONSENSUS = BLOCK_VALID_SCRIPTS;
|
||||
|
||||
class CBlockIndex;
|
||||
|
||||
// This class provides an accumulator for both the chainwork and the chainPOS value
|
||||
// CChainPower's can be compared, and the comparison ensures that work and proof of stake power
|
||||
// are both used equally to determine which chain has the most work. This makes an attack
|
||||
// that involves mining in secret completely ineffective, even before dPOW, unless a large part
|
||||
// of the staking supply is also controlled. It also enables a faster deterministic convergence,
|
||||
// aided by both POS and POW.
|
||||
class CChainPower
|
||||
{
|
||||
public:
|
||||
arith_uint256 chainWork;
|
||||
arith_uint256 chainStake;
|
||||
int32_t nHeight;
|
||||
|
||||
CChainPower() : nHeight(0), chainStake(0), chainWork(0) {}
|
||||
CChainPower(CBlockIndex *pblockIndex);
|
||||
CChainPower(CBlockIndex *pblockIndex, const arith_uint256 &stake, const arith_uint256 &work);
|
||||
CChainPower(int32_t height) : nHeight(height), chainStake(0), chainWork(0) {}
|
||||
CChainPower(int32_t height, const arith_uint256 &stake, const arith_uint256 &work) :
|
||||
nHeight(height), chainStake(stake), chainWork(work) {}
|
||||
|
||||
CChainPower &operator=(const CChainPower &chainPower)
|
||||
{
|
||||
chainWork = chainPower.chainWork;
|
||||
chainStake = chainPower.chainStake;
|
||||
nHeight = chainPower.nHeight;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CChainPower &operator+=(const CChainPower &chainPower)
|
||||
{
|
||||
this->chainWork += chainPower.chainWork;
|
||||
this->chainStake += chainPower.chainStake;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend CChainPower operator+(const CChainPower &chainPowerA, const CChainPower &chainPowerB)
|
||||
{
|
||||
CChainPower result = CChainPower(chainPowerA);
|
||||
result.chainWork += chainPowerB.chainWork;
|
||||
result.chainStake += chainPowerB.chainStake;
|
||||
return result;
|
||||
}
|
||||
|
||||
friend CChainPower operator-(const CChainPower &chainPowerA, const CChainPower &chainPowerB)
|
||||
{
|
||||
CChainPower result = CChainPower(chainPowerA);
|
||||
result.chainWork -= chainPowerB.chainWork;
|
||||
result.chainStake -= chainPowerB.chainStake;
|
||||
return result;
|
||||
}
|
||||
|
||||
friend CChainPower operator*(const CChainPower &chainPower, int32_t x)
|
||||
{
|
||||
CChainPower result = CChainPower(chainPower);
|
||||
result.chainWork *= x;
|
||||
result.chainStake *= x;
|
||||
return result;
|
||||
}
|
||||
|
||||
CChainPower &addStake(const arith_uint256 &nChainStake)
|
||||
{
|
||||
chainStake += nChainStake;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CChainPower &addWork(const arith_uint256 &nChainWork)
|
||||
{
|
||||
chainWork += nChainWork;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend bool operator==(const CChainPower &p1, const CChainPower &p2);
|
||||
|
||||
friend bool operator!=(const CChainPower &p1, const CChainPower &p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
friend bool operator<(const CChainPower &p1, const CChainPower &p2);
|
||||
|
||||
friend bool operator<=(const CChainPower &p1, const CChainPower &p2);
|
||||
|
||||
friend bool operator>(const CChainPower &p1, const CChainPower &p2)
|
||||
{
|
||||
return !(p1 <= p2);
|
||||
}
|
||||
|
||||
friend bool operator>=(const CChainPower &p1, const CChainPower &p2)
|
||||
{
|
||||
return !(p1 < p2);
|
||||
}
|
||||
};
|
||||
|
||||
/** The block chain is a tree shaped structure starting with the
|
||||
* genesis block at the root, with each block potentially having multiple
|
||||
* candidates to be the next block. A blockindex may have multiple pprev pointing
|
||||
@@ -121,7 +218,6 @@ public:
|
||||
CBlockIndex* pskip;
|
||||
|
||||
//! height of the entry in the chain. The genesis block has height 0
|
||||
int nHeight;
|
||||
int64_t newcoins,zfunds; int8_t segid; // jl777 fields
|
||||
//! Which # file this block is stored in (blk?????.dat)
|
||||
int nFile;
|
||||
@@ -133,7 +229,7 @@ public:
|
||||
unsigned int nUndoPos;
|
||||
|
||||
//! (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block
|
||||
arith_uint256 nChainWork;
|
||||
CChainPower chainPower;
|
||||
|
||||
//! Number of transactions in this block.
|
||||
//! Note: in a potential headers-first mode, this number cannot be relied upon
|
||||
@@ -195,11 +291,10 @@ public:
|
||||
segid = -2;
|
||||
pprev = NULL;
|
||||
pskip = NULL;
|
||||
nHeight = 0;
|
||||
nFile = 0;
|
||||
nDataPos = 0;
|
||||
nUndoPos = 0;
|
||||
nChainWork = arith_uint256();
|
||||
chainPower = CChainPower();
|
||||
nTx = 0;
|
||||
nChainTx = 0;
|
||||
nStatus = 0;
|
||||
@@ -239,6 +334,16 @@ public:
|
||||
nSolution = block.nSolution;
|
||||
}
|
||||
|
||||
int32_t SetHeight(int32_t height)
|
||||
{
|
||||
this->chainPower.nHeight = height;
|
||||
}
|
||||
|
||||
inline int32_t GetHeight() const
|
||||
{
|
||||
return this->chainPower.nHeight;
|
||||
}
|
||||
|
||||
CDiskBlockPos GetBlockPos() const {
|
||||
CDiskBlockPos ret;
|
||||
if (nStatus & BLOCK_HAVE_DATA) {
|
||||
@@ -301,7 +406,7 @@ public:
|
||||
std::string ToString() const
|
||||
{
|
||||
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
|
||||
pprev, nHeight,
|
||||
pprev, this->chainPower.nHeight,
|
||||
hashMerkleRoot.ToString(),
|
||||
GetBlockHash().ToString());
|
||||
}
|
||||
@@ -353,7 +458,7 @@ class CDiskBlockIndex : public CBlockIndex
|
||||
public:
|
||||
uint256 hashPrev;
|
||||
|
||||
CDiskBlockIndex() {
|
||||
CDiskBlockIndex() : CBlockIndex() {
|
||||
hashPrev = uint256();
|
||||
}
|
||||
|
||||
@@ -369,7 +474,10 @@ public:
|
||||
if (!(s.GetType() & SER_GETHASH))
|
||||
READWRITE(VARINT(nVersion));
|
||||
|
||||
READWRITE(VARINT(nHeight));
|
||||
if (ser_action.ForRead()) {
|
||||
chainPower = CChainPower();
|
||||
}
|
||||
READWRITE(VARINT(chainPower.nHeight));
|
||||
READWRITE(VARINT(nStatus));
|
||||
READWRITE(VARINT(nTx));
|
||||
if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO))
|
||||
@@ -478,18 +586,18 @@ public:
|
||||
|
||||
/** Efficiently check whether a block is present in this chain. */
|
||||
bool Contains(const CBlockIndex *pindex) const {
|
||||
return (*this)[pindex->nHeight] == pindex;
|
||||
return (*this)[pindex->GetHeight()] == pindex;
|
||||
}
|
||||
|
||||
/** Find the successor of a block in this chain, or NULL if the given index is not found or is the tip. */
|
||||
CBlockIndex *Next(const CBlockIndex *pindex) const {
|
||||
if (Contains(pindex))
|
||||
return (*this)[pindex->nHeight + 1];
|
||||
return (*this)[pindex->GetHeight() + 1];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->nHeight : -1. */
|
||||
/** Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->GetHeight() : -1. */
|
||||
int Height() const {
|
||||
return vChain.size() - 1;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ void *chainparams_commandline(void *ptr);
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||
extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC;
|
||||
extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS;
|
||||
extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER;
|
||||
extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH;
|
||||
|
||||
const arith_uint256 maxUint = UintToArith256(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
|
||||
@@ -115,9 +115,9 @@ public:
|
||||
consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nProtocolVersion = 170005;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = 1;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = 227520 - 120;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nProtocolVersion = 170007;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = 1;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = 227520;
|
||||
|
||||
// The best chain should have at least this much work.
|
||||
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000000281b32ff3198a1");
|
||||
@@ -266,6 +266,9 @@ void *chainparams_commandline(void *ptr)
|
||||
mainParams.consensus.nLwmaPOSAjustedWeight = 46531;
|
||||
}
|
||||
|
||||
mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = ASSETCHAINS_SAPLING;
|
||||
mainParams.consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = ASSETCHAINS_OVERWINTER;
|
||||
|
||||
// only require coinbase protection on Verus from the Komodo family of coins
|
||||
if (strcmp(ASSETCHAINS_SYMBOL,"VRSC") == 0)
|
||||
{
|
||||
|
||||
@@ -112,6 +112,8 @@ struct Params {
|
||||
int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; }
|
||||
int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; }
|
||||
int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; }
|
||||
int32_t SetSaplingHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; }
|
||||
int32_t SetOverwinterHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = height; }
|
||||
uint256 nMinimumChainWork;
|
||||
};
|
||||
} // namespace Consensus
|
||||
|
||||
@@ -133,7 +133,7 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_
|
||||
CBlockIndex blockIdx;
|
||||
if (!eval->GetTxConfirmed(assetChainProof.first, sourceNotarisation, blockIdx))
|
||||
throw std::runtime_error("Notarisation not found");
|
||||
kmdHeight = blockIdx.nHeight;
|
||||
kmdHeight = blockIdx.GetHeight();
|
||||
}
|
||||
|
||||
// We now have a kmdHeight of the notarisation from chain A. So we know that a MoM exists
|
||||
@@ -241,7 +241,7 @@ bool GetNextBacknotarisation(uint256 kmdNotarisationTxid, Notarisation &out)
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) ScanNotarisationsFromHeight(block.nHeight+1, &IsSameAssetChain, out);
|
||||
return (bool) ScanNotarisationsFromHeight(block.GetHeight()+1, &IsSameAssetChain, out);
|
||||
}
|
||||
|
||||
|
||||
@@ -267,19 +267,19 @@ TxProof GetAssetchainProof(uint256 hash)
|
||||
throw std::runtime_error("tx still in mempool");
|
||||
|
||||
blockIndex = mapBlockIndex[blockHash];
|
||||
int h = blockIndex->nHeight;
|
||||
int h = blockIndex->GetHeight();
|
||||
// The assumption here is that the first notarisation for a height GTE than
|
||||
// the transaction block height will contain the corresponding MoM. If there
|
||||
// are sequence issues with the notarisations this may fail.
|
||||
auto isTarget = [&](Notarisation ¬a) {
|
||||
if (!IsSameAssetChain(nota)) return false;
|
||||
return nota.second.height >= blockIndex->nHeight;
|
||||
return nota.second.height >= blockIndex->GetHeight();
|
||||
};
|
||||
if (!ScanNotarisationsFromHeight(blockIndex->nHeight, isTarget, nota))
|
||||
if (!ScanNotarisationsFromHeight(blockIndex->GetHeight(), isTarget, nota))
|
||||
throw std::runtime_error("backnotarisation not yet confirmed");
|
||||
|
||||
// index of block in MoM leaves
|
||||
nIndex = nota.second.height - blockIndex->nHeight;
|
||||
nIndex = nota.second.height - blockIndex->GetHeight();
|
||||
}
|
||||
|
||||
// build merkle chain from blocks to MoM
|
||||
|
||||
@@ -165,7 +165,7 @@ TEST_F(ContextualCheckBlockTest, BadCoinbaseHeight) {
|
||||
block.vtx[0] = tx2;
|
||||
CBlock prev;
|
||||
CBlockIndex indexPrev {prev};
|
||||
indexPrev.nHeight = 0;
|
||||
indexPrev.SetHeight(0);
|
||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-cb-height", false)).Times(1);
|
||||
EXPECT_FALSE(ContextualCheckBlock(block, state, &indexPrev));
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ TEST(PoW, DifficultyAveraging) {
|
||||
std::vector<CBlockIndex> blocks(lastBlk+1);
|
||||
for (int i = 0; i <= lastBlk; i++) {
|
||||
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
|
||||
blocks[i].nHeight = i;
|
||||
blocks[i].SetHeight(i);
|
||||
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
|
||||
blocks[i].nBits = 0x1e7fffff; /* target 0x007fffff000... */
|
||||
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
|
||||
blocks[i].chainPower = i ? (CChainPower(&blocks[i]) + blocks[i - 1].chainPower) + GetBlockProof(blocks[i - 1]) : CChainPower(&blocks[i]);
|
||||
}
|
||||
|
||||
// Result should be the same as if last difficulty was used
|
||||
|
||||
@@ -21,7 +21,7 @@ TEST(rpc, check_blockToJSON_returns_minified_solution) {
|
||||
ss >> block;
|
||||
|
||||
CBlockIndex index {block};
|
||||
index.nHeight = 1391;
|
||||
index.SetHeight(1391);
|
||||
|
||||
UniValue obj = blockToJSON(block, &index);
|
||||
EXPECT_EQ("009f44ff7505d789b964d6817734b8ce1377d456255994370d06e59ac99bd5791b6ad174a66fd71c70e60cfc7fd88243ffe06f80b1ad181625f210779c745524629448e25348a5fce4f346a1735e60fdf53e144c0157dbc47c700a21a236f1efb7ee75f65b8d9d9e29026cfd09048233175202b211b9a49de4ab46f1cac71b6ea57a686377bd612378746e70c61a659c9cd683269e9c2a5cbc1d19f1149345302bbd0a1e62bf4bab01e9caeea789a1519441a61b146de35a4cc75dbdf01029127e311ad5073e7e96397f47226a7df9df66b2086b70756db013bbaeb068260157014b2602fc7dc71336e1439c887d2742d9730b4e79b08ec7839c3e2a037ae1565d04e05e351bb3531e5ef42cf7b71ca1482a9205245dd41f4db0f71644f8bdb88e845558537c03834c06ac83f336651e54e2edfc12e15ea9b7ea2c074e6155654d44c4d3bd90d9511050e9ad87d170db01448e5be6f45419cd86008978db5e3ceab79890234f992648d69bf1053855387db646ccdee5575c65f81dd0f670b016d9f9a84707d91f77b862f697b8bb08365ba71fbe6bfa47af39155a75ebdcb1e5d69f59c40c9e3a64988c1ec26f7f5159eef5c244d504a9e46125948ecc389c2ec3028ac4ff39ffd66e7743970819272b21e0c2df75b308bc62896873952147e57ed79446db4cdb5a563e76ec4c25899d41128afb9a5f8fc8063621efb7a58b9dd666d30c73e318cdcf3393bfec200e160f500e645f7baac263db99fa4a7c1cb4fea219fc512193102034d379f244c21a81821301b8d47c90247713a3e902c762d7bafa6cdb744eeb6d3b50dd175599d02b6e9f5bbda59366e04862aa765135968426e7ac0116de7351940dc57c0ae451d63f667e39891bc81e09e6c76f6f8a7582f7447c6f5945f717b0e52a7e3dd0c6db4061362123cc53fd8ede4abed4865201dc4d8eb4e5d48baa565183b69a5304a44c0600bb24dcaeee9d95ceebd27c1b0a33e0b46f23797d7d7907300b2bb7d62ef2fc5aa139250c73930c621bb5f41fc235534ee8014dfaddd5245aeb01198420ba7b5c076545329c94d54fa725a8e807579f5f0cc9d98170598023268f5930893620190275e6b3c6f5181e36310a9a475208316911d78f917d724c5946c553b7ec042c563c540114b6b78bd4c6e808ee391a4a9d93e127032983c5b3708037b14aa604cfb034e7c8b0ffdd6936446fe80216178506a87402653a373926eeff66e704daf992a0a9a5c3ad80566c0339be9e5b8e35b3b3226b2f7767e20d992ea6c3d6e322eca37b0c7f7e60060802f5abcc1975841365cadbdc3867063addfc803766ae525375ecddee61f9df9ffcd20343c83ab82b0e91de039c59cb435c8d3159cc338b4901f40c9b5c27043bcf2bd5fa9b685b65c9ba5a1e11a51dd3f773051560341f9ec81d05bf259e2d4b7161f896fbb6812cfc924a32120b7367d5e40439e267adda6a1315bb0d6200ce6a503174c8d2a638ea6fd6b1f486d68db11bdca63c4f4a725d1ab6231ea875484e70b27d293c05803386924f283d4c12bb953474d92b7dd43d2d97193bd96281ebb63fa075d2f9ecd310c70ee1d97b5330bd8fb5791c5943ecf084e5f2c83915acac57519c46b166136068d6f9ec0dd598616e32c591128ce13705a283ca39d5b211409600e07b3713113374d9700207a45394eac5b3b7afc9b1b2bad7d89fd3f35f6b2413ce615ee7869b3569009403b96fdacdb32ef0a7e5229e2b666d51e95bdfb009b892e88bde70621a9b6509f068781392df4bdbc5723bb15071993f0d9a11575af5ff6ef85eaea39bc86805b35d8beee91b779354147f2d85304b8b49d053e7444fdd3deb9d16de331f2552af5b3be7766bb8f3f6a78c62148efb231f2268", find_value(obj, "solution").get_str());
|
||||
|
||||
@@ -1734,7 +1734,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
if (chainActive.Tip() && chainActive.Tip() != pindexRescan)
|
||||
{
|
||||
uiInterface.InitMessage(_("Rescanning..."));
|
||||
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight);
|
||||
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->GetHeight(), pindexRescan->GetHeight());
|
||||
nStart = GetTimeMillis();
|
||||
pwalletMain->ScanForWalletTransactions(pindexRescan, true);
|
||||
LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart);
|
||||
|
||||
32
src/komodo.h
32
src/komodo.h
@@ -510,7 +510,7 @@ int32_t komodo_validate_chain(uint256 srchash,int32_t notarized_height)
|
||||
static int32_t last_rewind; int32_t rewindtarget; CBlockIndex *pindex; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
|
||||
return(0);
|
||||
if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != notarized_height) )
|
||||
if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->GetHeight() != notarized_height) )
|
||||
{
|
||||
if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < notarized_height )
|
||||
rewindtarget = sp->NOTARIZED_HEIGHT - 1;
|
||||
@@ -800,33 +800,33 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash;
|
||||
int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
|
||||
memset(&zero,0,sizeof(zero));
|
||||
komodo_init(pindex->nHeight);
|
||||
komodo_init(pindex->GetHeight());
|
||||
KOMODO_INITDONE = (uint32_t)time(NULL);
|
||||
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
|
||||
{
|
||||
fprintf(stderr,"unexpected null komodostateptr.[%s]\n",ASSETCHAINS_SYMBOL);
|
||||
return;
|
||||
}
|
||||
//fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight);
|
||||
numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime());
|
||||
//fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->GetHeight());
|
||||
numnotaries = komodo_notaries(pubkeys,pindex->GetHeight(),pindex->GetBlockTime());
|
||||
calc_rmd160_sha256(rmd160,pubkeys[0],33);
|
||||
if ( pindex->nHeight > hwmheight )
|
||||
hwmheight = pindex->nHeight;
|
||||
if ( pindex->GetHeight() > hwmheight )
|
||||
hwmheight = pindex->GetHeight();
|
||||
else
|
||||
{
|
||||
if ( pindex->nHeight != hwmheight )
|
||||
if ( pindex->GetHeight() != hwmheight )
|
||||
{
|
||||
printf("%s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight);
|
||||
komodo_purge_ccdata((int32_t)pindex->nHeight);
|
||||
hwmheight = pindex->nHeight;
|
||||
printf("%s hwmheight.%d vs pindex->GetHeight().%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->GetHeight(),(uint32_t)pindex->nTime,hwmheight-pindex->GetHeight());
|
||||
komodo_purge_ccdata((int32_t)pindex->GetHeight());
|
||||
hwmheight = pindex->GetHeight();
|
||||
}
|
||||
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_event_rewind(sp,symbol,pindex->GetHeight());
|
||||
komodo_stateupdate(pindex->GetHeight(),0,0,0,zero,0,0,0,0,-pindex->GetHeight(),pindex->nTime,0,0,0,0,zero,0);
|
||||
}
|
||||
komodo_currentheight_set(chainActive.LastTip()->nHeight);
|
||||
komodo_currentheight_set(chainActive.LastTip()->GetHeight());
|
||||
if ( pindex != 0 )
|
||||
{
|
||||
height = pindex->nHeight;
|
||||
height = pindex->GetHeight();
|
||||
txn_count = block.vtx.size();
|
||||
for (i=0; i<txn_count; i++)
|
||||
{
|
||||
@@ -953,11 +953,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
}
|
||||
if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height);
|
||||
if ( pindex->nHeight == hwmheight )
|
||||
if ( pindex->GetHeight() == hwmheight )
|
||||
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0);
|
||||
} else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n");
|
||||
//KOMODO_INITDONE = (uint32_t)time(NULL);
|
||||
//fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight);
|
||||
//fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->GetHeight());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -630,13 +630,13 @@ int32_t komodo_isPoS(CBlock *pblock)
|
||||
void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
|
||||
{
|
||||
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
|
||||
//fprintf(stderr,"disconnect ht.%d\n",pindex->nHeight);
|
||||
komodo_init(pindex->nHeight);
|
||||
//fprintf(stderr,"disconnect ht.%d\n",pindex->GetHeight());
|
||||
komodo_init(pindex->GetHeight());
|
||||
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
|
||||
{
|
||||
//sp->rewinding = pindex->nHeight;
|
||||
//fprintf(stderr,"-%d ",pindex->nHeight);
|
||||
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->nHeight,ASSETCHAINS_SYMBOL);
|
||||
//sp->rewinding = pindex->GetHeight();
|
||||
//fprintf(stderr,"-%d ",pindex->GetHeight());
|
||||
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->GetHeight(),ASSETCHAINS_SYMBOL);
|
||||
}
|
||||
|
||||
int32_t komodo_is_notarytx(const CTransaction& tx)
|
||||
@@ -665,7 +665,7 @@ int32_t komodo_block2height(CBlock *block)
|
||||
int32_t i,n,height2=-1,height = 0; uint8_t *ptr; CBlockIndex *pindex;
|
||||
if ( (pindex= mapBlockIndex[block->GetHash()]) != 0 )
|
||||
{
|
||||
height2 = (int32_t)pindex->nHeight;
|
||||
height2 = (int32_t)pindex->GetHeight();
|
||||
if ( height2 >= 0 )
|
||||
return(height2);
|
||||
}
|
||||
@@ -750,9 +750,9 @@ CBlockIndex *komodo_chainactive(int32_t height)
|
||||
{
|
||||
if ( chainActive.LastTip() != 0 )
|
||||
{
|
||||
if ( height <= chainActive.LastTip()->nHeight )
|
||||
if ( height <= chainActive.LastTip()->GetHeight() )
|
||||
return(chainActive[height]);
|
||||
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->nHeight);
|
||||
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->GetHeight());
|
||||
}
|
||||
//fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height);
|
||||
return(0);
|
||||
@@ -772,7 +772,7 @@ uint32_t komodo_heightstamp(int32_t height)
|
||||
int32_t i,num; uint8_t pubkeys[64][33]; CBlock block;
|
||||
if ( pindex->didinit != 0 )
|
||||
return;
|
||||
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->nHeight,pindex->notaryid,height);
|
||||
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->GetHeight(),pindex->notaryid,height);
|
||||
if ( pindex->didinit == 0 )
|
||||
{
|
||||
pindex->notaryid = -1;
|
||||
@@ -784,12 +784,12 @@ uint32_t komodo_heightstamp(int32_t height)
|
||||
komodo_block2pubkey33(pindex->pubkey33,&block);
|
||||
//for (i=0; i<33; i++)
|
||||
// fprintf(stderr,"%02x",pindex->pubkey33[i]);
|
||||
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->nHeight,height);
|
||||
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->GetHeight(),height);
|
||||
//if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
|
||||
// pindex->didinit = (KOMODO_LOADINGBLOCKS == 0);
|
||||
} // else fprintf(stderr,"error loading block at %d/%d",pindex->nHeight,height);
|
||||
} // else fprintf(stderr,"error loading block at %d/%d",pindex->GetHeight(),height);
|
||||
}
|
||||
if ( pindex->didinit != 0 && pindex->nHeight >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
|
||||
if ( pindex->didinit != 0 && pindex->GetHeight() >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->GetHeight(),(uint32_t)pindex->nTime)) > 0 )
|
||||
{
|
||||
for (i=0; i<num; i++)
|
||||
{
|
||||
@@ -803,7 +803,7 @@ uint32_t komodo_heightstamp(int32_t height)
|
||||
{
|
||||
for (i=0; i<33; i++)
|
||||
fprintf(stderr,"%02x",pindex->pubkey33[i]);
|
||||
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->nHeight,height);
|
||||
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->GetHeight(),height);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -986,12 +986,12 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
|
||||
int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex;
|
||||
if ( (pindex= chainActive.LastTip()) == 0 )
|
||||
return(-1);
|
||||
notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid);
|
||||
notarized_height = komodo_notarizeddata(pindex->GetHeight(),¬arized_hash,¬arized_desttxid);
|
||||
*notarized_heightp = notarized_height;
|
||||
if ( notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
|
||||
if ( notarized_height >= 0 && notarized_height <= pindex->GetHeight() && (notary= mapBlockIndex[notarized_hash]) != 0 )
|
||||
{
|
||||
//printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str());
|
||||
if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg
|
||||
//printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->GetHeight(),notarized_height,notarized_hash.ToString().c_str());
|
||||
if ( notary->GetHeight() == notarized_height ) // if notarized_hash not in chain, reorg
|
||||
{
|
||||
if ( nHeight < notarized_height )
|
||||
{
|
||||
@@ -1003,10 +1003,10 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
|
||||
fprintf(stderr,"[%s] nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height);
|
||||
return(-1);
|
||||
}
|
||||
} //else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
|
||||
} //else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->GetHeight());
|
||||
}
|
||||
//else if ( notarized_height > 0 && notarized_height != 73880 && notarized_height >= 170000 )
|
||||
// fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->nHeight);
|
||||
// fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->GetHeight());
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -1024,7 +1024,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_
|
||||
if ( (pindex= mapBlockIndex[hashBlock]) != 0 )
|
||||
{
|
||||
*valuep = tx.vout[n].nValue;
|
||||
*txheightp = pindex->nHeight;
|
||||
*txheightp = pindex->GetHeight();
|
||||
*txheighttimep = pindex->nTime;
|
||||
if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
*tiptimep = (uint32_t)tipindex->nTime;
|
||||
@@ -1059,7 +1059,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.LastTip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() )
|
||||
if ( (pindex= chainActive.LastTip()) != 0 && pindex->GetHeight() >= (int32_t)komodo_longestchain() )
|
||||
return(1);
|
||||
else return(0);
|
||||
}
|
||||
@@ -1546,12 +1546,18 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
|
||||
//printf("after nNonce: %s, height: %d\n", nonce.GetHex().c_str(), height);
|
||||
//printf("POShash: %s\n\n", hash.GetHex().c_str());
|
||||
|
||||
if (newPOSActive && posHash != hash)
|
||||
{
|
||||
printf("blk hash: %s\nnonce: %s\ncorrect: %s\n", pblock->GetHash().GetHex().c_str(), pblock->nNonce.GetHex().c_str(), nonce.GetHex().c_str());
|
||||
}
|
||||
|
||||
|
||||
//if ((!newPOSActive || posHash == hash) && hash <= target)
|
||||
if (hash <= target)
|
||||
{
|
||||
if ((mapBlockIndex.count(blkHash) == 0) ||
|
||||
!(pastBlockIndex = mapBlockIndex[blkHash]) ||
|
||||
(height - pastBlockIndex->nHeight) < VERUS_MIN_STAKEAGE)
|
||||
(height - pastBlockIndex->GetHeight()) < VERUS_MIN_STAKEAGE)
|
||||
{
|
||||
fprintf(stderr,"ERROR: invalid PoS block %s - stake transaction too new\n",blkHash.ToString().c_str());
|
||||
}
|
||||
@@ -1660,7 +1666,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
return(0);
|
||||
}
|
||||
if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 )
|
||||
height = pprev->nHeight + 1;
|
||||
height = pprev->GetHeight() + 1;
|
||||
if ( height == 0 )
|
||||
return(0);
|
||||
}
|
||||
@@ -1800,21 +1806,21 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height)
|
||||
*zfundsp = 0;
|
||||
if ( (pindex= komodo_chainactive(height)) != 0 )
|
||||
{
|
||||
while ( pindex != 0 && pindex->nHeight > 0 )
|
||||
while ( pindex != 0 && pindex->GetHeight() > 0 )
|
||||
{
|
||||
if ( pindex->newcoins == 0 && pindex->zfunds == 0 )
|
||||
{
|
||||
if ( komodo_blockload(block,pindex) == 0 )
|
||||
pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block);
|
||||
pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->GetHeight(),&block);
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"error loading block.%d\n",pindex->nHeight);
|
||||
fprintf(stderr,"error loading block.%d\n",pindex->GetHeight());
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
supply += pindex->newcoins;
|
||||
zfunds += pindex->zfunds;
|
||||
//printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds));
|
||||
//printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->GetHeight(),dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds));
|
||||
pindex = pindex->pprev;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1494,7 +1494,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.LastTip()->nHeight;
|
||||
buf[0] = (uint32_t)chainActive.LastTip()->GetHeight();
|
||||
buf[1] = (uint32_t)komodo_longestchain();
|
||||
if ( buf[0] != 0 && buf[0] == buf[1] )
|
||||
{
|
||||
|
||||
@@ -86,6 +86,9 @@ int32_t VERUS_MIN_STAKEAGE = 150; // 1/2 this should also be a cap on the
|
||||
int32_t VERUS_CONSECUTIVE_POS_THRESHOLD = 7;
|
||||
int32_t VERUS_NOPOS_THRESHHOLD = 150; // if we have no POS blocks in this many blocks, set to default difficulty
|
||||
|
||||
int32_t ASSETCHAINS_SAPLING;
|
||||
int32_t ASSETCHAINS_OVERWINTER;
|
||||
|
||||
uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
|
||||
uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10;
|
||||
|
||||
|
||||
@@ -648,7 +648,7 @@ void jumblr_iteration()
|
||||
free(retstr);
|
||||
}
|
||||
}
|
||||
height = (int32_t)chainActive.LastTip()->nHeight;
|
||||
height = (int32_t)chainActive.LastTip()->GetHeight();
|
||||
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.LastTip() != 0 && height > chainActive.LastTip()->nHeight )
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && height > chainActive.LastTip()->GetHeight() )
|
||||
{
|
||||
if ( height < 100000000 )
|
||||
{
|
||||
static uint32_t counter;
|
||||
if ( counter++ < 3 )
|
||||
printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.LastTip()->nHeight);
|
||||
printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.LastTip()->GetHeight());
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -1759,8 +1759,14 @@ void komodo_args(char *argv0)
|
||||
ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey","");
|
||||
if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
|
||||
ASSETCHAINS_STAKED = 100;
|
||||
if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) > 100 )
|
||||
ASSETCHAINS_LWMAPOS = 100;
|
||||
|
||||
// for now, we only support 50% PoS due to other parts of the algorithm needing adjustment for
|
||||
// other values
|
||||
if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 )
|
||||
ASSETCHAINS_LWMAPOS = 50;
|
||||
|
||||
ASSETCHAINS_SAPLING = GetArg("-ac_sapling", 227520);
|
||||
ASSETCHAINS_OVERWINTER = GetArg("-ac_overwinter", (ASSETCHAINS_SAPLING - 120));
|
||||
|
||||
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 && ASSETCHAINS_COMMISSION > 0 && ASSETCHAINS_COMMISSION <= 100000000 )
|
||||
decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str());
|
||||
|
||||
379
src/main.cpp
379
src/main.cpp
File diff suppressed because it is too large
Load Diff
@@ -351,7 +351,7 @@ int printMetrics(size_t cols, bool mining)
|
||||
auto hash = *it;
|
||||
if (mapBlockIndex.count(hash) > 0 &&
|
||||
chainActive.Contains(mapBlockIndex[hash])) {
|
||||
int height = mapBlockIndex[hash]->nHeight;
|
||||
int height = mapBlockIndex[hash]->GetHeight();
|
||||
CAmount subsidy = GetBlockSubsidy(height, consensusParams);
|
||||
if ((height > 0) && (height <= consensusParams.GetLastFoundersRewardBlockHeight())) {
|
||||
subsidy -= subsidy/5;
|
||||
|
||||
@@ -176,7 +176,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
{
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
pindexPrev = chainActive.LastTip();
|
||||
const int nHeight = pindexPrev->nHeight + 1;
|
||||
const int nHeight = pindexPrev->GetHeight() + 1;
|
||||
uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus());
|
||||
|
||||
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
||||
@@ -360,7 +360,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
//fprintf(stderr,"dont have inputs\n");
|
||||
continue;
|
||||
}
|
||||
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut();
|
||||
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut();
|
||||
|
||||
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||
@@ -450,14 +450,14 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
if ( siglen > 0 )
|
||||
{
|
||||
CAmount txfees = 0;
|
||||
//if ( (int32_t)chainActive.LastTip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 )
|
||||
//if ( (int32_t)chainActive.LastTip()->GetHeight()+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.LastTip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13)));
|
||||
//printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13)));
|
||||
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
|
||||
}
|
||||
|
||||
@@ -644,7 +644,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
||||
hashPrevBlock = pblock->hashPrevBlock;
|
||||
}
|
||||
++nExtraNonce;
|
||||
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
|
||||
unsigned int nHeight = pindexPrev->GetHeight()+1; // Height first in coinbase required for block.version=2
|
||||
CMutableTransaction txCoinbase(pblock->vtx[0]);
|
||||
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
|
||||
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
||||
@@ -715,7 +715,7 @@ 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.LastTip()->nHeight+1);
|
||||
LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->GetHeight()+1);
|
||||
|
||||
// Found a solution
|
||||
{
|
||||
@@ -757,7 +757,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.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||
if (!ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, pblock, true, NULL))
|
||||
return error("KomodoMiner: ProcessNewBlock, block not accepted");
|
||||
|
||||
TrackMinedBlock(pblock->GetHash());
|
||||
@@ -803,12 +803,12 @@ CBlockIndex *get_chainactive(int32_t height)
|
||||
{
|
||||
if ( chainActive.LastTip() != 0 )
|
||||
{
|
||||
if ( height <= chainActive.LastTip()->nHeight )
|
||||
if ( height <= chainActive.LastTip()->GetHeight() )
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return(chainActive[height]);
|
||||
}
|
||||
// else fprintf(stderr,"get_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight);
|
||||
// else fprintf(stderr,"get_chainactive height %d > active.%d\n",height,chainActive.Tip()->GetHeight());
|
||||
}
|
||||
//fprintf(stderr,"get_chainactive null chainActive.Tip() height %d\n",height);
|
||||
return(0);
|
||||
@@ -833,7 +833,7 @@ void static VerusStaker(CWallet *pwallet)
|
||||
solnPlaceholder.resize(Eh200_9.SolutionWidth);
|
||||
uint8_t *script; uint64_t total,checktoshis; int32_t i,j;
|
||||
|
||||
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 &&
|
||||
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->GetHeight() != 235300 &&
|
||||
{
|
||||
sleep(1);
|
||||
if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 )
|
||||
@@ -854,13 +854,13 @@ void static VerusStaker(CWallet *pwallet)
|
||||
{
|
||||
waitForPeers(chainparams);
|
||||
CBlockIndex* pindexPrev = chainActive.LastTip();
|
||||
printf("Staking height %d for %s\n", pindexPrev->nHeight + 1, ASSETCHAINS_SYMBOL);
|
||||
printf("Staking height %d for %s\n", pindexPrev->GetHeight() + 1, ASSETCHAINS_SYMBOL);
|
||||
|
||||
// Create new block
|
||||
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
if ( Mining_height != pindexPrev->nHeight+1 )
|
||||
if ( Mining_height != pindexPrev->GetHeight()+1 )
|
||||
{
|
||||
Mining_height = pindexPrev->nHeight+1;
|
||||
Mining_height = pindexPrev->GetHeight()+1;
|
||||
Mining_start = (uint32_t)time(NULL);
|
||||
}
|
||||
|
||||
@@ -924,7 +924,7 @@ void static VerusStaker(CWallet *pwallet)
|
||||
|
||||
if ( pindexPrev != chainActive.LastTip() )
|
||||
{
|
||||
printf("Block %d added to chain\n", chainActive.LastTip()->nHeight);
|
||||
printf("Block %d added to chain\n", chainActive.LastTip()->GetHeight());
|
||||
MilliSleep(250);
|
||||
continue;
|
||||
}
|
||||
@@ -997,7 +997,7 @@ void static BitcoinMiner_noeq()
|
||||
solnPlaceholder.resize(Eh200_9.SolutionWidth);
|
||||
uint8_t *script; uint64_t total,checktoshis; int32_t i,j;
|
||||
|
||||
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 &&
|
||||
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->GetHeight() != 235300 &&
|
||||
{
|
||||
sleep(1);
|
||||
if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 )
|
||||
@@ -1032,7 +1032,7 @@ void static BitcoinMiner_noeq()
|
||||
sleep(1);
|
||||
|
||||
// prevent forking on startup before the diff algorithm kicks in
|
||||
if (pindexPrev->nHeight < 50 || pindexPrev != chainActive.LastTip())
|
||||
if (pindexPrev->GetHeight() < 50 || pindexPrev != chainActive.LastTip())
|
||||
{
|
||||
do {
|
||||
pindexPrev = chainActive.LastTip();
|
||||
@@ -1042,9 +1042,9 @@ void static BitcoinMiner_noeq()
|
||||
|
||||
// Create new block
|
||||
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
if ( Mining_height != pindexPrev->nHeight+1 )
|
||||
if ( Mining_height != pindexPrev->GetHeight()+1 )
|
||||
{
|
||||
Mining_height = pindexPrev->nHeight+1;
|
||||
Mining_height = pindexPrev->GetHeight()+1;
|
||||
Mining_start = (uint32_t)time(NULL);
|
||||
}
|
||||
|
||||
@@ -1116,7 +1116,7 @@ void static BitcoinMiner_noeq()
|
||||
if (lastChainTipPrinted != chainActive.LastTip())
|
||||
{
|
||||
lastChainTipPrinted = chainActive.LastTip();
|
||||
printf("Block %d added to chain\n", lastChainTipPrinted->nHeight);
|
||||
printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight());
|
||||
}
|
||||
MilliSleep(250);
|
||||
continue;
|
||||
@@ -1191,7 +1191,7 @@ void static BitcoinMiner_noeq()
|
||||
if (lastChainTipPrinted != chainActive.LastTip())
|
||||
{
|
||||
lastChainTipPrinted = chainActive.LastTip();
|
||||
printf("Block %d added to chain\n", lastChainTipPrinted->nHeight);
|
||||
printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1227,7 +1227,7 @@ void static BitcoinMiner_noeq()
|
||||
if (lastChainTipPrinted != chainActive.LastTip())
|
||||
{
|
||||
lastChainTipPrinted = chainActive.LastTip();
|
||||
printf("Block %d added to chain\n", lastChainTipPrinted->nHeight);
|
||||
printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1285,7 +1285,7 @@ void static BitcoinMiner()
|
||||
break;
|
||||
}
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
komodo_chosennotary(¬aryid,chainActive.LastTip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime());
|
||||
komodo_chosennotary(¬aryid,chainActive.LastTip()->GetHeight(),NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime());
|
||||
if ( notaryid != My_notaryid )
|
||||
My_notaryid = notaryid;
|
||||
std::string solver;
|
||||
@@ -1311,9 +1311,9 @@ void static BitcoinMiner()
|
||||
fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str());
|
||||
while (true)
|
||||
{
|
||||
if (chainparams.MiningRequiresPeers()) //chainActive.LastTip()->nHeight != 235300 &&
|
||||
if (chainparams.MiningRequiresPeers()) //chainActive.LastTip()->GetHeight() != 235300 &&
|
||||
{
|
||||
//if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->nHeight < 100 )
|
||||
//if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 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.
|
||||
@@ -1338,9 +1338,9 @@ void static BitcoinMiner()
|
||||
//
|
||||
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
CBlockIndex* pindexPrev = chainActive.LastTip();
|
||||
if ( Mining_height != pindexPrev->nHeight+1 )
|
||||
if ( Mining_height != pindexPrev->GetHeight()+1 )
|
||||
{
|
||||
Mining_height = pindexPrev->nHeight+1;
|
||||
Mining_height = pindexPrev->GetHeight()+1;
|
||||
Mining_start = (uint32_t)time(NULL);
|
||||
}
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED == 0 )
|
||||
@@ -1351,7 +1351,7 @@ void static BitcoinMiner()
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
// notaries always default to staking
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->nHeight+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0);
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0);
|
||||
#else
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey();
|
||||
#endif
|
||||
@@ -1409,7 +1409,7 @@ void static BitcoinMiner()
|
||||
int32_t dispflag = 0;
|
||||
if ( notaryid <= 3 || notaryid == 32 || (notaryid >= 43 && notaryid <= 45) &¬aryid == 51 || notaryid == 52 || notaryid == 56 || notaryid == 57 )
|
||||
dispflag = 1;
|
||||
komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,pindexPrev->nHeight);
|
||||
komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,pindexPrev->GetHeight());
|
||||
if ( nonzpkeys > 0 )
|
||||
{
|
||||
for (i=0; i<33; i++)
|
||||
@@ -1437,7 +1437,7 @@ void static BitcoinMiner()
|
||||
gpucount++;
|
||||
}
|
||||
if ( dispflag != 0 )
|
||||
fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u\n",pindexPrev->nHeight,notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL));
|
||||
fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u\n",pindexPrev->GetHeight(),notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL));
|
||||
}
|
||||
for (j=0; j<65; j++)
|
||||
if ( mids[j] == notaryid )
|
||||
@@ -1448,7 +1448,7 @@ void static BitcoinMiner()
|
||||
if ( (Mining_height >= 235300 && Mining_height < 236000) || (j == 65 && Mining_height > KOMODO_MAYBEMINED+1 && Mining_height > KOMODO_LASTMINED+64) )
|
||||
{
|
||||
HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS);
|
||||
fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1);
|
||||
fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->GetHeight()+1);
|
||||
} //else fprintf(stderr,"duplicate at j.%d\n",j);
|
||||
} else Mining_start = 0;
|
||||
} else Mining_start = 0;
|
||||
@@ -1529,7 +1529,7 @@ void static BitcoinMiner()
|
||||
while ( GetAdjustedTime() < B.nTime-2 )
|
||||
{
|
||||
sleep(1);
|
||||
if ( chainActive.LastTip()->nHeight >= Mining_height )
|
||||
if ( chainActive.LastTip()->GetHeight() >= Mining_height )
|
||||
{
|
||||
fprintf(stderr,"new block arrived\n");
|
||||
return(false);
|
||||
@@ -1550,7 +1550,7 @@ void static BitcoinMiner()
|
||||
while ( B.nTime-57 > GetAdjustedTime() )
|
||||
{
|
||||
sleep(1);
|
||||
if ( chainActive.LastTip()->nHeight >= Mining_height )
|
||||
if ( chainActive.LastTip()->GetHeight() >= Mining_height )
|
||||
return(false);
|
||||
}
|
||||
uint256 tmp = B.GetHash();
|
||||
|
||||
41
src/pow.cpp
41
src/pow.cpp
@@ -4,6 +4,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "pow.h"
|
||||
#include "consensus/upgrades.h"
|
||||
|
||||
#include "arith_uint256.h"
|
||||
#include "chain.h"
|
||||
@@ -21,7 +22,7 @@
|
||||
#endif // ENABLE_RUST
|
||||
uint32_t komodo_chainactive_timestamp();
|
||||
|
||||
extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_STAKED;
|
||||
extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_STAKED, ASSETCHAINS_LWMAPOS;
|
||||
extern char ASSETCHAINS_SYMBOL[65];
|
||||
extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD;
|
||||
unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params);
|
||||
@@ -229,7 +230,7 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus::
|
||||
if (x)
|
||||
{
|
||||
idx[i].consecutive = false;
|
||||
if (!memcmp(ASSETCHAINS_SYMBOL, "VRSC", 4) && pindexLast->nHeight < 67680)
|
||||
if (!memcmp(ASSETCHAINS_SYMBOL, "VRSC", 4) && pindexLast->GetHeight() < 67680)
|
||||
{
|
||||
idx[i].solveTime = VERUS_BLOCK_POSUNITS * (x + 1);
|
||||
}
|
||||
@@ -444,33 +445,49 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t
|
||||
return true;
|
||||
}
|
||||
|
||||
arith_uint256 GetBlockProof(const CBlockIndex& block)
|
||||
CChainPower GetBlockProof(const CBlockIndex& block)
|
||||
{
|
||||
arith_uint256 bnTarget;
|
||||
arith_uint256 bnWorkTarget, bnStakeTarget = arith_uint256();
|
||||
|
||||
bool fNegative;
|
||||
bool fOverflow;
|
||||
bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
|
||||
bnWorkTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
|
||||
|
||||
if (fNegative || fOverflow || bnWorkTarget == 0)
|
||||
return CChainPower(0);
|
||||
|
||||
CBlockHeader header = block.GetBlockHeader();
|
||||
|
||||
// if POS block, add stake
|
||||
if (!NetworkUpgradeActive(block.GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING) || !header.IsVerusPOSBlock())
|
||||
{
|
||||
return CChainPower(0, bnStakeTarget, (~bnWorkTarget / (bnWorkTarget + 1)) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
bnStakeTarget.SetCompact(header.GetVerusPOSTarget(), &fNegative, &fOverflow);
|
||||
if (fNegative || fOverflow || bnWorkTarget == 0)
|
||||
return CChainPower(0);
|
||||
}
|
||||
|
||||
if (fNegative || fOverflow || bnTarget == 0)
|
||||
return 0;
|
||||
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
|
||||
// as it's too large for a arith_uint256. However, as 2**256 is at least as large
|
||||
// as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
|
||||
// or ~bnTarget / (nTarget+1) + 1.
|
||||
return (~bnTarget / (bnTarget + 1)) + 1;
|
||||
return CChainPower(0, (~bnStakeTarget / (bnStakeTarget + 1)) + 1, (~bnWorkTarget / (bnWorkTarget + 1)) + 1);
|
||||
}
|
||||
|
||||
int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params)
|
||||
{
|
||||
arith_uint256 r;
|
||||
int sign = 1;
|
||||
if (to.nChainWork > from.nChainWork) {
|
||||
r = to.nChainWork - from.nChainWork;
|
||||
if (to.chainPower.chainWork > from.chainPower.chainWork) {
|
||||
r = to.chainPower.chainWork - from.chainPower.chainWork;
|
||||
} else {
|
||||
r = from.nChainWork - to.nChainWork;
|
||||
r = from.chainPower.chainWork - to.chainPower.chainWork;
|
||||
sign = -1;
|
||||
}
|
||||
r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip);
|
||||
r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip).chainWork;
|
||||
if (r.bits() > 63) {
|
||||
return sign * std::numeric_limits<int64_t>::max();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#ifndef BITCOIN_POW_H
|
||||
#define BITCOIN_POW_H
|
||||
|
||||
#include "chain.h"
|
||||
#include "consensus/params.h"
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -28,7 +29,7 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams&);
|
||||
|
||||
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
|
||||
bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t height, const Consensus::Params& params);
|
||||
arith_uint256 GetBlockProof(const CBlockIndex& block);
|
||||
CChainPower GetBlockProof(const CBlockIndex& block);
|
||||
|
||||
/** Return the time it would take to redo the work difference between from and to, assuming the current hashrate corresponds to the difficulty at tip, in seconds. */
|
||||
int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params&);
|
||||
|
||||
@@ -45,7 +45,8 @@ void CBlockHeader::SetVerusHash()
|
||||
CBlockHeader::hashFunction = &CBlockHeader::GetVerusHash;
|
||||
}
|
||||
|
||||
// returns false if unable to fast calculate the VerusPOSHash from the header. it can still be calculated from the block
|
||||
// returns false if unable to fast calculate the VerusPOSHash from the header.
|
||||
// if it returns false, value is set to 0, but it can still be calculated from the full block
|
||||
// in that case. the only difference between this and the POS hash for the contest is that it is not divided by the value out
|
||||
// this is used as a source of entropy
|
||||
bool CBlockHeader::GetRawVerusPOSHash(uint256 &value, int32_t nHeight) const
|
||||
@@ -53,7 +54,10 @@ bool CBlockHeader::GetRawVerusPOSHash(uint256 &value, int32_t nHeight) const
|
||||
// if below the required height or no storage space in the solution, we can't get
|
||||
// a cached txid value to calculate the POSHash from the header
|
||||
if (!(CPOSNonce::NewNonceActive(nHeight) && IsVerusPOSBlock()))
|
||||
{
|
||||
value = uint256();
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we can calculate, this assumes the protocol that the POSHash calculation is:
|
||||
// hashWriter << ASSETCHAINS_MAGIC;
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
static void SetVerusHash();
|
||||
|
||||
bool GetRawVerusPOSHash(uint256 &value, int32_t nHeight) const;
|
||||
|
||||
uint256 GetVerusEntropyHash(int32_t nHeight) const;
|
||||
|
||||
uint256 GetVerusV2Hash() const;
|
||||
|
||||
@@ -302,6 +302,7 @@ CAmount CTransaction::GetValueOut() const
|
||||
return nValueOut;
|
||||
}
|
||||
|
||||
// SAPLINGTODO: make this accurate for all transactions, including sapling
|
||||
CAmount CTransaction::GetShieldedValueIn() const
|
||||
{
|
||||
CAmount nValue = 0;
|
||||
|
||||
@@ -117,9 +117,9 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||
int confirmations = -1;
|
||||
// Only report confirmations if the block is on the main chain
|
||||
if (chainActive.Contains(blockindex))
|
||||
confirmations = chainActive.Height() - blockindex->nHeight + 1;
|
||||
confirmations = chainActive.Height() - blockindex->GetHeight() + 1;
|
||||
result.push_back(Pair("confirmations", confirmations));
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("height", blockindex->GetHeight()));
|
||||
result.push_back(Pair("version", blockindex->nVersion));
|
||||
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
|
||||
result.push_back(Pair("finalsaplingroot", blockindex->hashFinalSaplingRoot.GetHex()));
|
||||
@@ -128,7 +128,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||
result.push_back(Pair("solution", HexStr(blockindex->nSolution)));
|
||||
result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
|
||||
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
|
||||
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
|
||||
result.push_back(Pair("chainwork", blockindex->chainPower.chainWork.GetHex()));
|
||||
result.push_back(Pair("segid", (int64_t)blockindex->segid));
|
||||
|
||||
if (blockindex->pprev)
|
||||
@@ -146,13 +146,13 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
|
||||
int confirmations = -1;
|
||||
// Only report confirmations if the block is on the main chain
|
||||
if (chainActive.Contains(blockindex)) {
|
||||
confirmations = chainActive.Height() - blockindex->nHeight + 1;
|
||||
confirmations = chainActive.Height() - blockindex->GetHeight() + 1;
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block is an orphan");
|
||||
}
|
||||
result.push_back(Pair("confirmations", confirmations));
|
||||
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("height", blockindex->GetHeight()));
|
||||
result.push_back(Pair("version", block.nVersion));
|
||||
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
|
||||
result.push_back(Pair("segid", (int64_t)blockindex->segid));
|
||||
@@ -249,7 +249,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
|
||||
result.push_back(Pair("nonce", block.nNonce.GetHex()));
|
||||
result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
|
||||
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
|
||||
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
|
||||
result.push_back(Pair("chainwork", blockindex->chainPower.chainWork.GetHex()));
|
||||
|
||||
if (blockindex->pprev)
|
||||
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
|
||||
@@ -266,10 +266,10 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
|
||||
int confirmations = -1;
|
||||
// Only report confirmations if the block is on the main chain
|
||||
if (chainActive.Contains(blockindex))
|
||||
confirmations = chainActive.Height() - blockindex->nHeight + 1;
|
||||
confirmations = chainActive.Height() - blockindex->GetHeight() + 1;
|
||||
result.push_back(Pair("confirmations", confirmations));
|
||||
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("height", blockindex->GetHeight()));
|
||||
result.push_back(Pair("version", block.nVersion));
|
||||
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
|
||||
result.push_back(Pair("segid", (int64_t)blockindex->segid));
|
||||
@@ -292,7 +292,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
|
||||
result.push_back(Pair("solution", HexStr(block.nSolution)));
|
||||
result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
|
||||
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
|
||||
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
|
||||
result.push_back(Pair("chainwork", blockindex->chainPower.chainWork.GetHex()));
|
||||
result.push_back(Pair("anchor", blockindex->hashFinalSproutRoot.GetHex()));
|
||||
result.push_back(Pair("blocktype", block.IsVerusPOSBlock() ? "minted" : "mined"));
|
||||
|
||||
@@ -819,6 +819,7 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
|
||||
#define KOMODO_KVDURATION 1440
|
||||
#define KOMODO_KVBINARY 2
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern int32_t ASSETCHAINS_LWMAPOS;
|
||||
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume);
|
||||
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel);
|
||||
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
|
||||
@@ -856,13 +857,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.LastTip()->nHeight));
|
||||
ret.push_back(Pair("currentheight", (int64_t)chainActive.LastTip()->GetHeight()));
|
||||
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.LastTip()->nHeight,&flags,&height,value,key,keylen)) >= 0 )
|
||||
if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&flags,&height,value,key,keylen)) >= 0 )
|
||||
{
|
||||
std::string val; char *valuestr;
|
||||
val.resize(valuesize);
|
||||
@@ -890,7 +891,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.LastTip()->nHeight;
|
||||
height = chainActive.LastTip()->GetHeight();
|
||||
else
|
||||
{
|
||||
CBlockIndex *pblockindex = chainActive[height];
|
||||
@@ -952,7 +953,7 @@ UniValue notaries(const UniValue& params, bool fHelp)
|
||||
else timestamp = (uint32_t)time(NULL);
|
||||
if ( height < 0 )
|
||||
{
|
||||
height = chainActive.LastTip()->nHeight;
|
||||
height = chainActive.LastTip()->GetHeight();
|
||||
timestamp = chainActive.LastTip()->GetBlockTime();
|
||||
}
|
||||
else if ( params.size() < 2 )
|
||||
@@ -1041,7 +1042,7 @@ UniValue paxprice(const UniValue& params, bool fHelp)
|
||||
std::string rel = params[1].get_str();
|
||||
int32_t height;
|
||||
if ( params.size() == 2 )
|
||||
height = chainActive.LastTip()->nHeight;
|
||||
height = chainActive.LastTip()->GetHeight();
|
||||
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;
|
||||
@@ -1175,10 +1176,10 @@ UniValue gettxout(const UniValue& params, bool fHelp)
|
||||
ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
|
||||
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)
|
||||
ret.push_back(Pair("confirmations", 0));
|
||||
else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1));
|
||||
else ret.push_back(Pair("confirmations", pindex->GetHeight() - coins.nHeight + 1));
|
||||
ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue)));
|
||||
uint64_t interest; int32_t txheight; uint32_t locktime;
|
||||
if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue,(int32_t)pindex->nHeight)) != 0 )
|
||||
if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue,(int32_t)pindex->GetHeight())) != 0 )
|
||||
ret.push_back(Pair("interest", ValueFromAmount(interest)));
|
||||
UniValue o(UniValue::VOBJ);
|
||||
ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true);
|
||||
@@ -1338,11 +1339,15 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
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("headers", pindexBestHeader ? pindexBestHeader->GetHeight() : -1));
|
||||
obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex()));
|
||||
obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty()));
|
||||
obj.push_back(Pair("verificationprogress", progress));
|
||||
obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex()));
|
||||
obj.push_back(Pair("chainwork", chainActive.LastTip()->chainPower.chainWork.GetHex()));
|
||||
if (ASSETCHAINS_LWMAPOS)
|
||||
{
|
||||
obj.push_back(Pair("chainstake", chainActive.LastTip()->chainPower.chainStake.GetHex()));
|
||||
}
|
||||
obj.push_back(Pair("pruned", fPruneMode));
|
||||
|
||||
SproutMerkleTree tree;
|
||||
@@ -1364,13 +1369,13 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue upgrades(UniValue::VOBJ);
|
||||
for (int i = Consensus::UPGRADE_OVERWINTER; i < Consensus::MAX_NETWORK_UPGRADES; i++) {
|
||||
NetworkUpgradeDescPushBack(upgrades, consensusParams, Consensus::UpgradeIndex(i), tip->nHeight);
|
||||
NetworkUpgradeDescPushBack(upgrades, consensusParams, Consensus::UpgradeIndex(i), tip->GetHeight());
|
||||
}
|
||||
obj.push_back(Pair("upgrades", upgrades));
|
||||
|
||||
UniValue consensus(UniValue::VOBJ);
|
||||
consensus.push_back(Pair("chaintip", HexInt(CurrentEpochBranchId(tip->nHeight, consensusParams))));
|
||||
consensus.push_back(Pair("nextblock", HexInt(CurrentEpochBranchId(tip->nHeight + 1, consensusParams))));
|
||||
consensus.push_back(Pair("chaintip", HexInt(CurrentEpochBranchId(tip->GetHeight(), consensusParams))));
|
||||
consensus.push_back(Pair("nextblock", HexInt(CurrentEpochBranchId(tip->GetHeight() + 1, consensusParams))));
|
||||
obj.push_back(Pair("consensus", consensus));
|
||||
|
||||
if (fPruneMode)
|
||||
@@ -1379,7 +1384,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA))
|
||||
block = block->pprev;
|
||||
|
||||
obj.push_back(Pair("pruneheight", block->nHeight));
|
||||
obj.push_back(Pair("pruneheight", block->GetHeight()));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -1392,8 +1397,8 @@ struct CompareBlocksByHeight
|
||||
/* Make sure that unequal blocks with the same height do not compare
|
||||
equal. Use the pointers themselves to make a distinction. */
|
||||
|
||||
if (a->nHeight != b->nHeight)
|
||||
return (a->nHeight > b->nHeight);
|
||||
if (a->GetHeight() != b->GetHeight())
|
||||
return (a->GetHeight() > b->GetHeight());
|
||||
|
||||
return a < b;
|
||||
}
|
||||
@@ -1458,12 +1463,12 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
|
||||
BOOST_FOREACH(const CBlockIndex* block, setTips)
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("height", block->nHeight));
|
||||
obj.push_back(Pair("height", block->GetHeight()));
|
||||
obj.push_back(Pair("hash", block->phashBlock->GetHex()));
|
||||
forked = chainActive.FindFork(block);
|
||||
if ( forked != 0 )
|
||||
{
|
||||
const int branchLen = block->nHeight - forked->nHeight;
|
||||
const int branchLen = block->GetHeight() - forked->GetHeight();
|
||||
obj.push_back(Pair("branchlen", branchLen));
|
||||
|
||||
string status;
|
||||
|
||||
@@ -68,7 +68,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp)
|
||||
ret.push_back(Pair("error",(char *)"no active chain yet"));
|
||||
return(ret);
|
||||
}
|
||||
height = chainActive.Tip()->nHeight;
|
||||
height = chainActive.Tip()->GetHeight();
|
||||
}
|
||||
//fprintf(stderr,"height_MoM height.%d\n",height);
|
||||
depth = komodo_MoM(¬arized_height,&MoM,&kmdtxid,height,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi);
|
||||
|
||||
@@ -49,7 +49,7 @@ int64_t GetNetworkHashPS(int lookup, int height) {
|
||||
if (height >= 0 && height < chainActive.Height())
|
||||
pb = chainActive[height];
|
||||
|
||||
if (pb == NULL || !pb->nHeight)
|
||||
if (pb == NULL || !pb->GetHeight())
|
||||
return 0;
|
||||
|
||||
// If lookup is nonpositive, then use difficulty averaging window.
|
||||
@@ -57,8 +57,8 @@ int64_t GetNetworkHashPS(int lookup, int height) {
|
||||
lookup = Params().GetConsensus().nPowAveragingWindow;
|
||||
|
||||
// If lookup is larger than chain, then set it to chain length.
|
||||
if (lookup > pb->nHeight)
|
||||
lookup = pb->nHeight;
|
||||
if (lookup > pb->GetHeight())
|
||||
lookup = pb->GetHeight();
|
||||
|
||||
CBlockIndex *pb0 = pb;
|
||||
int64_t minTime = pb0->GetBlockTime();
|
||||
@@ -74,7 +74,7 @@ int64_t GetNetworkHashPS(int lookup, int height) {
|
||||
if (minTime == maxTime)
|
||||
return 0;
|
||||
|
||||
arith_uint256 workDiff = pb->nChainWork - pb0->nChainWork;
|
||||
arith_uint256 workDiff = pb->chainPower.chainWork - pb0->chainPower.chainWork;
|
||||
int64_t timeDiff = maxTime - minTime;
|
||||
|
||||
return (int64_t)(workDiff.getdouble() / timeDiff);
|
||||
@@ -273,7 +273,7 @@ UniValue generate(const UniValue& params, bool fHelp)
|
||||
}
|
||||
endloop:
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||
if (!ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, pblock, true, NULL))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
|
||||
++nHeight;
|
||||
blockHashes.push_back(pblock->GetHash().GetHex());
|
||||
@@ -657,7 +657,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
CReserveKey reservekey(pwalletMain);
|
||||
pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.LastTip()->nHeight+1,KOMODO_MAXGPUCOUNT);
|
||||
pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.LastTip()->GetHeight()+1,KOMODO_MAXGPUCOUNT);
|
||||
#else
|
||||
pblocktemplate = CreateNewBlockWithKey();
|
||||
#endif
|
||||
@@ -710,7 +710,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.LastTip()->nHeight+1, Params().GetConsensus());
|
||||
CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->GetHeight()+1, Params().GetConsensus());
|
||||
entry.push_back(Pair("coinbasevalue", nReward));
|
||||
entry.push_back(Pair("required", true));
|
||||
txCoinbase = entry;
|
||||
@@ -748,7 +748,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
if ( ASSETCHAINS_STAKED != 0 )
|
||||
{
|
||||
arith_uint256 POWtarget; int32_t PoSperc;
|
||||
POWtarget = komodo_PoWtarget(&PoSperc,hashTarget,(int32_t)(pindexPrev->nHeight+1),ASSETCHAINS_STAKED);
|
||||
POWtarget = komodo_PoWtarget(&PoSperc,hashTarget,(int32_t)(pindexPrev->GetHeight()+1),ASSETCHAINS_STAKED);
|
||||
result.push_back(Pair("target", POWtarget.GetHex()));
|
||||
result.push_back(Pair("PoSperc", (int64_t)PoSperc));
|
||||
result.push_back(Pair("ac_staked", (int64_t)ASSETCHAINS_STAKED));
|
||||
@@ -761,7 +761,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
|
||||
result.push_back(Pair("curtime", pblock->GetBlockTime()));
|
||||
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
|
||||
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
|
||||
result.push_back(Pair("height", (int64_t)(pindexPrev->GetHeight()+1)));
|
||||
|
||||
//fprintf(stderr,"return complete template\n");
|
||||
return result;
|
||||
@@ -835,7 +835,7 @@ UniValue submitblock(const UniValue& params, bool fHelp)
|
||||
CValidationState state;
|
||||
submitblock_StateCatcher sc(block.GetHash());
|
||||
RegisterValidationInterface(&sc);
|
||||
bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, &block, true, NULL);
|
||||
bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, &block, true, NULL);
|
||||
UnregisterValidationInterface(&sc);
|
||||
if (fBlockPresent)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ uint32_t komodo_segid32(char *coinaddr);
|
||||
int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height);
|
||||
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
|
||||
#define KOMODO_VERSION "0.2.1"
|
||||
#define VERUS_VERSION "0.3.13"
|
||||
#define VERUS_VERSION "0.3.2"
|
||||
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||
extern uint32_t ASSETCHAINS_CC;
|
||||
extern uint32_t ASSETCHAINS_MAGIC;
|
||||
@@ -156,7 +156,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.LastTip()->nHeight,komodo_chainactive_timestamp())) >= 0 )
|
||||
if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->GetHeight(),komodo_chainactive_timestamp())) >= 0 )
|
||||
{
|
||||
obj.push_back(Pair("notaryid", notaryid));
|
||||
obj.push_back(Pair("pubkey", pubkeystr));
|
||||
|
||||
@@ -233,7 +233,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && 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);
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight());
|
||||
out.push_back(Pair("interest", ValueFromAmount(interest)));
|
||||
}
|
||||
out.push_back(Pair("valueSat", txout.nValue)); // [+] Decker
|
||||
@@ -325,7 +325,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && 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);
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight());
|
||||
out.push_back(Pair("interest", ValueFromAmount(interest)));
|
||||
}
|
||||
out.push_back(Pair("valueZat", txout.nValue));
|
||||
@@ -357,7 +357,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
||||
if (mi != mapBlockIndex.end() && (*mi).second) {
|
||||
CBlockIndex* pindex = (*mi).second;
|
||||
if (chainActive.Contains(pindex)) {
|
||||
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
|
||||
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->GetHeight()));
|
||||
entry.push_back(Pair("time", pindex->GetBlockTime()));
|
||||
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
|
||||
}
|
||||
@@ -483,8 +483,8 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
|
||||
if (mi != mapBlockIndex.end() && (*mi).second) {
|
||||
CBlockIndex* pindex = (*mi).second;
|
||||
if (chainActive.Contains(pindex)) {
|
||||
nHeight = pindex->nHeight;
|
||||
nConfirmations = 1 + chainActive.Height() - pindex->nHeight;
|
||||
nHeight = pindex->GetHeight();
|
||||
nConfirmations = 1 + chainActive.Height() - pindex->GetHeight();
|
||||
nBlockTime = pindex->GetBlockTime();
|
||||
} else {
|
||||
nHeight = -1;
|
||||
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
eval.txs[sessionTx.GetHash()] = sessionTx;
|
||||
|
||||
CBlockIndex sessionBlock;
|
||||
sessionBlock.nHeight = 10;
|
||||
sessionBlock.SetHeight(10);
|
||||
eval.blocks[sessionTx.GetHash()] = sessionBlock;
|
||||
|
||||
std::vector<CTransaction> sessionSpends;
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace TestEvalNotarisation {
|
||||
modify(notary);
|
||||
|
||||
eval.txs[notary.GetHash()] = CTransaction(notary);
|
||||
eval.blocks[notary.GetHash()].nHeight = 780060;
|
||||
eval.blocks[notary.GetHash()].SetHeight(780060);
|
||||
eval.blocks[notary.GetHash()].nTime = 1522946781;
|
||||
}
|
||||
|
||||
|
||||
@@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(PartitionAlert)
|
||||
indexDummy[i].phashBlock = NULL;
|
||||
if (i == 0) indexDummy[i].pprev = NULL;
|
||||
else indexDummy[i].pprev = &indexDummy[i-1];
|
||||
indexDummy[i].nHeight = i;
|
||||
indexDummy[i].SetHeight(i);
|
||||
indexDummy[i].nTime = now - (400-i)*nPowTargetSpacing;
|
||||
// Other members don't matter, the partition check code doesn't
|
||||
// use them
|
||||
|
||||
@@ -387,13 +387,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
|
||||
// subsidy changing
|
||||
int nHeight = chainActive.Height();
|
||||
chainActive.Tip()->nHeight = 209999;
|
||||
chainActive.Tip()->SetHeight(209999);
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
|
||||
delete pblocktemplate;
|
||||
chainActive.Tip()->nHeight = 210000;
|
||||
chainActive.Tip()->SetHeight(210000);
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
|
||||
delete pblocktemplate;
|
||||
chainActive.Tip()->nHeight = nHeight;
|
||||
chainActive.Tip()->SetHeight(nHeight);
|
||||
|
||||
// non-final txs in mempool
|
||||
SetMockTime(chainActive.Tip()->GetMedianTimePast()+1);
|
||||
@@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
tx.vin[0].nSequence = 0;
|
||||
tx.vout[0].nValue = 49000LL;
|
||||
tx.vout[0].scriptPubKey = CScript() << OP_1;
|
||||
tx.nLockTime = chainActive.Tip()->nHeight+1;
|
||||
tx.nLockTime = chainActive.Tip()->GetHeight()+1;
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
||||
BOOST_CHECK(!CheckFinalTx(tx, LOCKTIME_MEDIAN_TIME_PAST));
|
||||
@@ -430,7 +430,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
delete pblocktemplate;
|
||||
|
||||
// However if we advance height and time by one, both will.
|
||||
chainActive.Tip()->nHeight++;
|
||||
chainActive.Tip()->SetHeight(chainActive.Tip()->GetHeight() + 1);
|
||||
SetMockTime(chainActive.Tip()->GetMedianTimePast()+2);
|
||||
|
||||
// FIXME: we should *actually* create a new block so the following test
|
||||
@@ -442,7 +442,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2);
|
||||
delete pblocktemplate;
|
||||
|
||||
chainActive.Tip()->nHeight--;
|
||||
chainActive.Tip()->SetHeight(chainActive.Tip()->GetHeight() - 1);
|
||||
SetMockTime(0);
|
||||
mempool.clear();
|
||||
|
||||
|
||||
@@ -78,10 +78,12 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
||||
std::vector<CBlockIndex> blocks(10000);
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
blocks[i].pprev = i ? &blocks[i - 1] : NULL;
|
||||
blocks[i].nHeight = i;
|
||||
blocks[i].SetHeight(i);
|
||||
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
|
||||
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
|
||||
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
|
||||
blocks[i].chainPower = CChainPower(&blocks[i]);
|
||||
if (i != 0)
|
||||
blocks[i].chainPower += GetBlockProof(blocks[i - 1]);
|
||||
}
|
||||
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
|
||||
@@ -1291,7 +1291,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_taddr_to_sapling)
|
||||
block.hashMerkleRoot = block.BuildMerkleTree();
|
||||
auto blockHash = block.GetHash();
|
||||
CBlockIndex fakeIndex {block};
|
||||
fakeIndex.nHeight = 1;
|
||||
fakeIndex.SetHeight(1);
|
||||
mapBlockIndex.insert(std::make_pair(blockHash, &fakeIndex));
|
||||
chainActive.SetTip(&fakeIndex);
|
||||
BOOST_CHECK(chainActive.Contains(&fakeIndex));
|
||||
|
||||
@@ -20,15 +20,15 @@ BOOST_AUTO_TEST_CASE(skiplist_test)
|
||||
std::vector<CBlockIndex> vIndex(SKIPLIST_LENGTH);
|
||||
|
||||
for (int i=0; i<SKIPLIST_LENGTH; i++) {
|
||||
vIndex[i].nHeight = i;
|
||||
vIndex[i].SetHeight(i);
|
||||
vIndex[i].pprev = (i == 0) ? NULL : &vIndex[i - 1];
|
||||
vIndex[i].BuildSkip();
|
||||
}
|
||||
|
||||
for (int i=0; i<SKIPLIST_LENGTH; i++) {
|
||||
if (i > 0) {
|
||||
BOOST_CHECK(vIndex[i].pskip == &vIndex[vIndex[i].pskip->nHeight]);
|
||||
BOOST_CHECK(vIndex[i].pskip->nHeight < i);
|
||||
BOOST_CHECK(vIndex[i].pskip == &vIndex[vIndex[i].pskip->GetHeight()]);
|
||||
BOOST_CHECK(vIndex[i].pskip->GetHeight() < i);
|
||||
} else {
|
||||
BOOST_CHECK(vIndex[i].pskip == NULL);
|
||||
}
|
||||
@@ -51,12 +51,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
std::vector<CBlockIndex> vBlocksMain(100000);
|
||||
for (unsigned int i=0; i<vBlocksMain.size(); i++) {
|
||||
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height, so we can quickly check the distances.
|
||||
vBlocksMain[i].nHeight = i;
|
||||
vBlocksMain[i].SetHeight(i);
|
||||
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : NULL;
|
||||
vBlocksMain[i].phashBlock = &vHashMain[i];
|
||||
vBlocksMain[i].BuildSkip();
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].nHeight);
|
||||
BOOST_CHECK(vBlocksMain[i].pprev == NULL || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].GetHeight());
|
||||
BOOST_CHECK(vBlocksMain[i].pprev == NULL || vBlocksMain[i].GetHeight() == vBlocksMain[i].pprev->GetHeight() + 1);
|
||||
}
|
||||
|
||||
// Build a branch that splits off at block 49999, 50000 blocks long.
|
||||
@@ -64,12 +64,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
std::vector<CBlockIndex> vBlocksSide(50000);
|
||||
for (unsigned int i=0; i<vBlocksSide.size(); i++) {
|
||||
vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
|
||||
vBlocksSide[i].nHeight = i + 50000;
|
||||
vBlocksSide[i].SetHeight(i + 50000);
|
||||
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : &vBlocksMain[49999];
|
||||
vBlocksSide[i].phashBlock = &vHashSide[i];
|
||||
vBlocksSide[i].BuildSkip();
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);
|
||||
BOOST_CHECK(vBlocksSide[i].pprev == NULL || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].GetHeight());
|
||||
BOOST_CHECK(vBlocksSide[i].pprev == NULL || vBlocksSide[i].GetHeight() == vBlocksSide[i].pprev->GetHeight() + 1);
|
||||
}
|
||||
|
||||
// Build a CChain for the main branch.
|
||||
@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
|
||||
// Entries 1 through 11 (inclusive) go back one step each.
|
||||
for (unsigned int i = 1; i < 12 && i < locator.vHave.size() - 1; i++) {
|
||||
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i]).GetLow64(), tip->nHeight - i);
|
||||
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i]).GetLow64(), tip->GetHeight() - i);
|
||||
}
|
||||
|
||||
// The further ones (excluding the last one) go back with exponential steps.
|
||||
|
||||
@@ -261,7 +261,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
|
||||
}
|
||||
{
|
||||
LOCK(cs_main);
|
||||
stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight;
|
||||
stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->GetHeight();
|
||||
}
|
||||
stats.hashSerialized = ss.GetHash();
|
||||
stats.nTotalAmount = nTotalAmount;
|
||||
@@ -675,7 +675,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
|
||||
// Construct block index object
|
||||
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
|
||||
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
|
||||
pindexNew->nHeight = diskindex.nHeight;
|
||||
pindexNew->SetHeight(diskindex.GetHeight());
|
||||
pindexNew->nFile = diskindex.nFile;
|
||||
pindexNew->nDataPos = diskindex.nDataPos;
|
||||
pindexNew->nUndoPos = diskindex.nUndoPos;
|
||||
@@ -700,8 +700,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
|
||||
if ( 0 ) // POW will be checked before any block is connected
|
||||
{
|
||||
uint8_t pubkey33[33];
|
||||
komodo_index2pubkey33(pubkey33,pindexNew,pindexNew->nHeight);
|
||||
if (!CheckProofOfWork(header,pubkey33,pindexNew->nHeight,Params().GetConsensus()))
|
||||
komodo_index2pubkey33(pubkey33,pindexNew,pindexNew->GetHeight());
|
||||
if (!CheckProofOfWork(header,pubkey33,pindexNew->GetHeight(),Params().GetConsensus()))
|
||||
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
|
||||
}
|
||||
pcursor->Next();
|
||||
|
||||
@@ -488,7 +488,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight)
|
||||
{
|
||||
const CTransaction& tx = it->GetTx();
|
||||
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)
|
||||
if (IsExpiredTx(tx, nBlockHeight) || (ASSETCHAINS_SYMBOL[0] == 0 && tipindex != 0 && komodo_validate_interest(tx,tipindex->GetHeight()+1,tipindex->GetMedianTimePast() + 777,0)) < 0)
|
||||
{
|
||||
transactionsToRemove.push_back(tx);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ uint32_t ASSETCHAINS_VERUSHASH = 1;
|
||||
uint32_t ASSETCHAINS_ALGO = 0;
|
||||
int32_t ASSETCHAINS_LWMAPOS = 0;
|
||||
int32_t VERUS_BLOCK_POSUNITS = 1000;
|
||||
int32_t ASSETCHAINS_OVERWINTER = 227520 - 120;
|
||||
int32_t ASSETCHAINS_SAPLING = 227520;
|
||||
|
||||
unsigned int MAX_BLOCK_SIGOPS = 20000;
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
||||
if (mapBlockIndex.find(wtx.hashBlock) == mapBlockIndex.end()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("mapBlockIndex does not contain block hash %s", wtx.hashBlock.ToString()));
|
||||
}
|
||||
wtxHeight = mapBlockIndex[wtx.hashBlock]->nHeight;
|
||||
wtxHeight = mapBlockIndex[wtx.hashBlock]->GetHeight();
|
||||
wtxDepth = wtx.GetDepthInMainChain();
|
||||
}
|
||||
LogPrint("zrpcunsafe", "%s: spending note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, height=%d, confirmations=%d)\n",
|
||||
|
||||
@@ -808,7 +808,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
if (mapBlockIndex.find(wtx.hashBlock) == mapBlockIndex.end()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("mapBlockIndex does not contain block hash %s", wtx.hashBlock.ToString()));
|
||||
}
|
||||
wtxHeight = mapBlockIndex[wtx.hashBlock]->nHeight;
|
||||
wtxHeight = mapBlockIndex[wtx.hashBlock]->GetHeight();
|
||||
wtxDepth = wtx.GetDepthInMainChain();
|
||||
}
|
||||
LogPrint("zrpcunsafe", "%s: spending note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, height=%d, confirmations=%d)\n",
|
||||
|
||||
@@ -243,7 +243,7 @@ TEST(WalletTests, FindUnspentSproutNotes) {
|
||||
auto blockHash2 = block2.GetHash();
|
||||
CBlockIndex fakeIndex2 {block2};
|
||||
mapBlockIndex.insert(std::make_pair(blockHash2, &fakeIndex2));
|
||||
fakeIndex2.nHeight = 1;
|
||||
fakeIndex2.SetHeight(1);
|
||||
chainActive.SetTip(&fakeIndex2);
|
||||
EXPECT_TRUE(chainActive.Contains(&fakeIndex2));
|
||||
EXPECT_EQ(1, chainActive.Height());
|
||||
@@ -302,7 +302,7 @@ TEST(WalletTests, FindUnspentSproutNotes) {
|
||||
auto blockHash3 = block3.GetHash();
|
||||
CBlockIndex fakeIndex3 {block3};
|
||||
mapBlockIndex.insert(std::make_pair(blockHash3, &fakeIndex3));
|
||||
fakeIndex3.nHeight = 2;
|
||||
fakeIndex3.SetHeight(2);
|
||||
chainActive.SetTip(&fakeIndex3);
|
||||
EXPECT_TRUE(chainActive.Contains(&fakeIndex3));
|
||||
EXPECT_EQ(2, chainActive.Height());
|
||||
@@ -1136,7 +1136,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) {
|
||||
auto blockHash2 = block2.GetHash();
|
||||
CBlockIndex fakeIndex2 {block2};
|
||||
mapBlockIndex.insert(std::make_pair(blockHash2, &fakeIndex2));
|
||||
fakeIndex2.nHeight = 1;
|
||||
fakeIndex2.SetHeight(1);
|
||||
chainActive.SetTip(&fakeIndex2);
|
||||
EXPECT_TRUE(chainActive.Contains(&fakeIndex2));
|
||||
EXPECT_EQ(1, chainActive.Height());
|
||||
@@ -1236,7 +1236,7 @@ TEST(WalletTests, CachedWitnessesChainTip) {
|
||||
{
|
||||
// First block (case tested in _empty_chain)
|
||||
CBlockIndex index1(block1);
|
||||
index1.nHeight = 1;
|
||||
index1.SetHeight(1);
|
||||
auto outpts = CreateValidBlock(wallet, sk, index1, block1, sproutTree, saplingTree);
|
||||
|
||||
// Called to fetch anchor
|
||||
@@ -1277,7 +1277,7 @@ TEST(WalletTests, CachedWitnessesChainTip) {
|
||||
block2.hashPrevBlock = block1.GetHash();
|
||||
block2.vtx.push_back(wtx);
|
||||
CBlockIndex index2(block2);
|
||||
index2.nHeight = 2;
|
||||
index2.SetHeight(2);
|
||||
SproutMerkleTree sproutTree2 {sproutTree};
|
||||
SaplingMerkleTree saplingTree2 {saplingTree};
|
||||
wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree2, saplingTree2);
|
||||
@@ -1337,7 +1337,7 @@ TEST(WalletTests, CachedWitnessesDecrementFirst) {
|
||||
// First block (case tested in _empty_chain)
|
||||
CBlock block1;
|
||||
CBlockIndex index1(block1);
|
||||
index1.nHeight = 1;
|
||||
index1.SetHeight(1);
|
||||
CreateValidBlock(wallet, sk, index1, block1, sproutTree, saplingTree);
|
||||
}
|
||||
|
||||
@@ -1347,7 +1347,7 @@ TEST(WalletTests, CachedWitnessesDecrementFirst) {
|
||||
|
||||
{
|
||||
// Second block (case tested in _chain_tip)
|
||||
index2.nHeight = 2;
|
||||
index2.SetHeight(2);
|
||||
auto outpts = CreateValidBlock(wallet, sk, index2, block2, sproutTree, saplingTree);
|
||||
|
||||
// Called to fetch anchor
|
||||
@@ -1428,7 +1428,7 @@ TEST(WalletTests, CachedWitnessesCleanIndex) {
|
||||
blocks.resize(numBlocks);
|
||||
indices.resize(numBlocks);
|
||||
for (size_t i = 0; i < numBlocks; i++) {
|
||||
indices[i].nHeight = i;
|
||||
indices[i].SetHeight(i);
|
||||
auto oldSproutRoot = sproutTree.root();
|
||||
auto oldSaplingRoot = saplingTree.root();
|
||||
auto outpts = CreateValidBlock(wallet, sk, indices[i], blocks[i], sproutTree, saplingTree);
|
||||
|
||||
@@ -362,7 +362,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys
|
||||
if (!pwalletMain->nTimeFirstKey || nTimeBegin < pwalletMain->nTimeFirstKey)
|
||||
pwalletMain->nTimeFirstKey = nTimeBegin;
|
||||
|
||||
LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->nHeight + 1);
|
||||
LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->GetHeight() + 1);
|
||||
pwalletMain->ScanForWalletTransactions(pindex);
|
||||
pwalletMain->MarkDirty();
|
||||
|
||||
|
||||
@@ -587,7 +587,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.LastTip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
|
||||
if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
|
||||
{
|
||||
if ( (tmpflags & KOMODO_KVPROTECTED) != 0 )
|
||||
{
|
||||
@@ -612,7 +612,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.LastTip()->nHeight;
|
||||
height = chainActive.LastTip()->GetHeight();
|
||||
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
|
||||
ret.push_back(Pair("owner",refpubkey.GetHex()));
|
||||
ret.push_back(Pair("height", (int64_t)height));
|
||||
@@ -684,7 +684,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.LastTip()->nHeight;
|
||||
height = chainActive.LastTip()->GetHeight();
|
||||
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);
|
||||
@@ -1981,7 +1981,7 @@ UniValue listsinceblock(const UniValue& params, bool fHelp)
|
||||
if(params[2].get_bool())
|
||||
filter = filter | ISMINE_WATCH_ONLY;
|
||||
|
||||
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
|
||||
int depth = pindex ? (1 + chainActive.Height() - pindex->GetHeight()) : -1;
|
||||
|
||||
UniValue transactions(UniValue::VARR);
|
||||
|
||||
@@ -2738,11 +2738,11 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
uint64_t interest; uint32_t locktime; int32_t txheight;
|
||||
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_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->GetHeight());
|
||||
//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.LastTip(),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->GetHeight());
|
||||
}
|
||||
entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
|
||||
entry.push_back(Pair("confirmations", out.nDepth));
|
||||
@@ -2772,8 +2772,8 @@ uint64_t komodo_interestsum()
|
||||
CBlockIndex *tipindex,*pindex = it->second;
|
||||
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);
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->GetHeight());
|
||||
//interest = komodo_interest(pindex->GetHeight(),nValue,out.tx->nLockTime,tipindex->nTime);
|
||||
sum += interest;
|
||||
}
|
||||
}
|
||||
@@ -3455,7 +3455,7 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp)
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
bool allowSapling = (Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight <= chainActive.LastTip()->nHeight);
|
||||
bool allowSapling = (Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight <= chainActive.LastTip()->GetHeight());
|
||||
|
||||
std::string defaultType = allowSapling ? ADDR_TYPE_SAPLING : ADDR_TYPE_SPROUT;
|
||||
|
||||
@@ -4371,7 +4371,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
|
||||
contextInfo.push_back(Pair("fee", ValueFromAmount(nFee)));
|
||||
|
||||
// Contextual transaction we will build on
|
||||
int blockHeight = chainActive.LastTip()->nHeight;
|
||||
int blockHeight = chainActive.LastTip()->GetHeight();
|
||||
nextBlockHeight = blockHeight + 1;
|
||||
CMutableTransaction contextualTx = CreateNewContextualCMutableTransaction(
|
||||
Params().GetConsensus(), nextBlockHeight);
|
||||
@@ -4988,7 +4988,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
|
||||
if ( (tipindex= chainActive.Tip()) == 0 )
|
||||
return(0);
|
||||
nHeight = tipindex->nHeight + 1;
|
||||
nHeight = tipindex->GetHeight() + 1;
|
||||
if ( (minage= nHeight*3) > 6000 ) // about 100 blocks
|
||||
minage = 6000;
|
||||
komodo_segids(hashbuf,nHeight-101,100);
|
||||
@@ -5006,7 +5006,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
}
|
||||
BOOST_FOREACH(const COutput& out, vecOutputs)
|
||||
{
|
||||
if ( (tipindex= chainActive.Tip()) == 0 || tipindex->nHeight+1 > nHeight )
|
||||
if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight )
|
||||
{
|
||||
fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter);
|
||||
return(0);
|
||||
@@ -5037,7 +5037,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57;
|
||||
for (i=winners=0; i<numkp; i++)
|
||||
{
|
||||
if ( (tipindex= chainActive.Tip()) == 0 || tipindex->nHeight+1 > nHeight )
|
||||
if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight )
|
||||
{
|
||||
fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter);
|
||||
return(0);
|
||||
|
||||
@@ -943,8 +943,8 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
||||
::CopyPreviousWitnesses(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize);
|
||||
::CopyPreviousWitnesses(wtxItem.second.mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize);
|
||||
::CopyPreviousWitnesses(wtxItem.second.mapSproutNoteData, pindex->GetHeight(), nWitnessCacheSize);
|
||||
::CopyPreviousWitnesses(wtxItem.second.mapSaplingNoteData, pindex->GetHeight(), nWitnessCacheSize);
|
||||
}
|
||||
|
||||
if (nWitnessCacheSize < WITNESS_CACHE_SIZE) {
|
||||
@@ -970,13 +970,13 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
|
||||
|
||||
// Increment existing witnesses
|
||||
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
||||
::AppendNoteCommitment(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize, note_commitment);
|
||||
::AppendNoteCommitment(wtxItem.second.mapSproutNoteData, pindex->GetHeight(), nWitnessCacheSize, note_commitment);
|
||||
}
|
||||
|
||||
// If this is our note, witness it
|
||||
if (txIsOurs) {
|
||||
JSOutPoint jsoutpt {hash, i, j};
|
||||
::WitnessNoteIfMine(mapWallet[hash].mapSproutNoteData, pindex->nHeight, nWitnessCacheSize, jsoutpt, sproutTree.witness());
|
||||
::WitnessNoteIfMine(mapWallet[hash].mapSproutNoteData, pindex->GetHeight(), nWitnessCacheSize, jsoutpt, sproutTree.witness());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -987,21 +987,21 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
|
||||
|
||||
// Increment existing witnesses
|
||||
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
||||
::AppendNoteCommitment(wtxItem.second.mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize, note_commitment);
|
||||
::AppendNoteCommitment(wtxItem.second.mapSaplingNoteData, pindex->GetHeight(), nWitnessCacheSize, note_commitment);
|
||||
}
|
||||
|
||||
// If this is our note, witness it
|
||||
if (txIsOurs) {
|
||||
SaplingOutPoint outPoint {hash, i};
|
||||
::WitnessNoteIfMine(mapWallet[hash].mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize, outPoint, saplingTree.witness());
|
||||
::WitnessNoteIfMine(mapWallet[hash].mapSaplingNoteData, pindex->GetHeight(), nWitnessCacheSize, outPoint, saplingTree.witness());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update witness heights
|
||||
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
||||
::UpdateWitnessHeights(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize);
|
||||
::UpdateWitnessHeights(wtxItem.second.mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize);
|
||||
::UpdateWitnessHeights(wtxItem.second.mapSproutNoteData, pindex->GetHeight(), nWitnessCacheSize);
|
||||
::UpdateWitnessHeights(wtxItem.second.mapSaplingNoteData, pindex->GetHeight(), nWitnessCacheSize);
|
||||
}
|
||||
|
||||
// For performance reasons, we write out the witness cache in
|
||||
@@ -1056,8 +1056,8 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
||||
::DecrementNoteWitnesses(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize);
|
||||
::DecrementNoteWitnesses(wtxItem.second.mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize);
|
||||
::DecrementNoteWitnesses(wtxItem.second.mapSproutNoteData, pindex->GetHeight(), nWitnessCacheSize);
|
||||
::DecrementNoteWitnesses(wtxItem.second.mapSaplingNoteData, pindex->GetHeight(), nWitnessCacheSize);
|
||||
}
|
||||
nWitnessCacheSize -= 1;
|
||||
// TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302)
|
||||
@@ -1225,7 +1225,9 @@ bool CWallet::VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult,
|
||||
{
|
||||
if (txout.fSpendable && (UintToArith256(txout.tx->GetVerusPOSHash(&(pBlock->nNonce), txout.i, nHeight, pastHash)) <= target) && (txout.nDepth >= VERUS_MIN_STAKEAGE))
|
||||
{
|
||||
printf("Found PoS block\nnNonce: %s\n", pBlock->nNonce.GetHex().c_str());
|
||||
printf("Found PoS block\nnNonce: %s\n", pBlock->nNonce.GetHex().c_str());
|
||||
pBlock->nNonce.SetPOSEntropy(pastHash, txout.tx->GetHash(), txout.i);
|
||||
printf("new nonce: %s\n", pBlock->nNonce.GetHex().c_str());
|
||||
// get the smallest winner
|
||||
if (Solver(txout.tx->vout[txout.i].scriptPubKey, whichType, vSolutions) && (whichType == TX_PUBKEY || whichType == TX_PUBKEYHASH) &&
|
||||
(!pwinner || pwinner->tx->vout[pwinner->i].nValue > txout.tx->vout[txout.i].nValue))
|
||||
@@ -1259,7 +1261,7 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe
|
||||
}
|
||||
bnTarget = lwmaGetNextPOSRequired(tipindex, Params().GetConsensus());
|
||||
|
||||
if (!VerusSelectStakeOutput(pBlock, hashResult, stakeSource, voutNum, tipindex->nHeight + 1, bnTarget) ||
|
||||
if (!VerusSelectStakeOutput(pBlock, hashResult, stakeSource, voutNum, tipindex->GetHeight() + 1, bnTarget) ||
|
||||
!Solver(stakeSource.vout[voutNum].scriptPubKey, whichType, vSolutions))
|
||||
{
|
||||
LogPrintf("Searched for eligible staking transactions, no winners found\n");
|
||||
@@ -2530,7 +2532,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip(), false);
|
||||
while (pindex)
|
||||
{
|
||||
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
||||
if (pindex->GetHeight() % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
||||
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
|
||||
|
||||
CBlock block;
|
||||
@@ -2547,7 +2549,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
// state on the path to the tip of our chain
|
||||
assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, sproutTree));
|
||||
if (pindex->pprev) {
|
||||
if (NetworkUpgradeActive(pindex->pprev->nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||
if (NetworkUpgradeActive(pindex->pprev->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||
assert(pcoinsTip->GetSaplingAnchorAt(pindex->pprev->hashFinalSaplingRoot, saplingTree));
|
||||
}
|
||||
}
|
||||
@@ -2557,7 +2559,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
pindex = chainActive.Next(pindex);
|
||||
if (GetTime() >= nNow + 60) {
|
||||
nNow = GetTime();
|
||||
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex));
|
||||
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->GetHeight(), Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex));
|
||||
}
|
||||
}
|
||||
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
|
||||
@@ -3021,20 +3023,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.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 )
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && chainActive.LastTip()->GetHeight() >= 60000 )
|
||||
{
|
||||
if ( pcoin->vout[i].nValue >= 10*COIN )
|
||||
{
|
||||
if ( (tipindex= chainActive.LastTip()) != 0 )
|
||||
{
|
||||
komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue,(int32_t)tipindex->nHeight);
|
||||
komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue,(int32_t)tipindex->GetHeight());
|
||||
interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime);
|
||||
} else interest = 0;
|
||||
//interest = komodo_interestnew(chainActive.LastTip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.LastTip()->nTime);
|
||||
//interest = komodo_interestnew(chainActive.LastTip()->GetHeight()+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.LastTip()->nHeight+1,pcoin->nLockTime,chainActive.LastTip()->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()->GetHeight()+1,pcoin->nLockTime,chainActive.LastTip()->nTime);
|
||||
//ptr = (uint64_t *)&pcoin->vout[i].nValue;
|
||||
//(*ptr) += interest;
|
||||
ptr = (uint64_t *)&pcoin->vout[i].interest;
|
||||
@@ -4457,14 +4459,14 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
|
||||
BlockMap::const_iterator blit = mapBlockIndex.find(wtx.hashBlock);
|
||||
if (blit != mapBlockIndex.end() && chainActive.Contains(blit->second)) {
|
||||
// ... which are already in a block
|
||||
int nHeight = blit->second->nHeight;
|
||||
int nHeight = blit->second->GetHeight();
|
||||
BOOST_FOREACH(const CTxOut &txout, wtx.vout) {
|
||||
// iterate over all their outputs
|
||||
CAffectedKeysVisitor(*this, vAffected).Process(txout.scriptPubKey);
|
||||
BOOST_FOREACH(const CKeyID &keyid, vAffected) {
|
||||
// ... and all their affected keys
|
||||
std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
|
||||
if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)
|
||||
if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->GetHeight())
|
||||
rit->second = blit->second;
|
||||
}
|
||||
vAffected.clear();
|
||||
@@ -4567,7 +4569,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock& block)
|
||||
if (!pindex || !chainActive.Contains(pindex))
|
||||
return 0;
|
||||
|
||||
return chainActive.Height() - pindex->nHeight + 1;
|
||||
return chainActive.Height() - pindex->GetHeight() + 1;
|
||||
}
|
||||
|
||||
int CMerkleTx::GetDepthInMainChainINTERNAL(const CBlockIndex* &pindexRet) const
|
||||
@@ -4593,7 +4595,7 @@ int CMerkleTx::GetDepthInMainChainINTERNAL(const CBlockIndex* &pindexRet) const
|
||||
}
|
||||
|
||||
pindexRet = pindex;
|
||||
return chainActive.Height() - pindex->nHeight + 1;
|
||||
return chainActive.Height() - pindex->GetHeight() + 1;
|
||||
}
|
||||
|
||||
int CMerkleTx::GetDepthInMainChain(const CBlockIndex* &pindexRet) const
|
||||
|
||||
@@ -321,7 +321,7 @@ double benchmark_increment_note_witnesses(size_t nTxs)
|
||||
block1.vtx.push_back(wtx);
|
||||
}
|
||||
CBlockIndex index1(block1);
|
||||
index1.nHeight = 1;
|
||||
index1.SetHeight(1);
|
||||
|
||||
// Increment to get transactions witnessed
|
||||
wallet.ChainTip(&index1, &block1, sproutTree, saplingTree, true);
|
||||
@@ -344,7 +344,7 @@ double benchmark_increment_note_witnesses(size_t nTxs)
|
||||
block2.vtx.push_back(wtx);
|
||||
}
|
||||
CBlockIndex index2(block2);
|
||||
index2.nHeight = 2;
|
||||
index2.SetHeight(2);
|
||||
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
@@ -412,10 +412,10 @@ double benchmark_connectblock_slow()
|
||||
|
||||
// Fake the chain
|
||||
CBlockIndex index(block);
|
||||
index.nHeight = 107134;
|
||||
index.SetHeight(107134);
|
||||
CBlockIndex indexPrev;
|
||||
indexPrev.phashBlock = &hashPrev;
|
||||
indexPrev.nHeight = index.nHeight - 1;
|
||||
indexPrev.SetHeight(index.GetHeight() - 1);
|
||||
index.pprev = &indexPrev;
|
||||
mapBlockIndex.insert(std::make_pair(hashPrev, &indexPrev));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user