Skip to content

Commit

Permalink
<fix>(dmc): Fix dmc deploy no gasUsed bug && use use isDynamicPrecomp…
Browse files Browse the repository at this point in the history
…iledAccountCode to check account (FISCO-BCOS#4400)
  • Loading branch information
JimmyShi22 authored Apr 23, 2024
1 parent c3075f2 commit 5b71bcd
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
6 changes: 3 additions & 3 deletions bcos-executor/src/executor/TransactionExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions bcos-executor/src/precompiled/common/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ inline std::string getDynamicPrecompiledCodeString(
return boost::join(std::vector<std::string>({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')
Expand Down
2 changes: 1 addition & 1 deletion bcos-executor/src/vm/HostContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion bcos-framework/bcos-framework/ledger/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)) ||
Expand Down
2 changes: 1 addition & 1 deletion bcos-framework/bcos-framework/protocol/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>::max();
const uint8_t MIN_MAJOR_VERSION = 3;
Expand Down
1 change: 1 addition & 0 deletions bcos-framework/test/unittests/interfaces/FeaturesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion bcos-scheduler/src/BlockExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tools/.ci/java_sdk_demo_ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5b71bcd

Please sign in to comment.