made the functional test workaround not break testnet
This commit is contained in:
parent
8028a44de5
commit
68ecea3fdb
3 changed files with 12 additions and 18 deletions
|
@ -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 leafHash = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
|
||||||
static const auto emptyHash = uint256S("0000000000000000000000000000000000000000000000000000000000000003");
|
static const auto emptyHash = uint256S("0000000000000000000000000000000000000000000000000000000000000003");
|
||||||
|
|
||||||
|
@ -264,8 +264,9 @@ uint256 CClaimTrieCacheHashFork::computeNodeHash(const std::string& name, int ta
|
||||||
claimHashQuery++;
|
claimHashQuery++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (childHashes.empty() && claimHashes.empty())
|
if (name.empty() && childHashes.empty() && claimHashes.empty()
|
||||||
return verifyEmptyTrie(name);
|
&& 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 left = childHashes.empty() ? leafHash : ComputeMerkleRoot(std::move(childHashes));
|
||||||
auto right = claimHashes.empty() ? emptyHash : ComputeMerkleRoot(std::move(claimHashes));
|
auto right = claimHashes.empty() ? emptyHash : ComputeMerkleRoot(std::move(claimHashes));
|
||||||
|
|
|
@ -117,7 +117,7 @@ CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
|
||||||
CClaimTrieCacheBase::~CClaimTrieCacheBase()
|
CClaimTrieCacheBase::~CClaimTrieCacheBase()
|
||||||
{
|
{
|
||||||
if (transacting) {
|
if (transacting) {
|
||||||
db << "rollback";
|
db << "ROLLBACK";
|
||||||
transacting = false;
|
transacting = false;
|
||||||
}
|
}
|
||||||
claimHashQuery.used(true);
|
claimHashQuery.used(true);
|
||||||
|
@ -438,14 +438,6 @@ void completeHash(uint256& partialHash, const std::string& key, int to)
|
||||||
partialHash = Hash(it, it + 1, partialHash.begin(), partialHash.end());
|
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)
|
uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeoverHeight)
|
||||||
{
|
{
|
||||||
const auto pos = name.size();
|
const auto pos = name.size();
|
||||||
|
@ -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()
|
bool CClaimTrieCacheBase::checkConsistency()
|
||||||
|
@ -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,
|
bool CClaimTrieCacheBase::removeClaim(const uint160& claimId, const COutPoint& outPoint, std::string& nodeName,
|
||||||
int& validHeight, int& originalHeight)
|
int& validHeight, int& originalHeight)
|
||||||
{
|
{
|
||||||
ensureTransacting();
|
|
||||||
|
|
||||||
// this gets tricky in that we may be removing an update
|
// 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 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
|
// 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
|
// 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
|
// 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;
|
<< claimId << outPoint.hash << outPoint.n << nNextHeight;
|
||||||
auto it = query.begin();
|
auto it = query.begin();
|
||||||
if (it == query.end())
|
if (it == query.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*it >> nodeName >> validHeight >> originalHeight;
|
*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())
|
if (!db.rows_modified())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
COutPoint::COutPoint() noexcept : n(std::numeric_limits<uint32_t>::max())
|
COutPoint::COutPoint() noexcept : n(std::numeric_limits<uint32_t>::max())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COutPoint::COutPoint(uint256 hashIn, uint32_t nIn) : hash(std::move(hashIn)), n(nIn)
|
COutPoint::COutPoint(uint256 hashIn, uint32_t nIn) : hash(std::move(hashIn)), n(nIn)
|
||||||
|
|
Loading…
Reference in a new issue