Skip to content

Commit 68ecea3

Browse files
committed
made the functional test workaround not break testnet
1 parent 8028a44 commit 68ecea3

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

src/claimtrie/forks.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ CClaimTrieCacheHashFork::CClaimTrieCacheHashFork(CClaimTrie* base) : CClaimTrieC
227227
{
228228
}
229229

230-
extern uint256 verifyEmptyTrie(const std::string&);
230+
static const auto emptyTrieHash = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
231231
static const auto leafHash = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
232232
static const auto emptyHash = uint256S("0000000000000000000000000000000000000000000000000000000000000003");
233233

@@ -264,8 +264,9 @@ uint256 CClaimTrieCacheHashFork::computeNodeHash(const std::string& name, int ta
264264
claimHashQuery++;
265265
}
266266

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

270271
auto left = childHashes.empty() ? leafHash : ComputeMerkleRoot(std::move(childHashes));
271272
auto right = claimHashes.empty() ? emptyHash : ComputeMerkleRoot(std::move(claimHashes));

src/claimtrie/trie.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
117117
CClaimTrieCacheBase::~CClaimTrieCacheBase()
118118
{
119119
if (transacting) {
120-
db << "rollback";
120+
db << "ROLLBACK";
121121
transacting = false;
122122
}
123123
claimHashQuery.used(true);
@@ -438,14 +438,6 @@ void completeHash(uint256& partialHash, const std::string& key, int to)
438438
partialHash = Hash(it, it + 1, partialHash.begin(), partialHash.end());
439439
}
440440

441-
uint256 verifyEmptyTrie(const std::string& name)
442-
{
443-
if (!name.empty())
444-
logPrint << "Corrupt trie near: " << name << Clog::endl;
445-
assert(name.empty());
446-
return emptyTrieHash;
447-
}
448-
449441
uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeoverHeight)
450442
{
451443
const auto pos = name.size();
@@ -466,7 +458,7 @@ uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeov
466458
}
467459
}
468460

469-
return vchToHash.empty() ? verifyEmptyTrie(name) : Hash(vchToHash.begin(), vchToHash.end());
461+
return vchToHash.empty() ? emptyTrieHash : Hash(vchToHash.begin(), vchToHash.end());
470462
}
471463

472464
bool CClaimTrieCacheBase::checkConsistency()
@@ -696,22 +688,24 @@ bool CClaimTrieCacheBase::addSupport(const std::string& name, const COutPoint& o
696688
bool CClaimTrieCacheBase::removeClaim(const uint160& claimId, const COutPoint& outPoint, std::string& nodeName,
697689
int& validHeight, int& originalHeight)
698690
{
699-
ensureTransacting();
700-
701691
// this gets tricky in that we may be removing an update
702692
// when going forward we spend a claim (aka, call removeClaim) before updating it (aka, call addClaim)
703693
// when going backwards we first remove the update by calling removeClaim
704694
// we then undo the spend of the previous one by calling addClaim with the original data
705695
// in order to maintain the proper takeover height the updater will need to use our height returned here
706696

707-
auto query = db << "SELECT nodeName, activationHeight, originalHeight FROM claim WHERE claimID = ? AND txID = ? AND txN = ? AND expirationHeight >= ?"
697+
auto query = db << "SELECT nodeName, activationHeight, originalHeight FROM claim "
698+
"WHERE claimID = ? AND txID = ? AND txN = ? AND expirationHeight >= ?"
708699
<< claimId << outPoint.hash << outPoint.n << nNextHeight;
709700
auto it = query.begin();
710701
if (it == query.end())
711702
return false;
712703

713704
*it >> nodeName >> validHeight >> originalHeight;
714-
db << "DELETE FROM claim WHERE claimID = ? AND txID = ? and txN = ?" << claimId << outPoint.hash << outPoint.n;
705+
706+
ensureTransacting();
707+
db << "DELETE FROM claim WHERE claimID = ? AND txID = ? AND txN = ?"
708+
<< claimId << outPoint.hash << outPoint.n;
715709
if (!db.rows_modified())
716710
return false;
717711

src/claimtrie/txoutpoint.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
COutPoint::COutPoint() noexcept : n(std::numeric_limits<uint32_t>::max())
88
{
9-
109
}
1110

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

0 commit comments

Comments
 (0)