From ab4c817c730b3b6d8c2c77fce103817de5fdcc3e Mon Sep 17 00:00:00 2001 From: jimboj Date: Mon, 26 Aug 2024 15:04:19 +0800 Subject: [PATCH] respond to feedback --- lib/runtime/wazero/imports.go | 39 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/runtime/wazero/imports.go b/lib/runtime/wazero/imports.go index 32535f5774d..b077d197311 100644 --- a/lib/runtime/wazero/imports.go +++ b/lib/runtime/wazero/imports.go @@ -2124,30 +2124,35 @@ func ext_storage_clear_prefix_version_2(ctx context.Context, m api.Module, prefi limitPtr = &maxLimit } - if !bytes.HasPrefix(prefix, childStorageKeyPrefix) { - numRemoved, all, err := storage.ClearPrefixLimit(prefix, *limitPtr) + if bytes.HasPrefix(prefix, childStorageKeyPrefix) { + logger.Warnf("cannot clear child prefix: 0x%x", prefix) + encBytes, err := toKillStorageResultEnum(false, 0) if err != nil { - logger.Errorf("failed to clear prefix limit: %s", err) panic(err) } - encBytes, err := toKillStorageResultEnum(all, numRemoved) - if err != nil { - logger.Errorf("failed to allocate memory: %s", err) - panic(err) - } + valueSpan := mustWrite(m, rtCtx.Allocator, encBytes) + return valueSpan + } - valueSpan, err := write(m, rtCtx.Allocator, encBytes) - if err != nil { - logger.Errorf("failed to allocate: %s", err) - panic(err) - } + numRemoved, all, err := storage.ClearPrefixLimit(prefix, *limitPtr) + if err != nil { + logger.Errorf("failed to clear prefix limit: %s", err) + panic(err) + } - return valueSpan - } else { - logger.Warnf("cannot clear prefix that is part of or contains a child storage key") + encBytes, err := toKillStorageResultEnum(all, numRemoved) + if err != nil { + logger.Errorf("failed to allocate memory: %s", err) + panic(err) } - return 0 + + valueSpan, err := write(m, rtCtx.Allocator, encBytes) + if err != nil { + logger.Errorf("failed to allocate: %s", err) + panic(err) + } + return valueSpan } func ext_storage_exists_version_1(ctx context.Context, m api.Module, keySpan uint64) uint32 {