Unify claimtrie tests, add some additional root hash checks #181

Closed
BrannonKing wants to merge 291 commits from unify_claimtrie_tests into master
4 changed files with 110 additions and 31 deletions
Showing only changes of commit cda9f1f0ff - Show all commits

View file

@ -266,6 +266,41 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
return false; return false;
} }
bool CClaimTrie::haveSupportInQueueRow(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, const std::vector<CSupportValueQueueEntry>& row) const
{
for (std::vector<CSupportValueQueueEntry>::const_iterator itRow = row.begin(); itRow != row.end(); ++itRow)
{
if (itRow->name == name && itRow->val.txhash == txhash && itRow->val.nOut == nOut && itRow->val.nHeight == nHeight)
{
return true;
}
}
return false;
}
bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
{
std::vector<CSupportValueQueueEntry> row;
if (getSupportQueueRow(nHeight, row))
{
if (haveSupportInQueueRow(name, txhash, nOut, nHeight, row))
{
nValidAtHeight = nHeight;
return true;
}
}
row.clear();
if (getSupportQueueRow(nHeight + DEFAULT_DELAY, row))
{
if (haveSupportInQueueRow(name, txhash, nOut, nHeight, row))
{
nValidAtHeight = nHeight + DEFAULT_DELAY;
return true;
}
}
return false;
}
unsigned int CClaimTrie::getTotalNamesInTrie() const unsigned int CClaimTrie::getTotalNamesInTrie() const
{ {
if (empty()) if (empty())
@ -502,9 +537,9 @@ bool CClaimTrie::getSupportNode(std::string name, supportMapNodeType& node) cons
return db.Read(std::make_pair(SUPPORT, name), node); return db.Read(std::make_pair(SUPPORT, name), node);
} }
bool CClaimTrie::getSupportQueueRow(int nHeight, std::vector<CSupportValueQueueEntry>& row) bool CClaimTrie::getSupportQueueRow(int nHeight, std::vector<CSupportValueQueueEntry>& row) const
{ {
supportValueQueueType::iterator itQueueRow = dirtySupportQueueRows.find(nHeight); supportValueQueueType::const_iterator itQueueRow = dirtySupportQueueRows.find(nHeight);
if (itQueueRow != dirtySupportQueueRows.end()) if (itQueueRow != dirtySupportQueueRows.end())
{ {
row = itQueueRow->second; row = itQueueRow->second;

View file

@ -235,11 +235,13 @@ public:
bool getExpirationQueueRow(int nHeight, std::vector<CValueQueueEntry>& row); bool getExpirationQueueRow(int nHeight, std::vector<CValueQueueEntry>& row);
bool getSupportNode(std::string name, supportMapNodeType& node); bool getSupportNode(std::string name, supportMapNodeType& node);
bool getSupportNode(std::string name, supportMapNodeType& node) const; bool getSupportNode(std::string name, supportMapNodeType& node) const;
bool getSupportQueueRow(int nHeight, std::vector<CSupportValueQueueEntry>& row); bool getSupportQueueRow(int nHeight, std::vector<CSupportValueQueueEntry>& row) const;
bool haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const; 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; bool haveClaimInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const;
bool haveClaimInQueueRow(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, const std::vector<CValueQueueEntry>& row) const; bool haveClaimInQueueRow(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, const std::vector<CValueQueueEntry>& row) const;
bool haveSupport(const std::string& name, const uint256& txhash, uint32_t nOut) 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;
bool haveSupportInQueueRow(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, const std::vector<CSupportValueQueueEntry>& row) 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;

View file

@ -1539,7 +1539,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTr
assert(vvchParams.size() == 3); assert(vvchParams.size() == 3);
std::string name(vvchParams[0].begin(), vvchParams[0].end()); std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint256 supportedTxid(vvchParams[1]); uint256 supportedTxid(vvchParams[1]);
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);; uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);
int nValidHeight = undo.nClaimValidHeight; int nValidHeight = undo.nClaimValidHeight;
if (nValidHeight > 0 && nValidHeight >= coins->nHeight) if (nValidHeight > 0 && nValidHeight >= coins->nHeight)
{ {

View file

@ -172,14 +172,18 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
"Result:\n" "Result:\n"
"[\n" "[\n"
" {\n" " {\n"
" \"nOut\" (numeric) the index of the claim in the transaction's list out outputs\n" " \"nOut\" (numeric) the index of the claim or support in the transaction's list out outputs\n"
" \"name\" (string) the name claimed\n" " \"claim type\" (string) 'claim' or 'support'\n"
" \"value\" (string) the value of the claim\n" " \"name\" (string) the name claimed or supported\n"
" \"value\" (string) if a name claim, the value of the claim\n"
" \"supported txid\" (string) if a support, the txid of the supported claim\n"
" \"supported nout\" (numeric) if a support, the index of the supported claim in its transaction\n"
" \"depth\" (numeric) the depth of the transaction in the main chain\n" " \"depth\" (numeric) the depth of the transaction in the main chain\n"
" \"in claim trie\" (boolean) whether the claim has made it into the trie\n" " \"in claim trie\" (boolean) if a name claim, whether the claim is active, i.e. has made it into the trie\n"
" \"is controlling\" (boolean) whether the claim is the current controlling claim for the name\n" " \"is controlling\" (boolean) if a name claim, whether the claim is the current controlling claim for the name\n"
" \"in queue\" (boolean) whether the claim is in a queue waiting to be inserted into the trie\n" " \"in support map\" (boolean) if a support, whether the support is active, i.e. has made it into the support map\n"
" \"blocks to valid\" (numeric) if in a queue, the number of blocks until it's inserted into the trie\n" " \"in queue\" (boolean) whether the claim is in a queue waiting to be inserted into the trie or support map\n"
" \"blocks to valid\" (numeric) if in a queue, the number of blocks until it's inserted into the trie or support map\n"
" }\n" " }\n"
"]\n" "]\n"
); );
@ -228,11 +232,23 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
o.push_back(Pair("nOut", (int64_t)i)); o.push_back(Pair("nOut", (int64_t)i));
std::string sName(vvchParams[0].begin(), vvchParams[0].end()); std::string sName(vvchParams[0].begin(), vvchParams[0].end());
o.push_back(Pair("name", sName)); o.push_back(Pair("name", sName));
if (op == OP_CLAIM_NAME)
{
std::string sValue(vvchParams[1].begin(), vvchParams[1].end()); std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
o.push_back(Pair("value", sValue)); o.push_back(Pair("value", sValue));
}
else if (op == OP_SUPPORT_CLAIM)
{
uint256 supportedTxid(vvchParams[1]);
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);
o.push_back(Pair("supported txid", supportedTxid.GetHex()));
o.push_back(Pair("supported nout", (int64_t)supportednOut));
}
if (nHeight > 0) if (nHeight > 0)
{ {
o.push_back(Pair("depth", chainActive.Height() - nHeight)); o.push_back(Pair("depth", chainActive.Height() - nHeight));
if (op == OP_CLAIM_NAME)
{
bool inClaimTrie = pclaimTrie->haveClaim(sName, hash, i); bool inClaimTrie = pclaimTrie->haveClaim(sName, hash, i);
o.push_back(Pair("in claim trie", inClaimTrie)); o.push_back(Pair("in claim trie", inClaimTrie));
if (inClaimTrie) if (inClaimTrie)
@ -247,7 +263,7 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
else else
{ {
int nValidAtHeight; int nValidAtHeight;
if (pclaimTrie->haveClaimInQueue(sName, hash, i, coin->nHeight, nValidAtHeight)) if (pclaimTrie->haveClaimInQueue(sName, hash, i, nHeight, 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()));
@ -258,10 +274,36 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
} }
} }
} }
else if (op == OP_SUPPORT_CLAIM)
{
bool inSupportMap = pclaimTrie->haveSupport(sName, hash, i);
o.push_back(Pair("in support map", inSupportMap));
if (!inSupportMap)
{
int nValidAtHeight;
if (pclaimTrie->haveSupportInQueue(sName, hash, i, nHeight, nValidAtHeight))
{
o.push_back(Pair("in queue", true));
o.push_back(Pair("blocks to valid", nValidAtHeight - chainActive.Height()));
}
else
{
o.push_back(Pair("in queue", false));
}
}
}
}
else else
{ {
o.push_back(Pair("depth", 0)); o.push_back(Pair("depth", 0));
if (op == OP_CLAIM_NAME)
{
o.push_back(Pair("in claim trie", false)); o.push_back(Pair("in claim trie", false));
}
else if (op == OP_SUPPORT_CLAIM)
{
o.push_back(Pair("in support map", false));
}
o.push_back(Pair("in queue", false)); o.push_back(Pair("in queue", false));
} }
ret.push_back(o); ret.push_back(o);