cache data instead of setting it in updateData (#5642)

Co-authored-by: Oleksandr <115580134+oleks-rip@users.noreply.github.com>
This commit is contained in:
Mayukha Vadari
2025-08-11 15:52:21 -04:00
committed by GitHub
parent c15947da56
commit 5dc0cee28a
4 changed files with 14 additions and 13 deletions

View File

@@ -1373,14 +1373,6 @@ struct WasmHostFuncImpl_test : public beast::unit_test::suite
if (BEAST_EXPECT(!tooBig.has_value()))
BEAST_EXPECT(
tooBig.error() == HostFunctionError::DATA_FIELD_TOO_LARGE);
// Should fail if ledger object not found (use a bogus keylet)
auto const bogusKeylet = keylet::escrow(env.master, 999999);
WasmHostFunctionsImpl hfs2(ac, bogusKeylet);
auto const notFound = hfs2.updateData(Slice(data.data(), data.size()));
if (BEAST_EXPECT(!notFound.has_value()))
BEAST_EXPECT(
notFound.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND);
}
void

View File

@@ -453,11 +453,7 @@ WasmHostFunctionsImpl::updateData(Slice const& data)
{
return Unexpected(HostFunctionError::DATA_FIELD_TOO_LARGE);
}
auto sle = ctx.view().peek(leKey);
if (!sle)
return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND);
sle->setFieldVL(sfData, data);
ctx.view().update(sle);
data_ = Bytes(data.begin(), data.end());
return 0;
}

View File

@@ -32,6 +32,7 @@ class WasmHostFunctionsImpl : public HostFunctions
static int constexpr MAX_CACHE = 256;
std::array<std::shared_ptr<SLE const>, MAX_CACHE> cache;
std::optional<Bytes> data_;
void const* rt_ = nullptr;
@@ -75,6 +76,12 @@ public:
return ctx.journal;
}
std::optional<Bytes> const&
getData() const
{
return data_;
}
Expected<std::uint32_t, HostFunctionError>
getLedgerSqn() override;

View File

@@ -1279,6 +1279,12 @@ EscrowFinish::doApply()
auto re = runEscrowWasm(
wasm, ESCROW_FUNCTION_NAME, {}, &ledgerDataProvider, allowance);
JLOG(j_.trace()) << "Escrow WASM ran";
if (auto const& data = ledgerDataProvider.getData(); data.has_value())
{
slep->setFieldVL(sfData, makeSlice(*data));
}
if (re.has_value())
{
auto reValue = re.value().result;