Skip to content

'Error: Uint8Array expected' when trying to delete from a trie with 'useNodePruning' enabled #3333

@bogdan-rosianu

Description

@bogdan-rosianu

package.json: "@ethereumjs/trie": "^6.2.0",

I have isolated the issue within an unit test:

it("test trie deletion", async () => {
    const trie = new Trie({ db: new MapDB(), useRootPersistence: true, useNodePruning: true });
    
    await trie.put(utf8ToBytes("key1"), utf8ToBytes("value1"));
    await trie.put(utf8ToBytes("key2"), utf8ToBytes("value2"));
    await trie.del(utf8ToBytes("key1"));
    expect(bytesToHex(trie.root())).toBe("0x9fabdc1cccb1e3a1fa5d991a12087b54360ea47811b36acc1193e2d9ede0cdef");
  });

This will fail when trying to delete with this error:

Error: Uint8Array expected

    at bytesToHex (.../node_modules/@noble/hashes/src/utils.ts:49:30)
    at .../node_modules/@ethereumjs/trie/src/db/checkpoint.ts:247:36
    at Array.map (<anonymous>)
    at CheckpointDB.batch (.../node_modules/@ethereumjs/trie/src/db/checkpoint.ts:240:36)
    at Trie.saveStack (.../node_modules/@ethereumjs/trie/src/trie.ts:1079:20)
    at Trie._deleteNode (.../node_modules/@ethereumjs/trie/src/trie.ts:1033:18)

Switching to useNodePruning: false fixes this issue.

Not sure if expected or not.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions