From 950a2c30545669d562fdac1cad19bad4de5211d8 Mon Sep 17 00:00:00 2001 From: Niven Date: Thu, 20 Jul 2023 13:53:17 +0800 Subject: [PATCH] Add bool flag to validation for evm context --- src/masternodes/mn_checks.cpp | 19 ++++++++++++++----- src/masternodes/mn_rpc.cpp | 3 +-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index f52c707cf2..05149f038a 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -769,6 +769,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor { uint64_t time; uint32_t txn; uint64_t evmContext; + bool useEvmContext; public: CCustomTxApplyVisitor(const CTransaction &tx, @@ -778,12 +779,14 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor { const Consensus::Params &consensus, uint64_t time, uint32_t txn, - const uint64_t evmContext) + const uint64_t evmContext, + const bool useEvmContext) : CCustomTxVisitor(tx, height, coins, mnview, consensus), time(time), txn(txn), - evmContext(evmContext) {} + evmContext(evmContext), + useEvmContext(useEvmContext) {} Res operator()(const CCreateMasterNodeMessage &obj) const { Require(CheckMasternodeCreationTx()); @@ -3927,7 +3930,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor { return Res::Err("evm tx size too large"); CrossBoundaryResult result; - const auto prevalidateResults = evm_try_prevalidate_raw_tx(result, HexStr(obj.evmTx), true, evmContext); + const auto prevalidateResults = evm_try_prevalidate_raw_tx(result, HexStr(obj.evmTx), useEvmContext, evmContext); // Completely remove this fork guard on mainnet upgrade to restore nonce check from EVM activation if (height >= static_cast(consensus.ChangiIntermediateHeight)) { @@ -4174,10 +4177,16 @@ Res CustomTxVisit(CCustomCSView &mnview, if (IsDisabledTx(height, tx, consensus)) { return Res::ErrCode(CustomTxErrCodes::Fatal, "Disabled custom transaction"); } + auto context = evmContext; - if (context == 0) context = evm_get_context(); + bool useEvmContext = true; + if (context == 0) { + useEvmContext = false; + context = evm_get_context(); + } + try { - return std::visit(CCustomTxApplyVisitor(tx, height, coins, mnview, consensus, time, txn, context), txMessage); + return std::visit(CCustomTxApplyVisitor(tx, height, coins, mnview, consensus, time, txn, context, useEvmContext), txMessage); } catch (const std::bad_variant_access &e) { return Res::Err(e.what()); } catch (...) { diff --git a/src/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index 7436fff374..20dae6f873 100644 --- a/src/masternodes/mn_rpc.cpp +++ b/src/masternodes/mn_rpc.cpp @@ -457,8 +457,7 @@ void execTestTx(const CTransaction& tx, uint32_t height, CTransactionRef optAuth if (optAuthTx) AddCoins(coins, *optAuthTx, height); CCustomCSView view(*pcustomcsview); - uint64_t gasUsed{}; - res = CustomTxVisit(view, coins, tx, height, Params().GetConsensus(), txMessage, ::ChainActive().Tip()->nTime, gasUsed); + res = CustomTxVisit(view, coins, tx, height, Params().GetConsensus(), txMessage, ::ChainActive().Tip()->nTime); } if (!res) { if (res.code == CustomTxErrCodes::NotEnoughBalance) {