You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the trie Node base type is extended in the extension and leaf node implementations (but unexpectedly, not in the branch node implementation) and it has some typing issues, such as the value() function on different node classes being typed to return a Uint8Array but it can also return null or Uint8Array[]. This issue, and other similar typing issues or class design issues should be considered and fixed if possible or notes/documented for future review. Also see this comment for more context on the problem.
The text was updated successfully, but these errors were encountered:
In order to recreate a basic example of the issue, check running npx vitest test/util/log.spec.ts in the trie package. Also navigate to and look at this code section of the onFound function in trie.ts in the src folder of the trie package:
for (const k of node.key()) {
console.log('dbg100')
console.log(node.value())
this.DEBUG && this.debug(`NextNode: ${node.value()}`, ['find_path', 'extension_node'])
if (k !== targetKey[progress]) {
result = { node: null, remaining: targetKey.slice(_progress), stack }
return
}
progress++
}
walkController.allChildren(node, keyProgress)
We debug by printing the node.value() of each node being walked.:
As can be seen above, we have Uint8Array as well as Uint8Array[] as the return type of value(), in this instance, we see a branch node that has embedded leaf nodes being represented as an array.
The issue here is that the return type of node.value() is left ambiguous and this causes issues when e.g. passing the value to a conversion function that is strictly expecting a Uint8Array-typed input, such as bytesToHex. It seems like value() should be typed as returning Uint8Array | null | Uint8Array[].
Currently, the trie
Node
base type is extended in the extension and leaf node implementations (but unexpectedly, not in the branch node implementation) and it has some typing issues, such as thevalue()
function on different node classes being typed to return aUint8Array
but it can also returnnull
orUint8Array[]
. This issue, and other similar typing issues or class design issues should be considered and fixed if possible or notes/documented for future review. Also see this comment for more context on the problem.The text was updated successfully, but these errors were encountered: