diff --git a/bcos-executor/src/executor/TransactionExecutor.cpp b/bcos-executor/src/executor/TransactionExecutor.cpp index 0158f2532b..9e7a1899ae 100644 --- a/bcos-executor/src/executor/TransactionExecutor.cpp +++ b/bcos-executor/src/executor/TransactionExecutor.cpp @@ -2073,14 +2073,14 @@ void TransactionExecutor::getCode( auto code = entry->getField(0); if (m_blockContext->features().get( ledger::Features::Flag::bugfix_eoa_as_contract) && - hasPrecompiledPrefix(code)) + bcos::precompiled::isDynamicPrecompiledAccountCode(code)) { - EXECUTOR_NAME_LOG(INFO) << "Get eoa code success"; + EXECUTOR_NAME_LOG(DEBUG) << "Get eoa code success, return empty code to evm"; callback(nullptr, bcos::bytes()); } else { - EXECUTOR_NAME_LOG(INFO) + EXECUTOR_NAME_LOG(DEBUG) << "Get code success" << LOG_KV("code size", code.size()); auto codeBytes = bcos::bytes(code.begin(), code.end()); callback(nullptr, std::move(codeBytes)); diff --git a/bcos-executor/src/precompiled/common/Utilities.h b/bcos-executor/src/precompiled/common/Utilities.h index a81a87e774..587b2e6a7b 100644 --- a/bcos-executor/src/precompiled/common/Utilities.h +++ b/bcos-executor/src/precompiled/common/Utilities.h @@ -87,6 +87,11 @@ inline std::string getDynamicPrecompiledCodeString( return boost::join(std::vector({PRECOMPILED_CODE_FIELD, _address, _params}), ","); } +inline bool isDynamicPrecompiledAccountCode(const std::string_view& _code) +{ + return std::string_view(getDynamicPrecompiledCodeString(ACCOUNT_ADDRESS, "")) == _code; +} + inline std::string trimHexPrefix(const std::string& _hex) { if (_hex.size() >= 2 && _hex[1] == 'x' && _hex[0] == '0') diff --git a/bcos-executor/src/vm/HostContext.cpp b/bcos-executor/src/vm/HostContext.cpp index 2f1baa9731..8e9e8c8197 100644 --- a/bcos-executor/src/vm/HostContext.cpp +++ b/bcos-executor/src/vm/HostContext.cpp @@ -485,7 +485,7 @@ bcos::bytes HostContext::externalCodeRequest(const std::string_view& address) if (m_executive->blockContext().features().get( ledger::Features::Flag::bugfix_eoa_as_contract) && - hasPrecompiledPrefix(fromBytes(response->data))) + precompiled::isDynamicPrecompiledAccountCode(fromBytes(response->data))) { return bytes(); } diff --git a/bcos-framework/bcos-framework/ledger/Features.h b/bcos-framework/bcos-framework/ledger/Features.h index e7bb50259c..11ff976a01 100644 --- a/bcos-framework/bcos-framework/ledger/Features.h +++ b/bcos-framework/bcos-framework/ledger/Features.h @@ -42,6 +42,7 @@ class Features bugfix_empty_abi_reset, // support empty abi reset of same code bugfix_eip55_addr, bugfix_eoa_as_contract, + bugfix_dmc_deploy_gas_used, feature_dmc2serial, feature_sharding, feature_rpbft, @@ -154,7 +155,8 @@ class Features {Flag::bugfix_empty_abi_reset, Flag::bugfix_eip55_addr, Flag::bugfix_sharding_call_in_child_executive, Flag::bugfix_internal_create_permission_denied}}, - {protocol::BlockVersion::V3_7_3_VERSION, {Flag::bugfix_eoa_as_contract}}}); + {protocol::BlockVersion::V3_7_3_VERSION, + {Flag::bugfix_eoa_as_contract, Flag::bugfix_dmc_deploy_gas_used}}}); for (const auto& upgradeFeatures : upgradeRoadmap) { if (((to < protocol::BlockVersion::V3_2_7_VERSION) && (to >= upgradeFeatures.to)) || diff --git a/bcos-framework/bcos-framework/protocol/Protocol.h b/bcos-framework/bcos-framework/protocol/Protocol.h index cdbd1f50e3..31eada485c 100644 --- a/bcos-framework/bcos-framework/protocol/Protocol.h +++ b/bcos-framework/bcos-framework/protocol/Protocol.h @@ -149,7 +149,7 @@ enum class TransactionVersion : uint32_t const std::string RC4_VERSION_STR = "3.0.0-rc4"; const std::string RC_VERSION_PREFIX = "3.0.0-rc"; -const BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_7_1_VERSION; +const BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_7_3_VERSION; const std::string DEFAULT_VERSION_STR = "3.7.3"; const uint8_t MAX_MAJOR_VERSION = std::numeric_limits::max(); const uint8_t MIN_MAJOR_VERSION = 3; diff --git a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp index 8ec4373c83..e6c9804209 100644 --- a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp +++ b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp @@ -142,6 +142,7 @@ BOOST_AUTO_TEST_CASE(feature) "bugfix_empty_abi_reset", "bugfix_eip55_addr", "bugfix_eoa_as_contract", + "bugfix_dmc_deploy_gas_used", "feature_dmc2serial", "feature_sharding", "feature_rpbft", diff --git a/bcos-scheduler/src/BlockExecutive.cpp b/bcos-scheduler/src/BlockExecutive.cpp index 2f45e91fe6..160f3a8d57 100644 --- a/bcos-scheduler/src/BlockExecutive.cpp +++ b/bcos-scheduler/src/BlockExecutive.cpp @@ -1578,9 +1578,20 @@ void BlockExecutive::onTxFinish(bcos::protocol::ExecutionMessage::UniquePtr outp { auto txGasUsed = m_gasLimit - output->gasAvailable(); // Calc the gas set to header + if (bcos::precompiled::c_systemTxsAddress.contains(output->from())) { - txGasUsed = 0; + // Note: We will not consume gas when EOA call sys contract directly. + // When dmc return, sys contract is from(), to() is EOA address. + // But if this tx is a deploy tx, from() is sys contract but to() is new address. + // So we need to fix this bug here: only consider output->newEVMContractAddress().empty() + // here. Leaving only EOA call sys contract here. + auto hasBugfix = m_scheduler->ledgerConfig().features().get( + ledger::Features::Flag::bugfix_dmc_deploy_gas_used); + if (!hasBugfix || (hasBugfix && output->newEVMContractAddress().empty())) + { + txGasUsed = 0; + } } m_gasUsed.fetch_add(txGasUsed); auto version = m_executiveResults[output->contextID() - m_startContextID].version; diff --git a/tools/.ci/java_sdk_demo_ci_test.sh b/tools/.ci/java_sdk_demo_ci_test.sh index 04625c8780..f3cfe58a9a 100755 --- a/tools/.ci/java_sdk_demo_ci_test.sh +++ b/tools/.ci/java_sdk_demo_ci_test.sh @@ -163,6 +163,17 @@ check_all_contract() { exit 1; fi + LOG_INFO "check block gasUsed" + local current_block_number=$(bash console.sh getBlockNumber|grep -v error) + LOG_INFO "check block gasUsed, current number is ${current_block_number}" + local gas_used=$(bash console.sh getBlockByNumber ${current_block_number} |grep gasUsed |awk -F "'" '{print $2}') + if [ ${gas_used} -ne 0 ]; then + LOG_INFO "check block gasUsed success, current gas is ${gas_used}" + else + LOG_ERROR "check block gasUsed failed, gas is ${gas_used}" + exit 1; + fi + LOG_INFO "addBalance to contract ${test_contract_address}" bash console.sh addBalance ${test_contract_address} 10000000