Skip to content

Commit

Permalink
4227
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Feb 20, 2024
1 parent c446ff0 commit 069695b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
30 changes: 20 additions & 10 deletions bcos-executor/src/executive/CoroutineTransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CallParameters::UniquePtr CoroutineTransactionExecutive::start(CallParameters::U

m_exchangeMessage = execute(std::move(callParameters));

if (m_blockContext.features().get(ledger::Features::Flag::bugfix_dmc_revert))
if (m_blockContext.lock()->features().get(ledger::Features::Flag::bugfix_dmc_revert))
{
m_exchangeMessage = waitingFinish(std::move(m_exchangeMessage));
}
Expand Down Expand Up @@ -92,27 +92,37 @@ CallParameters::UniquePtr CoroutineTransactionExecutive::externalCall(
// When resume, exchangeMessage set to output
auto output = std::move(m_exchangeMessage);

if (output->delegateCall && output->type != CallParameters::FINISHED)
if (m_blockContext.lock()->features().get(ledger::Features::Flag::bugfix_call_noaddr_return))
{
output->data = bytes();
if (m_blockContext.lock()->features().get(
ledger::Features::Flag::bugfix_call_noaddr_return))
if (output->delegateCall &&
output->status == (int32_t)bcos::protocol::TransactionStatus::CallAddressError)
{
// 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->data = bytes();
output->type = CallParameters::FINISHED;
output->status = (int32_t)bcos::protocol::TransactionStatus::None;
output->evmStatus = EVMC_SUCCESS;

EXECUTIVE_LOG(DEBUG) << "Could not getCode during DMC externalCall, but return success"
<< LOG_KV("codeAddress", output->codeAddress)
<< LOG_KV("status", output->status)
<< LOG_KV("evmStatus", output->evmStatus);
}
else
}
else
{
if (output->delegateCall && output->type != CallParameters::FINISHED)
{
output->data = bytes();
output->status = (int32_t)bcos::protocol::TransactionStatus::RevertInstruction;
output->evmStatus = EVMC_REVERT;

EXECUTIVE_LOG(DEBUG) << "Could not getCode during DMC externalCall"
<< LOG_KV("codeAddress", output->codeAddress)
<< LOG_KV("status", output->status)
<< LOG_KV("evmStatus", output->evmStatus);
}
EXECUTIVE_LOG(DEBUG) << "Could not getCode during DMC externalCall"
<< LOG_KV("codeAddress", output->codeAddress)
<< LOG_KV("status", output->status)
<< LOG_KV("evmStatus", output->evmStatus);
}

// After coroutine switch, set the recoder
Expand Down
17 changes: 13 additions & 4 deletions bcos-scheduler/src/DmcExecutor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "DmcExecutor.h"
#include "bcos-crypto/bcos-crypto/ChecksumAddress.h"
#include "bcos-framework/executor/ExecuteError.h"
#include <bcos-protocol/TransactionStatus.h>
#include <boost/format.hpp>


Expand Down Expand Up @@ -384,6 +385,7 @@ DmcExecutor::MessageHint DmcExecutor::handleExecutiveMessage(ExecutiveState::Ptr
<< "Could not getCode() from correspond executor during delegateCall: "
<< message->toString();
message->setType(protocol::ExecutionMessage::REVERT);
message->setStatus((int32_t)protocol::TransactionStatus::CallAddressError);
message->setCreate(false);
message->setKeyLocks({});
return MessageHint::NEED_PREPARE;
Expand Down Expand Up @@ -455,10 +457,6 @@ DmcExecutor::MessageHint DmcExecutor::handleExecutiveMessageV2(ExecutiveState::P
{
if (executiveState->message->data().toBytes() == bcos::protocol::GET_CODE_INPUT_BYTES)
{
auto newSeq = executiveState->currentSeq++;
executiveState->callStack.push(newSeq);
executiveState->message->setSeq(newSeq);

// getCode
DMC_LOG(DEBUG) << "Get external code in scheduler"
<< LOG_KV("codeAddress", executiveState->message->delegateCallAddress());
Expand All @@ -468,6 +466,9 @@ DmcExecutor::MessageHint DmcExecutor::handleExecutiveMessageV2(ExecutiveState::P
<< LOG_KV("codeSize", code.size());
executiveState->message->setData(code);
executiveState->message->setType(protocol::ExecutionMessage::PRE_FINISH);

executiveState->isRevertStackMessage = true;

return MessageHint::NEED_PREPARE;
}

Expand All @@ -494,6 +495,7 @@ DmcExecutor::MessageHint DmcExecutor::handleExecutiveMessageV2(ExecutiveState::P
<< "Could not getCode() from correspond executor during delegateCall: "
<< message->toString();
message->setType(protocol::ExecutionMessage::REVERT);
message->setStatus((int32_t)protocol::TransactionStatus::CallAddressError);
message->setCreate(false);
message->setKeyLocks({});

Expand All @@ -510,6 +512,13 @@ DmcExecutor::MessageHint DmcExecutor::handleExecutiveMessageV2(ExecutiveState::P
// Return type, pop stack
case protocol::ExecutionMessage::PRE_FINISH:
{
if (executiveState->isRevertStackMessage)
{
// handle schedule in message
executiveState->isRevertStackMessage = false;
return MessageHint::NEED_SEND;
}

// update my key locks in m_keyLocks
m_keyLocks->batchAcquireKeyLock(
message->from(), message->keyLocks(), message->contextID(), message->seq());
Expand Down

0 comments on commit 069695b

Please sign in to comment.