-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StateManager - _getStorageTrie
: Fix Input Checking Logic
#3434
StateManager - _getStorageTrie
: Fix Input Checking Logic
#3434
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me. @holgerd77 @jochem-brouwer any opinions here before merging?
I take that back, since builds are failing. |
* @private | ||
*/ | ||
// TODO PR: have a better interface for hashed address pull? | ||
protected _getStorageTrie(addressOrHash: Address | Uint8Array, account?: Account): Trie { | ||
protected _getStorageTrie( | ||
addressOrHash: Address | { bytes: Uint8Array } | Uint8Array, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this { bytes: Uint8Array }
to the type union since it breaks the build on CI. Does this add some benefit in the specific usecase your PR addresses related to @ethereumjs/statemanager
as a sub-dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added type simply documents that the function doesn't rely on any of the properties or methods of Address
other than the bytes
property. The resulting union is no more restrictive than the original, and allows usage without instantiating a complete Address object (e.g. for unit testing).
The build failure was due to the compiler not identifying the boolean inputIsHash
flag as type narrowing via the instanceof
call. Removing the flag and making that operation inline fixed the build failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will take another look!
…//github.com/Dappsters/ethereumjs-monorepo into statemanager-fix-getStorageTrie-input-checks
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @Dappsters, just to let you know: we have a very very late release round this time - since we had (close to) no release pressure - so that issues like this only get in now (or: in 1-2 weeks on release). 😬 Apologies! |
This PR fixes input checking logic for the
StateManager._getStorageTrie
function, removes repeated code, and adds documentation.Changes
instanceof
checks against theAddress
class sometimes returnedfalse
when the package was loadedas a sub-dependency due to differing references for the class definition. This caused an error to be thrown (see example below).
Uint8Array
for type checking, which is consistent across use cases.Uint8Array
, the hashing function was called twice because the intermediate value was discarded.Uint8Array
, the intermediate value is reused and the hashing function is only called once.Resolved Issues
Fixes an error condition when the package is loaded as a sub-dependency causing inconsistent
instanceof Address
evaluations that resulted in the incorrect value being passed to thebytesToUnprefixedHex
function which then throws an error.'Bad' project dependencies structure:
Thrown error example for reference:
Notes
The pre-existing comment
// TODO PR: have a better interface for hashed address pull?
references discussion from #3031, which states that the function may be removed as part of an ongoing cleanup effort in #3117. Because #3117 appears to be relatively inactive, this PR is still needed for the immediate future. The comment was left as-is.