Rebase LBRY on top of Bitcoin 0.17 #263

Closed
lbrynaut wants to merge 18 commits from updated-rebase-0.17-deps into bitcoin-0.17
4 changed files with 143 additions and 79 deletions
Showing only changes of commit 462892464e - Show all commits

View file

@ -69,7 +69,7 @@ bool CClaimTrieNode::removeClaim(const COutPoint& outPoint, CClaimValue& claim)
{
if (itClaims->outPoint == outPoint)
{
claim = *itClaims;
std::swap(claim, *itClaims);
break;
}
}
@ -500,8 +500,7 @@ claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const
}
}
}
claimsForNameType allClaims(claims, supports, nLastTakeoverHeight);
return allClaims;
return { std::move(claims), std::move(supports), nLastTakeoverHeight };
}
//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);
itQueueRow = ret.first;
}
claimtrie::swap(row, itQueueRow->second);
itQueueRow->second.swap(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);
itQueueRow = ret.first;
}
claimtrie::swap(row, itQueueRow->second);
itQueueRow->second.swap(row);
}
void CClaimTrie::updateExpirationRow(int nHeight, expirationQueueRowType& row)
@ -670,7 +669,7 @@ void CClaimTrie::updateExpirationRow(int nHeight, expirationQueueRowType& row)
assert(ret.second);
itQueueRow = ret.first;
}
claimtrie::swap(row, itQueueRow->second);
itQueueRow->second.swap(row);
}
void CClaimTrie::updateSupportMap(const std::string& name, supportMapEntryType& node)
@ -684,7 +683,7 @@ void CClaimTrie::updateSupportMap(const std::string& name, supportMapEntryType&
assert(ret.second);
itNode = ret.first;
}
claimtrie::swap(node, itNode->second);
itNode->second.swap(node);
}
void CClaimTrie::updateSupportQueue(int nHeight, supportQueueRowType& row)
@ -698,7 +697,7 @@ void CClaimTrie::updateSupportQueue(int nHeight, supportQueueRowType& row)
assert(ret.second);
itQueueRow = ret.first;
}
claimtrie::swap(row, itQueueRow->second);
itQueueRow->second.swap(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);
itQueueRow = ret.first;
}
claimtrie::swap(row, itQueueRow->second);
itQueueRow->second.swap(row);
}
void CClaimTrie::updateSupportExpirationQueue(int nHeight, expirationQueueRowType& row)
@ -726,7 +725,7 @@ void CClaimTrie::updateSupportExpirationQueue(int nHeight, expirationQueueRowTyp
assert(ret.second);
itQueueRow = ret.first;
}
claimtrie::swap(row, itQueueRow->second);
itQueueRow->second.swap(row);
}
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);
claimtrie::swap(updatedNode->claims, current->claims);
current->claims.swap(updatedNode->claims);
markNodeDirty(name, current);
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())
{
claim = itQueue->second;
std::swap(claim, itQueue->second);
itQueueNameRow->second.erase(itQueueName);
itQueueRow->second.erase(itQueue);
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
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %s, nCurrentHeight: %s\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nCurrentHeight);
bool removed = false;
CClaimValue claim;
if (removeClaimFromQueue(name, outPoint, claim))
{
removed = true;
}
if (removed == false && removeClaimFromTrie(name, outPoint, claim, fCheckTakeover))
{
removed = true;
}
if (removed == true)
{
if (removeClaimFromQueue(name, outPoint, claim)
|| removeClaimFromTrie(name, outPoint, claim, fCheckTakeover)) {
nValidAtHeight = claim.nValidAtHeight;
int expirationHeight = claim.nHeight + base->nExpirationTime;
removeFromExpirationQueue(name, outPoint, expirationHeight);
claimsToDelete.insert(claim);
return true;
}
return removed;
return false;
}
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())
{
claimtrie::swap(support, *itSupport);
std::swap(support, *itSupport);
cachedNode->second.erase(itSupport);
return reorderTrieNode(name, fCheckTakeover);
}
@ -1929,7 +1921,7 @@ bool CClaimTrieCache::removeSupportFromQueue(const std::string& name, const COut
}
if (itQueue != itQueueRow->second.end())
{
claimtrie::swap(support, itQueue->second);
std::swap(support, itQueue->second);
itQueueNameRow->second.erase(itQueueName);
itQueueRow->second.erase(itQueue);
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;
if (removeSupportFromQueue(name, outPoint, support))
removed = true;
if (removed == false && removeSupportFromMap(name, outPoint, support, fCheckTakeover))
removed = true;
if (removed)
{
int expirationHeight = nHeight + base->nExpirationTime;
if (removeSupportFromQueue(name, outPoint, support)
|| removeSupportFromMap(name, outPoint, support, fCheckTakeover)) {
int expirationHeight = support.nHeight + base->nExpirationTime;
removeSupportFromExpirationQueue(name, outPoint, expirationHeight);
nValidAtHeight = support.nValidAtHeight;
return true;
}
return removed;
return false;
}
void CClaimTrieCache::addSupportToExpirationQueue(int nExpirationHeight, nameOutPointType& entry) const
@ -2036,17 +2024,17 @@ expirationQueueType::iterator CClaimTrieCache::getSupportExpirationQueueCacheRow
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;
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);
return removeSupport(name, outPoint, nHeight, nValidAtHeight, true);
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nCurrentHeight);
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
@ -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
@ -2686,11 +2674,10 @@ bool CClaimTrieCache::getProofForName(const std::string& name, CClaimTrieProof&
}
valueHash.SetNull();
}
CClaimTrieProofNode node(children, fNodeHasValue, valueHash);
nodes.push_back(node);
nodes.emplace_back(std::move(children), fNodeHasValue, valueHash);
current = nextCurrent;
}
proof = CClaimTrieProof(nodes, fNameHasValue, outPoint, nHeightOfLastTakeover);
proof = CClaimTrieProof(std::move(nodes), fNameHasValue, outPoint, nHeightOfLastTakeover);
return true;
}

View file

@ -28,20 +28,6 @@
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
{
public:
@ -61,6 +47,11 @@ public:
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
{}
CClaimValue(CClaimValue&&) = default;
CClaimValue(const CClaimValue&) = default;
CClaimValue& operator=(CClaimValue&&) = default;
CClaimValue& operator=(const CClaimValue&) = default;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
@ -117,6 +108,11 @@ public:
, nValidAtHeight(nValidAtHeight)
{}
CSupportValue(CSupportValue&&) = default;
CSupportValue(const CSupportValue&) = default;
CSupportValue& operator=(CSupportValue&&) = default;
CSupportValue& operator=(const CSupportValue&) = default;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
@ -153,6 +149,26 @@ class CClaimTrieNode
public:
CClaimTrieNode() : 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;
nodeMapType children;
int nHeightOfLastTakeover;
@ -225,8 +241,8 @@ struct nameOutPointHeightType
nameOutPointHeightType() {}
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;
template <typename Stream, typename Operation>
@ -246,7 +262,7 @@ struct nameOutPointType
nameOutPointType() {}
nameOutPointType(std::string name, COutPoint outPoint)
: name(name), outPoint(outPoint) {}
: name(std::move(name)), outPoint(outPoint) {}
ADD_SERIALIZE_METHODS;
@ -307,7 +323,25 @@ struct claimsForNameType
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;
@ -452,8 +486,25 @@ public:
CClaimTrieProofNode() {};
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256> > children,
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;
bool hasValue;
uint256 valHash;
@ -463,7 +514,26 @@ class CClaimTrieProof
{
public:
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;
bool hasValue;
COutPoint outPoint;
@ -525,10 +595,8 @@ public:
bool addSupport(const std::string& name, const COutPoint& outPoint,
CAmount nAmount, uint160 supportedClaimId,
int nHeight) const;
bool undoAddSupport(const std::string& name, const COutPoint& outPoint,
int nHeight) const;
bool spendSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight) const;
bool undoAddSupport(const std::string& name, const COutPoint& outPoint) const;
bool spendSupport(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const;
bool undoSpendSupport(const std::string& name, const COutPoint& outPoint,
uint160 supportedClaimId, CAmount nAmount,
int nHeight, int nValidAtHeight) const;
@ -623,9 +691,7 @@ protected:
expirationQueueType::iterator getExpirationQueueCacheRow(int nHeight,
bool createIfNotExists) const;
bool removeSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight,
bool fCheckTakeover) const;
bool removeSupport(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight, bool fCheckTakeover) const;
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint,
CSupportValue& support,
bool fCheckTakeover) const;

View file

@ -338,6 +338,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
// mempool has a lot of entries.
const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
int64_t nConsecutiveFailed = 0;
std::vector<CTransactionRef> txs;
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());
const Coin& coin = view.AccessCoin(txin.prevout);
int nTxinHeight = coin.nHeight;
CScript scriptPubKey = coin.out.scriptPubKey;
CScript 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;
int op;
@ -474,7 +484,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
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__);
}
@ -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.
nConsecutiveFailed = 0;

View file

@ -1217,7 +1217,6 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund
bool is_spent = inputs.SpendCoin(txin.prevout, &coin);
assert(is_spent);
txundo.vprevout.push_back(coin);
txundo.claimInfo[i] = { coin.nHeight, true };
}
}
// add outputs
@ -1618,7 +1617,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
__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",
__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());
}
}
@ -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",
__func__, supportedClaimId.ToString(), name, txin.prevout.hash.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;
}