Browse Source

WIP: main.cpp compiled.

cn
Jianping Wu 6 years ago
parent
commit
97b35682e0
  1. 15
      src/chainparams.cpp
  2. 2
      src/chainparams.h
  3. 2
      src/coins.cpp
  4. 4
      src/coins.h
  5. 26
      src/keva/common.cpp
  6. 6
      src/keva/common.h
  7. 54
      src/keva/main.cpp
  8. 6
      src/keva/main.h
  9. 4
      src/script/interpreter.h
  10. 1
      src/txmempool.h
  11. 1
      src/undo.h
  12. 2
      src/wallet/rpckeva.cpp

15
src/chainparams.cpp

@ -199,6 +199,11 @@ public:
0.06 // * estimated number of transactions per second after that timestamp 0.06 // * estimated number of transactions per second after that timestamp
}; };
} }
int DefaultCheckNameDB() const
{
return -1;
}
}; };
/** /**
@ -304,6 +309,11 @@ public:
}; };
} }
int DefaultCheckNameDB() const
{
return -1;
}
}; };
/** /**
@ -396,6 +406,11 @@ public:
bech32_hrp = "rltc"; bech32_hrp = "rltc";
} }
int DefaultCheckNameDB() const
{
return 0;
}
}; };
static std::unique_ptr<CChainParams> globalChainParams; static std::unique_ptr<CChainParams> globalChainParams;

2
src/chainparams.h

@ -59,6 +59,8 @@ public:
const CBlock& GenesisBlock() const { return genesis; } const CBlock& GenesisBlock() const { return genesis; }
/** Default value for -checkmempool and -checkblockindex argument */ /** Default value for -checkmempool and -checkblockindex argument */
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; } bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
/** Default value for -checknamedb argument */
virtual int DefaultCheckNameDB() const = 0;
/** Policy: Filter transactions that do not match well-defined patterns */ /** Policy: Filter transactions that do not match well-defined patterns */
bool RequireStandard() const { return fRequireStandard; } bool RequireStandard() const { return fRequireStandard; }
uint64_t PruneAfterHeight() const { return nPruneAfterHeight; } uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }

2
src/coins.cpp

@ -14,6 +14,7 @@ bool CCoinsView::GetName(const valtype &nameSpace, const valtype &key, CKevaData
bool CCoinsView::GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const { return false; } bool CCoinsView::GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const { return false; }
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; } bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
CCoinsViewCursor *CCoinsView::Cursor() const { return nullptr; } CCoinsViewCursor *CCoinsView::Cursor() const { return nullptr; }
bool CCoinsView::ValidateNameDB() const { return false; }
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
{ {
@ -32,6 +33,7 @@ void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); } bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); }
CCoinsViewCursor *CCoinsViewBacked::Cursor() const { return base->Cursor(); } CCoinsViewCursor *CCoinsViewBacked::Cursor() const { return base->Cursor(); }
size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); } size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
bool CCoinsViewBacked::ValidateNameDB() const { return base->ValidateNameDB(); }
SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {} SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}

4
src/coins.h

@ -177,6 +177,9 @@ public:
//! Get a cursor to iterate over the whole state //! Get a cursor to iterate over the whole state
virtual CCoinsViewCursor *Cursor() const; virtual CCoinsViewCursor *Cursor() const;
// Validate the name database.
virtual bool ValidateNameDB() const;
//! As we use CCoinsViews polymorphically, have a virtual destructor //! As we use CCoinsViews polymorphically, have a virtual destructor
virtual ~CCoinsView() {} virtual ~CCoinsView() {}
@ -203,6 +206,7 @@ public:
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override; bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override;
CCoinsViewCursor *Cursor() const override; CCoinsViewCursor *Cursor() const override;
size_t EstimateSize() const override; size_t EstimateSize() const override;
bool ValidateNameDB() const;
}; };

26
src/keva/common.cpp

@ -40,6 +40,7 @@ CNameIterator::~CNameIterator ()
/* ************************************************************************** */ /* ************************************************************************** */
/* CKevaCacheNameIterator. */ /* CKevaCacheNameIterator. */
// JWU TODO: this doesn't work at all!!!!
class CCacheNameIterator : public CNameIterator class CCacheNameIterator : public CNameIterator
{ {
@ -104,7 +105,7 @@ CCacheNameIterator::advanceBaseIterator ()
assert (baseHasMore); assert (baseHasMore);
do do
baseHasMore = base->next (baseName, baseData); baseHasMore = base->next (baseName, baseData);
while (baseHasMore && cache.isDeleted (baseName)); while (baseHasMore && cache.isDeleted(baseName, baseName));
} }
void void
@ -175,7 +176,8 @@ CCacheNameIterator::next (valtype& name, CKevaData& data)
bool bool
CKevaCache::get (const valtype& nameSpace, const valtype& key, CKevaData& data) const CKevaCache::get (const valtype& nameSpace, const valtype& key, CKevaData& data) const
{ {
valtype name = nameSpace + key; valtype name = nameSpace;
name.insert( name.end(), key.begin(), key.end() );
const EntryMap::const_iterator i = entries.find (name); const EntryMap::const_iterator i = entries.find (name);
if (i == entries.end ()) if (i == entries.end ())
return false; return false;
@ -187,7 +189,8 @@ CKevaCache::get (const valtype& nameSpace, const valtype& key, CKevaData& data)
void void
CKevaCache::set (const valtype& nameSpace, const valtype& key, const CKevaData& data) CKevaCache::set (const valtype& nameSpace, const valtype& key, const CKevaData& data)
{ {
valtype name = nameSpace + key; valtype name = nameSpace;
name.insert( name.end(), key.begin(), key.end() );
const std::set<valtype>::iterator di = deleted.find (name); const std::set<valtype>::iterator di = deleted.find (name);
if (di != deleted.end ()) if (di != deleted.end ())
deleted.erase (di); deleted.erase (di);
@ -202,7 +205,8 @@ CKevaCache::set (const valtype& nameSpace, const valtype& key, const CKevaData&
void void
CKevaCache::remove (const valtype& nameSpace, const valtype& key) CKevaCache::remove (const valtype& nameSpace, const valtype& key)
{ {
valtype name = nameSpace + key; valtype name = nameSpace;
name.insert( name.end(), key.begin(), key.end() );
const EntryMap::iterator ei = entries.find (name); const EntryMap::iterator ei = entries.find (name);
if (ei != entries.end ()) if (ei != entries.end ())
entries.erase (ei); entries.erase (ei);
@ -250,6 +254,7 @@ CKevaCache::updateNamesForHeight (unsigned nHeight,
/* Seek in the map of cached entries to the first one corresponding /* Seek in the map of cached entries to the first one corresponding
to our height. */ to our height. */
#if 0
const ExpireEntry seekEntry(nHeight, valtype ()); const ExpireEntry seekEntry(nHeight, valtype ());
std::map<ExpireEntry, bool>::const_iterator it; std::map<ExpireEntry, bool>::const_iterator it;
@ -265,8 +270,10 @@ CKevaCache::updateNamesForHeight (unsigned nHeight,
else else
names.erase (cur.name); names.erase (cur.name);
} }
#endif
} }
#if 0
void void
CKevaCache::addExpireIndex (const valtype& name, unsigned height) CKevaCache::addExpireIndex (const valtype& name, unsigned height)
{ {
@ -280,17 +287,19 @@ CKevaCache::removeExpireIndex (const valtype& name, unsigned height)
const ExpireEntry entry(height, name); const ExpireEntry entry(height, name);
expireIndex[entry] = false; expireIndex[entry] = false;
} }
#endif
#if 0
void void
CKevaCache::apply(const CKevaCache& cache) CKevaCache::apply(const CKevaCache& cache)
{ {
for (EntryMap::const_iterator i = cache.entries.begin (); for (EntryMap::const_iterator i = cache.entries.begin (); i != cache.entries.end (); ++i) {
i != cache.entries.end (); ++i)
set (i->first, i->second); set (i->first, i->second);
}
for (std::set<valtype>::const_iterator i = cache.deleted.begin (); for (std::set<valtype>::const_iterator i = cache.deleted.begin (); i != cache.deleted.end (); ++i) {
i != cache.deleted.end (); ++i)
remove (*i); remove (*i);
}
for (std::map<valtype, CNameHistory>::const_iterator i for (std::map<valtype, CNameHistory>::const_iterator i
= cache.history.begin (); i != cache.history.end (); ++i) = cache.history.begin (); i != cache.history.end (); ++i)
@ -300,3 +309,4 @@ CKevaCache::apply (const CKevaCache& cache)
= cache.expireIndex.begin (); i != cache.expireIndex.end (); ++i) = cache.expireIndex.begin (); i != cache.expireIndex.end (); ++i)
expireIndex[i->first] = i->second; expireIndex[i->first] = i->second;
} }
#endif

6
src/keva/common.h

@ -439,7 +439,11 @@ public:
inline bool inline bool
isDeleted (const valtype& nameSpace, const valtype& key) const isDeleted (const valtype& nameSpace, const valtype& key) const
{ {
#if 0
return (deleted.count(name) > 0); return (deleted.count(name) > 0);
#else
return false;
#endif
} }
/* Try to get a name's associated data. This looks only /* Try to get a name's associated data. This looks only
@ -490,7 +494,9 @@ public:
#endif #endif
/* Apply all the changes in the passed-in record on top of this one. */ /* Apply all the changes in the passed-in record on top of this one. */
#if 0
void apply (const CKevaCache& cache); void apply (const CKevaCache& cache);
#endif
/* Write all cached changes to a database batch update object. */ /* Write all cached changes to a database batch update object. */
void writeBatch (CDBBatch& batch) const; void writeBatch (CDBBatch& batch) const;

54
src/keva/main.cpp

@ -83,7 +83,7 @@ CKevaMemPool::addUnchecked (const uint256& hash, const CTxMemPoolEntry& entry)
const valtype& key = entry.getKey(); const valtype& key = entry.getKey();
NamespaceKeyTuple tuple(nameSpace, key); NamespaceKeyTuple tuple(nameSpace, key);
assert(mapNamespaceKeyUpdates.count(tuple) == 0); assert(mapNamespaceKeyUpdates.count(tuple) == 0);
mapNamespaceKeyUpdates.insert (std::make_pair (name, hash)); mapNamespaceKeyUpdates.insert (std::make_pair(tuple, hash));
} }
} }
@ -143,7 +143,7 @@ CKevaMemPool::check(const CCoinsView& coins) const
nHeight = mapBlockIndex.find (blockHash)->second->nHeight; nHeight = mapBlockIndex.find (blockHash)->second->nHeight;
std::set<valtype> nameRegs; std::set<valtype> nameRegs;
std::set<valtype> nameUpdates; std::set<std::tuple<const valtype&, const valtype&>> namespaceKeyUpdates;
for (const auto& entry : pool.mapTx) { for (const auto& entry : pool.mapTx) {
const uint256 txHash = entry.GetTx ().GetHash (); const uint256 txHash = entry.GetTx ().GetHash ();
if (entry.isNamespaceRegistration()) { if (entry.isNamespaceRegistration()) {
@ -155,43 +155,54 @@ CKevaMemPool::check(const CCoinsView& coins) const
assert (nameRegs.count(nameSpace) == 0); assert (nameRegs.count(nameSpace) == 0);
nameRegs.insert(nameSpace); nameRegs.insert(nameSpace);
#if 0
/* The old name should be expired already. Note that we use /* The old name should be expired already. Note that we use
nHeight+1 for the check, because that's the height at which nHeight+1 for the check, because that's the height at which
the mempool tx will actually be mined. */ the mempool tx will actually be mined. */
CKevaData data; CKevaData data;
if (coins.GetName(name, data)) if (coins.GetName(name, data))
assert (data.isExpired (nHeight + 1)); assert (data.isExpired (nHeight + 1));
#endif
} }
if (entry.isNamespaceKeyUpdate()) { if (entry.isNamespaceKeyUpdate()) {
const valtype& name = entry.getName (); const valtype& nameSpace = entry.getNamespace();
const valtype& key = entry.getKey();
const NameTxMap::const_iterator mit = mapNameUpdates.find (name); std::tuple<const valtype&, const valtype&> tuple(nameSpace, key);
assert (mit != mapNameUpdates.end ()); const NamespaceKeyTxMap::const_iterator mit = mapNamespaceKeyUpdates.find(tuple);
assert (mit != mapNamespaceKeyUpdates.end ());
assert (mit->second == txHash); assert (mit->second == txHash);
assert (nameUpdates.count (name) == 0); assert (namespaceKeyUpdates.count(tuple) == 0);
nameUpdates.insert(name); namespaceKeyUpdates.insert(tuple);
#if 0
/* As above, use nHeight+1 for the expiration check. */ /* As above, use nHeight+1 for the expiration check. */
CKevaData data; CKevaData data;
if (!coins.GetName(name, data)) if (!coins.GetName(name, data)) {
assert (false); assert (false);
}
assert (!data.isExpired (nHeight + 1)); assert (!data.isExpired (nHeight + 1));
#endif
} }
} }
assert (nameRegs.size () == mapNameRegs.size ()); assert(nameRegs.size() == mapNamespaceRegs.size());
assert (nameUpdates.size () == mapNameUpdates.size ()); assert(namespaceKeyUpdates.size() == mapNamespaceKeyUpdates.size());
/* Check that nameRegs and nameUpdates are disjoint. They must be since /* Check that nameRegs and nameUpdates are disjoint. They must be since
a name can only be in either category, depending on whether it exists a name can only be in either category, depending on whether it exists
at the moment or not. */ at the moment or not. */
for (const auto& name : nameRegs) #if 0
assert (nameUpdates.count (name) == 0); // Is this neccesary?
for (const auto& name : nameUpdates) for (const auto& nameSpace : nameRegs) {
assert (nameRegs.count (name) == 0); assert(namespaceKeyUpdates.count(name) == 0);
}
#endif
for (const auto& namespaceKey : namespaceKeyUpdates) {
assert(nameRegs.count(std::get<0>(namespaceKey)) == 0);
}
} }
bool bool
@ -285,7 +296,7 @@ CheckNameTransaction (const CTransaction& tx, unsigned nHeight,
{ {
const std::string strTxid = tx.GetHash ().GetHex (); const std::string strTxid = tx.GetHash ().GetHex ();
const char* txid = strTxid.c_str (); const char* txid = strTxid.c_str ();
const bool fMempool = (flags & SCRIPT_VERIFY_NAMES_MEMPOOL); const bool fMempool = (flags & SCRIPT_VERIFY_KEVA_MEMPOOL);
#if 0 #if 0
/* Ignore historic bugs. */ /* Ignore historic bugs. */
@ -354,9 +365,16 @@ CheckNameTransaction (const CTransaction& tx, unsigned nHeight,
__func__, txid)); __func__, txid));
/* Reject "greedy names". */ /* Reject "greedy names". */
#if 0
const Consensus::Params& params = Params ().GetConsensus (); const Consensus::Params& params = Params ().GetConsensus ();
if (tx.vout[nameOut].nValue < params.rules->MinNameCoinAmount(nHeight)) if (tx.vout[nameOut].nValue < params.rules->MinNameCoinAmount(nHeight)) {
return state.Invalid (error ("%s: greedy name", __func__));
}
#else
if (tx.vout[nameOut].nValue < KEVA_LOCKED_AMOUNT) {
return state.Invalid (error ("%s: greedy name", __func__)); return state.Invalid (error ("%s: greedy name", __func__));
}
#endif
#if 0 #if 0
/* Handle NAME_NEW now, since this is easy and different from the other /* Handle NAME_NEW now, since this is easy and different from the other

6
src/keva/main.h

@ -70,11 +70,13 @@ public:
template<typename Stream, typename Operation> template<typename Stream, typename Operation>
inline void SerializationOp (Stream& s, Operation ser_action) inline void SerializationOp (Stream& s, Operation ser_action)
{ {
READWRITE (name); READWRITE (nameSpace);
READWRITE (key);
READWRITE (isNew); READWRITE (isNew);
if (!isNew) if (!isNew) {
READWRITE (oldData); READWRITE (oldData);
} }
}
/** /**
* Set the data for an update/registration of the given name. The CCoinsView * Set the data for an update/registration of the given name. The CCoinsView

4
src/script/interpreter.h

@ -115,6 +115,10 @@ enum
// Making OP_CODESEPARATOR and FindAndDelete fail any non-segwit scripts // Making OP_CODESEPARATOR and FindAndDelete fail any non-segwit scripts
// //
SCRIPT_VERIFY_CONST_SCRIPTCODE = (1U << 16), SCRIPT_VERIFY_CONST_SCRIPTCODE = (1U << 16),
// Perform namespace/key checks in "mempool" mode. This allows / disallows
// certain stuff.
SCRIPT_VERIFY_KEVA_MEMPOOL = (1U << 24),
}; };
bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror); bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);

1
src/txmempool.h

@ -20,6 +20,7 @@
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <sync.h> #include <sync.h>
#include <random.h> #include <random.h>
#include <script/keva.h>
#include <boost/multi_index_container.hpp> #include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/hashed_index.hpp>

1
src/undo.h

@ -8,6 +8,7 @@
#include <compressor.h> #include <compressor.h>
#include <consensus/consensus.h> #include <consensus/consensus.h>
#include <keva/main.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <serialize.h> #include <serialize.h>

2
src/wallet/rpckeva.cpp

@ -12,7 +12,7 @@
#include "rpc/mining.h" #include "rpc/mining.h"
#include "rpc/safemode.h" #include "rpc/safemode.h"
#include "rpc/server.h" #include "rpc/server.h"
#include "script/kava.h" #include "script/keva.h"
#include "txmempool.h" #include "txmempool.h"
#include "util.h" #include "util.h"
#include "validation.h" #include "validation.h"

Loading…
Cancel
Save