mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-27 07:14:48 +00:00
Fixed namespace/key update checking.
This commit is contained in:
parent
fecf3a8ab5
commit
6b28595a6f
@ -45,28 +45,6 @@ CKevaTxUndo::apply(CCoinsViewCache& view) const
|
||||
/* ************************************************************************** */
|
||||
/* CKevaMemPool. */
|
||||
|
||||
uint256
|
||||
CKevaMemPool::getTxForNamespace(const valtype& nameSpace) const
|
||||
{
|
||||
#if 0
|
||||
// JWU TODO: implement this!
|
||||
NamespaceTxMap::const_iterator mi;
|
||||
|
||||
mi = mapNamespaceRegs.find(nameSpace);
|
||||
if (mi != mapNamespaceRegs.end()) {
|
||||
assert(mapNamespaceKeyUpdates.count(name) == 0);
|
||||
return mi->second;
|
||||
}
|
||||
|
||||
mi = mapNamespaceKeyUpdates.find(name);
|
||||
if (mi != mapNameUpdates.end ()) {
|
||||
assert (mapNameRegs.count (name) == 0);
|
||||
return mi->second;
|
||||
}
|
||||
#endif
|
||||
return uint256();
|
||||
}
|
||||
|
||||
void
|
||||
CKevaMemPool::addUnchecked (const uint256& hash, const CTxMemPoolEntry& entry)
|
||||
{
|
||||
@ -80,10 +58,8 @@ CKevaMemPool::addUnchecked (const uint256& hash, const CTxMemPoolEntry& entry)
|
||||
|
||||
if (entry.isNamespaceKeyUpdate ()) {
|
||||
const valtype& nameSpace = entry.getNamespace();
|
||||
const valtype& key = entry.getKey();
|
||||
NamespaceKeyTuple tuple(nameSpace, key);
|
||||
assert(mapNamespaceKeyUpdates.count(tuple) == 0);
|
||||
mapNamespaceKeyUpdates.insert (std::make_pair(tuple, hash));
|
||||
assert(mapNamespaceUpdates.count(nameSpace) == 0);
|
||||
mapNamespaceUpdates.insert (std::make_pair(nameSpace, hash));
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,17 +68,16 @@ CKevaMemPool::remove (const CTxMemPoolEntry& entry)
|
||||
{
|
||||
AssertLockHeld (pool.cs);
|
||||
|
||||
if (entry.isNamespaceRegistration ()) {
|
||||
const NamespaceTxMap::iterator mit = mapNamespaceRegs.find (entry.getNamespace());
|
||||
if (entry.isNamespaceRegistration()) {
|
||||
const NamespaceTxMap::iterator mit = mapNamespaceRegs.find(entry.getNamespace());
|
||||
assert (mit != mapNamespaceRegs.end());
|
||||
mapNamespaceRegs.erase (mit);
|
||||
mapNamespaceRegs.erase(mit);
|
||||
}
|
||||
|
||||
if (entry.isNamespaceKeyUpdate ()) {
|
||||
NamespaceKeyTuple tuple(entry.getNamespace(), entry.getKey());
|
||||
const NamespaceKeyTxMap::iterator mit = mapNamespaceKeyUpdates.find(tuple);
|
||||
assert (mit != mapNamespaceKeyUpdates.end());
|
||||
mapNamespaceKeyUpdates.erase (mit);
|
||||
if (entry.isNamespaceKeyUpdate()) {
|
||||
const NamespaceTxMap::iterator mit = mapNamespaceUpdates.find(entry.getNamespace());
|
||||
assert (mit != mapNamespaceUpdates.end());
|
||||
mapNamespaceUpdates.erase(mit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +118,7 @@ CKevaMemPool::check(const CCoinsView& coins) const
|
||||
nHeight = mapBlockIndex.find (blockHash)->second->nHeight;
|
||||
|
||||
std::set<valtype> nameRegs;
|
||||
std::set<std::tuple<valtype, valtype>> namespaceKeyUpdates;
|
||||
std::set<valtype> namespaceKeyUpdates;
|
||||
for (const auto& entry : pool.mapTx) {
|
||||
const uint256 txHash = entry.GetTx ().GetHash ();
|
||||
if (entry.isNamespaceRegistration()) {
|
||||
@ -167,14 +142,12 @@ CKevaMemPool::check(const CCoinsView& coins) const
|
||||
|
||||
if (entry.isNamespaceKeyUpdate()) {
|
||||
const valtype& nameSpace = entry.getNamespace();
|
||||
const valtype& key = entry.getKey();
|
||||
std::tuple<valtype, valtype> tuple(nameSpace, key);
|
||||
const NamespaceKeyTxMap::const_iterator mit = mapNamespaceKeyUpdates.find(tuple);
|
||||
assert (mit != mapNamespaceKeyUpdates.end ());
|
||||
const NamespaceTxMap::const_iterator mit = mapNamespaceUpdates.find(nameSpace);
|
||||
assert (mit != mapNamespaceUpdates.end ());
|
||||
assert (mit->second == txHash);
|
||||
|
||||
assert (namespaceKeyUpdates.count(tuple) == 0);
|
||||
namespaceKeyUpdates.insert(tuple);
|
||||
assert (namespaceKeyUpdates.count(nameSpace) == 0);
|
||||
namespaceKeyUpdates.insert(nameSpace);
|
||||
|
||||
#if 0
|
||||
/* As above, use nHeight+1 for the expiration check. */
|
||||
@ -188,7 +161,7 @@ CKevaMemPool::check(const CCoinsView& coins) const
|
||||
}
|
||||
|
||||
assert(nameRegs.size() == mapNamespaceRegs.size());
|
||||
assert(namespaceKeyUpdates.size() == mapNamespaceKeyUpdates.size());
|
||||
assert(namespaceKeyUpdates.size() == mapNamespaceUpdates.size());
|
||||
|
||||
/* Check that nameRegs and nameUpdates are disjoint. They must be since
|
||||
a name can only be in either category, depending on whether it exists
|
||||
@ -200,8 +173,8 @@ CKevaMemPool::check(const CCoinsView& coins) const
|
||||
}
|
||||
#endif
|
||||
|
||||
for (const auto& namespaceKey : namespaceKeyUpdates) {
|
||||
assert(nameRegs.count(std::get<0>(namespaceKey)) == 0);
|
||||
for (const auto& nameSpace : namespaceKeyUpdates) {
|
||||
assert(nameRegs.count(nameSpace) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,8 +211,9 @@ CKevaMemPool::checkTx (const CTransaction& tx) const
|
||||
{
|
||||
const valtype& nameSpace = nameOp.getOpNamespace();
|
||||
const valtype& key = nameOp.getOpKey();
|
||||
if (updatesKey(nameSpace, key))
|
||||
if (updatesNamespace(nameSpace)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ private:
|
||||
* Keep track of key that are updated by transactions in the pool.
|
||||
* Map key to registering transaction.
|
||||
*/
|
||||
NamespaceKeyTxMap mapNamespaceKeyUpdates;
|
||||
NamespaceTxMap mapNamespaceUpdates;
|
||||
|
||||
public:
|
||||
|
||||
@ -160,15 +160,14 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a particular name has a pending update. Does not lock.
|
||||
* @param name The name to check for.
|
||||
* @return True iff there's a matching name update in the pool.
|
||||
* Check whether a particular namespace has a pending update. Does not lock.
|
||||
* @param name The namespace to check for.
|
||||
* @return True iff there's a matching namespace update in the pool.
|
||||
*/
|
||||
inline bool
|
||||
updatesKey (const valtype& nameSpace, const valtype& key) const
|
||||
updatesNamespace(const valtype& nameSpace) const
|
||||
{
|
||||
NamespaceKeyTuple tuple(nameSpace, key);
|
||||
return mapNamespaceKeyUpdates.count(tuple) > 0;
|
||||
return mapNamespaceUpdates.count(nameSpace) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,7 +187,7 @@ public:
|
||||
clear ()
|
||||
{
|
||||
mapNamespaceRegs.clear();
|
||||
mapNamespaceKeyUpdates.clear();
|
||||
mapNamespaceUpdates.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -671,10 +671,10 @@ public:
|
||||
return kevaMemPool.registersNamespace(nameSpace);
|
||||
}
|
||||
|
||||
inline bool updatesKey(const valtype& nameSpace, const valtype& key) const
|
||||
inline bool updatesNamespace(const valtype& nameSpace) const
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
return kevaMemPool.updatesKey(nameSpace, key);
|
||||
return kevaMemPool.updatesNamespace(nameSpace);
|
||||
}
|
||||
|
||||
inline uint256 getTxForNamespace(const valtype& name) const
|
||||
|
@ -232,7 +232,7 @@ UniValue keva_put(const JSONRPCRequest& request)
|
||||
rules, but it is necessary with the current mempool implementation. */
|
||||
{
|
||||
LOCK (mempool.cs);
|
||||
if (mempool.updatesKey(nameSpace, key)) {
|
||||
if (mempool.updatesNamespace(nameSpace)) {
|
||||
throw JSONRPCError (RPC_TRANSACTION_ERROR,
|
||||
"there is already a pending update for this name");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user