diff --git a/src/consensus/tx_check.cpp b/src/consensus/tx_check.cpp index 74a6fb37b1f..39716eb3a42 100644 --- a/src/consensus/tx_check.cpp +++ b/src/consensus/tx_check.cpp @@ -4,7 +4,6 @@ #include -#include #include #include @@ -69,8 +68,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe bool ParseScriptByMarker(CScript const & script, const std::vector & marker, std::vector & metadata, - uint8_t& hasAdditionalOpcodes, - CExpirationAndVersion* customTxParams) + bool& hasAdditionalOpcodes) { opcodetype opcode; auto pc = script.begin(); @@ -85,20 +83,8 @@ bool ParseScriptByMarker(CScript const & script, } // Check that no more opcodes are found in the script - std::vector expirationAndVersion; - if (script.GetOp(pc, opcode, expirationAndVersion)) { - hasAdditionalOpcodes |= HasForks::FortCanning; - if (expirationAndVersion.size() == sizeof(uint32_t) + sizeof(uint8_t)) { - if (customTxParams) { - VectorReader stream(SER_DISK, CLIENT_VERSION, expirationAndVersion, 0); - stream >> *customTxParams; - } - } else { - hasAdditionalOpcodes |= HasForks::GreatWorld; - } - if (pc != script.end()) { - hasAdditionalOpcodes |= HasForks::GreatWorld; - } + if (script.GetOp(pc, opcode)) { + hasAdditionalOpcodes = true; } metadata.erase(metadata.begin(), metadata.begin() + marker.size()); @@ -110,7 +96,7 @@ bool IsAnchorRewardTx(CTransaction const & tx, std::vector & meta if (!tx.IsCoinBase() || tx.vout.size() != 2 || tx.vout[0].nValue != 0) { return false; } - uint8_t hasAdditionalOpcodes{HasForks::None}; + bool hasAdditionalOpcodes{false}; const auto result = ParseScriptByMarker(tx.vout[0].scriptPubKey, DfAnchorFinalizeTxMarker, metadata, hasAdditionalOpcodes); if (fortCanning && hasAdditionalOpcodes) { return false; @@ -118,15 +104,14 @@ bool IsAnchorRewardTx(CTransaction const & tx, std::vector & meta return result; } -bool IsAnchorRewardTxPlus(CTransaction const & tx, std::vector & metadata, uint8_t hasForks) +bool IsAnchorRewardTxPlus(CTransaction const & tx, std::vector & metadata, bool fortCanning) { if (!tx.IsCoinBase() || tx.vout.size() != 2 || tx.vout[0].nValue != 0) { return false; } - uint8_t hasAdditionalOpcodes{HasForks::None}; + bool hasAdditionalOpcodes{false}; const auto result = ParseScriptByMarker(tx.vout[0].scriptPubKey, DfAnchorFinalizeTxMarkerPlus, metadata, hasAdditionalOpcodes); - if ((hasForks & HasForks::FortCanning && !(hasForks & HasForks::GreatWorld) && hasAdditionalOpcodes & HasForks::FortCanning) || - (hasForks & HasForks::GreatWorld && hasAdditionalOpcodes & HasForks::GreatWorld)) { + if (fortCanning && hasAdditionalOpcodes) { return false; } return result; @@ -140,7 +125,7 @@ bool IsTokenSplitTx(CTransaction const & tx, std::vector & metada if (!tx.IsCoinBase() || tx.vout.size() != 1 || tx.vout[0].nValue != 0) { return false; } - uint8_t hasAdditionalOpcodes{HasForks::None}; + bool hasAdditionalOpcodes{false}; const auto result = ParseScriptByMarker(tx.vout[0].scriptPubKey, DfTokenSplitMarker, metadata, hasAdditionalOpcodes); if (hasAdditionalOpcodes) { return false; diff --git a/src/consensus/tx_check.h b/src/consensus/tx_check.h index ef8fc97d2d1..eac08d11edc 100644 --- a/src/consensus/tx_check.h +++ b/src/consensus/tx_check.h @@ -12,7 +12,6 @@ * belongs in tx_verify.h/cpp instead. */ -#include #include extern const std::vector DfTxMarker; @@ -20,26 +19,18 @@ extern const std::vector DfAnchorFinalizeTxMarker; extern const std::vector DfAnchorFinalizeTxMarkerPlus; extern const std::vector DfTokenSplitMarker; -struct CExpirationAndVersion; class CScript; class CTransaction; class CValidationState; -enum HasForks : uint8_t { - None = 0, - FortCanning = 1 << 0, - GreatWorld = 1 << 1, -}; - bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true); bool ParseScriptByMarker(CScript const & script, const std::vector & marker, std::vector & metadata, - uint8_t& hasAdditionalOpcodes, - CExpirationAndVersion* customTxParams = nullptr); + bool& hasAdditionalOpcodes); bool IsAnchorRewardTx(CTransaction const & tx, std::vector & metadata, bool fortCanning = false); -bool IsAnchorRewardTxPlus(CTransaction const & tx, std::vector & metadata, uint8_t hasForks = HasForks::None); +bool IsAnchorRewardTxPlus(CTransaction const & tx, std::vector & metadata, bool fortCanning = false); bool IsTokenSplitTx(CTransaction const & tx, std::vector & metadata, bool fortCanningCrunch = true); #endif // DEFI_CONSENSUS_TX_CHECK_H diff --git a/src/init.cpp b/src/init.cpp index ca0518ee6e4..ac461bce054 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -416,7 +416,6 @@ void SetupServerArgs() gArgs.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); gArgs.AddArg("-dbcache=", strprintf("Maximum database cache size MiB (%d to %d, default: %d). In addition, unused mempool memory is shared for this cache (see -maxmempool).", nMinDbCache, nMaxDbCache, nDefaultDbCache), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-debuglogfile=", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - gArgs.AddArg("-customtxexpiration=", strprintf("Number of blocks ahead of tip locally created transaction will expire (default: %u)", DEFAULT_CUSTOM_TX_EXPIRATION), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); gArgs.AddArg("-includeconf=", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-loadblock=", "Imports blocks from external blk000??.dat file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); @@ -1729,9 +1728,6 @@ bool AppInitMain(InitInterfaces& interfaces) // Ensure we are on latest DB version pcustomcsview->SetDbVersion(CCustomCSView::DbVersion); - // Set custom Tx expiration - pcustomcsview->SetGlobalCustomTxExpiration(gArgs.GetArg("-customtxexpiration", DEFAULT_CUSTOM_TX_EXPIRATION)); - // make account history db paccountHistoryDB.reset(); if (gArgs.GetBoolArg("-acindex", DEFAULT_ACINDEX)) { diff --git a/src/masternodes/masternodes.cpp b/src/masternodes/masternodes.cpp index 1ca14e3a589..1a3b916f7f6 100644 --- a/src/masternodes/masternodes.cpp +++ b/src/masternodes/masternodes.cpp @@ -744,16 +744,6 @@ CCustomCSView::CCustomCSView(CCustomCSView & other) CheckPrefixes(); } -void CCustomCSView::SetGlobalCustomTxExpiration(const uint32_t height) -{ - globalCustomTxExpiration = height; -} - -uint32_t CCustomCSView::GetGlobalCustomTxExpiration() const -{ - return globalCustomTxExpiration; -} - int CCustomCSView::GetDbVersion() const { int version; diff --git a/src/masternodes/masternodes.h b/src/masternodes/masternodes.h index a9db52b6e02..992989274d1 100644 --- a/src/masternodes/masternodes.h +++ b/src/masternodes/masternodes.h @@ -53,7 +53,6 @@ enum class UpdateMasternodeType : uint8_t }; constexpr uint8_t SUBNODE_COUNT{4}; -constexpr uint32_t DEFAULT_CUSTOM_TX_EXPIRATION{120}; class CMasternode { @@ -437,9 +436,6 @@ class CCustomCSView std::unique_ptr accHistoryStore; std::unique_ptr vauHistoryStore; - - uint32_t globalCustomTxExpiration{DEFAULT_CUSTOM_TX_EXPIRATION}; - public: // Increase version when underlaying tables are changed static constexpr const int DbVersion = 1; @@ -484,9 +480,6 @@ class CCustomCSView int GetDbVersion() const; - void SetGlobalCustomTxExpiration(const uint32_t height); - uint32_t GetGlobalCustomTxExpiration() const; - uint256 MerkleRoot(); // we construct it as it diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index 9589dd6a9d6..9043069e398 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -123,7 +123,7 @@ static ResVal MintedTokens(CTransaction const & tx, uint32_t mintingO return {balances, Res::Ok()}; } -CCustomTxMessage customTypeToMessage(CustomTxType txType, uint8_t version) { +CCustomTxMessage customTypeToMessage(CustomTxType txType) { switch (txType) { case CustomTxType::CreateMasternode: return CCreateMasterNodeMessage{}; @@ -3691,7 +3691,7 @@ void PopulateVaultHistoryData(CHistoryWriters* writers, CAccountsHistoryWriter& } } -Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTransaction& tx, const Consensus::Params& consensus, uint32_t height, uint64_t time, uint256* canSpend, uint32_t* customTxExpiration, uint32_t txn, CHistoryWriters* writers) { +Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTransaction& tx, const Consensus::Params& consensus, uint32_t height, uint64_t time, uint256* canSpend, uint32_t txn, CHistoryWriters* writers) { auto res = Res::Ok(); if (tx.IsCoinBase() && height > 0) { // genesis contains custom coinbase txs return res; @@ -3699,8 +3699,7 @@ Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTr std::vector metadata; const auto metadataValidation = height >= static_cast(consensus.FortCanningHeight); - CExpirationAndVersion customTxParams; - auto txType = GuessCustomTxType(tx, metadata, metadataValidation, height, &customTxParams); + auto txType = GuessCustomTxType(tx, metadata, metadataValidation); if (txType == CustomTxType::None) { return res; } @@ -3708,23 +3707,7 @@ Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTr if (metadataValidation && txType == CustomTxType::Reject) { return Res::ErrCode(CustomTxErrCodes::Fatal, "Invalid custom transaction"); } - - if (height >= static_cast(consensus.GreatWorldHeight)) { - if (customTxParams.expiration == 0) { - return Res::ErrCode(CustomTxErrCodes::Fatal, "Invalid transaction expiration set"); - } - if (customTxParams.version > static_cast(MetadataVersion::Two)) { - return Res::ErrCode(CustomTxErrCodes::Fatal, "Invalid transaction version set"); - } - if (height > customTxParams.expiration) { - return Res::ErrCode(CustomTxErrCodes::Fatal, "Transaction has expired"); - } - if (customTxExpiration) { - *customTxExpiration = customTxParams.expiration; - } - } - - auto txMessage = customTypeToMessage(txType, customTxParams.version); + auto txMessage = customTypeToMessage(txType); CAccountsHistoryWriter view(mnview, height, txn, tx.GetHash(), uint8_t(txType), writers); if ((res = CustomMetadataParse(height, consensus, metadata, txMessage))) { if (pvaultHistoryDB && writers) { diff --git a/src/masternodes/mn_checks.h b/src/masternodes/mn_checks.h index c2d1b522b2c..0736cf5ca35 100644 --- a/src/masternodes/mn_checks.h +++ b/src/masternodes/mn_checks.h @@ -104,12 +104,6 @@ enum class CustomTxType : uint8_t TokenSplit = 'P', }; -enum class MetadataVersion : uint8_t { - None = 0, - One = 1, - Two = 2, -}; - inline CustomTxType CustomTxCodeToType(uint8_t ch) { auto type = static_cast(ch); switch(type) { @@ -353,11 +347,11 @@ using CCustomTxMessage = std::variant< CAuctionBidMessage >; -CCustomTxMessage customTypeToMessage(CustomTxType txType, uint8_t version); +CCustomTxMessage customTypeToMessage(CustomTxType txType); bool IsMempooledCustomTxCreate(const CTxMemPool& pool, const uint256& txid); Res RpcInfo(const CTransaction& tx, uint32_t height, CustomTxType& type, UniValue& results); Res CustomMetadataParse(uint32_t height, const Consensus::Params& consensus, const std::vector& metadata, CCustomTxMessage& txMessage); -Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTransaction& tx, const Consensus::Params& consensus, uint32_t height, uint64_t time = 0, uint256* canSpend = nullptr, uint32_t* customTxExpiration = nullptr, uint32_t txn = 0, CHistoryWriters* writers = nullptr); +Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTransaction& tx, const Consensus::Params& consensus, uint32_t height, uint64_t time = 0, uint256* canSpend = nullptr, uint32_t txn = 0, CHistoryWriters* writers = nullptr); Res CustomTxVisit(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTransaction& tx, uint32_t height, const Consensus::Params& consensus, const CCustomTxMessage& txMessage, uint64_t time, uint32_t txn = 0); ResVal ApplyAnchorRewardTx(CCustomCSView& mnview, const CTransaction& tx, int height, const uint256& prevStakeModifier, const std::vector& metadata, const Consensus::Params& consensusParams); ResVal ApplyAnchorRewardTxPlus(CCustomCSView& mnview, const CTransaction& tx, int height, const std::vector& metadata, const Consensus::Params& consensusParams); @@ -381,8 +375,7 @@ inline bool OraclePriceFeed(CCustomCSView& view, const CTokenCurrencyPair& price /* * Checks if given tx is probably one of 'CustomTx', returns tx type and serialized metadata in 'data' */ -inline CustomTxType GuessCustomTxType(CTransaction const & tx, std::vector & metadata, bool metadataValidation = false, - uint32_t height = 0, CExpirationAndVersion* customTxParams = nullptr){ +inline CustomTxType GuessCustomTxType(CTransaction const & tx, std::vector & metadata, bool metadataValidation = false){ if (tx.vout.empty()) { return CustomTxType::None; } @@ -391,25 +384,21 @@ inline CustomTxType GuessCustomTxType(CTransaction const & tx, std::vector dummydata; - uint8_t dummyOpcodes{HasForks::None}; + bool dummyOpcodes{false}; if (ParseScriptByMarker(tx.vout[i].scriptPubKey, DfTxMarker, dummydata, dummyOpcodes)) { return CustomTxType::Reject; } } } - uint8_t hasAdditionalOpcodes{HasForks::None}; - if (!ParseScriptByMarker(tx.vout[0].scriptPubKey, DfTxMarker, metadata, hasAdditionalOpcodes, customTxParams)) { + bool hasAdditionalOpcodes{false}; + if (!ParseScriptByMarker(tx.vout[0].scriptPubKey, DfTxMarker, metadata, hasAdditionalOpcodes)) { return CustomTxType::None; } // If metadata contains additional opcodes mark as Reject. - if (metadataValidation) { - if (height < static_cast(Params().GetConsensus().GreatWorldHeight) && hasAdditionalOpcodes & HasForks::FortCanning) { - return CustomTxType::Reject; - } else if (height >= static_cast(Params().GetConsensus().GreatWorldHeight) && hasAdditionalOpcodes & HasForks::GreatWorld) { - return CustomTxType::Reject; - } + if (metadataValidation && hasAdditionalOpcodes) { + return CustomTxType::Reject; } auto txType = CustomTxCodeToType(metadata[0]); diff --git a/src/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index 466608b3572..3aba67f1935 100644 --- a/src/masternodes/mn_rpc.cpp +++ b/src/masternodes/mn_rpc.cpp @@ -425,9 +425,8 @@ std::vector GetAuthInputsSmart(CWalletCoinsUnlocker& pwallet, int32_t txV void execTestTx(const CTransaction& tx, uint32_t height, CTransactionRef optAuthTx) { std::vector metadata; - CExpirationAndVersion customTxParams; - auto txType = GuessCustomTxType(tx, metadata, false, 0, &customTxParams); - auto txMessage = customTypeToMessage(txType, customTxParams.version); + auto txType = GuessCustomTxType(tx, metadata); + auto txMessage = customTypeToMessage(txType); auto res = CustomMetadataParse(height, Params().GetConsensus(), metadata, txMessage); if (res) { LOCK(cs_main); @@ -950,44 +949,6 @@ static UniValue clearmempool(const JSONRPCRequest& request) return removed; } -UniValue setcustomtxexpiration(const JSONRPCRequest& request) { - RPCHelpMan{"setcustomtxexpiration", - "\nSet the expiration in blocks of locally created transactions. This expiration is to be\n" - "added to the current block height at the point of transaction creation. Once the chain reaches the\n" - "combined height if the transaction has not been added to a block it will be removed from the mempool\n" - "and can no longer be added to a block\n", - { - {"blockCount", RPCArg::Type::NUM, RPCArg::Optional::NO, ""} - }, - RPCResults{}, - RPCExamples{ - HelpExampleCli("setcustomtxexpiration", "10") - + HelpExampleRpc("setcustomtxexpiration", "10") - }, - }.Check(request); - - RPCTypeCheck(request.params, {UniValue::VNUM}, false); - - LOCK(cs_main); - - pcustomcsview->SetGlobalCustomTxExpiration(request.params[0].get_int()); - - return {}; -} - -void AddVersionAndExpiration(CScript& metaData, const uint32_t height, const MetadataVersion version) -{ - if (height < static_cast(Params().GetConsensus().GreatWorldHeight)) { - return; - } - - CExpirationAndVersion customTxParams{height + pcustomcsview->GetGlobalCustomTxExpiration(), static_cast(version)}; - - CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); - stream << customTxParams; - - metaData << ToByteVector(stream); -} static const CRPCCommand commands[] = { @@ -1000,7 +961,6 @@ static const CRPCCommand commands[] = {"blockchain", "isappliedcustomtx", &isappliedcustomtx, {"txid", "blockHeight"}}, {"blockchain", "listsmartcontracts", &listsmartcontracts, {}}, {"blockchain", "clearmempool", &clearmempool, {} }, - {"blockchain", "setcustomtxexpiration", &setcustomtxexpiration, {"blockHeight"}}, }; void RegisterMNBlockchainRPCCommands(CRPCTable& tableRPC) { diff --git a/src/masternodes/mn_rpc.h b/src/masternodes/mn_rpc.h index ca7c05d08a7..c2eabb9802f 100644 --- a/src/masternodes/mn_rpc.h +++ b/src/masternodes/mn_rpc.h @@ -78,6 +78,5 @@ void execTestTx(const CTransaction& tx, uint32_t height, CTransactionRef optAuth CScript CreateScriptForHTLC(const JSONRPCRequest& request, uint32_t &blocks, std::vector& image); CPubKey PublickeyFromString(const std::string &pubkey); std::optional GetFuturesBlock(const uint32_t typeId); -void AddVersionAndExpiration(CScript& metadata, const uint32_t height, const MetadataVersion version = MetadataVersion::One); #endif // DEFI_MASTERNODES_MN_RPC_H diff --git a/src/masternodes/rpc_customtx.cpp b/src/masternodes/rpc_customtx.cpp index 3933f7fc6ae..5e2573f6414 100644 --- a/src/masternodes/rpc_customtx.cpp +++ b/src/masternodes/rpc_customtx.cpp @@ -483,12 +483,11 @@ class CCustomTxRpcVisitor Res RpcInfo(const CTransaction& tx, uint32_t height, CustomTxType& txType, UniValue& results) { std::vector metadata; - CExpirationAndVersion customTxParams; - txType = GuessCustomTxType(tx, metadata, false, 0, &customTxParams); + txType = GuessCustomTxType(tx, metadata); if (txType == CustomTxType::None) { return Res::Ok(); } - auto txMessage = customTypeToMessage(txType, customTxParams.version); + auto txMessage = customTypeToMessage(txType); auto res = CustomMetadataParse(height, Params().GetConsensus(), metadata, txMessage); if (res) { CCustomCSView mnview(*pcustomcsview); diff --git a/src/masternodes/rpc_poolpair.cpp b/src/masternodes/rpc_poolpair.cpp index 5d4421074b9..5be8db78d86 100644 --- a/src/masternodes/rpc_poolpair.cpp +++ b/src/masternodes/rpc_poolpair.cpp @@ -366,7 +366,6 @@ UniValue addpoolliquidity(const JSONRPCRequest& request) { << msg; CScript scriptMeta; scriptMeta << OP_RETURN << ToByteVector(markedMetadata); - AddVersionAndExpiration(scriptMeta, chainHeight(*pwallet->chain().lock())); int targetHeight = chainHeight(*pwallet->chain().lock()) + 1; @@ -456,7 +455,6 @@ UniValue removepoolliquidity(const JSONRPCRequest& request) { << msg; CScript scriptMeta; scriptMeta << OP_RETURN << ToByteVector(markedMetadata); - AddVersionAndExpiration(scriptMeta, chainHeight(*pwallet->chain().lock())); int targetHeight = chainHeight(*pwallet->chain().lock()) + 1; @@ -847,7 +845,6 @@ UniValue poolswap(const JSONRPCRequest& request) { CScript scriptMeta; scriptMeta << OP_RETURN << ToByteVector(metadata); - AddVersionAndExpiration(scriptMeta, chainHeight(*pwallet->chain().lock())); const auto txVersion = GetTransactionVersion(targetHeight); CMutableTransaction rawTx(txVersion); @@ -978,7 +975,6 @@ UniValue compositeswap(const JSONRPCRequest& request) { CScript scriptMeta; scriptMeta << OP_RETURN << ToByteVector(metadata); - AddVersionAndExpiration(scriptMeta, chainHeight(*pwallet->chain().lock())); const auto txVersion = GetTransactionVersion(targetHeight); CMutableTransaction rawTx(txVersion); diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 7aa5c649dd1..d4a12b875a1 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -479,22 +479,6 @@ inline void SerializeTransaction(const TxType& tx, Stream& s) { s << tx.nLockTime; } -/* - * DeFiChain custom transaction expiration and version added after metadata. - */ -struct CExpirationAndVersion { - uint32_t expiration{std::numeric_limits::max()}; - uint8_t version{0}; - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) - { - READWRITE(expiration); - READWRITE(version); - } -}; typedef std::shared_ptr CTransactionRef; static inline CTransactionRef MakeTransactionRef() { return std::make_shared(); } diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index e8bac6385e9..5bde5daaf51 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -316,7 +316,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "setgovheight", 2, "inputs" }, { "isappliedcustomtx", 1, "blockHeight" }, - { "setcustomtxexpiration", 0, "blockHeight" }, { "sendtokenstoaddress", 0, "from" }, { "sendtokenstoaddress", 1, "to" }, { "getanchorteams", 0, "blockHeight" }, diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 64cf237dada..35d1b092ee3 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -21,10 +21,9 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee, int64_t _nTime, unsigned int _entryHeight, - bool _spendsCoinbase, int64_t _sigOpsCost, - LockPoints lp, uint32_t customTxExpiration) + bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp) : tx(_tx), nFee(_nFee), nTxWeight(GetTransactionWeight(*tx)), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight), - spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp), customTxExpiration(customTxExpiration) + spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp) { nCountWithDescendants = 1; nSizeWithDescendants = GetTxSize(); @@ -972,23 +971,6 @@ int CTxMemPool::Expire(int64_t time) { return stage.size(); } -uint32_t CTxMemPool::ExpireByHeight(const uint32_t blockHeight) { - AssertLockHeld(cs); - indexed_transaction_set::index::type::iterator it = mapTx.get().begin(); - setEntries toremove; - for (; it != mapTx.get().end(); ++it) { - if (blockHeight >= it->GetCustomTxExpiration()) { - toremove.insert(mapTx.project<0>(it)); - } - } - setEntries stage; - for (txiter removeit : toremove) { - CalculateDescendants(removeit, stage); - } - RemoveStaged(stage, false, MemPoolRemovalReason::EXPIRY); - return stage.size(); -} - void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate) { setEntries setAncestors; diff --git a/src/txmempool.h b/src/txmempool.h index 64de9cbbb04..f4176d1027c 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -79,7 +79,6 @@ class CTxMemPoolEntry const int64_t sigOpCost; //!< Total sigop cost int64_t feeDelta; //!< Used for determining the priority of the transaction for mining in a block LockPoints lockPoints; //!< Track the height and time at which tx was final - uint32_t customTxExpiration; //!< Block height at which transaction will expire // Information about descendants of this transaction that are in the // mempool; if we remove this transaction we must remove all of these @@ -98,8 +97,7 @@ class CTxMemPoolEntry CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee, int64_t _nTime, unsigned int _entryHeight, bool spendsCoinbase, - int64_t nSigOpsCost, LockPoints lp, - uint32_t customTxExpiration = std::numeric_limits::max()); + int64_t nSigOpsCost, LockPoints lp); const CTransaction& GetTx() const { return *this->tx; } CTransactionRef GetSharedTx() const { return this->tx; } @@ -133,7 +131,6 @@ class CTxMemPoolEntry uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; } - uint32_t GetCustomTxExpiration() const { return customTxExpiration; } mutable size_t vTxHashesIdx; //!< Index in mempool's vTxHashes }; @@ -669,9 +666,6 @@ class CTxMemPool /** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */ int Expire(int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs); - /** Expire all custom transaction (and their dependencies) in the mempool by their expiration height. Return the number of removed transactions. */ - uint32_t ExpireByHeight(const uint32_t blockHeight); - /** * Calculate the ancestor and descendant count for the given transaction. * The counts include the transaction itself. diff --git a/src/validation.cpp b/src/validation.cpp index 352c73f22d0..2b8d018656f 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -642,8 +642,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INVALID, "bad-txns-inputs-below-tx-fee"); } - uint32_t customTxExpiration{std::numeric_limits::max()}; - auto res = ApplyCustomTx(mnview, view, tx, chainparams.GetConsensus(), height, nAcceptTime, nullptr, &customTxExpiration); + auto res = ApplyCustomTx(mnview, view, tx, chainparams.GetConsensus(), height, nAcceptTime); if (!res.ok || (res.code & CustomTxErrCodes::Fatal)) { return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INVALID, res.msg); } @@ -685,7 +684,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool } CTxMemPoolEntry entry(ptx, nFees, nAcceptTime, ::ChainActive().Height(), - fSpendsCoinbase, nSigOpsCost, lp, customTxExpiration); + fSpendsCoinbase, nSigOpsCost, lp); unsigned int nSize = entry.GetTxSize(); if (nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST) @@ -1654,7 +1653,7 @@ int ApplyTxInUndo(Coin&& undo, CCoinsViewCache& view, const COutPoint& out) } static bool GetCreationTransactions(const CBlock& block, const uint32_t id, const int32_t multiplier, uint256& tokenCreationTx, std::vector& poolCreationTx) { - uint8_t opcodes{HasForks::None}; + bool opcodes{false}; std::vector metadata; uint32_t type; uint32_t metaId; @@ -2545,7 +2544,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl // init view|db with genesis here for (size_t i = 0; i < block.vtx.size(); ++i) { CHistoryWriters writers{paccountHistoryDB.get(), nullptr, nullptr}; - const auto res = ApplyCustomTx(mnview, view, *block.vtx[i], chainparams.GetConsensus(), pindex->nHeight, pindex->GetBlockTime(), nullptr, nullptr, i, &writers); + const auto res = ApplyCustomTx(mnview, view, *block.vtx[i], chainparams.GetConsensus(), pindex->nHeight, pindex->GetBlockTime(), nullptr, i, &writers); if (!res.ok) { return error("%s: Genesis block ApplyCustomTx failed. TX: %s Error: %s", __func__, block.vtx[i]->GetHash().ToString(), res.msg); @@ -2814,7 +2813,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl } CHistoryWriters writers{paccountHistoryDB.get(), pburnHistoryDB.get(), pvaultHistoryDB.get()}; - const auto res = ApplyCustomTx(mnview, view, tx, chainparams.GetConsensus(), pindex->nHeight, pindex->GetBlockTime(), nullptr, nullptr, i, &writers); + const auto res = ApplyCustomTx(mnview, view, tx, chainparams.GetConsensus(), pindex->nHeight, pindex->GetBlockTime(), nullptr, i, &writers); if (!res.ok && (res.code & CustomTxErrCodes::Fatal)) { if (pindex->nHeight >= chainparams.GetConsensus().EunosHeight) { return state.Invalid(ValidationInvalidReason::CONSENSUS, @@ -3104,14 +3103,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl } } - if (pindex->nHeight >= chainparams.GetConsensus().GreatWorldHeight) { - // Remove any TXs from mempool that are now expired - const auto removed = mempool.ExpireByHeight(pindex->nHeight); - if (removed) { - LogPrintf("%s: %d transaction expired at height %d\n", __func__, removed, pindex->nHeight); - } - } - if (isSplitsBlock) { LogPrintf("Token split block validation time: %.2fms\n", MILLI * (GetTimeMicros() - nTime1)); } @@ -6074,13 +6065,10 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P // skip this validation if it is Genesis (due to mn creation txs) if (block.GetHash() != consensusParams.hashGenesisBlock) { TBytes dummy; - uint8_t hashForks{HasForks::None}; - hashForks |= height >= consensusParams.FortCanningHeight ? HasForks::FortCanning : HasForks::None; - hashForks |= height >= consensusParams.GreatWorldHeight ? HasForks::GreatWorld : HasForks::None; for (unsigned int i = 1; i < block.vtx.size(); i++) { if (block.vtx[i]->IsCoinBase() && !IsAnchorRewardTx(*block.vtx[i], dummy, height >= consensusParams.FortCanningHeight) && - !IsAnchorRewardTxPlus(*block.vtx[i], dummy, hashForks) && + !IsAnchorRewardTxPlus(*block.vtx[i], dummy, height >= consensusParams.FortCanningHeight) && !IsTokenSplitTx(*block.vtx[i], dummy, height >= consensusParams.FortCanningCrunchHeight)) return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-cb-multiple", "more than one coinbase"); } diff --git a/test/functional/feature_reject_customtxs.py b/test/functional/feature_reject_customtxs.py index 2e865f82486..e11272d74c6 100755 --- a/test/functional/feature_reject_customtxs.py +++ b/test/functional/feature_reject_customtxs.py @@ -8,13 +8,13 @@ from test_framework.test_framework import DefiTestFramework from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal, assert_raises_rpc_error +from test_framework.util import assert_equal class RejectCustomTx(DefiTestFramework): def set_test_params(self): self.num_nodes = 1 self.setup_clean_chain = True - self.extra_args = [['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1', '-bayfrontgardensheight=1', '-dakotaheight=1', '-fortcanningheight=120', '-greatworldheight=140', '-customtxexpiration=6']] + self.extra_args = [['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1', '-bayfrontgardensheight=1', '-dakotaheight=1', '-fortcanningheight=120']] def run_test(self): self.nodes[0].generate(101) @@ -114,48 +114,5 @@ def run_test(self): errorString = e.error['message'] assert("Invalid custom transaction" in errorString) - # Set up for GW TX expiration tests - address = self.nodes[0].getnewaddress("", "legacy") - - # Create token - self.nodes[0].createtoken({ - "symbol": "LTC", - "name": "Litecoin", - "isDAT": True, - "collateralAddress": address - }) - self.nodes[0].generate(1) - - # Create pool - self.nodes[0].createpoolpair({ - "tokenA": 'LTC', - "tokenB": 'DFI', - "commission": 0.01, - "status": True, - "ownerAddress": address - }, []) - self.nodes[0].generate(1) - - # Fund address with DFI and LTC - self.nodes[0].minttokens(["0.1@LTC"]) - self.nodes[0].sendtoaddress(address, 0.1) - self.nodes[0].utxostoaccount({address: "10@DFI"}) - self.nodes[0].generate(1) - - # Move to GreatWorld height - self.nodes[0].generate(140 - self.nodes[0].getblockcount()) - - # Create transaction with new expiration and version fields - tx = self.nodes[0].addpoolliquidity({address: ["0.1@LTC", "10@DFI"]}, address) - rawtx = self.nodes[0].getrawtransaction(tx) - self.nodes[0].clearmempool() - - # Append extra data and test failure - rawtx = rawtx.replace('ffffffff0200000000000000005c', 'ffffffff0200000000000000005d') - expiration = self.nodes[0].getblockcount() + 6 - rawtx = rawtx.replace('05' + hex(expiration)[2:] + '00000001', '05' + hex(expiration)[2:] + '0000000100') - signed_rawtx = self.nodes[0].signrawtransactionwithwallet(rawtx) - assert_raises_rpc_error(-26, "Invalid custom transaction", self.nodes[0].sendrawtransaction, signed_rawtx['hex']) - if __name__ == '__main__': RejectCustomTx().main() diff --git a/test/functional/feature_tx_versioning_and_expiration.py b/test/functional/feature_tx_versioning_and_expiration.py deleted file mode 100755 index 8e66a00ee1f..00000000000 --- a/test/functional/feature_tx_versioning_and_expiration.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2014-2019 The Bitcoin Core developers -# Copyright (c) DeFi Blockchain Developers -# Distributed under the MIT software license, see the accompanying -# file LICENSE or http://www.opensource.org/licenses/mit-license.php. -"""Test Tx version and expiration.""" - -from test_framework.test_framework import DefiTestFramework - -from test_framework.util import assert_equal, assert_raises_rpc_error - -class TxVersionAndExpirationTest (DefiTestFramework): - def set_test_params(self): - self.num_nodes = 1 - self.setup_clean_chain = True - self.extra_args = [['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1', '-eunosheight=1', '-txindex=1', '-fortcanningheight=101', '-greatworldheight=101']] - - def run_test(self): - self.nodes[0].generate(101) - - # Create token and pool address - address = self.nodes[0].get_genesis_keys().ownerAuthAddress - - # Create token - self.nodes[0].createtoken({ - "symbol": "LTC", - "name": "Litecoin", - "isDAT": True, - "collateralAddress": address - }) - self.nodes[0].generate(1) - - # Create pool - self.nodes[0].createpoolpair({ - "tokenA": 'LTC', - "tokenB": 'DFI', - "commission": 0.01, - "status": True, - "ownerAddress": address - }, []) - self.nodes[0].generate(1) - - # Fund address with DFI and LTC - self.nodes[0].minttokens(["0.1@LTC"]) - self.nodes[0].utxostoaccount({address: "10@DFI"}) - self.nodes[0].generate(1) - - # Create transaction to use in testing - tx = self.nodes[0].addpoolliquidity({address: ["0.1@LTC", "10@DFI"]}, address) - rawtx = self.nodes[0].getrawtransaction(tx) - self.nodes[0].clearmempool() - - # Test invalid version - print(rawtx) - invalid_version = rawtx.replace('05e000000001', '05e0000000ff') - signed_rawtx = self.nodes[0].signrawtransactionwithwallet(invalid_version) - assert_raises_rpc_error(-26, "Invalid transaction version set", self.nodes[0].sendrawtransaction, signed_rawtx['hex']) - - # Test invalid expiration - invalid_expiration = rawtx.replace('05e000000001', '050000000001') - signed_rawtx = self.nodes[0].signrawtransactionwithwallet(invalid_expiration) - assert_raises_rpc_error(-26, "Invalid transaction expiration set", self.nodes[0].sendrawtransaction, signed_rawtx['hex']) - - # Check block acceptance just below expiration height - self.nodes[0].generate(119) - self.nodes[0].sendrawtransaction(rawtx) - self.nodes[0].clearmempool() - - # Test mempool rejection at expiration height - self.nodes[0].generate(1) - assert_raises_rpc_error(-26, "Transaction has expired", self.nodes[0].sendrawtransaction, rawtx) - - # Test expiration value set by startup flag - self.stop_node(0) - self.start_node(0, ['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1', '-eunosheight=1', '-txindex=1', '-fortcanningheight=101', '-greatworldheight=101', '-customtxexpiration=1']) - - # Create expiration TX - tx = self.nodes[0].addpoolliquidity({address: ["0.1@LTC", "10@DFI"]}, address) - rawtx = self.nodes[0].getrawtransaction(tx, 1) - self.nodes[0].clearmempool() - - # Check expiration is now 1 block - expiration = self.nodes[0].getblockcount() + 1 - assert_equal(rawtx['vout'][0]['scriptPubKey']['hex'][172:], '05' + hex(expiration)[2:] + '00000001') - self.nodes[0].clearmempool() - - # Create expiration TX - self.nodes[0].setcustomtxexpiration(10) - tx = self.nodes[0].addpoolliquidity({address: ["0.1@LTC", "10@DFI"]}, address) - rawtx = self.nodes[0].getrawtransaction(tx, 1) - self.nodes[0].clearmempool() - - # Check expiration is now 10 blocks - expiration = self.nodes[0].getblockcount() + 10 - assert_equal(rawtx['vout'][0]['scriptPubKey']['hex'][172:], '05' + hex(expiration)[2:] + '00000001') - self.nodes[0].clearmempool() - -if __name__ == '__main__': - TxVersionAndExpirationTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 5e942ae8654..00580843420 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -291,7 +291,6 @@ 'feature_checkpoint.py', 'rpc_getmininginfo.py', 'feature_burn_address.py', - 'feature_tx_versioning_and_expiration.py', 'feature_eunos_balances.py', 'feature_sendutxosfrom.py', 'feature_update_mn.py',