Rename CClaimTrieCache to CClaimTrieUpdateBuffer #156
5 changed files with 365 additions and 529 deletions
|
@ -249,7 +249,7 @@ bool CClaimTrie::haveSupport(const std::string& name, const uint256& txhash, uin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
|
bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int& nValidAtHeight) const
|
||||||
{
|
{
|
||||||
std::vector<CClaimValue> nameRow;
|
std::vector<CClaimValue> nameRow;
|
||||||
if (!getQueueNameRow(name, nameRow))
|
if (!getQueueNameRow(name, nameRow))
|
||||||
|
@ -259,7 +259,7 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
|
||||||
std::vector<CClaimValue>::const_iterator itNameRow;
|
std::vector<CClaimValue>::const_iterator itNameRow;
|
||||||
for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow)
|
for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow)
|
||||||
{
|
{
|
||||||
if (itNameRow->txhash == txhash && itNameRow->nOut == nOut && itNameRow->nHeight == nHeight)
|
if (itNameRow->txhash == txhash && itNameRow->nOut == nOut)
|
||||||
{
|
{
|
||||||
nValidAtHeight = itNameRow->nValidAtHeight;
|
nValidAtHeight = itNameRow->nValidAtHeight;
|
||||||
break;
|
break;
|
||||||
|
@ -274,7 +274,7 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
|
||||||
{
|
{
|
||||||
for (claimQueueRowType::const_iterator itRow = row.begin(); itRow != row.end(); ++itRow)
|
for (claimQueueRowType::const_iterator itRow = row.begin(); itRow != row.end(); ++itRow)
|
||||||
{
|
{
|
||||||
if (itRow->first == name && itRow->second.txhash == txhash && itRow->second.nOut == nOut && itRow->second.nHeight == nHeight)
|
if (itRow->first == name && itRow->second.txhash == txhash && itRow->second.nOut == nOut)
|
||||||
{
|
{
|
||||||
if (itRow->second.nValidAtHeight != nValidAtHeight)
|
if (itRow->second.nValidAtHeight != nValidAtHeight)
|
||||||
{
|
{
|
||||||
|
@ -288,7 +288,7 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
|
bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int& nValidAtHeight) const
|
||||||
{
|
{
|
||||||
std::vector<CSupportValue> nameRow;
|
std::vector<CSupportValue> nameRow;
|
||||||
if (!getSupportQueueNameRow(name, nameRow))
|
if (!getSupportQueueNameRow(name, nameRow))
|
||||||
|
@ -298,7 +298,7 @@ bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txha
|
||||||
std::vector<CSupportValue>::const_iterator itNameRow;
|
std::vector<CSupportValue>::const_iterator itNameRow;
|
||||||
for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow)
|
for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow)
|
||||||
{
|
{
|
||||||
if (itNameRow->txhash == txhash && itNameRow->nOut == nOut && itNameRow->nHeight == nHeight)
|
if (itNameRow->txhash == txhash && itNameRow->nOut == nOut)
|
||||||
{
|
{
|
||||||
nValidAtHeight = itNameRow->nValidAtHeight;
|
nValidAtHeight = itNameRow->nValidAtHeight;
|
||||||
break;
|
break;
|
||||||
|
@ -309,11 +309,11 @@ bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txha
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
supportQueueRowType row;
|
supportQueueRowType row;
|
||||||
if (getSupportQueueRow(nHeight, row))
|
if (getSupportQueueRow(nValidAtHeight, row))
|
||||||
{
|
{
|
||||||
for (supportQueueRowType::const_iterator itRow = row.begin(); itRow != row.end(); ++itRow)
|
for (supportQueueRowType::const_iterator itRow = row.begin(); itRow != row.end(); ++itRow)
|
||||||
{
|
{
|
||||||
if (itRow->first == name && itRow->second.txhash == txhash && itRow->second.nOut == nOut && itRow->second.nHeight == nHeight)
|
if (itRow->first == name && itRow->second.txhash == txhash && itRow->second.nOut == nOut)
|
||||||
{
|
{
|
||||||
if (itRow->second.nValidAtHeight != nValidAtHeight)
|
if (itRow->second.nValidAtHeight != nValidAtHeight)
|
||||||
{
|
{
|
||||||
|
@ -1955,7 +1955,7 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
|
||||||
takeoverHappened = true;
|
takeoverHappened = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (takeoverHappened && !base->fConstantDelay)
|
if (takeoverHappened)
|
||||||
{
|
{
|
||||||
// Get all claims in the queue for that name
|
// Get all claims in the queue for that name
|
||||||
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(*itNamesToCheck, false);
|
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(*itNamesToCheck, false);
|
||||||
|
@ -2040,9 +2040,7 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
|
||||||
// remove all supports from the queue for that name
|
// remove all supports from the queue for that name
|
||||||
itSupportQueueNameRow->second.clear();
|
itSupportQueueNameRow->second.clear();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (takeoverHappened)
|
|
||||||
{
|
|
||||||
// save the old last height so that it can be restored if the block is undone
|
// save the old last height so that it can be restored if the block is undone
|
||||||
if (haveClaimInTrie)
|
if (haveClaimInTrie)
|
||||||
{
|
{
|
||||||
|
@ -2127,23 +2125,16 @@ bool CClaimTrieCache::getLastTakeoverForName(const std::string& name, int& lastT
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CClaimTrieCache::getDelayForName(const std::string name) const
|
int CClaimTrieCache::getDelayForName(const std::string& name) const
|
||||||
{
|
{
|
||||||
if (base->fConstantDelay)
|
int nHeightOfLastTakeover;
|
||||||
|
if (getLastTakeoverForName(name, nHeightOfLastTakeover))
|
||||||
{
|
{
|
||||||
return base->nConstantDelayHeight;
|
return (nCurrentHeight - nHeightOfLastTakeover) / base->nProportionalDelayFactor;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int nHeightOfLastTakeover;
|
return 0;
|
||||||
if (getLastTakeoverForName(name, nHeightOfLastTakeover))
|
|
||||||
{
|
|
||||||
return nHeightOfLastTakeover >> base->nProportionalDelayBits;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,11 +222,10 @@ class CClaimTrieCache;
|
||||||
class CClaimTrie
|
class CClaimTrie
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CClaimTrie(bool fMemory = false, bool fWipe = false, bool fConstantDelay = false)
|
CClaimTrie(bool fMemory = false, bool fWipe = false, int nProportionalDelayFactor = 32)
|
||||||
: db(GetDataDir() / "claimtrie", 100, fMemory, fWipe, false)
|
: db(GetDataDir() / "claimtrie", 100, fMemory, fWipe, false)
|
||||||
, nCurrentHeight(0), nExpirationTime(262974)
|
, nCurrentHeight(0), nExpirationTime(262974)
|
||||||
, fConstantDelay(fConstantDelay), nConstantDelayHeight(100)
|
, nProportionalDelayFactor(nProportionalDelayFactor)
|
||||||
, nProportionalDelayBits(5)
|
|
||||||
, root(uint256S("0000000000000000000000000000000000000000000000000000000000000001"))
|
, root(uint256S("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -261,14 +260,12 @@ public:
|
||||||
bool haveClaim(const std::string& name, const uint256& txhash,
|
bool haveClaim(const std::string& name, const uint256& txhash,
|
||||||
uint32_t nOut) const;
|
uint32_t nOut) const;
|
||||||
bool haveClaimInQueue(const std::string& name, const uint256& txhash,
|
bool haveClaimInQueue(const std::string& name, const uint256& txhash,
|
||||||
uint32_t nOut, int nHeight,
|
uint32_t nOut, int& nValidAtHeight) const;
|
||||||
int& nValidAtHeight) const;
|
|
||||||
|
|
||||||
bool haveSupport(const std::string& name, const uint256& txhash,
|
bool haveSupport(const std::string& name, const uint256& txhash,
|
||||||
uint32_t nOut) const;
|
uint32_t nOut) const;
|
||||||
bool haveSupportInQueue(const std::string& name, const uint256& txhash,
|
bool haveSupportInQueue(const std::string& name, const uint256& txhash,
|
||||||
uint32_t nOut, int nHeight,
|
uint32_t nOut, int& nValidAtHeight) const;
|
||||||
int& nValidAtHeight) const;
|
|
||||||
|
|
||||||
unsigned int getTotalNamesInTrie() const;
|
unsigned int getTotalNamesInTrie() const;
|
||||||
unsigned int getTotalClaimsInTrie() const;
|
unsigned int getTotalClaimsInTrie() const;
|
||||||
|
@ -279,9 +276,7 @@ public:
|
||||||
CLevelDBWrapper db;
|
CLevelDBWrapper db;
|
||||||
int nCurrentHeight;
|
int nCurrentHeight;
|
||||||
int nExpirationTime;
|
int nExpirationTime;
|
||||||
bool fConstantDelay;
|
int nProportionalDelayFactor;
|
||||||
int nConstantDelayHeight;
|
|
||||||
int nProportionalDelayBits;
|
|
||||||
private:
|
private:
|
||||||
void clear(CClaimTrieNode* current);
|
void clear(CClaimTrieNode* current);
|
||||||
|
|
||||||
|
@ -491,7 +486,7 @@ private:
|
||||||
|
|
||||||
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
||||||
|
|
||||||
int getDelayForName(const std::string name) const;
|
int getDelayForName(const std::string& name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_CLAIMTRIE_H
|
#endif // BITCOIN_CLAIMTRIE_H
|
||||||
|
|
|
@ -263,7 +263,7 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int nValidAtHeight;
|
int nValidAtHeight;
|
||||||
if (pclaimTrie->haveClaimInQueue(sName, hash, i, nHeight, nValidAtHeight))
|
if (pclaimTrie->haveClaimInQueue(sName, hash, i, nValidAtHeight))
|
||||||
{
|
{
|
||||||
o.push_back(Pair("in queue", true));
|
o.push_back(Pair("in queue", true));
|
||||||
o.push_back(Pair("blocks to valid", nValidAtHeight - chainActive.Height()));
|
o.push_back(Pair("blocks to valid", nValidAtHeight - chainActive.Height()));
|
||||||
|
@ -281,7 +281,7 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
|
||||||
if (!inSupportMap)
|
if (!inSupportMap)
|
||||||
{
|
{
|
||||||
int nValidAtHeight;
|
int nValidAtHeight;
|
||||||
if (pclaimTrie->haveSupportInQueue(sName, hash, i, nHeight, nValidAtHeight))
|
if (pclaimTrie->haveSupportInQueue(sName, hash, i, nValidAtHeight))
|
||||||
{
|
{
|
||||||
o.push_back(Pair("in queue", true));
|
o.push_back(Pair("in queue", true));
|
||||||
o.push_back(Pair("blocks to valid", nValidAtHeight - chainActive.Height()));
|
o.push_back(Pair("blocks to valid", nValidAtHeight - chainActive.Height()));
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -59,7 +59,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||||
pblocktree = new CBlockTreeDB(1 << 20, true);
|
pblocktree = new CBlockTreeDB(1 << 20, true);
|
||||||
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
||||||
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
|
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
|
||||||
pclaimTrie = new CClaimTrie(true, false, true);
|
pclaimTrie = new CClaimTrie(true, false, 1);
|
||||||
InitBlockIndex();
|
InitBlockIndex();
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
bool fFirstRun;
|
bool fFirstRun;
|
||||||
|
|
Loading…
Reference in a new issue