ai review nits fixes of host functions (#6963)

This commit is contained in:
pwang200
2026-04-30 13:56:55 -04:00
committed by GitHub
parent ce2586c039
commit 1600b3e7f3
3 changed files with 17 additions and 14 deletions

View File

@@ -293,7 +293,8 @@ private:
int64_t gas,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports);
ImportVec const& imports,
beast::Journal j);
NotTEC
checkHlp(
@@ -301,7 +302,8 @@ private:
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports);
ImportVec const& imports,
beast::Journal j);
int
addModule(Bytes const& wasmCode, bool instantiate, ImportVec const& imports, int64_t gas);

View File

@@ -491,6 +491,7 @@ isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
if (auto const ret = hf->isAmendmentEnabled(uint256::fromVoid(slice->data()));
ret && *ret == 1)
return returnResult(runtime, params, results, ret, index);
// Fall through to string lookup — the 32 bytes may be an amendment name
}
if (slice->size() > 64)

View File

@@ -756,24 +756,22 @@ WasmiEngine::run(
ImportVec const& imports,
beast::Journal j)
{
j_ = j;
if (gas <= 0)
return Unexpected<TER>(temBAD_AMOUNT);
try
{
checkImports(imports, &hfs);
return runHlp(wasmCode, hfs, gas, funcName, params, imports);
return runHlp(wasmCode, hfs, gas, funcName, params, imports, j);
}
catch (std::exception const& e)
{
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j_);
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j);
}
// LCOV_EXCL_START
catch (...)
{
print_wasm_error(std::string("exception: unknown"), nullptr, j_);
print_wasm_error(std::string("exception: unknown"), nullptr, j);
}
// LCOV_EXCL_STOP
return Unexpected<TER>(tecFAILED_PROCESSING);
@@ -786,10 +784,12 @@ WasmiEngine::runHlp(
int64_t gas,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports)
ImportVec const& imports,
beast::Journal j)
{
// currently only 1 module support, possible parallel UT run
std::lock_guard<decltype(m_)> const lg(m_);
j_ = j;
if (wasmCode.empty())
throw std::runtime_error("empty module");
@@ -861,21 +861,19 @@ WasmiEngine::check(
ImportVec const& imports,
beast::Journal j)
{
j_ = j;
try
{
checkImports(imports, &hfs);
return checkHlp(wasmCode, hfs, funcName, params, imports);
return checkHlp(wasmCode, hfs, funcName, params, imports, j);
}
catch (std::exception const& e)
{
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j_);
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j);
}
// LCOV_EXCL_START
catch (...)
{
print_wasm_error(std::string("exception: unknown"), nullptr, j_);
print_wasm_error(std::string("exception: unknown"), nullptr, j);
}
// LCOV_EXCL_STOP
@@ -888,10 +886,12 @@ WasmiEngine::checkHlp(
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports)
ImportVec const& imports,
beast::Journal j)
{
// currently only 1 module support, possible parallel UT run
std::lock_guard<decltype(m_)> const lg(m_);
j_ = j;
// Create and instantiate the module.
if (wasmCode.empty())