Rename CClaimTrieCache to CClaimTrieUpdateBuffer #156

Closed
kaykurokawa wants to merge 276 commits from cclaimtriecache_change into master
2 changed files with 45 additions and 44 deletions
Showing only changes of commit 4d3c19e626 - Show all commits

View file

@ -255,17 +255,17 @@ bool CClaimTrie::haveSupport(const std::string& name, const COutPoint& outPoint)
bool CClaimTrie::haveClaimInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const bool CClaimTrie::haveClaimInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const
{ {
std::vector<CClaimValue> nameRow; std::vector<claimQueueNamesEntryType> nameRow;
if (!getQueueNameRow(name, nameRow)) if (!getQueueNameRow(name, nameRow))
{ {
return false; return false;
} }
std::vector<CClaimValue>::const_iterator itNameRow; std::vector<claimQueueNamesEntryType>::const_iterator itNameRow;
for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow) for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow)
{ {
if (itNameRow->outPoint == outPoint) if (itNameRow->first == outPoint)
{ {
nValidAtHeight = itNameRow->nValidAtHeight; nValidAtHeight = itNameRow->second;
break; break;
} }
} }
@ -289,7 +289,7 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const COutPoint& outP
} }
} }
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nValidAtHeight, nCurrentHeight); LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nValidAtHeight, nCurrentHeight);
return false; return false;
} }
bool CClaimTrie::haveSupportInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const bool CClaimTrie::haveSupportInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const
@ -499,7 +499,7 @@ bool CClaimTrie::getQueueRow(int nHeight, claimQueueRowType& row) const
return db.Read(std::make_pair(CLAIM_QUEUE_ROW, nHeight), row); return db.Read(std::make_pair(CLAIM_QUEUE_ROW, nHeight), row);
} }
bool CClaimTrie::getQueueNameRow(const std::string& name, std::vector<CClaimValue>& row) const bool CClaimTrie::getQueueNameRow(const std::string& name, std::vector<claimQueueNamesEntryType>& row) const
{ {
claimQueueNamesType::const_iterator itQueueNameRow = dirtyQueueNameRows.find(name); claimQueueNamesType::const_iterator itQueueNameRow = dirtyQueueNameRows.find(name);
if (itQueueNameRow != dirtyQueueNameRows.end()) if (itQueueNameRow != dirtyQueueNameRows.end())
@ -535,14 +535,14 @@ void CClaimTrie::updateQueueRow(int nHeight, claimQueueRowType& row)
itQueueRow->second.swap(row); itQueueRow->second.swap(row);
} }
void CClaimTrie::updateQueueNameRow(const std::string& name, std::vector<CClaimValue>& row) void CClaimTrie::updateQueueNameRow(const std::string& name, std::vector<claimQueueNamesEntryType>& row)
{ {
claimQueueNamesType::iterator itQueueRow = dirtyQueueNameRows.find(name); claimQueueNamesType::iterator itQueueRow = dirtyQueueNameRows.find(name);
if (itQueueRow == dirtyQueueNameRows.end()) if (itQueueRow == dirtyQueueNameRows.end())
{ {
std::vector<CClaimValue> newRow; std::vector<claimQueueNamesEntryType> newRow;
std::pair<claimQueueNamesType::iterator, bool> ret; std::pair<claimQueueNamesType::iterator, bool> ret;
ret = dirtyQueueNameRows.insert(std::pair<std::string, std::vector<CClaimValue> >(name, newRow)); ret = dirtyQueueNameRows.insert(std::pair<std::string, std::vector<claimQueueNamesEntryType> >(name, newRow));
assert(ret.second); assert(ret.second);
itQueueRow = ret.first; itQueueRow = ret.first;
} }
@ -1389,7 +1389,7 @@ claimQueueNamesType::iterator CClaimTrieCache::getQueueCacheNameRow(const std::s
if (itQueueNameRow == claimQueueNameCache.end()) if (itQueueNameRow == claimQueueNameCache.end())
{ {
// Have to make a new name row and put it in the cache, if createIfNotExists is true // Have to make a new name row and put it in the cache, if createIfNotExists is true
std::vector<CClaimValue> queueNameRow; std::vector<claimQueueNamesEntryType> queueNameRow;
// If the row exists in the base, copy its claims into the new row. // If the row exists in the base, copy its claims into the new row.
bool exists = base->getQueueNameRow(name, queueNameRow); bool exists = base->getQueueNameRow(name, queueNameRow);
if (!exists) if (!exists)
@ -1397,7 +1397,7 @@ claimQueueNamesType::iterator CClaimTrieCache::getQueueCacheNameRow(const std::s
return itQueueNameRow; return itQueueNameRow;
// Stick the new row in the cache // Stick the new row in the cache
std::pair<claimQueueNamesType::iterator, bool> ret; std::pair<claimQueueNamesType::iterator, bool> ret;
ret = claimQueueNameCache.insert(std::pair<std::string, std::vector<CClaimValue> >(name, queueNameRow)); ret = claimQueueNameCache.insert(std::pair<std::string, std::vector<claimQueueNamesEntryType> >(name, queueNameRow));
assert(ret.second); assert(ret.second);
itQueueNameRow = ret.first; itQueueNameRow = ret.first;
} }
@ -1446,7 +1446,7 @@ bool CClaimTrieCache::addClaimToQueues(const std::string& name, CClaimValue& cla
claimQueueType::iterator itQueueRow = getQueueCacheRow(claim.nValidAtHeight, true); claimQueueType::iterator itQueueRow = getQueueCacheRow(claim.nValidAtHeight, true);
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(name, true); claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(name, true);
itQueueRow->second.push_back(entry); itQueueRow->second.push_back(entry);
itQueueNameRow->second.push_back(claim); itQueueNameRow->second.push_back(std::make_pair(claim.outPoint, claim.nValidAtHeight));
addToExpirationQueue(entry); addToExpirationQueue(entry);
return true; return true;
} }
@ -1458,10 +1458,10 @@ bool CClaimTrieCache::removeClaimFromQueue(const std::string& name, const COutPo
{ {
return false; return false;
} }
std::vector<CClaimValue>::iterator itQueueName; std::vector<claimQueueNamesEntryType>::iterator itQueueName;
for (itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName) for (itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName)
{ {
if (itQueueName->outPoint == outPoint) if (itQueueName->first == outPoint)
{ {
break; break;
} }
@ -1470,7 +1470,7 @@ bool CClaimTrieCache::removeClaimFromQueue(const std::string& name, const COutPo
{ {
return false; return false;
} }
claimQueueType::iterator itQueueRow = getQueueCacheRow(itQueueName->nValidAtHeight, false); claimQueueType::iterator itQueueRow = getQueueCacheRow(itQueueName->second, false);
if (itQueueRow != claimQueueCache.end()) if (itQueueRow != claimQueueCache.end())
{ {
claimQueueRowType::iterator itQueue; claimQueueRowType::iterator itQueue;
@ -1489,7 +1489,7 @@ bool CClaimTrieCache::removeClaimFromQueue(const std::string& name, const COutPo
return true; return true;
} }
} }
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, itQueueName->nValidAtHeight, nCurrentHeight); LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, itQueueName->second, nCurrentHeight);
return false; return false;
} }
@ -1926,9 +1926,9 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(itEntry->first, false); claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(itEntry->first, false);
if (itQueueNameRow != claimQueueNameCache.end()) if (itQueueNameRow != claimQueueNameCache.end())
{ {
for (std::vector<CClaimValue>::iterator itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName) for (std::vector<claimQueueNamesEntryType>::iterator itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName)
{ {
if (*itQueueName == itEntry->second) if (itQueueName->first == itEntry->second.outPoint && itQueueName->second == nCurrentHeight)
{ {
found = true; found = true;
itQueueNameRow->second.erase(itQueueName); itQueueNameRow->second.erase(itQueueName);
@ -1942,9 +1942,9 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
if (itQueueNameRow != claimQueueNameCache.end()) if (itQueueNameRow != claimQueueNameCache.end())
{ {
LogPrintf("Claims found for that name:\n"); LogPrintf("Claims found for that name:\n");
for (std::vector<CClaimValue>::iterator itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName) for (std::vector<claimQueueNamesEntryType>::iterator itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName)
{ {
LogPrintf("\ttxid: %s, nOut: %d, nValidAtHeight: %d\n", itQueueName->outPoint.hash.GetHex(), itQueueName->outPoint.n, itQueueName->nValidAtHeight); LogPrintf("\ttxid: %s, nOut: %d, nValidAtHeight: %d\n", itQueueName->first.hash.GetHex(), itQueueName->first.n, itQueueName->second);
} }
} }
else else
@ -1952,6 +1952,7 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
LogPrintf("No claims found for that name\n"); LogPrintf("No claims found for that name\n");
} }
} }
assert(found);
insertClaimIntoTrie(itEntry->first, itEntry->second, true); insertClaimIntoTrie(itEntry->first, itEntry->second, true);
insertUndo.push_back(*itEntry); insertUndo.push_back(*itEntry);
} }
@ -2075,39 +2076,38 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(*itNamesToCheck, false); claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(*itNamesToCheck, false);
if (itQueueNameRow != claimQueueNameCache.end()) if (itQueueNameRow != claimQueueNameCache.end())
{ {
for (std::vector<CClaimValue>::iterator itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName) for (std::vector<claimQueueNamesEntryType>::iterator itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName)
{ {
bool found = false;
// Pull those claims out of the height-based queue // Pull those claims out of the height-based queue
claimQueueType::iterator itQueueRow = getQueueCacheRow(itQueueName->nValidAtHeight, false); claimQueueType::iterator itQueueRow = getQueueCacheRow(itQueueName->second, false);
claimQueueRowType::iterator itQueue;
if (itQueueRow != claimQueueCache.end()) if (itQueueRow != claimQueueCache.end())
{ {
claimQueueRowType::iterator itQueue;
for (itQueue = itQueueRow->second.begin(); itQueue != itQueueRow->second.end(); ++itQueue) for (itQueue = itQueueRow->second.begin(); itQueue != itQueueRow->second.end(); ++itQueue)
{ {
if (*itNamesToCheck == itQueue->first && itQueue->second == *itQueueName) if (*itNamesToCheck == itQueue->first && itQueue->second.outPoint == itQueueName->first && itQueue->second.nValidAtHeight == itQueueName->second)
{ {
found = true;
break; break;
} }
} }
if (itQueue != itQueueRow->second.end()) }
{ if (found)
// Insert them into the queue undo with their previous nValidAtHeight {
insertUndo.push_back(*itQueue); // Insert them into the queue undo with their previous nValidAtHeight
// Insert them into the name trie with the new nValidAtHeight insertUndo.push_back(*itQueue);
itQueue->second.nValidAtHeight = nCurrentHeight; // Insert them into the name trie with the new nValidAtHeight
insertClaimIntoTrie(itQueue->first, itQueue->second, false); itQueue->second.nValidAtHeight = nCurrentHeight;
// Delete them from the height-based queue insertClaimIntoTrie(itQueue->first, itQueue->second, false);
itQueueRow->second.erase(itQueue); // Delete them from the height-based queue
} itQueueRow->second.erase(itQueue);
else
{
// here be problems
}
} }
else else
{ {
// here be problems LogPrintf("%s(): An inconsistency was found in the claim queue. Please report this to the developers:\nClaim found in name queue but not in height based queue:\nname: %s, txid: %s, nOut: %d, nValidAtHeight in name based queue: %d, current height: %d\n", __func__, *itNamesToCheck, itQueueName->first.hash.GetHex(), itQueueName->first.n, itQueueName->second, nCurrentHeight);
} }
assert(found);
} }
// remove all claims from the queue for that name // remove all claims from the queue for that name
itQueueNameRow->second.clear(); itQueueNameRow->second.clear();
@ -2184,8 +2184,8 @@ bool CClaimTrieCache::decrementBlock(claimQueueRowType& insertUndo, claimQueueRo
CClaimValue claim; CClaimValue claim;
assert(removeClaimFromTrie(itInsertUndo->first, itInsertUndo->second.outPoint, claim, false)); assert(removeClaimFromTrie(itInsertUndo->first, itInsertUndo->second.outPoint, claim, false));
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(itInsertUndo->first, true); claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(itInsertUndo->first, true);
itQueueRow->second.push_back(*itInsertUndo); itQueueRow->second.push_back(std::make_pair(itInsertUndo->first, claim));
itQueueNameRow->second.push_back(itInsertUndo->second); itQueueNameRow->second.push_back(std::make_pair(itInsertUndo->second.outPoint, itInsertUndo->second.nValidAtHeight));
} }
if (expireUndo.begin() != expireUndo.end()) if (expireUndo.begin() != expireUndo.end())
{ {

View file

@ -186,7 +186,8 @@ typedef std::map<std::string, supportMapEntryType> supportMapType;
typedef std::vector<claimQueueEntryType> claimQueueRowType; typedef std::vector<claimQueueEntryType> claimQueueRowType;
typedef std::map<int, claimQueueRowType> claimQueueType; typedef std::map<int, claimQueueRowType> claimQueueType;
typedef std::map<std::string, std::vector<CClaimValue> > claimQueueNamesType; typedef std::pair<COutPoint, int> claimQueueNamesEntryType;
typedef std::map<std::string, std::vector<claimQueueNamesEntryType> > claimQueueNamesType;
typedef std::vector<supportQueueEntryType> supportQueueRowType; typedef std::vector<supportQueueEntryType> supportQueueRowType;
typedef std::map<int, supportQueueRowType> supportQueueType; typedef std::map<int, supportQueueRowType> supportQueueType;
@ -231,7 +232,7 @@ public:
void setExpirationTime(int t); void setExpirationTime(int t);
bool getQueueRow(int nHeight, claimQueueRowType& row) const; bool getQueueRow(int nHeight, claimQueueRowType& row) const;
bool getQueueNameRow(const std::string& name, std::vector<CClaimValue>& row) const; bool getQueueNameRow(const std::string& name, std::vector<claimQueueNamesEntryType>& row) const;
bool getExpirationQueueRow(int nHeight, claimQueueRowType& row) const; bool getExpirationQueueRow(int nHeight, claimQueueRowType& row) const;
bool getSupportNode(std::string name, supportMapEntryType& node) const; bool getSupportNode(std::string name, supportMapEntryType& node) const;
bool getSupportQueueRow(int nHeight, supportQueueRowType& row) const; bool getSupportQueueRow(int nHeight, supportQueueRowType& row) const;
@ -290,7 +291,7 @@ private:
void markNodeDirty(const std::string& name, CClaimTrieNode* node); void markNodeDirty(const std::string& name, CClaimTrieNode* node);
void updateQueueRow(int nHeight, claimQueueRowType& row); void updateQueueRow(int nHeight, claimQueueRowType& row);
void updateQueueNameRow(const std::string& name, void updateQueueNameRow(const std::string& name,
std::vector<CClaimValue>& row); std::vector<claimQueueNamesEntryType>& row);
void updateExpirationRow(int nHeight, claimQueueRowType& row); void updateExpirationRow(int nHeight, claimQueueRowType& row);
void updateSupportMap(const std::string& name, supportMapEntryType& node); void updateSupportMap(const std::string& name, supportMapEntryType& node);
void updateSupportQueue(int nHeight, supportQueueRowType& row); void updateSupportQueue(int nHeight, supportQueueRowType& row);