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. 28
      src/keva/common.cpp
  6. 8
      src/keva/common.h
  7. 60
      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: @@ -199,6 +199,11 @@ public:
0.06 // * estimated number of transactions per second after that timestamp
};
}
int DefaultCheckNameDB() const
{
return -1;
}
};
/**
@ -304,6 +309,11 @@ public: @@ -304,6 +309,11 @@ public:
};
}
int DefaultCheckNameDB() const
{
return -1;
}
};
/**
@ -396,6 +406,11 @@ public: @@ -396,6 +406,11 @@ public:
bech32_hrp = "rltc";
}
int DefaultCheckNameDB() const
{
return 0;
}
};
static std::unique_ptr<CChainParams> globalChainParams;

2
src/chainparams.h

@ -59,6 +59,8 @@ public: @@ -59,6 +59,8 @@ public:
const CBlock& GenesisBlock() const { return genesis; }
/** Default value for -checkmempool and -checkblockindex argument */
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 */
bool RequireStandard() const { return fRequireStandard; }
uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }

2
src/coins.cpp

@ -14,6 +14,7 @@ bool CCoinsView::GetName(const valtype &nameSpace, const valtype &key, CKevaData @@ -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::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
CCoinsViewCursor *CCoinsView::Cursor() const { return nullptr; }
bool CCoinsView::ValidateNameDB() const { return false; }
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
{
@ -32,6 +33,7 @@ void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; } @@ -32,6 +33,7 @@ void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); }
CCoinsViewCursor *CCoinsViewBacked::Cursor() const { return base->Cursor(); }
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())) {}

4
src/coins.h

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

28
src/keva/common.cpp

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

8
src/keva/common.h

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

60
src/keva/main.cpp

@ -75,7 +75,7 @@ CKevaMemPool::addUnchecked (const uint256& hash, const CTxMemPoolEntry& entry) @@ -75,7 +75,7 @@ CKevaMemPool::addUnchecked (const uint256& hash, const CTxMemPoolEntry& entry)
if (entry.isNamespaceRegistration()) {
const valtype& nameSpace = entry.getNamespace();
assert(mapNamespaceRegs.count(nameSpace) == 0);
mapNamespaceRegs.insert(std::make_pair (nameSpace, hash));
mapNamespaceRegs.insert(std::make_pair(nameSpace, hash));
}
if (entry.isNamespaceKeyUpdate ()) {
@ -83,7 +83,7 @@ CKevaMemPool::addUnchecked (const uint256& hash, const CTxMemPoolEntry& entry) @@ -83,7 +83,7 @@ CKevaMemPool::addUnchecked (const uint256& hash, const CTxMemPoolEntry& entry)
const valtype& key = entry.getKey();
NamespaceKeyTuple tuple(nameSpace, key);
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 @@ -143,7 +143,7 @@ CKevaMemPool::check(const CCoinsView& coins) const
nHeight = mapBlockIndex.find (blockHash)->second->nHeight;
std::set<valtype> nameRegs;
std::set<valtype> nameUpdates;
std::set<std::tuple<const valtype&, const valtype&>> namespaceKeyUpdates;
for (const auto& entry : pool.mapTx) {
const uint256 txHash = entry.GetTx ().GetHash ();
if (entry.isNamespaceRegistration()) {
@ -155,43 +155,54 @@ CKevaMemPool::check(const CCoinsView& coins) const @@ -155,43 +155,54 @@ CKevaMemPool::check(const CCoinsView& coins) const
assert (nameRegs.count(nameSpace) == 0);
nameRegs.insert(nameSpace);
#if 0
/* The old name should be expired already. Note that we use
nHeight+1 for the check, because that's the height at which
the mempool tx will actually be mined. */
CKevaData data;
if (coins.GetName(name, data))
assert (data.isExpired (nHeight + 1));
#endif
}
if (entry.isNamespaceKeyUpdate()) {
const valtype& name = entry.getName ();
const NameTxMap::const_iterator mit = mapNameUpdates.find (name);
assert (mit != mapNameUpdates.end ());
const valtype& nameSpace = entry.getNamespace();
const valtype& key = entry.getKey();
std::tuple<const valtype&, const valtype&> tuple(nameSpace, key);
const NamespaceKeyTxMap::const_iterator mit = mapNamespaceKeyUpdates.find(tuple);
assert (mit != mapNamespaceKeyUpdates.end ());
assert (mit->second == txHash);
assert (nameUpdates.count (name) == 0);
nameUpdates.insert(name);
assert (namespaceKeyUpdates.count(tuple) == 0);
namespaceKeyUpdates.insert(tuple);
#if 0
/* As above, use nHeight+1 for the expiration check. */
CKevaData data;
if (!coins.GetName(name, data))
if (!coins.GetName(name, data)) {
assert (false);
}
assert (!data.isExpired (nHeight + 1));
#endif
}
}
assert (nameRegs.size () == mapNameRegs.size ());
assert (nameUpdates.size () == mapNameUpdates.size ());
assert(nameRegs.size() == mapNamespaceRegs.size());
assert(namespaceKeyUpdates.size() == mapNamespaceKeyUpdates.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
at the moment or not. */
for (const auto& name : nameRegs)
assert (nameUpdates.count (name) == 0);
for (const auto& name : nameUpdates)
assert (nameRegs.count (name) == 0);
#if 0
// Is this neccesary?
for (const auto& nameSpace : nameRegs) {
assert(namespaceKeyUpdates.count(name) == 0);
}
#endif
for (const auto& namespaceKey : namespaceKeyUpdates) {
assert(nameRegs.count(std::get<0>(namespaceKey)) == 0);
}
}
bool
@ -285,7 +296,7 @@ CheckNameTransaction (const CTransaction& tx, unsigned nHeight, @@ -285,7 +296,7 @@ CheckNameTransaction (const CTransaction& tx, unsigned nHeight,
{
const std::string strTxid = tx.GetHash ().GetHex ();
const char* txid = strTxid.c_str ();
const bool fMempool = (flags & SCRIPT_VERIFY_NAMES_MEMPOOL);
const bool fMempool = (flags & SCRIPT_VERIFY_KEVA_MEMPOOL);
#if 0
/* Ignore historic bugs. */
@ -354,9 +365,16 @@ CheckNameTransaction (const CTransaction& tx, unsigned nHeight, @@ -354,9 +365,16 @@ CheckNameTransaction (const CTransaction& tx, unsigned nHeight,
__func__, txid));
/* Reject "greedy names". */
#if 0
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__));
}
#endif
#if 0
/* Handle NAME_NEW now, since this is easy and different from the other
@ -656,7 +674,7 @@ void @@ -656,7 +674,7 @@ void
CheckNameDB (bool disconnect)
{
const int option
= gArgs.GetArg ("-checknamedb", Params ().DefaultCheckNameDB ());
= gArgs.GetArg ("-checknamedb", Params().DefaultCheckNameDB ());
if (option == -1)
return;
@ -669,7 +687,7 @@ CheckNameDB (bool disconnect) @@ -669,7 +687,7 @@ CheckNameDB (bool disconnect)
}
pcoinsTip->Flush ();
const bool ok = pcoinsTip->ValidateNameDB ();
const bool ok = pcoinsTip->ValidateNameDB();
/* The DB is inconsistent (mismatch between UTXO set and names DB) between
(roughly) blocks 139,000 and 180,000. This is caused by libcoin's

6
src/keva/main.h

@ -70,10 +70,12 @@ public: @@ -70,10 +70,12 @@ public:
template<typename Stream, typename Operation>
inline void SerializationOp (Stream& s, Operation ser_action)
{
READWRITE (name);
READWRITE (nameSpace);
READWRITE (key);
READWRITE (isNew);
if (!isNew)
if (!isNew) {
READWRITE (oldData);
}
}
/**

4
src/script/interpreter.h

@ -115,6 +115,10 @@ enum @@ -115,6 +115,10 @@ enum
// Making OP_CODESEPARATOR and FindAndDelete fail any non-segwit scripts
//
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);

1
src/txmempool.h

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

1
src/undo.h

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

2
src/wallet/rpckeva.cpp

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

Loading…
Cancel
Save