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 @@
#include <consensus/tx_verify.h> #include <consensus/tx_verify.h>
#include <consensus/consensus.h> #include <consensus/consensus.h>
#include <keva/main.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <script/interpreter.h> #include <script/interpreter.h>
#include <consensus/validation.h> #include <consensus/validation.h>
@ -205,8 +206,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
return true; 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? // are the actual inputs available?
if (!inputs.HaveInputs(tx)) { if (!inputs.HaveInputs(tx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-missingorspent", false, return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-missingorspent", false,

4
src/consensus/tx_verify.h

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

2
src/keva/main.cpp

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

6
src/keva/main.h

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

25
src/txmempool.cpp

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

4
src/validation.cpp

@ -681,7 +681,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
return state.DoS(0, false, REJECT_NONSTANDARD, "non-BIP68-final"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-BIP68-final");
CAmount nFees = 0; 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)); 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
if (!tx.IsCoinBase()) if (!tx.IsCoinBase())
{ {
CAmount txfee = 0; 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)); return error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), FormatStateMessage(state));
} }
nFees += txfee; nFees += txfee;

3
src/wallet/rpckeva.cpp

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

12
src/wallet/wallet.cpp

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

Loading…
Cancel
Save