feat: vm.PrecompileEnvironment
access to block info
#27
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.
Why this should be merged
Provides all extra block context required by stateful precompiles.
The warp precompile is dependent on a transformation (i.e. validation) of access lists, which is stored in
types.Header.Extra
, which is also made available.Closes #23
How this works
vm.BlockContext
has a*types.Header
field added as an all-purpose carrier of context not otherwise included. Although there are many places that construct aBlockContext
,core.NewEVMBlockContext()
is in the hot path of most (and also has atypes.Header
argument) so it populates the new field.A shallow copy of the header is available through
vm.PrecompileEnvironment.BlockHeader()
. Note that this returns an error if theBlockContext.Header
pointer is nil. If this occurs then we can track the code path that led to creation of theBlockContext
and populate it as necessary.BlockNumber
andBlockTime
, although available via theHeader
are already in theBlockContext
so are exposed via their own methods, neither of which return errors.How this was tested
The existing integration test is extended to demonstrate proper plumbing of all newly accessible data. The
makeOutput()
function was becoming unwieldy so I abstracted it into a struct with aString() string
method.