diff --git a/lib/runtime/storage/trie.go b/lib/runtime/storage/trie.go index ebd3b4b76a6..eede3103bb2 100644 --- a/lib/runtime/storage/trie.go +++ b/lib/runtime/storage/trie.go @@ -189,7 +189,8 @@ func (s *TrieState) DeleteChildLimit(key []byte, limit *[]byte) ( return 0, false, err } - qtyEntries := uint32(len(tr.Entries())) + childTrieEntries := tr.Entries() + qtyEntries := uint32(len(childTrieEntries)) if limit == nil { err = s.t.DeleteChild(key) if err != nil { @@ -200,8 +201,8 @@ func (s *TrieState) DeleteChildLimit(key []byte, limit *[]byte) ( } limitUint := binary.LittleEndian.Uint32(*limit) - keys := make([]string, 0, len(tr.Entries())) - for k := range tr.Entries() { + keys := make([]string, 0, qtyEntries) + for k := range childTrieEntries { keys = append(keys, k) } sort.Strings(keys) diff --git a/lib/runtime/wasmer/imports_test.go b/lib/runtime/wasmer/imports_test.go index 7061110a773..c2d0efda051 100644 --- a/lib/runtime/wasmer/imports_test.go +++ b/lib/runtime/wasmer/imports_test.go @@ -1502,7 +1502,7 @@ func Test_ext_default_child_storage_storage_kill_version_2_limit_all(t *testing. child, err = inst.ctx.Storage.GetChild(testChildKey) require.NoError(t, err) - require.Equal(t, 0, len(child.Entries())) + require.Empty(t, child.Entries()) } func Test_ext_default_child_storage_storage_kill_version_2_limit_1(t *testing.T) {