diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp index 8e50601609..11524e1dfd 100644 --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -182,8 +182,7 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c CCustomCSView discardCache(mnview, nullptr, nullptr, nullptr); // Note: TXs are already filtered. So we pass isEVMEnabled to false, but for future proof, refactor this enough, // that it's propagated. - uint64_t gasUsed{}; - auto res = ApplyCustomTx(discardCache, inputs, tx, chainparams.GetConsensus(), nSpendHeight, gasUsed, 0, &canSpend, 0, 0, false, false); + auto res = ApplyCustomTx(discardCache, inputs, tx, chainparams.GetConsensus(), nSpendHeight, 0, &canSpend, 0, 0, false, false); if (!res.ok && (res.code & CustomTxErrCodes::Fatal)) { return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-txns-customtx", res.msg); } diff --git a/src/masternodes/consensus/txvisitor.cpp b/src/masternodes/consensus/txvisitor.cpp index e440eaabc3..f4e4f53b86 100644 --- a/src/masternodes/consensus/txvisitor.cpp +++ b/src/masternodes/consensus/txvisitor.cpp @@ -62,7 +62,6 @@ CCustomTxVisitor::CCustomTxVisitor(const CTransaction &tx, const uint32_t txn, const uint64_t evmQueueId, const bool isEvmEnabledForBlock, - uint64_t &gasUsed, const bool evmPreValidate) : height(height), mnview(mnview), @@ -73,7 +72,6 @@ CCustomTxVisitor::CCustomTxVisitor(const CTransaction &tx, txn(txn), evmQueueId(evmQueueId), isEvmEnabledForBlock(isEvmEnabledForBlock), - gasUsed(gasUsed), evmPreValidate(evmPreValidate) {} Res CCustomTxVisitor::HasAuth(const CScript &auth) const { diff --git a/src/masternodes/consensus/txvisitor.h b/src/masternodes/consensus/txvisitor.h index 5d964d810e..986f853d5e 100644 --- a/src/masternodes/consensus/txvisitor.h +++ b/src/masternodes/consensus/txvisitor.h @@ -52,7 +52,6 @@ class CCustomTxVisitor { const uint32_t txn; uint64_t evmQueueId; bool isEvmEnabledForBlock; - uint64_t &gasUsed; bool evmPreValidate; public: @@ -65,7 +64,6 @@ class CCustomTxVisitor { const uint32_t txn, const uint64_t evmQueueId, const bool isEvmEnabledForBlock, - uint64_t &gasUsed, const bool evmPreValidate); protected: diff --git a/src/masternodes/consensus/xvm.cpp b/src/masternodes/consensus/xvm.cpp index 78ce679e41..1599961304 100644 --- a/src/masternodes/consensus/xvm.cpp +++ b/src/masternodes/consensus/xvm.cpp @@ -380,5 +380,6 @@ Res CXVMConsensus::operator()(const CEvmTxMessage &obj) const { if (!res) { LogPrintf("Failed to store EVMToDVM TX hash for DFI TX %s\n", txHash); } + return Res::Ok(); } diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index 8ff632a08b..4ecc63c1e1 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -331,7 +331,6 @@ class CCustomTxApplyVisitor { uint32_t txn; uint64_t evmQueueId; bool isEvmEnabledForBlock; - uint64_t &gasUsed; bool evmPreValidate; template @@ -340,7 +339,7 @@ class CCustomTxApplyVisitor { static_assert(std::is_base_of_v, "CCustomTxVisitor base required"); if constexpr (std::is_invocable_v) - return T1{tx, height, coins, mnview, consensus, time, txn, evmQueueId, isEvmEnabledForBlock, gasUsed, evmPreValidate}(obj); + return T1{tx, height, coins, mnview, consensus, time, txn, evmQueueId, isEvmEnabledForBlock, evmPreValidate}(obj); else if constexpr (sizeof...(Args) != 0) return ConsensusHandler(obj); else @@ -359,7 +358,6 @@ class CCustomTxApplyVisitor { uint32_t txn, const uint64_t evmQueueId, const bool isEvmEnabledForBlock, - uint64_t &gasUsed, const bool evmPreValidate) : tx(tx), @@ -371,7 +369,6 @@ class CCustomTxApplyVisitor { txn(txn), evmQueueId(evmQueueId), isEvmEnabledForBlock(isEvmEnabledForBlock), - gasUsed(gasUsed), evmPreValidate(evmPreValidate) {} template @@ -447,7 +444,6 @@ Res CustomTxVisit(CCustomCSView &mnview, const Consensus::Params &consensus, const CCustomTxMessage &txMessage, const uint64_t time, - uint64_t &gasUsed, const uint32_t txn, const uint64_t evmQueueId, const bool isEvmEnabledForBlock, @@ -466,7 +462,7 @@ Res CustomTxVisit(CCustomCSView &mnview, try { auto res = std::visit( - CCustomTxApplyVisitor(tx, height, coins, mnview, consensus, time, txn, q, isEvmEnabledForBlock, gasUsed, evmPreValidate), + CCustomTxApplyVisitor(tx, height, coins, mnview, consensus, time, txn, q, isEvmEnabledForBlock, evmPreValidate), txMessage); if (wipeQueue) { XResultStatusLogged(evm_unsafe_try_remove_queue(result, q)); @@ -560,7 +556,6 @@ Res ApplyCustomTx(CCustomCSView &mnview, const CTransaction &tx, const Consensus::Params &consensus, uint32_t height, - uint64_t &gasUsed, uint64_t time, uint256 *canSpend, uint32_t txn, @@ -605,7 +600,7 @@ Res ApplyCustomTx(CCustomCSView &mnview, PopulateVaultHistoryData(mnview.GetHistoryWriters(), view, txMessage, txType, height, txn, tx.GetHash()); } - res = CustomTxVisit(view, coins, tx, height, consensus, txMessage, time, gasUsed, txn, evmQueueId, isEvmEnabledForBlock, evmPreValidate); + res = CustomTxVisit(view, coins, tx, height, consensus, txMessage, time, txn, evmQueueId, isEvmEnabledForBlock, evmPreValidate); if (res) { if (canSpend && txType == CustomTxType::UpdateMasternode) { diff --git a/src/masternodes/mn_checks.h b/src/masternodes/mn_checks.h index 2f053f9b4b..4f45897be0 100644 --- a/src/masternodes/mn_checks.h +++ b/src/masternodes/mn_checks.h @@ -170,7 +170,6 @@ Res ApplyCustomTx(CCustomCSView &mnview, const CTransaction &tx, const Consensus::Params &consensus, uint32_t height, - uint64_t &gasUsed, uint64_t time, uint256 *canSpend, uint32_t txn, @@ -185,7 +184,6 @@ Res CustomTxVisit(CCustomCSView &mnview, const Consensus::Params &consensus, const CCustomTxMessage &txMessage, const uint64_t time, - uint64_t &gasUsed, const uint32_t txn, const uint64_t evmQueueId, const bool isEvmEnabledForBlock, diff --git a/src/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index 08ff4980b5..596eab3a67 100644 --- a/src/masternodes/mn_rpc.cpp +++ b/src/masternodes/mn_rpc.cpp @@ -458,8 +458,7 @@ void execTestTx(const CTransaction& tx, uint32_t height, CTransactionRef optAuth CCustomCSView view(*pcustomcsview); auto consensus = Params().GetConsensus(); auto isEvmEnabledForBlock = IsEVMEnabled(height, view, consensus); - uint64_t gasUsed{}; - res = CustomTxVisit(view, coins, tx, height, consensus, txMessage, ::ChainActive().Tip()->nTime, gasUsed, 0, 0, isEvmEnabledForBlock, true); + res = CustomTxVisit(view, coins, tx, height, consensus, txMessage, ::ChainActive().Tip()->nTime, 0, 0, isEvmEnabledForBlock, true); } if (!res) { if (res.code == CustomTxErrCodes::NotEnoughBalance) { diff --git a/src/masternodes/rpc_tokens.cpp b/src/masternodes/rpc_tokens.cpp index 6c6a189e9f..faf52c0af4 100644 --- a/src/masternodes/rpc_tokens.cpp +++ b/src/masternodes/rpc_tokens.cpp @@ -607,8 +607,7 @@ UniValue getcustomtx(const JSONRPCRequest& request) auto consensus = Params().GetConsensus(); auto isEvmEnabledForBlock = IsEVMEnabled(nHeight, mnview, consensus); - uint64_t gasUsed{}; - auto res = ApplyCustomTx(mnview, view, *tx, consensus, nHeight, gasUsed, 0, nullptr, 0, 0, isEvmEnabledForBlock, false); + auto res = ApplyCustomTx(mnview, view, *tx, consensus, nHeight, 0, nullptr, 0, 0, isEvmEnabledForBlock, false); result.pushKV("valid", res.ok); } else { diff --git a/src/miner.cpp b/src/miner.cpp index 23256e3c4e..ebd35342a6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -706,9 +706,6 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda // Keep track of EVM entries that failed nonce check std::multimap failedNonces; - // Variable to tally total gas used in the block - uint64_t totalGas{}; - while (mi != mempool.mapTx.get().end() || !mapModifiedTxSet.empty() || !failedNonces.empty()) { // First try to find a new transaction in mapTx to evaluate. if (mi != mempool.mapTx.get().end() && @@ -857,8 +854,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda } } - uint64_t gasUsed{}; - const auto res = ApplyCustomTx(view, coins, tx, chainparams.GetConsensus(), nHeight, gasUsed, pblock->nTime, nullptr, 0, evmQueueId, isEvmEnabledForBlock, false); + const auto res = ApplyCustomTx(view, coins, tx, chainparams.GetConsensus(), nHeight, pblock->nTime, nullptr, 0, evmQueueId, isEvmEnabledForBlock, false); // Not okay invalidate, undo and skip if (!res.ok) { customTxPassed = false; @@ -866,12 +862,6 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda break; } - if (totalGas + gasUsed > MAX_BLOCK_GAS_LIMIT) { - customTxPassed = false; - break; - } - totalGas += gasUsed; - // Track checked TXs to avoid double applying checkedDfTxHashSet.insert(tx.GetHash()); } diff --git a/src/test/applytx_tests.cpp b/src/test/applytx_tests.cpp index 748f9ed30d..2b77f0323e 100644 --- a/src/test/applytx_tests.cpp +++ b/src/test/applytx_tests.cpp @@ -108,8 +108,6 @@ BOOST_AUTO_TEST_CASE(apply_a2a_neg) rawTx.vout = { CTxOut(0, CScript()) }; rawTx.vin = { CTxIn(auth_out) }; - uint64_t gasUsed{}; - // try to send "A:-1@DFI" { msg.to = { @@ -118,7 +116,7 @@ BOOST_AUTO_TEST_CASE(apply_a2a_neg) rawTx.vout[0].scriptPubKey = CreateMetaA2A(msg); - res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, gasUsed, 0, nullptr, 0, 0, false, false); + res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, 0, nullptr, 0, 0, false, false); BOOST_CHECK(!res.ok); BOOST_CHECK_NE(res.msg.find("negative amount"), std::string::npos); // check that nothing changes: @@ -134,8 +132,7 @@ BOOST_AUTO_TEST_CASE(apply_a2a_neg) rawTx.vout[0].scriptPubKey = CreateMetaA2A(msg); - uint64_t gasUsed{}; - res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, gasUsed, 0, nullptr, 0, 0, false, false); + res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, 0, nullptr, 0, 0, false, false); BOOST_CHECK(!res.ok); BOOST_CHECK_EQUAL(res.code, (uint32_t) CustomTxErrCodes::NotEnoughBalance); // check that nothing changes: @@ -152,7 +149,7 @@ BOOST_AUTO_TEST_CASE(apply_a2a_neg) rawTx.vout[0].scriptPubKey = CreateMetaA2A(msg); - res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, gasUsed, 0, nullptr, 0, 0, false, false); + res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, 0, nullptr, 0, 0, false, false); BOOST_CHECK(!res.ok); BOOST_CHECK_NE(res.msg.find("negative amount"), std::string::npos); // check that nothing changes: @@ -169,7 +166,7 @@ BOOST_AUTO_TEST_CASE(apply_a2a_neg) rawTx.vout[0].scriptPubKey = CreateMetaA2A(msg); - res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, gasUsed, 0, nullptr, 0, 0, false, false); + res = ApplyCustomTx(mnview, coinview, CTransaction(rawTx), amkCheated, 1, 0, nullptr, 0, 0, false, false); BOOST_CHECK(res.ok); // check result balances: auto const dfi90 = CTokenAmount{DFI, 90}; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index a21003e2ac..573d16e5c8 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1246,8 +1246,7 @@ void CTxMemPool::rebuildAccountsView(int height, const CCoinsViewCache& coinsCac vtx.push_back(it->GetSharedTx()); continue; } - uint64_t gasUsed{}; - auto res = ApplyCustomTx(viewDuplicate, coinsCache, tx, consensus, height, gasUsed, 0, nullptr, 0, 0, isEvmEnabledForBlock, true); + auto res = ApplyCustomTx(viewDuplicate, coinsCache, tx, consensus, height, 0, nullptr, 0, 0, isEvmEnabledForBlock, true); if (!res && (res.code & CustomTxErrCodes::Fatal)) { LogPrintf("%s: Remove conflicting custom TX: %s\n", __func__, tx.GetHash().GetHex()); staged.insert(mapTx.project<0>(it)); diff --git a/src/validation.cpp b/src/validation.cpp index d8fd6a6cd8..518320b59c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -650,8 +650,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INVALID, "bad-txns-inputs-below-tx-fee"); } - uint64_t gasUsed{}; - auto res = ApplyCustomTx(mnview, view, tx, consensus, height, gasUsed, nAcceptTime, nullptr, 0, 0, isEvmEnabledForBlock, true); + auto res = ApplyCustomTx(mnview, view, tx, consensus, height, nAcceptTime, nullptr, 0, 0, isEvmEnabledForBlock, true); if (!res.ok || (res.code & CustomTxErrCodes::Fatal)) { return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INVALID, res.msg); } @@ -2430,8 +2429,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl // Do not track burns in genesis mnview.GetHistoryWriters().GetBurnView() = nullptr; for (size_t i = 0; i < block.vtx.size(); ++i) { - uint64_t gasUsed{}; - const auto res = ApplyCustomTx(mnview, view, *block.vtx[i], chainparams.GetConsensus(), pindex->nHeight, gasUsed, pindex->GetBlockTime(), nullptr, i, 0, false, false); + const auto res = ApplyCustomTx(mnview, view, *block.vtx[i], chainparams.GetConsensus(), pindex->nHeight, pindex->GetBlockTime(), nullptr, i, 0, false, false); if (!res.ok) { return error("%s: Genesis block ApplyCustomTx failed. TX: %s Error: %s", __func__, block.vtx[i]->GetHash().ToString(), res.msg); @@ -2714,8 +2712,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl } const auto applyCustomTxTime = GetTimeMicros(); - uint64_t gasUsed{}; - const auto res = ApplyCustomTx(accountsView, view, tx, consensus, pindex->nHeight, gasUsed, pindex->GetBlockTime(), nullptr, i, evmQueueId, isEvmEnabledForBlock, false); + const auto res = ApplyCustomTx(accountsView, view, tx, consensus, pindex->nHeight, pindex->GetBlockTime(), nullptr, i, evmQueueId, isEvmEnabledForBlock, false); LogApplyCustomTx(tx, applyCustomTxTime); if (!res.ok && (res.code & CustomTxErrCodes::Fatal)) {