Rebase LBRY on top of Bitcoin 0.17 #263
4 changed files with 143 additions and 79 deletions
|
@ -69,7 +69,7 @@ bool CClaimTrieNode::removeClaim(const COutPoint& outPoint, CClaimValue& claim)
|
||||||
{
|
{
|
||||||
if (itClaims->outPoint == outPoint)
|
if (itClaims->outPoint == outPoint)
|
||||||
{
|
{
|
||||||
claim = *itClaims;
|
std::swap(claim, *itClaims);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,8 +500,7 @@ claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
claimsForNameType allClaims(claims, supports, nLastTakeoverHeight);
|
return { std::move(claims), std::move(supports), nLastTakeoverHeight };
|
||||||
return allClaims;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//return effective amount from claim, retuns 0 if claim is not found
|
//return effective amount from claim, retuns 0 if claim is not found
|
||||||
|
@ -642,7 +641,7 @@ void CClaimTrie::updateQueueRow(int nHeight, claimQueueRowType& row)
|
||||||
assert(ret.second);
|
assert(ret.second);
|
||||||
itQueueRow = ret.first;
|
itQueueRow = ret.first;
|
||||||
}
|
}
|
||||||
claimtrie::swap(row, itQueueRow->second);
|
itQueueRow->second.swap(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrie::updateQueueNameRow(const std::string& name, queueNameRowType& row)
|
void CClaimTrie::updateQueueNameRow(const std::string& name, queueNameRowType& row)
|
||||||
|
@ -656,7 +655,7 @@ void CClaimTrie::updateQueueNameRow(const std::string& name, queueNameRowType& r
|
||||||
assert(ret.second);
|
assert(ret.second);
|
||||||
itQueueRow = ret.first;
|
itQueueRow = ret.first;
|
||||||
}
|
}
|
||||||
claimtrie::swap(row, itQueueRow->second);
|
itQueueRow->second.swap(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrie::updateExpirationRow(int nHeight, expirationQueueRowType& row)
|
void CClaimTrie::updateExpirationRow(int nHeight, expirationQueueRowType& row)
|
||||||
|
@ -670,7 +669,7 @@ void CClaimTrie::updateExpirationRow(int nHeight, expirationQueueRowType& row)
|
||||||
assert(ret.second);
|
assert(ret.second);
|
||||||
itQueueRow = ret.first;
|
itQueueRow = ret.first;
|
||||||
}
|
}
|
||||||
claimtrie::swap(row, itQueueRow->second);
|
itQueueRow->second.swap(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrie::updateSupportMap(const std::string& name, supportMapEntryType& node)
|
void CClaimTrie::updateSupportMap(const std::string& name, supportMapEntryType& node)
|
||||||
|
@ -684,7 +683,7 @@ void CClaimTrie::updateSupportMap(const std::string& name, supportMapEntryType&
|
||||||
assert(ret.second);
|
assert(ret.second);
|
||||||
itNode = ret.first;
|
itNode = ret.first;
|
||||||
}
|
}
|
||||||
claimtrie::swap(node, itNode->second);
|
itNode->second.swap(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrie::updateSupportQueue(int nHeight, supportQueueRowType& row)
|
void CClaimTrie::updateSupportQueue(int nHeight, supportQueueRowType& row)
|
||||||
|
@ -698,7 +697,7 @@ void CClaimTrie::updateSupportQueue(int nHeight, supportQueueRowType& row)
|
||||||
assert(ret.second);
|
assert(ret.second);
|
||||||
itQueueRow = ret.first;
|
itQueueRow = ret.first;
|
||||||
}
|
}
|
||||||
claimtrie::swap(row, itQueueRow->second);
|
itQueueRow->second.swap(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrie::updateSupportNameQueue(const std::string& name, queueNameRowType& row)
|
void CClaimTrie::updateSupportNameQueue(const std::string& name, queueNameRowType& row)
|
||||||
|
@ -712,7 +711,7 @@ void CClaimTrie::updateSupportNameQueue(const std::string& name, queueNameRowTyp
|
||||||
assert(ret.second);
|
assert(ret.second);
|
||||||
itQueueRow = ret.first;
|
itQueueRow = ret.first;
|
||||||
}
|
}
|
||||||
claimtrie::swap(row, itQueueRow->second);
|
itQueueRow->second.swap(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrie::updateSupportExpirationQueue(int nHeight, expirationQueueRowType& row)
|
void CClaimTrie::updateSupportExpirationQueue(int nHeight, expirationQueueRowType& row)
|
||||||
|
@ -726,7 +725,7 @@ void CClaimTrie::updateSupportExpirationQueue(int nHeight, expirationQueueRowTyp
|
||||||
assert(ret.second);
|
assert(ret.second);
|
||||||
itQueueRow = ret.first;
|
itQueueRow = ret.first;
|
||||||
}
|
}
|
||||||
claimtrie::swap(row, itQueueRow->second);
|
itQueueRow->second.swap(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClaimTrie::getSupportNode(std::string name, supportMapEntryType& node) const
|
bool CClaimTrie::getSupportNode(std::string name, supportMapEntryType& node) const
|
||||||
|
@ -863,7 +862,7 @@ bool CClaimTrie::updateName(const std::string &name, CClaimTrieNode* updatedNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(current != NULL);
|
assert(current != NULL);
|
||||||
claimtrie::swap(updatedNode->claims, current->claims);
|
current->claims.swap(updatedNode->claims);
|
||||||
markNodeDirty(name, current);
|
markNodeDirty(name, current);
|
||||||
for (nodeMapType::iterator itchild = current->children.begin(); itchild != current->children.end();)
|
for (nodeMapType::iterator itchild = current->children.begin(); itchild != current->children.end();)
|
||||||
{
|
{
|
||||||
|
@ -1619,7 +1618,7 @@ bool CClaimTrieCache::removeClaimFromQueue(const std::string& name, const COutPo
|
||||||
}
|
}
|
||||||
if (itQueue != itQueueRow->second.end())
|
if (itQueue != itQueueRow->second.end())
|
||||||
{
|
{
|
||||||
claim = itQueue->second;
|
std::swap(claim, itQueue->second);
|
||||||
itQueueNameRow->second.erase(itQueueName);
|
itQueueNameRow->second.erase(itQueueName);
|
||||||
itQueueRow->second.erase(itQueue);
|
itQueueRow->second.erase(itQueue);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1643,24 +1642,17 @@ bool CClaimTrieCache::spendClaim(const std::string& name, const COutPoint& outPo
|
||||||
bool CClaimTrieCache::removeClaim(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight, bool fCheckTakeover) const
|
bool CClaimTrieCache::removeClaim(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight, bool fCheckTakeover) const
|
||||||
{
|
{
|
||||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %s, nCurrentHeight: %s\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nCurrentHeight);
|
LogPrintf("%s: name: %s, txhash: %s, nOut: %s, nCurrentHeight: %s\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nCurrentHeight);
|
||||||
bool removed = false;
|
|
||||||
CClaimValue claim;
|
CClaimValue claim;
|
||||||
if (removeClaimFromQueue(name, outPoint, claim))
|
if (removeClaimFromQueue(name, outPoint, claim)
|
||||||
{
|
|| removeClaimFromTrie(name, outPoint, claim, fCheckTakeover)) {
|
||||||
removed = true;
|
|
||||||
}
|
|
||||||
if (removed == false && removeClaimFromTrie(name, outPoint, claim, fCheckTakeover))
|
|
||||||
{
|
|
||||||
removed = true;
|
|
||||||
}
|
|
||||||
if (removed == true)
|
|
||||||
{
|
|
||||||
nValidAtHeight = claim.nValidAtHeight;
|
nValidAtHeight = claim.nValidAtHeight;
|
||||||
int expirationHeight = claim.nHeight + base->nExpirationTime;
|
int expirationHeight = claim.nHeight + base->nExpirationTime;
|
||||||
removeFromExpirationQueue(name, outPoint, expirationHeight);
|
removeFromExpirationQueue(name, outPoint, expirationHeight);
|
||||||
claimsToDelete.insert(claim);
|
claimsToDelete.insert(claim);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return removed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrieCache::addToExpirationQueue(int nExpirationHeight, nameOutPointType& entry) const
|
void CClaimTrieCache::addToExpirationQueue(int nExpirationHeight, nameOutPointType& entry) const
|
||||||
|
@ -1834,7 +1826,7 @@ bool CClaimTrieCache::removeSupportFromMap(const std::string& name, const COutPo
|
||||||
}
|
}
|
||||||
if (itSupport != cachedNode->second.end())
|
if (itSupport != cachedNode->second.end())
|
||||||
{
|
{
|
||||||
claimtrie::swap(support, *itSupport);
|
std::swap(support, *itSupport);
|
||||||
cachedNode->second.erase(itSupport);
|
cachedNode->second.erase(itSupport);
|
||||||
return reorderTrieNode(name, fCheckTakeover);
|
return reorderTrieNode(name, fCheckTakeover);
|
||||||
}
|
}
|
||||||
|
@ -1929,7 +1921,7 @@ bool CClaimTrieCache::removeSupportFromQueue(const std::string& name, const COut
|
||||||
}
|
}
|
||||||
if (itQueue != itQueueRow->second.end())
|
if (itQueue != itQueueRow->second.end())
|
||||||
{
|
{
|
||||||
claimtrie::swap(support, itQueue->second);
|
std::swap(support, itQueue->second);
|
||||||
itQueueNameRow->second.erase(itQueueName);
|
itQueueNameRow->second.erase(itQueueName);
|
||||||
itQueueRow->second.erase(itQueue);
|
itQueueRow->second.erase(itQueue);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1974,21 +1966,17 @@ bool CClaimTrieCache::undoSpendSupport(const std::string& name, const COutPoint&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClaimTrieCache::removeSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover) const
|
bool CClaimTrieCache::removeSupport(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight, bool fCheckTakeover) const
|
||||||
{
|
{
|
||||||
bool removed = false;
|
|
||||||
CSupportValue support;
|
CSupportValue support;
|
||||||
if (removeSupportFromQueue(name, outPoint, support))
|
if (removeSupportFromQueue(name, outPoint, support)
|
||||||
removed = true;
|
|| removeSupportFromMap(name, outPoint, support, fCheckTakeover)) {
|
||||||
if (removed == false && removeSupportFromMap(name, outPoint, support, fCheckTakeover))
|
int expirationHeight = support.nHeight + base->nExpirationTime;
|
||||||
removed = true;
|
|
||||||
if (removed)
|
|
||||||
{
|
|
||||||
int expirationHeight = nHeight + base->nExpirationTime;
|
|
||||||
removeSupportFromExpirationQueue(name, outPoint, expirationHeight);
|
removeSupportFromExpirationQueue(name, outPoint, expirationHeight);
|
||||||
nValidAtHeight = support.nValidAtHeight;
|
nValidAtHeight = support.nValidAtHeight;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return removed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrieCache::addSupportToExpirationQueue(int nExpirationHeight, nameOutPointType& entry) const
|
void CClaimTrieCache::addSupportToExpirationQueue(int nExpirationHeight, nameOutPointType& entry) const
|
||||||
|
@ -2036,17 +2024,17 @@ expirationQueueType::iterator CClaimTrieCache::getSupportExpirationQueueCacheRow
|
||||||
return itQueueRow;
|
return itQueueRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClaimTrieCache::undoAddSupport(const std::string& name, const COutPoint& outPoint, int nHeight) const
|
bool CClaimTrieCache::undoAddSupport(const std::string& name, const COutPoint& outPoint) const
|
||||||
{
|
{
|
||||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nHeight, nCurrentHeight);
|
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nCurrentHeight);
|
||||||
int throwaway;
|
int throwaway;
|
||||||
return removeSupport(name, outPoint, nHeight, throwaway, false);
|
return removeSupport(name, outPoint, throwaway, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClaimTrieCache::spendSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight) const
|
bool CClaimTrieCache::spendSupport(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const
|
||||||
{
|
{
|
||||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nHeight, nCurrentHeight);
|
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nCurrentHeight);
|
||||||
return removeSupport(name, outPoint, nHeight, nValidAtHeight, true);
|
return removeSupport(name, outPoint, nValidAtHeight, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClaimTrieCache::incrementBlock(insertUndoType& insertUndo, claimQueueRowType& expireUndo, insertUndoType& insertSupportUndo, supportQueueRowType& expireSupportUndo, std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const
|
bool CClaimTrieCache::incrementBlock(insertUndoType& insertUndo, claimQueueRowType& expireUndo, insertUndoType& insertSupportUndo, supportQueueRowType& expireSupportUndo, std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const
|
||||||
|
@ -2581,7 +2569,7 @@ claimsForNameType CClaimTrieCache::getClaimsForName(const std::string& name) con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return claimsForNameType(claims, supports, nLastTakeoverHeight);
|
return { std::move(claims), std::move(supports), nLastTakeoverHeight };
|
||||||
}
|
}
|
||||||
|
|
||||||
CAmount CClaimTrieCache::getEffectiveAmountForClaim(const std::string& name, const uint160& claimId, std::vector<CSupportValue>* supports) const
|
CAmount CClaimTrieCache::getEffectiveAmountForClaim(const std::string& name, const uint160& claimId, std::vector<CSupportValue>* supports) const
|
||||||
|
@ -2686,11 +2674,10 @@ bool CClaimTrieCache::getProofForName(const std::string& name, CClaimTrieProof&
|
||||||
}
|
}
|
||||||
valueHash.SetNull();
|
valueHash.SetNull();
|
||||||
}
|
}
|
||||||
CClaimTrieProofNode node(children, fNodeHasValue, valueHash);
|
nodes.emplace_back(std::move(children), fNodeHasValue, valueHash);
|
||||||
nodes.push_back(node);
|
|
||||||
current = nextCurrent;
|
current = nextCurrent;
|
||||||
}
|
}
|
||||||
proof = CClaimTrieProof(nodes, fNameHasValue, outPoint, nHeightOfLastTakeover);
|
proof = CClaimTrieProof(std::move(nodes), fNameHasValue, outPoint, nHeightOfLastTakeover);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
118
src/claimtrie.h
118
src/claimtrie.h
|
@ -28,20 +28,6 @@
|
||||||
|
|
||||||
uint256 getValueHash(COutPoint outPoint, int nHeightOfLastTakeover);
|
uint256 getValueHash(COutPoint outPoint, int nHeightOfLastTakeover);
|
||||||
|
|
||||||
// Provides pre-C++11 copy semantics of std::swap, rather than move
|
|
||||||
// semantics (available in C++11).
|
|
||||||
namespace claimtrie
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static inline void swap(T& x, T& y) {
|
|
||||||
const auto tmp = x;
|
|
||||||
y = x;
|
|
||||||
x = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace claimtrie
|
|
||||||
|
|
||||||
class CClaimValue
|
class CClaimValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -61,6 +47,11 @@ public:
|
||||||
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
CClaimValue(CClaimValue&&) = default;
|
||||||
|
CClaimValue(const CClaimValue&) = default;
|
||||||
|
CClaimValue& operator=(CClaimValue&&) = default;
|
||||||
|
CClaimValue& operator=(const CClaimValue&) = default;
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
|
@ -117,6 +108,11 @@ public:
|
||||||
, nValidAtHeight(nValidAtHeight)
|
, nValidAtHeight(nValidAtHeight)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
CSupportValue(CSupportValue&&) = default;
|
||||||
|
CSupportValue(const CSupportValue&) = default;
|
||||||
|
CSupportValue& operator=(CSupportValue&&) = default;
|
||||||
|
CSupportValue& operator=(const CSupportValue&) = default;
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
|
@ -153,6 +149,26 @@ class CClaimTrieNode
|
||||||
public:
|
public:
|
||||||
CClaimTrieNode() : nHeightOfLastTakeover(0) {}
|
CClaimTrieNode() : nHeightOfLastTakeover(0) {}
|
||||||
CClaimTrieNode(uint256 hash) : hash(hash), nHeightOfLastTakeover(0) {}
|
CClaimTrieNode(uint256 hash) : hash(hash), nHeightOfLastTakeover(0) {}
|
||||||
|
CClaimTrieNode(const CClaimTrieNode&) = default;
|
||||||
|
CClaimTrieNode(CClaimTrieNode&& other)
|
||||||
|
{
|
||||||
|
hash = other.hash;
|
||||||
|
claims = std::move(other.claims);
|
||||||
|
children = std::move(other.children);
|
||||||
|
nHeightOfLastTakeover = other.nHeightOfLastTakeover;
|
||||||
|
}
|
||||||
|
CClaimTrieNode& operator=(const CClaimTrieNode&) = default;
|
||||||
|
CClaimTrieNode& operator=(CClaimTrieNode&& other)
|
||||||
|
{
|
||||||
|
if (this != &other) {
|
||||||
|
hash = other.hash;
|
||||||
|
claims = std::move(other.claims);
|
||||||
|
children = std::move(other.children);
|
||||||
|
nHeightOfLastTakeover = other.nHeightOfLastTakeover;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
nodeMapType children;
|
nodeMapType children;
|
||||||
int nHeightOfLastTakeover;
|
int nHeightOfLastTakeover;
|
||||||
|
@ -225,7 +241,7 @@ struct nameOutPointHeightType
|
||||||
nameOutPointHeightType() {}
|
nameOutPointHeightType() {}
|
||||||
|
|
||||||
nameOutPointHeightType(std::string name, COutPoint outPoint, int nHeight)
|
nameOutPointHeightType(std::string name, COutPoint outPoint, int nHeight)
|
||||||
: name(name), outPoint(outPoint), nHeight(nHeight) {}
|
: name(std::move(name)), outPoint(outPoint), nHeight(nHeight) {}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
@ -246,7 +262,7 @@ struct nameOutPointType
|
||||||
nameOutPointType() {}
|
nameOutPointType() {}
|
||||||
|
|
||||||
nameOutPointType(std::string name, COutPoint outPoint)
|
nameOutPointType(std::string name, COutPoint outPoint)
|
||||||
: name(name), outPoint(outPoint) {}
|
: name(std::move(name)), outPoint(outPoint) {}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
@ -307,7 +323,25 @@ struct claimsForNameType
|
||||||
int nLastTakeoverHeight;
|
int nLastTakeoverHeight;
|
||||||
|
|
||||||
claimsForNameType(std::vector<CClaimValue> claims, std::vector<CSupportValue> supports, int nLastTakeoverHeight)
|
claimsForNameType(std::vector<CClaimValue> claims, std::vector<CSupportValue> supports, int nLastTakeoverHeight)
|
||||||
: claims(claims), supports(supports), nLastTakeoverHeight(nLastTakeoverHeight) {}
|
: claims(std::move(claims)), supports(std::move(supports)), nLastTakeoverHeight(nLastTakeoverHeight) {}
|
||||||
|
|
||||||
|
claimsForNameType(const claimsForNameType&) = default;
|
||||||
|
claimsForNameType(claimsForNameType&& other)
|
||||||
|
{
|
||||||
|
claims = std::move(other.claims);
|
||||||
|
supports = std::move(other.supports);
|
||||||
|
nLastTakeoverHeight = other.nLastTakeoverHeight;
|
||||||
|
}
|
||||||
|
claimsForNameType& operator=(const claimsForNameType&) = default;
|
||||||
|
claimsForNameType& operator=(claimsForNameType&& other)
|
||||||
|
{
|
||||||
|
if (this != &other) {
|
||||||
|
claims = std::move(other.claims);
|
||||||
|
supports = std::move(other.supports);
|
||||||
|
nLastTakeoverHeight = other.nLastTakeoverHeight;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CClaimTrieCache;
|
class CClaimTrieCache;
|
||||||
|
@ -452,8 +486,25 @@ public:
|
||||||
CClaimTrieProofNode() {};
|
CClaimTrieProofNode() {};
|
||||||
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256> > children,
|
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256> > children,
|
||||||
bool hasValue, uint256 valHash)
|
bool hasValue, uint256 valHash)
|
||||||
: children(children), hasValue(hasValue), valHash(valHash)
|
: children(std::move(children)), hasValue(hasValue), valHash(valHash)
|
||||||
{};
|
{};
|
||||||
|
CClaimTrieProofNode(const CClaimTrieProofNode&) = default;
|
||||||
|
CClaimTrieProofNode(CClaimTrieProofNode&& other)
|
||||||
|
{
|
||||||
|
hasValue = other.hasValue;
|
||||||
|
valHash = other.valHash;
|
||||||
|
children = std::move(other.children);
|
||||||
|
}
|
||||||
|
CClaimTrieProofNode& operator=(const CClaimTrieProofNode&) = default;
|
||||||
|
CClaimTrieProofNode& operator=(CClaimTrieProofNode&& other)
|
||||||
|
{
|
||||||
|
if (this != &other) {
|
||||||
|
hasValue = other.hasValue;
|
||||||
|
valHash = other.valHash;
|
||||||
|
children = std::move(other.children);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
std::vector<std::pair<unsigned char, uint256> > children;
|
std::vector<std::pair<unsigned char, uint256> > children;
|
||||||
bool hasValue;
|
bool hasValue;
|
||||||
uint256 valHash;
|
uint256 valHash;
|
||||||
|
@ -463,7 +514,26 @@ class CClaimTrieProof
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CClaimTrieProof() {};
|
CClaimTrieProof() {};
|
||||||
CClaimTrieProof(std::vector<CClaimTrieProofNode> nodes, bool hasValue, COutPoint outPoint, int nHeightOfLastTakeover) : nodes(nodes), hasValue(hasValue), outPoint(outPoint), nHeightOfLastTakeover(nHeightOfLastTakeover) {}
|
CClaimTrieProof(std::vector<CClaimTrieProofNode> nodes, bool hasValue, COutPoint outPoint, int nHeightOfLastTakeover) : nodes(std::move(nodes)), hasValue(hasValue), outPoint(outPoint), nHeightOfLastTakeover(nHeightOfLastTakeover) {}
|
||||||
|
CClaimTrieProof(const CClaimTrieProof&) = default;
|
||||||
|
CClaimTrieProof(CClaimTrieProof&& other)
|
||||||
|
{
|
||||||
|
hasValue = other.hasValue;
|
||||||
|
outPoint = other.outPoint;
|
||||||
|
nodes = std::move(other.nodes);
|
||||||
|
nHeightOfLastTakeover = other.nHeightOfLastTakeover;
|
||||||
|
}
|
||||||
|
CClaimTrieProof& operator=(const CClaimTrieProof&) = default;
|
||||||
|
CClaimTrieProof& operator=(CClaimTrieProof&& other)
|
||||||
|
{
|
||||||
|
if (this != &other) {
|
||||||
|
hasValue = other.hasValue;
|
||||||
|
outPoint = other.outPoint;
|
||||||
|
nodes = std::move(other.nodes);
|
||||||
|
nHeightOfLastTakeover = other.nHeightOfLastTakeover;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
std::vector<CClaimTrieProofNode> nodes;
|
std::vector<CClaimTrieProofNode> nodes;
|
||||||
bool hasValue;
|
bool hasValue;
|
||||||
COutPoint outPoint;
|
COutPoint outPoint;
|
||||||
|
@ -525,10 +595,8 @@ public:
|
||||||
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;
|
||||||
bool undoAddSupport(const std::string& name, const COutPoint& outPoint,
|
bool undoAddSupport(const std::string& name, const COutPoint& outPoint) const;
|
||||||
int nHeight) const;
|
bool spendSupport(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const;
|
||||||
bool spendSupport(const std::string& name, const COutPoint& outPoint,
|
|
||||||
int nHeight, int& nValidAtHeight) const;
|
|
||||||
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;
|
||||||
|
@ -623,9 +691,7 @@ protected:
|
||||||
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& nValidAtHeight, bool fCheckTakeover) const;
|
||||||
int nHeight, int& nValidAtHeight,
|
|
||||||
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;
|
||||||
|
|
|
@ -338,6 +338,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
|
||||||
// mempool has a lot of entries.
|
// mempool has a lot of entries.
|
||||||
const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
|
const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
|
||||||
int64_t nConsecutiveFailed = 0;
|
int64_t nConsecutiveFailed = 0;
|
||||||
|
std::vector<CTransactionRef> txs;
|
||||||
|
|
||||||
while (mi != mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty())
|
while (mi != mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty())
|
||||||
{
|
{
|
||||||
|
@ -436,8 +437,17 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
|
||||||
{
|
{
|
||||||
CCoinsViewCache view(pcoinsTip.get());
|
CCoinsViewCache view(pcoinsTip.get());
|
||||||
const Coin& coin = view.AccessCoin(txin.prevout);
|
const Coin& coin = view.AccessCoin(txin.prevout);
|
||||||
int nTxinHeight = coin.nHeight;
|
CScript scriptPubKey;
|
||||||
CScript scriptPubKey = coin.out.scriptPubKey;
|
if (coin.out.IsNull()) {
|
||||||
|
auto it = std::find_if(txs.begin(), txs.end(), [&txin](const CTransactionRef& tx) {
|
||||||
|
return tx->GetHash() == txin.prevout.hash;
|
||||||
|
});
|
||||||
|
if (it == txs.end() || txin.prevout.n >= (*it)->vout.size())
|
||||||
|
continue;
|
||||||
|
scriptPubKey = (*it)->vout[txin.prevout.n].scriptPubKey;
|
||||||
|
} else {
|
||||||
|
scriptPubKey = coin.out.scriptPubKey;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::vector<unsigned char> > vvchParams;
|
std::vector<std::vector<unsigned char> > vvchParams;
|
||||||
int op;
|
int op;
|
||||||
|
@ -474,7 +484,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
|
||||||
assert(vvchParams.size() == 2);
|
assert(vvchParams.size() == 2);
|
||||||
std::string name(vvchParams[0].begin(), vvchParams[0].end());
|
std::string name(vvchParams[0].begin(), vvchParams[0].end());
|
||||||
int throwaway;
|
int throwaway;
|
||||||
if (!trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), nTxinHeight, throwaway))
|
if (!trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), throwaway))
|
||||||
{
|
{
|
||||||
LogPrintf("%s(): The support was not found in the trie or queue\n", __func__);
|
LogPrintf("%s(): The support was not found in the trie or queue\n", __func__);
|
||||||
}
|
}
|
||||||
|
@ -536,6 +546,8 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txs.emplace_back(MakeTransactionRef(tx));
|
||||||
|
|
||||||
// This transaction will make it in; reset the failed counter.
|
// This transaction will make it in; reset the failed counter.
|
||||||
nConsecutiveFailed = 0;
|
nConsecutiveFailed = 0;
|
||||||
|
|
||||||
|
|
|
@ -1217,7 +1217,6 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund
|
||||||
bool is_spent = inputs.SpendCoin(txin.prevout, &coin);
|
bool is_spent = inputs.SpendCoin(txin.prevout, &coin);
|
||||||
assert(is_spent);
|
assert(is_spent);
|
||||||
txundo.vprevout.push_back(coin);
|
txundo.vprevout.push_back(coin);
|
||||||
txundo.claimInfo[i] = { coin.nHeight, true };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add outputs
|
// add outputs
|
||||||
|
@ -1618,7 +1617,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
|
||||||
__func__, pindex->nHeight, name, supportedClaimId.GetHex(), hash.ToString(), j);
|
__func__, pindex->nHeight, name, supportedClaimId.GetHex(), hash.ToString(), j);
|
||||||
LogPrintf("%s: (txid: %s, nOut: %d) Removing support for claim id %s on %s due to its block being disconnected\n",
|
LogPrintf("%s: (txid: %s, nOut: %d) Removing support for claim id %s on %s due to its block being disconnected\n",
|
||||||
__func__, hash.ToString(), j, supportedClaimId.ToString(), name);
|
__func__, hash.ToString(), j, supportedClaimId.ToString(), name);
|
||||||
if (!trieCache.undoAddSupport(name, COutPoint(hash, j), pindex->nHeight))
|
if (!trieCache.undoAddSupport(name, COutPoint(hash, j)))
|
||||||
LogPrintf("%s: Something went wrong removing support for name %s in hash %s\n", __func__, name.c_str(), hash.ToString());
|
LogPrintf("%s: Something went wrong removing support for name %s in hash %s\n", __func__, name.c_str(), hash.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2155,7 +2154,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||||
LogPrintf("%s: Removing support for %s in %s. Tx: %s, nOut: %d, removed txid: %s\n",
|
LogPrintf("%s: Removing support for %s in %s. Tx: %s, nOut: %d, removed txid: %s\n",
|
||||||
__func__, supportedClaimId.ToString(), name, txin.prevout.hash.ToString(),
|
__func__, supportedClaimId.ToString(), name, txin.prevout.hash.ToString(),
|
||||||
txin.prevout.n, tx.GetHash().ToString());
|
txin.prevout.n, tx.GetHash().ToString());
|
||||||
if (trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), coin.nHeight, nValidAtHeight))
|
if (trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), nValidAtHeight))
|
||||||
{
|
{
|
||||||
mClaimUndoHeights[j] = nValidAtHeight;
|
mClaimUndoHeights[j] = nValidAtHeight;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue