-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
core, state: introduce code reader interface #30816
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.
I think this structure looks very nice. Just had a comment about performance of the multireader.
This might be a stupid suggestion, but what do you think about renaming the interface a little bit like this:
Makes the name of the interface a bit longer, but the methods themselves a bit shorter and a user will still understand that this Reader is for contract code |
@MariusVanDerWijden applied! |
@s1na @MariusVanDerWijden I have updated the implementation, please take another look. |
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
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
if cached, ok := r.codeSizeCache.Get(codeHash); ok { | ||
return cached, nil | ||
} | ||
code, err := r.Code(addr, codeHash) |
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.
Shouldn't you add it to the code/codeSize caches too, before returning?
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 codeSizeCache is filled in the r.Code(addr, codeHash)
call.
It's a little bit weird, I can change it if you want.
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.
Oh right, yeah never mind!
It's an alternative of #30808
This PR introduces a
ContractCodeReader
interface with functions defined:This interface can be implemented in various ways. Although the codebase currently includes only one implementation, additional implementations could be created for different purposes and scenarios, such as a code reader designed for the Verkle tree approach or one that reads code from the witness.
Notably, this interface modifies the function’s semantics. If the contract code is not found, no error will be returned. An error should only be returned in the event of an unexpected issue, primarily for future implementations.
Besides, the original
Reader
interface is extended withContractCodeReader
, it gives us more flexibility to manipulate the reader with additional logics on top, e.g. Hooks.