exposing GetCodeHash in StateDB interface #455
+1
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Expose
GetCodeHash
(already merged and exposed in Geth) in thetracing.StateDB
Interface for Improved Tracing PerformanceDescription
This PR proposes exposing the
GetCodeHash
method in thetracing.StateDB
interface. This method is already implemented internally but is not currently publicly accessible. Additionally, it's already exposed in geth https://github.com/ethereum/go-ethereum/blob/c0882429f032da58620bcaa610007939aa7e0adb/core/tracing/hooks.go#L45Motivation
The
GetCodeHash
method allows direct retrieval of the code hash for a given address without recomputing it. Without this, users must resort to a workaround like:This approach involves:
Both steps are computationally expensive, especially when performed repeatedly in tracing scenarios. This inefficiency is particularly problematic for live tracing, where synchronous tracing occurs directly on the node. High overhead in this process can block or slow down the node, leading to potential tracing and block discovery delays.
Proven Results
This method is already exposed and utilized in native Go-Ethereum (
geth
), where it has delivered significant performance improvements in tracing workflows. By avoiding redundant code fetching and hashing, tools relying on this method have observed a substantial reduction in tracing overhead.Impact
Exposing
GetCodeHash
in thetracing.StateDB
interface will:Implementation
This change makes the existing
GetCodeHash
method publicly accessible via thetracing.StateDB
interface, ensuring it can be utilized by external tracing tools without altering its internal logic.Testing
Given the method is already implemented and in use internally, no changes were made to its core logic. Standard interface exposure testing ensures compatibility.
Example Usage
With this change, users (especially live tracers) can directly call:
This removes the need to manually fetch and hash code, streamlining tracing workflows.
Exposing
GetCodeHash
in thetracing.StateDB
interface is a minimal yet impactful change that aligns with best practices and has proven benefits, as seen in native Go-Ethereum. This improvement is expected to significantly enhance the performance and reliability of tracing tools within the Optimism ecosystem.