Separate disk related functions in CClaimTrieDb #140
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;
|
||||
}
|
||||
|
||||
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;
|
||||
if (!getQueueNameRow(name, nameRow))
|
||||
|
@ -259,7 +259,7 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
|
|||
std::vector<CClaimValue>::const_iterator 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;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -288,7 +288,7 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
|
|||
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;
|
||||
if (!getSupportQueueNameRow(name, nameRow))
|
||||
|
@ -298,7 +298,7 @@ bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txha
|
|||
std::vector<CSupportValue>::const_iterator 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;
|
||||
break;
|
||||
|
@ -309,11 +309,11 @@ bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txha
|
|||
return false;
|
||||
}
|
||||
supportQueueRowType row;
|
||||
if (getSupportQueueRow(nHeight, row))
|
||||
if (getSupportQueueRow(nValidAtHeight, row))
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -1955,7 +1955,7 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
|
|||
takeoverHappened = true;
|
||||
}
|
||||
}
|
||||
if (takeoverHappened && !base->fConstantDelay)
|
||||
if (takeoverHappened)
|
||||
{
|
||||
// Get all claims in the queue for that name
|
||||
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
|
||||
itSupportQueueNameRow->second.clear();
|
||||
}
|
||||
}
|
||||
if (takeoverHappened)
|
||||
{
|
||||
|
||||
// save the old last height so that it can be restored if the block is undone
|
||||
if (haveClaimInTrie)
|
||||
{
|
||||
|
@ -2127,23 +2125,16 @@ bool CClaimTrieCache::getLastTakeoverForName(const std::string& name, int& lastT
|
|||
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
|
||||
{
|
||||
int nHeightOfLastTakeover;
|
||||
if (getLastTakeoverForName(name, nHeightOfLastTakeover))
|
||||
{
|
||||
return nHeightOfLastTakeover >> base->nProportionalDelayBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -222,11 +222,10 @@ class CClaimTrieCache;
|
|||
class CClaimTrie
|
||||
{
|
||||
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)
|
||||
, nCurrentHeight(0), nExpirationTime(262974)
|
||||
, fConstantDelay(fConstantDelay), nConstantDelayHeight(100)
|
||||
, nProportionalDelayBits(5)
|
||||
, nProportionalDelayFactor(nProportionalDelayFactor)
|
||||
, root(uint256S("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
{}
|
||||
|
||||
|
@ -261,14 +260,12 @@ public:
|
|||
bool haveClaim(const std::string& name, const uint256& txhash,
|
||||
uint32_t nOut) const;
|
||||
bool haveClaimInQueue(const std::string& name, const uint256& txhash,
|
||||
uint32_t nOut, int nHeight,
|
||||
int& nValidAtHeight) const;
|
||||
uint32_t nOut, int& nValidAtHeight) const;
|
||||
|
||||
bool haveSupport(const std::string& name, const uint256& txhash,
|
||||
uint32_t nOut) const;
|
||||
bool haveSupportInQueue(const std::string& name, const uint256& txhash,
|
||||
uint32_t nOut, int nHeight,
|
||||
int& nValidAtHeight) const;
|
||||
uint32_t nOut, int& nValidAtHeight) const;
|
||||
|
||||
unsigned int getTotalNamesInTrie() const;
|
||||
unsigned int getTotalClaimsInTrie() const;
|
||||
|
@ -279,9 +276,7 @@ public:
|
|||
CLevelDBWrapper db;
|
||||
int nCurrentHeight;
|
||||
int nExpirationTime;
|
||||
bool fConstantDelay;
|
||||
int nConstantDelayHeight;
|
||||
int nProportionalDelayBits;
|
||||
int nProportionalDelayFactor;
|
||||
private:
|
||||
void clear(CClaimTrieNode* current);
|
||||
|
||||
|
@ -491,7 +486,7 @@ private:
|
|||
|
||||
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
|
||||
|
|
|
@ -263,7 +263,7 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
|
|||
else
|
||||
{
|
||||
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("blocks to valid", nValidAtHeight - chainActive.Height()));
|
||||
|
@ -281,7 +281,7 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
|
|||
if (!inSupportMap)
|
||||
{
|
||||
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("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);
|
||||
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
||||
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
|
||||
pclaimTrie = new CClaimTrie(true, false, true);
|
||||
pclaimTrie = new CClaimTrie(true, false, 1);
|
||||
InitBlockIndex();
|
||||
#ifdef ENABLE_WALLET
|
||||
bool fFirstRun;
|
||||
|
|
Loading…
Reference in a new issue