Skip to content

Commit

Permalink
fix call_no_addr_return bug && fix small log bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Jan 10, 2024
1 parent b02da97 commit 7fe618d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 34 deletions.
89 changes: 58 additions & 31 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,43 +124,58 @@ CallParameters::UniquePtr TransactionExecutive::externalCall(CallParameters::Uni

// get codeHash in contract table
auto codeHashEntry = storage().getRow(tableName, ACCOUNT_CODE_HASH);
if (!codeHashEntry || codeHashEntry->get().empty())
do
{
auto& output = input;
EXECUTIVE_LOG(DEBUG) << "Could not getCodeHash during externalCall"
<< LOG_KV("codeAddress", input->codeAddress);

output->data = bytes();
if (m_blockContext.features().get(ledger::Features::Flag::bugfix_call_noaddr_return))
if (!codeHashEntry || codeHashEntry->get().empty())
{
// This is eth's bug, but we still need to compat with it :)
// https://docs.soliditylang.org/en/v0.8.17/control-structures.html#error-handling-assert-require-revert-and-exceptions
output->status = (int32_t)TransactionStatus::None;
output->evmStatus = EVMC_SUCCESS;
auto& output = input;
EXECUTIVE_LOG(DEBUG) << "Could not getCodeHash during externalCall"
<< LOG_KV("codeAddress", input->codeAddress);

if (m_blockContext.features().get(
ledger::Features::Flag::bugfix_call_noaddr_return))
{
auto entry = storage().getRow(tableName, ACCOUNT_CODE);
if (entry && !entry->get().empty())
{
input->delegateCallCode = toBytes(entry->get());
break;
}
}

output->data = bytes();
if (m_blockContext.features().get(
ledger::Features::Flag::bugfix_call_noaddr_return))
{
// This is eth's bug, but we still need to compat with it :)
// https://docs.soliditylang.org/en/v0.8.17/control-structures.html#error-handling-assert-require-revert-and-exceptions
output->status = (int32_t)TransactionStatus::None;
output->evmStatus = EVMC_SUCCESS;
}
else
{
output->status = (int32_t)TransactionStatus::RevertInstruction;
output->evmStatus = EVMC_REVERT;
}
return std::move(output);
}
else

auto codeHash = codeHashEntry->getField(0);

// get code in code binary table
auto entry = storage().getRow(bcos::ledger::SYS_CODE_BINARY, codeHash);
if (!entry || entry->get().empty())
{
auto& output = input;
EXECUTIVE_LOG(DEBUG) << "Could not getCode during externalCall"
<< LOG_KV("codeAddress", input->codeAddress);
output->data = bytes();
output->status = (int32_t)TransactionStatus::RevertInstruction;
output->evmStatus = EVMC_REVERT;
return std::move(output);
}
return std::move(output);
}

auto codeHash = codeHashEntry->getField(0);

// get code in code binary table
auto entry = storage().getRow(bcos::ledger::SYS_CODE_BINARY, codeHash);
if (!entry || entry->get().empty())
{
auto& output = input;
EXECUTIVE_LOG(DEBUG) << "Could not getCode during externalCall"
<< LOG_KV("codeAddress", input->codeAddress);
output->data = bytes();
output->status = (int32_t)TransactionStatus::RevertInstruction;
output->evmStatus = EVMC_REVERT;
return std::move(output);
}
input->delegateCallCode = toBytes(entry->get());
input->delegateCallCode = toBytes(entry->get());
} while (0);
}

if (input->data == bcos::protocol::GET_CODE_INPUT_BYTES)
Expand All @@ -175,6 +190,16 @@ CallParameters::UniquePtr TransactionExecutive::externalCall(CallParameters::Uni
auto codeHashEntry = storage().getRow(tableName, ACCOUNT_CODE_HASH);
if (!codeHashEntry || codeHashEntry->get().empty())
{
if (m_blockContext.features().get(ledger::Features::Flag::bugfix_call_noaddr_return))
{
auto entry = storage().getRow(tableName, ACCOUNT_CODE);
if (entry && !entry->get().empty())
{
output->data = toBytes(entry->get());
return std::move(output);
}
}

EXECUTIVE_LOG(DEBUG) << "Could not get external code hash from local storage"
<< LOG_KV("codeAddress", input->codeAddress);
output->data = bytes();
Expand Down Expand Up @@ -959,7 +984,9 @@ CallParameters::UniquePtr TransactionExecutive::go(

if (m_blockContext.features().get(
ledger::Features::Flag::bugfix_call_noaddr_return) &&
callResult->staticCall)
callResult->staticCall &&
callResult->seq > 0 // must staticCall from contract(not from rpc call)
)
{
// Note: to be the same as eth
// Just fix DMC:
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 @@ -133,7 +133,7 @@ evmc_result HostContext::externalRequest(const evmc_message* _msg)
evmAddress2String(_msg->sender) ==
std::string(bcos::precompiled::EVM_BALANCE_SENDER_ADDRESS))
{
// for AccountPrecompiled to sub and add
// comes from selfdestruct() getAccountBalance use EVM_BALANCE_SENDER_ADDRESS as msg->sender
request->senderAddress = std::string(bcos::precompiled::EVM_BALANCE_SENDER_ADDRESS);
}
else
Expand Down
5 changes: 3 additions & 2 deletions bcos-utilities/bcos-utilities/BoostLogInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ struct BoostLogLevelResetHandler
<< LOG_KV("logLevelStr", logLevelStr) << LOG_KV("logLevel", logLevel);
}
catch (...)
{}
{
}
}

static std::string configFile;
Expand Down Expand Up @@ -213,7 +214,7 @@ boost::shared_ptr<bcos::BoostLogInitializer::sink_t> BoostLogInitializer::initHo
std::string fileName = _logPath + "/" + _logPrefix + "_%Y%m%d%H.%M.log";

boost::shared_ptr<sink_t> sink(new sink_t());
sink->locked_backend()->set_open_mode(std::ios::app);
sink->locked_backend()->set_open_mode(std::ios::ate);
sink->locked_backend()->set_time_based_rotation(
boost::bind(&BoostLogInitializer::canRotate, this, (m_currentHourVec.size() - 1)));

Expand Down

0 comments on commit 7fe618d

Please sign in to comment.