Browse Source

Continued adding keva support.

cn
Jianping Wu 6 years ago
parent
commit
adb513eeaa
  1. 7
      src/consensus/tx_verify.cpp
  2. 4
      src/consensus/tx_verify.h
  3. 2
      src/keva/main.cpp
  4. 6
      src/keva/main.h
  5. 25
      src/txmempool.cpp
  6. 4
      src/validation.cpp
  7. 3
      src/wallet/rpckeva.cpp
  8. 12
      src/wallet/wallet.cpp

7
src/consensus/tx_verify.cpp

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
#include <consensus/tx_verify.h>
#include <consensus/consensus.h>
#include <keva/main.h>
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <consensus/validation.h>
@ -205,8 +206,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe @@ -205,8 +206,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
return true;
}
bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee)
bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, unsigned flags, CAmount& txfee)
{
if (!CheckKevaTransaction (tx, nSpendHeight, inputs, state, flags)) {
return state.Invalid(false, 0, "", "Tx invalid for Namecoin");
}
// are the actual inputs available?
if (!inputs.HaveInputs(tx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-missingorspent", false,

4
src/consensus/tx_verify.h

@ -27,7 +27,7 @@ namespace Consensus { @@ -27,7 +27,7 @@ namespace Consensus {
* @param[out] txfee Set to the transaction fee if successful.
* Preconditions: tx.IsCoinBase() is false.
*/
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee);
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, unsigned flags, CAmount& txfee);
} // namespace Consensus
/** Auxiliary functions for transaction validation (ideally should not be exposed) */
@ -41,7 +41,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx); @@ -41,7 +41,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx);
/**
* Count ECDSA signature operations in pay-to-script-hash inputs.
*
*
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
* @return maximum number of sigops required to validate this transaction's inputs
* @see CTransaction::FetchInputs

2
src/keva/main.cpp

@ -290,7 +290,7 @@ CNameConflictTracker::AddConflictedEntry (CTransactionRef txRemoved) @@ -290,7 +290,7 @@ CNameConflictTracker::AddConflictedEntry (CTransactionRef txRemoved)
/* ************************************************************************** */
bool
CheckNameTransaction (const CTransaction& tx, unsigned nHeight,
CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
const CCoinsView& view,
CValidationState& state, unsigned flags)
{

6
src/keva/main.h

@ -263,8 +263,8 @@ public: @@ -263,8 +263,8 @@ public:
/* ************************************************************************** */
/**
* Check a transaction according to the additional Namecoin rules. This
* ensures that all name operations (if any) are valid and that it has
* Check a transaction according to the additional Kevacoin rules. This
* ensures that all keva operations (if any) are valid and that it has
* name operations iff it is marked as Namecoin tx by its version.
* @param tx The transaction to check.
* @param nHeight Height at which the tx will be.
@ -273,7 +273,7 @@ public: @@ -273,7 +273,7 @@ public:
* @param flags Verification flags.
* @return True in case of success.
*/
bool CheckNameTransaction (const CTransaction& tx, unsigned nHeight,
bool CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
const CCoinsView& view,
CValidationState& state, unsigned flags);

25
src/txmempool.cpp

@ -22,7 +22,8 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe @@ -22,7 +22,8 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe
int64_t _nTime, unsigned int _entryHeight,
bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp):
tx(_tx), nFee(_nFee), nTime(_nTime), entryHeight(_entryHeight),
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp),
kevaOp()
{
nTxWeight = GetTransactionWeight(*tx);
nUsageSize = RecursiveDynamicUsage(tx);
@ -37,6 +38,19 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe @@ -37,6 +38,19 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe
nSizeWithAncestors = GetTxSize();
nModFeesWithAncestors = nFee;
nSigOpCostWithAncestors = sigOpCost;
if (_tx->IsKevacoin()) {
for (const auto& txOut : _tx->vout) {
const CKevaScript curNameOp(txOut.scriptPubKey);
if (!curNameOp.isKevaOp()) {
continue;
}
assert(!kevaOp.isKevaOp());
kevaOp = curNameOp;
}
assert(kevaOp.isKevaOp());
}
}
void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
@ -409,6 +423,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, @@ -409,6 +423,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
nTransactionsUpdated++;
totalTxSize += entry.GetTxSize();
if (minerPolicyEstimator) {minerPolicyEstimator->processTransaction(entry, validFeeEstimate);}
kevaMemPool.addUnchecked (hash, entry);
vTxHashes.emplace_back(tx.GetWitnessHash(), newit);
newit->vTxHashesIdx = vTxHashes.size() - 1;
@ -418,6 +433,8 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, @@ -418,6 +433,8 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
{
kevaMemPool.remove (*it);
NotifyEntryRemoved(it->GetSharedTx(), reason);
const uint256 hash = it->GetTx().GetHash();
for (const CTxIn& txin : it->GetTx().vin)
@ -554,6 +571,9 @@ void CTxMemPool::removeConflicts(const CTransaction &tx) @@ -554,6 +571,9 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
}
}
}
/* Remove conflicting keva registrations. */
kevaMemPool.removeConflicts (tx);
}
/**
@ -593,6 +613,7 @@ void CTxMemPool::_clear() @@ -593,6 +613,7 @@ void CTxMemPool::_clear()
mapLinks.clear();
mapTx.clear();
mapNextTx.clear();
kevaMemPool.clear();
totalTxSize = 0;
cachedInnerUsage = 0;
lastRollingFeeUpdate = GetTime();
@ -611,7 +632,7 @@ static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& m @@ -611,7 +632,7 @@ static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& m
{
CValidationState state;
CAmount txfee = 0;
bool fCheckResult = tx.IsCoinBase() || Consensus::CheckTxInputs(tx, state, mempoolDuplicate, spendheight, txfee);
bool fCheckResult = tx.IsCoinBase() || Consensus::CheckTxInputs(tx, state, mempoolDuplicate, spendheight, SCRIPT_VERIFY_KEVA_MEMPOOL, txfee);
assert(fCheckResult);
UpdateCoins(tx, mempoolDuplicate, 1000000);
}

4
src/validation.cpp

@ -681,7 +681,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool @@ -681,7 +681,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
return state.DoS(0, false, REJECT_NONSTANDARD, "non-BIP68-final");
CAmount nFees = 0;
if (!Consensus::CheckTxInputs(tx, state, view, GetSpendHeight(view), nFees)) {
if (!Consensus::CheckTxInputs(tx, state, view, GetSpendHeight(view), SCRIPT_VERIFY_KEVA_MEMPOOL, nFees)) {
return error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), FormatStateMessage(state));
}
@ -1920,7 +1920,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl @@ -1920,7 +1920,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
if (!tx.IsCoinBase())
{
CAmount txfee = 0;
if (!Consensus::CheckTxInputs(tx, state, view, pindex->nHeight, txfee)) {
if (!Consensus::CheckTxInputs(tx, state, view, pindex->nHeight, SCRIPT_VERIFY_KEVA_MEMPOOL, txfee)) {
return error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), FormatStateMessage(state));
}
nFees += txfee;

3
src/wallet/rpckeva.cpp

@ -33,13 +33,14 @@ UniValue keva_namespace(const JSONRPCRequest& request) @@ -33,13 +33,14 @@ UniValue keva_namespace(const JSONRPCRequest& request)
if (request.fHelp || request.params.size () != 1)
throw std::runtime_error (
"keva_namespace \"display_name\"\n"
"\nStart creation of the given namespace.\n"
"\nRegister a namespace with the given display name.\n"
+ HelpRequiringPassphrase (pwallet) +
"\nArguments:\n"
"1. \"display_name\" (string, required) the display name of the namespace\n"
"\nResult:\n"
"[\n"
" xxxxx, (string) the txid, required for keva_put\n"
" xxxxx, (string) the unique namespace id, required for keva_put\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli ("keva_namespace", "\"display name\"")

12
src/wallet/wallet.cpp

@ -2670,6 +2670,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, @@ -2670,6 +2670,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
CAmount nValue = 0;
int nChangePosRequest = nChangePosInOut;
unsigned int nSubtractFeeFromAmount = 0;
bool isKevacoin = false;
for (const auto& recipient : vecSend)
{
if (nValue < 0 || recipient.nAmount < 0)
@ -2681,6 +2682,9 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, @@ -2681,6 +2682,9 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
if (recipient.fSubtractFeeFromAmount)
nSubtractFeeFromAmount++;
if (CKevaScript::isKevaScript (recipient.scriptPubKey))
isKevacoin = true;
}
if (vecSend.empty())
{
@ -2702,11 +2706,9 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, @@ -2702,11 +2706,9 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
wtxNew.BindWallet(this);
CMutableTransaction txNew;
#if 0
// JWU TODO implement this!
if (isNamecoin)
txNew.SetNamecoin();
#endif
if (isKevacoin) {
txNew.SetKevacoin();
}
// Discourage fee sniping.
//

Loading…
Cancel
Save