Rename CClaimTrieCache to CClaimTrieUpdateBuffer #156
3 changed files with 59 additions and 14 deletions
|
@ -112,8 +112,27 @@ bool CClaimTrieNode::haveValue(const uint256& txhash, uint32_t nOut) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClaimTrieNode::reorderValues()
|
void CClaimTrieNode::reorderValues(supportMapNodeType& supports)
|
||||||
{
|
{
|
||||||
|
std::vector<CNodeValue>::iterator itVal;
|
||||||
|
|
||||||
|
for (itVal = values.begin(); itVal != values.end(); ++itVal)
|
||||||
|
{
|
||||||
|
itVal->nEffectiveAmount = itVal->nAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (supportMapNodeType::iterator itSupport = supports.begin(); itSupport != supports.end(); ++itSupport)
|
||||||
|
{
|
||||||
|
for (itVal = values.begin(); itVal != values.end(); ++itVal)
|
||||||
|
{
|
||||||
|
if (itSupport->supportTxhash == itVal->txhash && itSupport->supportnOut == itVal->nOut)
|
||||||
|
{
|
||||||
|
itVal->nEffectiveAmount += itSupport->nAmount;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::make_heap(values.begin(), values.end());
|
std::make_heap(values.begin(), values.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,7 +939,9 @@ bool CClaimTrieCache::insertClaimIntoTrie(const std::string name, CNodeValue val
|
||||||
{
|
{
|
||||||
CNodeValue currentTop = currentNode->values.front();
|
CNodeValue currentTop = currentNode->values.front();
|
||||||
currentNode->insertValue(val);
|
currentNode->insertValue(val);
|
||||||
currentNode->reorderValues();
|
supportMapNodeType node;
|
||||||
|
getSupportsForName(name, node);
|
||||||
|
currentNode->reorderValues(node);
|
||||||
if (currentTop != currentNode->values.front())
|
if (currentTop != currentNode->values.front())
|
||||||
fChanged = true;
|
fChanged = true;
|
||||||
}
|
}
|
||||||
|
@ -990,7 +1011,9 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash
|
||||||
|
|
||||||
if (!currentNode->values.empty())
|
if (!currentNode->values.empty())
|
||||||
{
|
{
|
||||||
currentNode->reorderValues();
|
supportMapNodeType node;
|
||||||
|
getSupportsForName(name, node);
|
||||||
|
currentNode->reorderValues(node);
|
||||||
if (currentTop != currentNode->values.front())
|
if (currentTop != currentNode->values.front())
|
||||||
fChanged = true;
|
fChanged = true;
|
||||||
}
|
}
|
||||||
|
@ -1312,8 +1335,10 @@ bool CClaimTrieCache::reorderTrieNode(const std::string name) const
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CNodeValue currentTop = cachedNode->second->values.front();
|
CNodeValue currentTop = cachedNode->second->values.front();
|
||||||
cachedNode->second->reorderValues();
|
supportMapNodeType node;
|
||||||
if (currentTop != cachedNode->second->values.front())
|
getSupportsForName(name, node);
|
||||||
|
cachedNode->second->reorderValues(node);
|
||||||
|
if (cachedNode->second->values.front() != currentTop)
|
||||||
fChanged = true;
|
fChanged = true;
|
||||||
}
|
}
|
||||||
if (fChanged)
|
if (fChanged)
|
||||||
|
@ -1328,6 +1353,21 @@ bool CClaimTrieCache::reorderTrieNode(const std::string name) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CClaimTrieCache::getSupportsForName(const std::string name, supportMapNodeType& node) const
|
||||||
|
{
|
||||||
|
supportMapType::iterator cachedNode;
|
||||||
|
cachedNode = supportCache.find(name);
|
||||||
|
if (cachedNode != supportCache.end())
|
||||||
|
{
|
||||||
|
node = cachedNode->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return base->getSupportNode(name, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CClaimTrieCache::insertSupportIntoMap(const std::string name, CSupportNodeValue val) const
|
bool CClaimTrieCache::insertSupportIntoMap(const std::string name, CSupportNodeValue val) const
|
||||||
{
|
{
|
||||||
supportMapType::iterator cachedNode;
|
supportMapType::iterator cachedNode;
|
||||||
|
@ -1432,8 +1472,7 @@ bool CClaimTrieCache::removeSupportFromQueue(const std::string name, uint256 txh
|
||||||
|
|
||||||
bool CClaimTrieCache::addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight) const
|
bool CClaimTrieCache::addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight) const
|
||||||
{
|
{
|
||||||
std::cout << "just adding some support" << std::endl;
|
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
|
||||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedTxhash.GetHex(), supportednOut, nHeight);
|
|
||||||
assert(nHeight == nCurrentHeight);
|
assert(nHeight == nCurrentHeight);
|
||||||
CNodeValue val;
|
CNodeValue val;
|
||||||
if (base->getInfoForName(name, val))
|
if (base->getInfoForName(name, val))
|
||||||
|
|
|
@ -31,10 +31,11 @@ public:
|
||||||
uint256 txhash;
|
uint256 txhash;
|
||||||
uint32_t nOut;
|
uint32_t nOut;
|
||||||
CAmount nAmount;
|
CAmount nAmount;
|
||||||
|
CAmount nEffectiveAmount;
|
||||||
int nHeight;
|
int nHeight;
|
||||||
int nValidAtHeight;
|
int nValidAtHeight;
|
||||||
CNodeValue() {};
|
CNodeValue() {};
|
||||||
CNodeValue(uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) : txhash(txhash), nOut(nOut), nAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight) {}
|
CNodeValue(uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) : txhash(txhash), nOut(nOut), nAmount(nAmount), nEffectiveAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight) {}
|
||||||
uint256 GetHash() const;
|
uint256 GetHash() const;
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
@ -49,9 +50,9 @@ public:
|
||||||
|
|
||||||
bool operator<(const CNodeValue& other) const
|
bool operator<(const CNodeValue& other) const
|
||||||
{
|
{
|
||||||
if (nAmount < other.nAmount)
|
if (nEffectiveAmount < other.nEffectiveAmount)
|
||||||
return true;
|
return true;
|
||||||
else if (nAmount == other.nAmount)
|
else if (nEffectiveAmount == other.nEffectiveAmount)
|
||||||
{
|
{
|
||||||
if (nHeight > other.nHeight)
|
if (nHeight > other.nHeight)
|
||||||
return true;
|
return true;
|
||||||
|
@ -114,6 +115,8 @@ public:
|
||||||
class CClaimTrieNode;
|
class CClaimTrieNode;
|
||||||
class CClaimTrie;
|
class CClaimTrie;
|
||||||
|
|
||||||
|
typedef std::vector<CSupportNodeValue> supportMapNodeType;
|
||||||
|
|
||||||
typedef std::map<unsigned char, CClaimTrieNode*> nodeMapType;
|
typedef std::map<unsigned char, CClaimTrieNode*> nodeMapType;
|
||||||
|
|
||||||
typedef std::pair<std::string, CClaimTrieNode> namedNodeType;
|
typedef std::pair<std::string, CClaimTrieNode> namedNodeType;
|
||||||
|
@ -131,7 +134,7 @@ public:
|
||||||
bool getBestValue(CNodeValue& val) const;
|
bool getBestValue(CNodeValue& val) const;
|
||||||
bool empty() const {return children.empty() && values.empty();}
|
bool empty() const {return children.empty() && values.empty();}
|
||||||
bool haveValue(const uint256& txhash, uint32_t nOut) const;
|
bool haveValue(const uint256& txhash, uint32_t nOut) const;
|
||||||
void reorderValues();
|
void reorderValues(supportMapNodeType& supports);
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
|
@ -195,7 +198,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<CSupportNodeValue> supportMapNodeType;
|
|
||||||
typedef std::map<std::string, supportMapNodeType> supportMapType;
|
typedef std::map<std::string, supportMapNodeType> supportMapType;
|
||||||
|
|
||||||
typedef std::map<int, std::vector<CValueQueueEntry> > valueQueueType;
|
typedef std::map<int, std::vector<CValueQueueEntry> > valueQueueType;
|
||||||
|
@ -328,6 +330,7 @@ private:
|
||||||
bool addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight, int nValidAtHeight) const;
|
bool addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight, int nValidAtHeight) const;
|
||||||
bool removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeightToCheck, int& nValidAtHeight) const;
|
bool removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeightToCheck, int& nValidAtHeight) const;
|
||||||
uint256 hashBlock;
|
uint256 hashBlock;
|
||||||
|
bool getSupportsForName(const std::string name, supportMapNodeType& node) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_ClaimTRIE_H
|
#endif // BITCOIN_ClaimTRIE_H
|
||||||
|
|
|
@ -1296,14 +1296,17 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
|
||||||
|
|
||||||
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
|
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
|
||||||
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
|
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
|
||||||
|
tx1.vout[0].nValue = 100000000;
|
||||||
|
|
||||||
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
|
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
|
||||||
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
|
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
|
||||||
|
tx2.vout[0].nValue = 500000000;
|
||||||
|
|
||||||
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
|
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
|
||||||
std::string sTx1Hash = tx1.GetHash().ToString();
|
uint256 tx1Hash = tx1.GetHash();
|
||||||
std::vector<unsigned char> vchTx1Hash(sTx1Hash.begin(), sTx1Hash.end());
|
std::vector<unsigned char> vchTx1Hash(tx1Hash.begin(), tx1Hash.end());
|
||||||
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1Hash << CScriptNum(0) << OP_2DROP << OP_2DROP << OP_TRUE;
|
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1Hash << CScriptNum(0) << OP_2DROP << OP_2DROP << OP_TRUE;
|
||||||
|
tx3.vout[0].nValue = 500000000;
|
||||||
|
|
||||||
CNodeValue val;
|
CNodeValue val;
|
||||||
std::vector<uint256> blocks_to_invalidate;
|
std::vector<uint256> blocks_to_invalidate;
|
||||||
|
|
Loading…
Reference in a new issue