hacktober fest #214
3 changed files with 184 additions and 71 deletions
|
@ -591,6 +591,48 @@ bool CClaimTrie::recursiveCheckConsistency(const CClaimTrieNode* node) const
|
||||||
return calculatedHash == node->hash;
|
return calculatedHash == node->hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CClaimTrie::addToClaimIndex(const std::string& name, const CClaimValue& claim)
|
||||||
|
{
|
||||||
|
// sanity checks only
|
||||||
|
claimIndexType::const_iterator itClaim = claimIndex.find(claim.claimId);
|
||||||
|
if (itClaim != claimIndex.end() && itClaim->second.claim != claim)
|
||||||
|
LogPrintf("%s: WARNING: ClaimIndex Conflict on claim id %s\n", __func__, claim.claimId.GetHex());
|
||||||
|
|
||||||
|
CClaimIndexElement element = { name, claim };
|
||||||
|
claimIndex[claim.claimId] = element;
|
||||||
|
LogPrintf("%s: ClaimIndex[%s] updated %s\n", __func__, claim.claimId.GetHex(), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CClaimTrie::removeFromClaimIndex(const CClaimValue& claim)
|
||||||
|
{
|
||||||
|
claimIndexType::iterator itClaim = claimIndex.find(claim.claimId);
|
||||||
|
if (itClaim != claimIndex.end())
|
||||||
|
{
|
||||||
|
LogPrintf("%s: ClaimIndex[%s] removing %s\n", __func__, claim.claimId.GetHex(), itClaim->second.name);
|
||||||
|
claimIndex.erase(itClaim);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CClaimTrie::getClaimById(const uint160 claimId, std::string& name, CClaimValue& claim) const
|
||||||
|
{
|
||||||
|
claimIndexType::const_iterator itClaim = claimIndex.find(claimId);
|
||||||
|
if (itClaim != claimIndex.end())
|
||||||
|
{
|
||||||
|
name = itClaim->second.name;
|
||||||
|
claim = itClaim->second.claim;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CClaimIndexElement element;
|
||||||
|
if (db.Read(std::make_pair(CLAIM_BY_ID, claimId), element))
|
||||||
|
{
|
||||||
|
name = element.name;
|
||||||
|
claim = element.claim;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CClaimTrie::getQueueRow(int nHeight, claimQueueRowType& row) const
|
bool CClaimTrie::getQueueRow(int nHeight, claimQueueRowType& row) const
|
||||||
{
|
{
|
||||||
claimQueueType::const_iterator itQueueRow = dirtyQueueRows.find(nHeight);
|
claimQueueType::const_iterator itQueueRow = dirtyQueueRows.find(nHeight);
|
||||||
|
@ -927,6 +969,16 @@ bool CClaimTrie::updateTakeoverHeight(const std::string& name, int nTakeoverHeig
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CClaimTrie::BatchWriteClaimIndex(CDBBatch& batch) const
|
||||||
|
{
|
||||||
|
for(claimIndexType::const_iterator itClaim = claimIndex.begin();
|
||||||
|
itClaim != claimIndex.end(); ++itClaim)
|
||||||
|
{
|
||||||
|
batch.Write(std::make_pair(CLAIM_BY_ID, itClaim->second.claim.claimId), itClaim->second);
|
||||||
|
LogPrintf("%s: Writing %s to disk\n", __func__, itClaim->second.claim.claimId.GetHex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CClaimTrie::BatchWriteNode(CDBBatch& batch, const std::string& name, const CClaimTrieNode* pNode) const
|
void CClaimTrie::BatchWriteNode(CDBBatch& batch, const std::string& name, const CClaimTrieNode* pNode) const
|
||||||
{
|
{
|
||||||
uint32_t num_claims = 0;
|
uint32_t num_claims = 0;
|
||||||
|
@ -1064,6 +1116,8 @@ bool CClaimTrie::WriteToDisk()
|
||||||
dirtySupportQueueNameRows.clear();
|
dirtySupportQueueNameRows.clear();
|
||||||
BatchWriteSupportExpirationQueueRows(batch);
|
BatchWriteSupportExpirationQueueRows(batch);
|
||||||
dirtySupportExpirationQueueRows.clear();
|
dirtySupportExpirationQueueRows.clear();
|
||||||
|
BatchWriteClaimIndex(batch);
|
||||||
|
claimIndex.clear();
|
||||||
batch.Write(HASH_BLOCK, hashBlock);
|
batch.Write(HASH_BLOCK, hashBlock);
|
||||||
batch.Write(CURRENT_HEIGHT, nCurrentHeight);
|
batch.Write(CURRENT_HEIGHT, nCurrentHeight);
|
||||||
return db.WriteBatch(batch);
|
return db.WriteBatch(batch);
|
||||||
|
@ -1085,6 +1139,11 @@ bool CClaimTrie::InsertFromDisk(const std::string& name, CClaimTrieNode* node)
|
||||||
current = itchild->second;
|
current = itchild->second;
|
||||||
}
|
}
|
||||||
current->children[name[name.size()-1]] = node;
|
current->children[name[name.size()-1]] = node;
|
||||||
|
|
||||||
|
for(size_t i = 0; i < current->claims.size(); ++i)
|
||||||
|
{
|
||||||
|
addToClaimIndex(name.substr(0, name.size()-1), current->claims[i]);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1095,6 +1154,32 @@ bool CClaimTrie::ReadFromDisk(bool check)
|
||||||
if (!db.Read(CURRENT_HEIGHT, nCurrentHeight))
|
if (!db.Read(CURRENT_HEIGHT, nCurrentHeight))
|
||||||
LogPrintf("%s: Couldn't read the current height\n", __func__);
|
LogPrintf("%s: Couldn't read the current height\n", __func__);
|
||||||
boost::scoped_ptr<CDBIterator> pcursor(const_cast<CDBWrapper*>(&db)->NewIterator());
|
boost::scoped_ptr<CDBIterator> pcursor(const_cast<CDBWrapper*>(&db)->NewIterator());
|
||||||
|
|
||||||
|
pcursor->SeekToFirst();
|
||||||
|
while (pcursor->Valid())
|
||||||
|
{
|
||||||
|
std::pair<char, std::string> key;
|
||||||
|
if (pcursor->GetKey(key) && (key.first == CLAIM_BY_ID))
|
||||||
|
{
|
||||||
|
CClaimIndexElement element;
|
||||||
|
if (pcursor->GetValue(element))
|
||||||
|
{
|
||||||
|
claimIndex[element.claim.claimId] = element;
|
||||||
|
LogPrintf("%s: ClaimIndex Read %s from disk\n", __func__, element.claim.claimId.GetHex());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return error("%s(): error reading claim index entry from disk", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pcursor->Next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (claimIndex.empty())
|
||||||
|
LogPrintf("Building ClaimIndex from persistent ClaimTrie...\n");
|
||||||
|
else
|
||||||
|
LogPrintf("Restored ClaimIndex with %lu elements...\n", claimIndex.size());
|
||||||
|
|
||||||
pcursor->SeekToFirst();
|
pcursor->SeekToFirst();
|
||||||
|
|
||||||
while (pcursor->Valid())
|
while (pcursor->Valid())
|
||||||
|
@ -1120,6 +1205,7 @@ bool CClaimTrie::ReadFromDisk(bool check)
|
||||||
}
|
}
|
||||||
pcursor->Next();
|
pcursor->Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check)
|
if (check)
|
||||||
{
|
{
|
||||||
LogPrintf("Checking Claim trie consistency...");
|
LogPrintf("Checking Claim trie consistency...");
|
||||||
|
@ -1318,6 +1404,7 @@ bool CClaimTrieCache::insertClaimIntoTrie(const std::string& name, CClaimValue c
|
||||||
{
|
{
|
||||||
fChanged = true;
|
fChanged = true;
|
||||||
currentNode->insertClaim(claim);
|
currentNode->insertClaim(claim);
|
||||||
|
base->addToClaimIndex(name, claim);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1392,7 +1479,8 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string& name, const COutPoi
|
||||||
CClaimValue currentTop = currentNode->claims.front();
|
CClaimValue currentTop = currentNode->claims.front();
|
||||||
|
|
||||||
success = currentNode->removeClaim(outPoint, claim);
|
success = currentNode->removeClaim(outPoint, claim);
|
||||||
|
base->removeFromClaimIndex(claim);
|
||||||
|
|
||||||
if (!currentNode->claims.empty())
|
if (!currentNode->claims.empty())
|
||||||
{
|
{
|
||||||
supportMapEntryType node;
|
supportMapEntryType node;
|
||||||
|
@ -1589,6 +1677,7 @@ bool CClaimTrieCache::addClaimToQueues(const std::string& name, CClaimValue& cla
|
||||||
itQueueNameRow->second.push_back(outPointHeightType(claim.outPoint, claim.nValidAtHeight));
|
itQueueNameRow->second.push_back(outPointHeightType(claim.outPoint, claim.nValidAtHeight));
|
||||||
nameOutPointType expireEntry(name, claim.outPoint);
|
nameOutPointType expireEntry(name, claim.outPoint);
|
||||||
addToExpirationQueue(claim.nHeight + base->nExpirationTime, expireEntry);
|
addToExpirationQueue(claim.nHeight + base->nExpirationTime, expireEntry);
|
||||||
|
base->addToClaimIndex(name, claim);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1627,6 +1716,8 @@ bool CClaimTrieCache::removeClaimFromQueue(const std::string& name, const COutPo
|
||||||
std::swap(claim, itQueue->second);
|
std::swap(claim, itQueue->second);
|
||||||
itQueueNameRow->second.erase(itQueueName);
|
itQueueNameRow->second.erase(itQueueName);
|
||||||
itQueueRow->second.erase(itQueue);
|
itQueueRow->second.erase(itQueue);
|
||||||
|
|
||||||
|
base->removeFromClaimIndex(claim);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
125
src/claimtrie.h
125
src/claimtrie.h
|
@ -10,11 +10,13 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
// leveldb keys
|
// leveldb keys
|
||||||
#define HASH_BLOCK 'h'
|
#define HASH_BLOCK 'h'
|
||||||
#define CURRENT_HEIGHT 't'
|
#define CURRENT_HEIGHT 't'
|
||||||
#define TRIE_NODE 'n'
|
#define TRIE_NODE 'n'
|
||||||
|
#define CLAIM_BY_ID 'i'
|
||||||
#define CLAIM_QUEUE_ROW 'r'
|
#define CLAIM_QUEUE_ROW 'r'
|
||||||
#define CLAIM_QUEUE_NAME_ROW 'm'
|
#define CLAIM_QUEUE_NAME_ROW 'm'
|
||||||
#define EXP_QUEUE_ROW 'e'
|
#define EXP_QUEUE_ROW 'e'
|
||||||
|
@ -54,7 +56,7 @@ public:
|
||||||
READWRITE(nHeight);
|
READWRITE(nHeight);
|
||||||
READWRITE(nValidAtHeight);
|
READWRITE(nValidAtHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const CClaimValue& other) const
|
bool operator<(const CClaimValue& other) const
|
||||||
{
|
{
|
||||||
if (nEffectiveAmount < other.nEffectiveAmount)
|
if (nEffectiveAmount < other.nEffectiveAmount)
|
||||||
|
@ -71,12 +73,12 @@ public:
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const CClaimValue& other) const
|
bool operator==(const CClaimValue& other) const
|
||||||
{
|
{
|
||||||
return outPoint == other.outPoint && claimId == other.claimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
|
return outPoint == other.outPoint && claimId == other.claimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const CClaimValue& other) const
|
bool operator!=(const CClaimValue& other) const
|
||||||
{
|
{
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
|
@ -91,7 +93,7 @@ public:
|
||||||
CAmount nAmount;
|
CAmount nAmount;
|
||||||
int nHeight;
|
int nHeight;
|
||||||
int nValidAtHeight;
|
int nValidAtHeight;
|
||||||
|
|
||||||
CSupportValue() {};
|
CSupportValue() {};
|
||||||
CSupportValue(COutPoint outPoint, uint160 supportedClaimId,
|
CSupportValue(COutPoint outPoint, uint160 supportedClaimId,
|
||||||
CAmount nAmount, int nHeight, int nValidAtHeight)
|
CAmount nAmount, int nHeight, int nValidAtHeight)
|
||||||
|
@ -99,7 +101,7 @@ public:
|
||||||
, nAmount(nAmount), nHeight(nHeight)
|
, nAmount(nAmount), nHeight(nHeight)
|
||||||
, nValidAtHeight(nValidAtHeight)
|
, nValidAtHeight(nValidAtHeight)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
|
@ -147,7 +149,7 @@ public:
|
||||||
bool empty() const {return children.empty() && claims.empty();}
|
bool empty() const {return children.empty() && claims.empty();}
|
||||||
bool haveClaim(const COutPoint& outPoint) const;
|
bool haveClaim(const COutPoint& outPoint) const;
|
||||||
void reorderClaims(supportMapEntryType& supports);
|
void reorderClaims(supportMapEntryType& supports);
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
|
@ -156,7 +158,7 @@ public:
|
||||||
READWRITE(claims);
|
READWRITE(claims);
|
||||||
READWRITE(nHeightOfLastTakeover);
|
READWRITE(nHeightOfLastTakeover);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const CClaimTrieNode& other) const
|
bool operator==(const CClaimTrieNode& other) const
|
||||||
{
|
{
|
||||||
return hash == other.hash && claims == other.claims;
|
return hash == other.hash && claims == other.claims;
|
||||||
|
@ -241,6 +243,21 @@ struct nameOutPointType
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CClaimIndexElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
template <typename Stream, typename Operation>
|
||||||
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
|
READWRITE(name);
|
||||||
|
READWRITE(claim);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
CClaimValue claim;
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::pair<std::string, CClaimValue> claimQueueEntryType;
|
typedef std::pair<std::string, CClaimValue> claimQueueEntryType;
|
||||||
|
|
||||||
typedef std::pair<std::string, CSupportValue> supportQueueEntryType;
|
typedef std::pair<std::string, CSupportValue> supportQueueEntryType;
|
||||||
|
@ -265,6 +282,8 @@ typedef std::map<std::string, CClaimTrieNode*, nodenamecompare> nodeCacheType;
|
||||||
|
|
||||||
typedef std::map<std::string, uint256> hashMapType;
|
typedef std::map<std::string, uint256> hashMapType;
|
||||||
|
|
||||||
|
typedef std::map<uint160, CClaimIndexElement> claimIndexType;
|
||||||
|
|
||||||
struct claimsForNameType
|
struct claimsForNameType
|
||||||
{
|
{
|
||||||
std::vector<CClaimValue> claims;
|
std::vector<CClaimValue> claims;
|
||||||
|
@ -286,32 +305,36 @@ public:
|
||||||
, nProportionalDelayFactor(nProportionalDelayFactor)
|
, nProportionalDelayFactor(nProportionalDelayFactor)
|
||||||
, root(uint256S("0000000000000000000000000000000000000000000000000000000000000001"))
|
, root(uint256S("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
uint256 getMerkleHash();
|
uint256 getMerkleHash();
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool checkConsistency() const;
|
bool checkConsistency() const;
|
||||||
|
|
||||||
bool WriteToDisk();
|
bool WriteToDisk();
|
||||||
bool ReadFromDisk(bool check = false);
|
bool ReadFromDisk(bool check = false);
|
||||||
|
|
||||||
std::vector<namedNodeType> flattenTrie() const;
|
std::vector<namedNodeType> flattenTrie() const;
|
||||||
bool getInfoForName(const std::string& name, CClaimValue& claim) const;
|
bool getInfoForName(const std::string& name, CClaimValue& claim) const;
|
||||||
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
||||||
|
|
||||||
claimsForNameType getClaimsForName(const std::string& name) const;
|
claimsForNameType getClaimsForName(const std::string& name) const;
|
||||||
CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const;
|
CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const;
|
||||||
|
|
||||||
bool queueEmpty() const;
|
bool queueEmpty() const;
|
||||||
bool supportEmpty() const;
|
bool supportEmpty() const;
|
||||||
bool supportQueueEmpty() const;
|
bool supportQueueEmpty() const;
|
||||||
bool expirationQueueEmpty() const;
|
bool expirationQueueEmpty() const;
|
||||||
bool supportExpirationQueueEmpty() const;
|
bool supportExpirationQueueEmpty() const;
|
||||||
|
|
||||||
void setExpirationTime(int t);
|
void setExpirationTime(int t);
|
||||||
|
|
||||||
|
void addToClaimIndex(const std::string& name, const CClaimValue& claim);
|
||||||
|
void removeFromClaimIndex(const CClaimValue& claim);
|
||||||
|
|
||||||
|
bool getClaimById(const uint160 claimId, std::string& name, CClaimValue& claim) const;
|
||||||
bool getQueueRow(int nHeight, claimQueueRowType& row) const;
|
bool getQueueRow(int nHeight, claimQueueRowType& row) const;
|
||||||
bool getQueueNameRow(const std::string& name, queueNameRowType& row) const;
|
bool getQueueNameRow(const std::string& name, queueNameRowType& row) const;
|
||||||
bool getExpirationQueueRow(int nHeight, expirationQueueRowType& row) const;
|
bool getExpirationQueueRow(int nHeight, expirationQueueRowType& row) const;
|
||||||
|
@ -319,21 +342,22 @@ public:
|
||||||
bool getSupportQueueRow(int nHeight, supportQueueRowType& row) const;
|
bool getSupportQueueRow(int nHeight, supportQueueRowType& row) const;
|
||||||
bool getSupportQueueNameRow(const std::string& name, queueNameRowType& row) const;
|
bool getSupportQueueNameRow(const std::string& name, queueNameRowType& row) const;
|
||||||
bool getSupportExpirationQueueRow(int nHeight, expirationQueueRowType& row) const;
|
bool getSupportExpirationQueueRow(int nHeight, expirationQueueRowType& row) const;
|
||||||
|
|
||||||
|
|
||||||
bool haveClaim(const std::string& name, const COutPoint& outPoint) const;
|
bool haveClaim(const std::string& name, const COutPoint& outPoint) const;
|
||||||
bool haveClaimInQueue(const std::string& name, const COutPoint& outPoint,
|
bool haveClaimInQueue(const std::string& name, const COutPoint& outPoint,
|
||||||
int& nValidAtHeight) const;
|
int& nValidAtHeight) const;
|
||||||
|
|
||||||
bool haveSupport(const std::string& name, const COutPoint& outPoint) const;
|
bool haveSupport(const std::string& name, const COutPoint& outPoint) const;
|
||||||
bool haveSupportInQueue(const std::string& name, const COutPoint& outPoint,
|
bool haveSupportInQueue(const std::string& name, const COutPoint& outPoint,
|
||||||
int& nValidAtHeight) const;
|
int& nValidAtHeight) const;
|
||||||
|
|
||||||
unsigned int getTotalNamesInTrie() const;
|
unsigned int getTotalNamesInTrie() const;
|
||||||
unsigned int getTotalClaimsInTrie() const;
|
unsigned int getTotalClaimsInTrie() const;
|
||||||
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
|
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
|
||||||
|
|
||||||
friend class CClaimTrieCache;
|
friend class CClaimTrieCache;
|
||||||
|
|
||||||
CDBWrapper db;
|
CDBWrapper db;
|
||||||
int nCurrentHeight;
|
int nCurrentHeight;
|
||||||
int nExpirationTime;
|
int nExpirationTime;
|
||||||
|
@ -342,7 +366,7 @@ private:
|
||||||
void clear(CClaimTrieNode* current);
|
void clear(CClaimTrieNode* current);
|
||||||
|
|
||||||
const CClaimTrieNode* getNodeForName(const std::string& name) const;
|
const CClaimTrieNode* getNodeForName(const std::string& name) const;
|
||||||
|
|
||||||
bool update(nodeCacheType& cache, hashMapType& hashes,
|
bool update(nodeCacheType& cache, hashMapType& hashes,
|
||||||
std::map<std::string, int>& takeoverHeights,
|
std::map<std::string, int>& takeoverHeights,
|
||||||
const uint256& hashBlock, claimQueueType& queueCache,
|
const uint256& hashBlock, claimQueueType& queueCache,
|
||||||
|
@ -356,11 +380,11 @@ private:
|
||||||
bool updateHash(const std::string& name, uint256& hash);
|
bool updateHash(const std::string& name, uint256& hash);
|
||||||
bool updateTakeoverHeight(const std::string& name, int nTakeoverHeight);
|
bool updateTakeoverHeight(const std::string& name, int nTakeoverHeight);
|
||||||
bool recursiveNullify(CClaimTrieNode* node, std::string& name);
|
bool recursiveNullify(CClaimTrieNode* node, std::string& name);
|
||||||
|
|
||||||
bool recursiveCheckConsistency(const CClaimTrieNode* node) const;
|
bool recursiveCheckConsistency(const CClaimTrieNode* node) const;
|
||||||
|
|
||||||
bool InsertFromDisk(const std::string& name, CClaimTrieNode* node);
|
bool InsertFromDisk(const std::string& name, CClaimTrieNode* node);
|
||||||
|
|
||||||
unsigned int getTotalNamesRecursive(const CClaimTrieNode* current) const;
|
unsigned int getTotalNamesRecursive(const CClaimTrieNode* current) const;
|
||||||
unsigned int getTotalClaimsRecursive(const CClaimTrieNode* current) const;
|
unsigned int getTotalClaimsRecursive(const CClaimTrieNode* current) const;
|
||||||
CAmount getTotalValueOfClaimsRecursive(const CClaimTrieNode* current,
|
CAmount getTotalValueOfClaimsRecursive(const CClaimTrieNode* current,
|
||||||
|
@ -368,7 +392,7 @@ private:
|
||||||
bool recursiveFlattenTrie(const std::string& name,
|
bool recursiveFlattenTrie(const std::string& name,
|
||||||
const CClaimTrieNode* current,
|
const CClaimTrieNode* current,
|
||||||
std::vector<namedNodeType>& nodes) const;
|
std::vector<namedNodeType>& nodes) const;
|
||||||
|
|
||||||
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,
|
||||||
|
@ -379,10 +403,11 @@ private:
|
||||||
void updateSupportNameQueue(const std::string& name,
|
void updateSupportNameQueue(const std::string& name,
|
||||||
queueNameRowType& row);
|
queueNameRowType& row);
|
||||||
void updateSupportExpirationQueue(int nHeight, expirationQueueRowType& row);
|
void updateSupportExpirationQueue(int nHeight, expirationQueueRowType& row);
|
||||||
|
|
||||||
void BatchWriteNode(CDBBatch& batch, const std::string& name,
|
void BatchWriteNode(CDBBatch& batch, const std::string& name,
|
||||||
const CClaimTrieNode* pNode) const;
|
const CClaimTrieNode* pNode) const;
|
||||||
void BatchEraseNode(CDBBatch& batch, const std::string& nome) const;
|
void BatchEraseNode(CDBBatch& batch, const std::string& nome) const;
|
||||||
|
void BatchWriteClaimIndex(CDBBatch& batch) const;
|
||||||
void BatchWriteQueueRows(CDBBatch& batch);
|
void BatchWriteQueueRows(CDBBatch& batch);
|
||||||
void BatchWriteQueueNameRows(CDBBatch& batch);
|
void BatchWriteQueueNameRows(CDBBatch& batch);
|
||||||
void BatchWriteExpirationQueueRows(CDBBatch& batch);
|
void BatchWriteExpirationQueueRows(CDBBatch& batch);
|
||||||
|
@ -391,20 +416,22 @@ private:
|
||||||
void BatchWriteSupportQueueNameRows(CDBBatch& batch);
|
void BatchWriteSupportQueueNameRows(CDBBatch& batch);
|
||||||
void BatchWriteSupportExpirationQueueRows(CDBBatch& batch);
|
void BatchWriteSupportExpirationQueueRows(CDBBatch& batch);
|
||||||
template<typename K> bool keyTypeEmpty(char key, K& dummy) const;
|
template<typename K> bool keyTypeEmpty(char key, K& dummy) const;
|
||||||
|
|
||||||
CClaimTrieNode root;
|
CClaimTrieNode root;
|
||||||
uint256 hashBlock;
|
uint256 hashBlock;
|
||||||
|
|
||||||
claimQueueType dirtyQueueRows;
|
claimQueueType dirtyQueueRows;
|
||||||
queueNameType dirtyQueueNameRows;
|
queueNameType dirtyQueueNameRows;
|
||||||
expirationQueueType dirtyExpirationQueueRows;
|
expirationQueueType dirtyExpirationQueueRows;
|
||||||
|
|
||||||
supportQueueType dirtySupportQueueRows;
|
supportQueueType dirtySupportQueueRows;
|
||||||
queueNameType dirtySupportQueueNameRows;
|
queueNameType dirtySupportQueueNameRows;
|
||||||
expirationQueueType dirtySupportExpirationQueueRows;
|
expirationQueueType dirtySupportExpirationQueueRows;
|
||||||
|
|
||||||
nodeCacheType dirtyNodes;
|
nodeCacheType dirtyNodes;
|
||||||
supportMapType dirtySupportNodes;
|
supportMapType dirtySupportNodes;
|
||||||
|
|
||||||
|
mutable claimIndexType claimIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CClaimTrieProofNode
|
class CClaimTrieProofNode
|
||||||
|
@ -441,13 +468,13 @@ public:
|
||||||
assert(base);
|
assert(base);
|
||||||
nCurrentHeight = base->nCurrentHeight;
|
nCurrentHeight = base->nCurrentHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 getMerkleHash() const;
|
uint256 getMerkleHash() const;
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
bool flush();
|
bool flush();
|
||||||
bool dirty() const { return !dirtyHashes.empty(); }
|
bool dirty() const { return !dirtyHashes.empty(); }
|
||||||
|
|
||||||
bool addClaim(const std::string& name, const COutPoint& outPoint,
|
bool addClaim(const std::string& name, const COutPoint& outPoint,
|
||||||
uint160 claimId, CAmount nAmount, int nHeight) const;
|
uint160 claimId, CAmount nAmount, int nHeight) const;
|
||||||
bool undoAddClaim(const std::string& name, const COutPoint& outPoint,
|
bool undoAddClaim(const std::string& name, const COutPoint& outPoint,
|
||||||
|
@ -457,7 +484,7 @@ public:
|
||||||
bool undoSpendClaim(const std::string& name, const COutPoint& outPoint,
|
bool undoSpendClaim(const std::string& name, const COutPoint& outPoint,
|
||||||
uint160 claimId, CAmount nAmount, int nHeight,
|
uint160 claimId, CAmount nAmount, int nHeight,
|
||||||
int nValidAtHeight) const;
|
int nValidAtHeight) const;
|
||||||
|
|
||||||
bool addSupport(const std::string& name, const COutPoint& outPoint,
|
bool addSupport(const std::string& name, const COutPoint& outPoint,
|
||||||
CAmount nAmount, uint160 supportedClaimId,
|
CAmount nAmount, uint160 supportedClaimId,
|
||||||
int nHeight) const;
|
int nHeight) const;
|
||||||
|
@ -468,7 +495,7 @@ public:
|
||||||
bool undoSpendSupport(const std::string& name, const COutPoint& outPoint,
|
bool undoSpendSupport(const std::string& name, const COutPoint& outPoint,
|
||||||
uint160 supportedClaimId, CAmount nAmount,
|
uint160 supportedClaimId, CAmount nAmount,
|
||||||
int nHeight, int nValidAtHeight) const;
|
int nHeight, int nValidAtHeight) const;
|
||||||
|
|
||||||
uint256 getBestBlock();
|
uint256 getBestBlock();
|
||||||
void setBestBlock(const uint256& hashBlock);
|
void setBestBlock(const uint256& hashBlock);
|
||||||
|
|
||||||
|
@ -482,9 +509,9 @@ public:
|
||||||
insertUndoType& insertSupportUndo,
|
insertUndoType& insertSupportUndo,
|
||||||
supportQueueRowType& expireSupportUndo,
|
supportQueueRowType& expireSupportUndo,
|
||||||
std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const;
|
std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const;
|
||||||
|
|
||||||
~CClaimTrieCache() { clear(); }
|
~CClaimTrieCache() { clear(); }
|
||||||
|
|
||||||
bool insertClaimIntoTrie(const std::string& name, CClaimValue claim,
|
bool insertClaimIntoTrie(const std::string& name, CClaimValue claim,
|
||||||
bool fCheckTakeover = false) const;
|
bool fCheckTakeover = false) const;
|
||||||
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint,
|
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint,
|
||||||
|
@ -513,48 +540,48 @@ protected:
|
||||||
mutable std::map<std::string, int> cacheTakeoverHeights;
|
mutable std::map<std::string, int> cacheTakeoverHeights;
|
||||||
mutable int nCurrentHeight; // Height of the block that is being worked on, which is
|
mutable int nCurrentHeight; // Height of the block that is being worked on, which is
|
||||||
// one greater than the height of the chain's tip
|
// one greater than the height of the chain's tip
|
||||||
|
|
||||||
uint256 hashBlock;
|
uint256 hashBlock;
|
||||||
|
|
||||||
uint256 computeHash() const;
|
uint256 computeHash() const;
|
||||||
|
|
||||||
bool reorderTrieNode(const std::string& name, bool fCheckTakeover) const;
|
bool reorderTrieNode(const std::string& name, bool fCheckTakeover) const;
|
||||||
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent,
|
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent,
|
||||||
std::string sPos) const;
|
std::string sPos) const;
|
||||||
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos,
|
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos,
|
||||||
std::string sName,
|
std::string sName,
|
||||||
bool* pfNullified = NULL) const;
|
bool* pfNullified = NULL) const;
|
||||||
|
|
||||||
bool clear() const;
|
bool clear() const;
|
||||||
|
|
||||||
bool removeClaim(const std::string& name, const COutPoint& outPoint,
|
bool removeClaim(const std::string& name, const COutPoint& outPoint,
|
||||||
int nHeight, int& nValidAtHeight, bool fCheckTakeover) const;
|
int nHeight, int& nValidAtHeight, bool fCheckTakeover) const;
|
||||||
|
|
||||||
bool addClaimToQueues(const std::string& name, CClaimValue& claim) const;
|
bool addClaimToQueues(const std::string& name, CClaimValue& claim) const;
|
||||||
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint,
|
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint,
|
||||||
CClaimValue& claim) const;
|
CClaimValue& claim) const;
|
||||||
void addToExpirationQueue(int nExpirationHeight, nameOutPointType& entry) const;
|
void addToExpirationQueue(int nExpirationHeight, nameOutPointType& entry) const;
|
||||||
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint,
|
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint,
|
||||||
int nHeight) const;
|
int nHeight) const;
|
||||||
|
|
||||||
claimQueueType::iterator getQueueCacheRow(int nHeight,
|
claimQueueType::iterator getQueueCacheRow(int nHeight,
|
||||||
bool createIfNotExists) const;
|
bool createIfNotExists) const;
|
||||||
queueNameType::iterator getQueueCacheNameRow(const std::string& name,
|
queueNameType::iterator getQueueCacheNameRow(const std::string& name,
|
||||||
bool createIfNotExists) const;
|
bool createIfNotExists) const;
|
||||||
expirationQueueType::iterator getExpirationQueueCacheRow(int nHeight,
|
expirationQueueType::iterator getExpirationQueueCacheRow(int nHeight,
|
||||||
bool createIfNotExists) const;
|
bool createIfNotExists) const;
|
||||||
|
|
||||||
bool removeSupport(const std::string& name, const COutPoint& outPoint,
|
bool removeSupport(const std::string& name, const COutPoint& outPoint,
|
||||||
int nHeight, int& nValidAtHeight,
|
int nHeight, int& nValidAtHeight,
|
||||||
bool fCheckTakeover) const;
|
bool fCheckTakeover) const;
|
||||||
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint,
|
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint,
|
||||||
CSupportValue& support,
|
CSupportValue& support,
|
||||||
bool fCheckTakeover) const;
|
bool fCheckTakeover) const;
|
||||||
|
|
||||||
bool insertSupportIntoMap(const std::string& name,
|
bool insertSupportIntoMap(const std::string& name,
|
||||||
CSupportValue support,
|
CSupportValue support,
|
||||||
bool fCheckTakeover) const;
|
bool fCheckTakeover) const;
|
||||||
|
|
||||||
supportQueueType::iterator getSupportQueueCacheRow(int nHeight,
|
supportQueueType::iterator getSupportQueueCacheRow(int nHeight,
|
||||||
bool createIfNotExists) const;
|
bool createIfNotExists) const;
|
||||||
queueNameType::iterator getSupportQueueCacheNameRow(const std::string& name,
|
queueNameType::iterator getSupportQueueCacheNameRow(const std::string& name,
|
||||||
|
@ -571,12 +598,12 @@ protected:
|
||||||
void removeSupportFromExpirationQueue(const std::string& name,
|
void removeSupportFromExpirationQueue(const std::string& name,
|
||||||
const COutPoint& outPoint,
|
const COutPoint& outPoint,
|
||||||
int nHeight) const;
|
int nHeight) const;
|
||||||
|
|
||||||
bool getSupportsForName(const std::string& name,
|
bool getSupportsForName(const std::string& name,
|
||||||
supportMapEntryType& node) const;
|
supportMapEntryType& node) const;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
uint256 getLeafHashForProof(const std::string& currentPosition, unsigned char nodeChar,
|
uint256 getLeafHashForProof(const std::string& currentPosition, unsigned char nodeChar,
|
||||||
|
|
|
@ -374,27 +374,22 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
|
||||||
uint160 claimId;
|
uint160 claimId;
|
||||||
claimId.SetHex(params[0].get_str());
|
claimId.SetHex(params[0].get_str());
|
||||||
UniValue claim(UniValue::VOBJ);
|
UniValue claim(UniValue::VOBJ);
|
||||||
std::vector<namedNodeType> nodes = pclaimTrie->flattenTrie();
|
std::string name;
|
||||||
for (std::vector<namedNodeType>::iterator it = nodes.begin(); it != nodes.end(); ++it) {
|
CClaimValue claimValue;
|
||||||
if (!it->second.claims.empty()) {
|
pclaimTrie->getClaimById(claimId, name, claimValue);
|
||||||
for (std::vector<CClaimValue>::iterator itClaims = it->second.claims.begin();
|
if (claimValue.claimId == claimId)
|
||||||
itClaims != it->second.claims.end(); ++itClaims) {
|
{
|
||||||
if (claimId == itClaims->claimId) {
|
std::string sValue;
|
||||||
std::string sValue;
|
getValueForClaim(claimValue.outPoint, sValue);
|
||||||
getValueForClaim(itClaims->outPoint, sValue);
|
claim.push_back(Pair("name", name));
|
||||||
claim.push_back(Pair("name", it->first));
|
claim.push_back(Pair("value", sValue));
|
||||||
claim.push_back(Pair("value", sValue));
|
claim.push_back(Pair("claimId", claimValue.claimId.GetHex()));
|
||||||
claim.push_back(Pair("claimId", itClaims->claimId.GetHex()));
|
claim.push_back(Pair("txid", claimValue.outPoint.hash.GetHex()));
|
||||||
claim.push_back(Pair("txid", itClaims->outPoint.hash.GetHex()));
|
claim.push_back(Pair("n", (int) claimValue.outPoint.n));
|
||||||
claim.push_back(Pair("n", (int) itClaims->outPoint.n));
|
claim.push_back(Pair("amount", claimValue.nAmount));
|
||||||
claim.push_back(Pair("amount", itClaims->nAmount));
|
claim.push_back(Pair("effective amount",
|
||||||
claim.push_back(Pair("effective amount",
|
pclaimTrie->getEffectiveAmountForClaim(name, claimValue.claimId)));
|
||||||
pclaimTrie->getEffectiveAmountForClaim(it->first, itClaims->claimId)));
|
claim.push_back(Pair("height", claimValue.nHeight));
|
||||||
claim.push_back(Pair("height", itClaims->nHeight));
|
|
||||||
return claim;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return claim;
|
return claim;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue