Skip to content

Commit

Permalink
fix registerCaller bug and evmStatus problem
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlinlee committed Nov 30, 2023
1 parent 6a8b0f0 commit f82abe2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
18 changes: 15 additions & 3 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ CallParameters::UniquePtr TransactionExecutive::callPrecompiled(
revert();
callParameters->type = CallParameters::REVERT;
callParameters->status = (int32_t)TransactionStatus::PrecompiledError;
if (m_blockContext.blockVersion() >= (uint32_t)(bcos::protocol::BlockVersion::V3_6_VERSION))
{
callParameters->evmStatus = EVMC_REVERT;
}
callParameters->message = e.what();
}
catch (Exception const& e)
Expand Down Expand Up @@ -990,10 +994,18 @@ std::shared_ptr<precompiled::PrecompiledExecResult> TransactionExecutive::execPr
{
auto precompiled = getPrecompiled(_precompiledParams->m_precompiledAddress);

if (precompiled)
try
{
if (precompiled)
{
auto execResult = precompiled->call(shared_from_this(), _precompiledParams);
return execResult;
}
}
catch (protocol::PrecompiledError const& e)
{
auto execResult = precompiled->call(shared_from_this(), _precompiledParams);
return execResult;
EXECUTIVE_LOG(ERROR) << "Precompiled error: " << diagnostic_information(e);
BOOST_THROW_EXCEPTION(PrecompiledError(e.what()));
}
[[unlikely]] EXECUTIVE_LOG(WARNING)
<< LOG_DESC("[call]Can't find precompiled address")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void AccountPrecompiled::getAccountBalance(const std::string& accountTableName,
<< LOG_BADGE("AccountPrecompiled, getAccountBalance")
<< LOG_DESC("balance not exist, return 0 by default")
<< LOG_KV("account", accountTableName);
_callParameters->setExecResult(codec.encode(0));
BOOST_THROW_EXCEPTION(PrecompiledError("Account balance not exist!"));
return;
}
balance = u256(std::string(entry->get()));
Expand Down Expand Up @@ -351,6 +351,7 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName,
<< LOG_BADGE("AccountPrecompiled, subAccountBalance")
<< LOG_DESC("table not exist, create and initialize balance is 0");
_callParameters->setExecResult(codec.encode(int32_t(CODE_ACCOUNT_BALANCE_NOT_ENOUGH)));
BOOST_THROW_EXCEPTION(PrecompiledError("Account table not exist!"));
return;
}

Expand All @@ -366,6 +367,7 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName,
<< LOG_BADGE("AccountPrecompiled, subAccountBalance")
<< LOG_DESC("account balance not enough");
_callParameters->setExecResult(codec.encode(int32_t(CODE_ACCOUNT_BALANCE_NOT_ENOUGH)));
BOOST_THROW_EXCEPTION(PrecompiledError("Account balance is not enough!"));
return;
}
else
Expand All @@ -385,6 +387,7 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName,
Balance.importFields({boost::lexical_cast<std::string>(0)});
_executive->storage().setRow(accountTableName, ACCOUNT_BALANCE, std::move(Balance));
_callParameters->setExecResult(codec.encode(int32_t(CODE_ACCOUNT_SUB_BALANCE_FAILED)));
BOOST_THROW_EXCEPTION(PrecompiledError("Account balance is not enough!"));
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ void BalancePrecompiled::transfer(const std::shared_ptr<executor::TransactionExe
else
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_TRANSFER_FAILED)));
BOOST_THROW_EXCEPTION(protocol::PrecompiledError(
"transfer failed, subBalance failed, please check the balance try again"));
PRECOMPILED_LOG(ERROR) << BLOCK_NUMBER(blockContext.number())
<< LOG_BADGE("BalancePrecompiled") << LOG_DESC("transfer")
<< LOG_KV("from", fromStr) << LOG_KV("to", toStr)
Expand Down Expand Up @@ -383,7 +385,7 @@ void BalancePrecompiled::registerCaller(
else
{
auto callerEntry = table->getRow(accountStr);
if (callerEntry->get() == "1")
if (callerEntry && callerEntry->get() == "1")
{
_callParameters->setExecResult(
codec.encode(int32_t(CODE_REGISTER_CALLER_ALREADY_EXIST)));
Expand Down

0 comments on commit f82abe2

Please sign in to comment.