Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
morebtcg authored and JimmyShi22 committed Apr 10, 2024
1 parent c8f106e commit 0b32a5c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions bcos-executor/src/CallParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct CallParameters
// delegateCall
bool delegateCall = false;
bytes delegateCallCode;
h256 delegateCallCodeHash;
std::string delegateCallSender;

std::string toString()
Expand Down
23 changes: 10 additions & 13 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ CallParameters::UniquePtr TransactionExecutive::externalCall(CallParameters::Uni

bool needTryFromContractTable = m_blockContext.lock()->features().get(
ledger::Features::Flag::bugfix_call_noaddr_return);
auto codeEntry = getCodeByContractTableName(tableName, needTryFromContractTable);
auto [codeHash, codeEntry] =
getCodeByContractTableName(tableName, needTryFromContractTable);
if (codeEntry && codeEntry.has_value() && !codeEntry->get().empty())
{
input->delegateCallCodeHash = codeHash;
input->delegateCallCode = toBytes(codeEntry->get());
}
else
Expand Down Expand Up @@ -170,7 +172,8 @@ CallParameters::UniquePtr TransactionExecutive::externalCall(CallParameters::Uni

bool needTryFromContractTable = m_blockContext.lock()->features().get(
ledger::Features::Flag::bugfix_call_noaddr_return);
auto codeEntry = getCodeByContractTableName(tableName, needTryFromContractTable);
auto [codeHash, codeEntry] =
getCodeByContractTableName(tableName, needTryFromContractTable);
if (codeEntry && codeEntry.has_value() && !codeEntry->get().empty())
{
output->data = toBytes(codeEntry->get());
Expand Down Expand Up @@ -268,30 +271,24 @@ std::optional<storage::Entry> TransactionExecutive::getCodeByHash(const std::str
{
return entry;
}
else
{
return {};
}
return {};
}

std::optional<storage::Entry> TransactionExecutive::getCodeByContractTableName(
std::tuple<h256, std::optional<storage::Entry>> TransactionExecutive::getCodeByContractTableName(
const std::string_view& contractTableName, bool tryFromContractTable)
{
auto hash = getCodeHash(contractTableName);
auto entry = getCodeByHash(std::string_view((char*)hash.data(), hash.size()));
if (entry && entry.has_value() && !entry->get().empty())
{
return entry;
return {hash, std::move(entry)};
}

if (tryFromContractTable)
{
return getCodeEntryFromContractTable(contractTableName);
}
else
{
return {};
return {hash, getCodeEntryFromContractTable(contractTableName)};
}
return {};
}


Expand Down
6 changes: 5 additions & 1 deletion bcos-executor/src/executive/TransactionExecutive.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ class TransactionExecutive : public std::enable_shared_from_this<TransactionExec
std::optional<storage::Entry> getCodeEntryFromContractTable(
const std::string_view contractTableName);
std::optional<storage::Entry> getCodeByHash(const std::string_view& codeHash);
std::optional<storage::Entry> getCodeByContractTableName(

bool setCode(std::string_view contractTableName,
std::variant<std::string_view, std::string, bcos::bytes> code);
void setAbiByCodeHash(std::string_view codeHash, std::string_view abi);
std::tuple<h256, std::optional<storage::Entry>> getCodeByContractTableName(
const std::string_view& contractTableName, bool needTryFromContractTable = true);

protected:
Expand Down
13 changes: 10 additions & 3 deletions bcos-executor/src/vm/DelegateHostContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ using namespace bcos::executor;

DelegateHostContext::DelegateHostContext(CallParameters::UniquePtr callParameters,
std::shared_ptr<TransactionExecutive> executive, std::string tableName)
: HostContext(std::move(callParameters), executive, tableName)
: HostContext(std::move(callParameters), std::move(executive), std::move(tableName))
{
if (!getCallParameters()->delegateCall)
{
EXECUTOR_LOG(FATAL) << "Construct a DelegateHostContext using non delegateCall params"
<< getCallParameters()->toFullString();
exit(1);
}
m_codeHash = getCallParameters()->delegateCallCodeHash;
setCode(getCallParameters()->delegateCallCode);

m_delegateCallSender = getCallParameters()->delegateCallSender;
m_thisAddress = getCallParameters()->receiveAddress;
}
Expand All @@ -27,7 +29,11 @@ bool DelegateHostContext::setCode(bytes code)
storage::Entry codeEntry;
codeEntry.importFields({code});
m_code = codeEntry;
m_codeHash = hashImpl()->hash(code);
if (m_codeHash == h256{})
{
m_codeHash = hashImpl()->hash(code);
}

return true;
}

Expand All @@ -38,7 +44,8 @@ h256 DelegateHostContext::codeHash()

std::string_view DelegateHostContext::myAddress() const
{
if (this->features().get(ledger::Features::Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy))
if (this->features().get(
ledger::Features::Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy))
{
return m_thisAddress;
}
Expand Down

0 comments on commit 0b32a5c

Please sign in to comment.