diff --git a/peripherals/proxy/nginx.conf b/peripherals/proxy/nginx.conf index eb48460a..949577fc 100644 --- a/peripherals/proxy/nginx.conf +++ b/peripherals/proxy/nginx.conf @@ -66,7 +66,8 @@ http { add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' '*'; - return 204; + add_header 'Content-Type' 'text/html'; + return 200 'This is an API endpoint that only accepts JSON-RPC requests.
Please visit https://docs.eosnetwork.com/docs/latest/eos-evm/ for information about EOS EVM. \n'; } resolver 127.0.0.11; diff --git a/silkrpc/core/estimate_gas_oracle.cpp b/silkrpc/core/estimate_gas_oracle.cpp index 43686397..cab21da2 100644 --- a/silkrpc/core/estimate_gas_oracle.cpp +++ b/silkrpc/core/estimate_gas_oracle.cpp @@ -86,7 +86,7 @@ boost::asio::awaitable EstimateGasOracle::estimate_gas(const Call auto mid = (hi + lo) / 2; transaction.gas_limit = mid; - auto failed = co_await try_execution(transaction); + auto [failed, _]= co_await try_execution(transaction); if (failed) { lo = mid; @@ -97,10 +97,19 @@ boost::asio::awaitable EstimateGasOracle::estimate_gas(const Call if (hi == cap) { transaction.gas_limit = hi; - auto failed = co_await try_execution(transaction); + auto [failed, res] = co_await try_execution(transaction); SILKRPC_DEBUG << "HI == cap tested again with " << (failed ? "failure" : "succeed") << "\n"; if (failed) { + if(res && res->error_code != evmc_status_code::EVMC_OUT_OF_GAS) { + const auto error_message = EVMExecutor<>::get_error_message(res->error_code, res->data); + SILKRPC_DEBUG << "result message " << error_message << ", code " << res->error_code << "\n"; + if (res->data.empty()) { + throw EstimateGasException{-32000, error_message}; + } else { + throw EstimateGasException{3, error_message, res->data}; + } + } throw EstimateGasException{-1, "gas required exceeds allowance (" + std::to_string(cap) + ")"}; } } @@ -109,30 +118,19 @@ boost::asio::awaitable EstimateGasOracle::estimate_gas(const Call co_return hi; } -boost::asio::awaitable EstimateGasOracle::try_execution(const silkworm::Transaction& transaction) { +boost::asio::awaitable>> EstimateGasOracle::try_execution(const silkworm::Transaction& transaction) { const auto result = co_await executor_(transaction); - bool failed = true; if (result.pre_check_error) { SILKRPC_DEBUG << "result error " << result.pre_check_error.value() << "\n"; - throw EstimateGasException{-32000, result.pre_check_error.value()}; - } else if (result.error_code == evmc_status_code::EVMC_SUCCESS) { - SILKRPC_DEBUG << "result SUCCESS\n"; - failed = false; - } else if (result.error_code == evmc_status_code::EVMC_OUT_OF_GAS) { - SILKRPC_DEBUG << "result EVMC_OUT_OF_GAS\n"; - failed = true; - } else { - const auto error_message = EVMExecutor<>::get_error_message(result.error_code, result.data); - SILKRPC_DEBUG << "result message " << error_message << ", code " << result.error_code << "\n"; - if (result.data.empty()) { - throw EstimateGasException{-32000, error_message}; - } else { - throw EstimateGasException{3, error_message, result.data}; - } + if(!result.pre_check_error.value().starts_with("intrinsic gas too low")) + throw EstimateGasException{-32000, result.pre_check_error.value()}; + + co_return std::make_tuple>(true, {}); } - co_return failed; + bool failed = result.error_code != evmc_status_code::EVMC_SUCCESS; + co_return std::make_tuple>(std::move(failed), std::move(result)); } } // namespace silkrpc::ego diff --git a/silkrpc/core/estimate_gas_oracle.hpp b/silkrpc/core/estimate_gas_oracle.hpp index 9f5d9c6f..7ef91bdd 100644 --- a/silkrpc/core/estimate_gas_oracle.hpp +++ b/silkrpc/core/estimate_gas_oracle.hpp @@ -88,7 +88,7 @@ class EstimateGasOracle { boost::asio::awaitable estimate_gas(const Call& call, uint64_t block_number); private: - boost::asio::awaitable try_execution(const silkworm::Transaction& transaction); + boost::asio::awaitable>> try_execution(const silkworm::Transaction& transaction); const BlockHeaderProvider& block_header_provider_; const AccountReader& account_reader_;