diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 9707325fee..0b019342b7 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -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) @@ -990,10 +994,18 @@ std::shared_ptr 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") diff --git a/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp b/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp index 31d072c553..36bbaf071f 100644 --- a/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp +++ b/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp @@ -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())); @@ -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; } @@ -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 @@ -385,6 +387,7 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName, Balance.importFields({boost::lexical_cast(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; } } \ No newline at end of file diff --git a/bcos-executor/src/precompiled/extension/BalancePrecompiled.cpp b/bcos-executor/src/precompiled/extension/BalancePrecompiled.cpp index 325caf4858..663c505579 100644 --- a/bcos-executor/src/precompiled/extension/BalancePrecompiled.cpp +++ b/bcos-executor/src/precompiled/extension/BalancePrecompiled.cpp @@ -328,6 +328,8 @@ void BalancePrecompiled::transfer(const std::shared_ptrsetExecResult(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) @@ -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)));