Skip to content

Commit

Permalink
made the functional test workaround not break testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
BrannonKing committed Apr 22, 2020
1 parent 8028a44 commit 68ecea3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/claimtrie/forks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ CClaimTrieCacheHashFork::CClaimTrieCacheHashFork(CClaimTrie* base) : CClaimTrieC
{
}

extern uint256 verifyEmptyTrie(const std::string&);
static const auto emptyTrieHash = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
static const auto leafHash = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
static const auto emptyHash = uint256S("0000000000000000000000000000000000000000000000000000000000000003");

Expand Down Expand Up @@ -264,8 +264,9 @@ uint256 CClaimTrieCacheHashFork::computeNodeHash(const std::string& name, int ta
claimHashQuery++;
}

if (childHashes.empty() && claimHashes.empty())
return verifyEmptyTrie(name);
if (name.empty() && childHashes.empty() && claimHashes.empty()
&& base->nMaxRemovalWorkaroundHeight < 0) // detecting regtest, but maybe all on next hard-fork?
return emptyTrieHash; // here for compatibility with the functional tests

auto left = childHashes.empty() ? leafHash : ComputeMerkleRoot(std::move(childHashes));
auto right = claimHashes.empty() ? emptyHash : ComputeMerkleRoot(std::move(claimHashes));
Expand Down
22 changes: 8 additions & 14 deletions src/claimtrie/trie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
CClaimTrieCacheBase::~CClaimTrieCacheBase()
{
if (transacting) {
db << "rollback";
db << "ROLLBACK";
transacting = false;
}
claimHashQuery.used(true);
Expand Down Expand Up @@ -438,14 +438,6 @@ void completeHash(uint256& partialHash, const std::string& key, int to)
partialHash = Hash(it, it + 1, partialHash.begin(), partialHash.end());
}

uint256 verifyEmptyTrie(const std::string& name)
{
if (!name.empty())
logPrint << "Corrupt trie near: " << name << Clog::endl;
assert(name.empty());
return emptyTrieHash;
}

uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeoverHeight)
{
const auto pos = name.size();
Expand All @@ -466,7 +458,7 @@ uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeov
}
}

return vchToHash.empty() ? verifyEmptyTrie(name) : Hash(vchToHash.begin(), vchToHash.end());
return vchToHash.empty() ? emptyTrieHash : Hash(vchToHash.begin(), vchToHash.end());
}

bool CClaimTrieCacheBase::checkConsistency()
Expand Down Expand Up @@ -696,22 +688,24 @@ bool CClaimTrieCacheBase::addSupport(const std::string& name, const COutPoint& o
bool CClaimTrieCacheBase::removeClaim(const uint160& claimId, const COutPoint& outPoint, std::string& nodeName,
int& validHeight, int& originalHeight)
{
ensureTransacting();

// this gets tricky in that we may be removing an update
// when going forward we spend a claim (aka, call removeClaim) before updating it (aka, call addClaim)
// when going backwards we first remove the update by calling removeClaim
// we then undo the spend of the previous one by calling addClaim with the original data
// in order to maintain the proper takeover height the updater will need to use our height returned here

auto query = db << "SELECT nodeName, activationHeight, originalHeight FROM claim WHERE claimID = ? AND txID = ? AND txN = ? AND expirationHeight >= ?"
auto query = db << "SELECT nodeName, activationHeight, originalHeight FROM claim "
"WHERE claimID = ? AND txID = ? AND txN = ? AND expirationHeight >= ?"
<< claimId << outPoint.hash << outPoint.n << nNextHeight;
auto it = query.begin();
if (it == query.end())
return false;

*it >> nodeName >> validHeight >> originalHeight;
db << "DELETE FROM claim WHERE claimID = ? AND txID = ? and txN = ?" << claimId << outPoint.hash << outPoint.n;

ensureTransacting();
db << "DELETE FROM claim WHERE claimID = ? AND txID = ? AND txN = ?"
<< claimId << outPoint.hash << outPoint.n;
if (!db.rows_modified())
return false;

Expand Down
1 change: 0 additions & 1 deletion src/claimtrie/txoutpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

COutPoint::COutPoint() noexcept : n(std::numeric_limits<uint32_t>::max())
{

}

COutPoint::COutPoint(uint256 hashIn, uint32_t nIn) : hash(std::move(hashIn)), n(nIn)
Expand Down

0 comments on commit 68ecea3

Please sign in to comment.