-
Notifications
You must be signed in to change notification settings - Fork 140
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
predicate results: alternate approach (similar to master) #679
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// (c) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package params | ||
|
||
// GetPredicateResultBytes returns the predicate result bytes from extraData. If | ||
// extraData is too short to include predicate results, it returns nil. | ||
func GetPredicateResultBytes(extraData []byte) []byte { | ||
// Prior to Durango, the VM enforces the extra data is smaller than or equal | ||
// to this size. | ||
if len(extraData) <= DynamicFeeExtraDataSize { | ||
return nil | ||
} | ||
// After Durango, the extra data past the dynamic fee rollup window represents | ||
// predicate results. | ||
return extraData[DynamicFeeExtraDataSize:] | ||
} | ||
|
||
// SetPredicateResultBytes sets the predicate results in the extraData in the | ||
// block header. This is used to set the predicate results in a block header | ||
// without modifying the initial portion of the extra data (dynamic fee window | ||
// rollup). | ||
func SetPredicateResultBytes(extraData []byte, predicateResults []byte) []byte { | ||
return append(extraData[:DynamicFeeExtraDataSize], predicateResults...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// (c) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package params | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ava-labs/avalanchego/utils" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPredicateResultsBytes(t *testing.T) { | ||
require := require.New(t) | ||
dataTooShort := utils.RandomBytes(DynamicFeeExtraDataSize - 1) | ||
resultBytes := GetPredicateResultBytes(dataTooShort) | ||
require.Empty(resultBytes) | ||
|
||
preDurangoData := utils.RandomBytes(DynamicFeeExtraDataSize) | ||
resultBytes = GetPredicateResultBytes(preDurangoData) | ||
require.Empty(resultBytes) | ||
postDurangoData := utils.RandomBytes(DynamicFeeExtraDataSize + 2) | ||
resultBytes = GetPredicateResultBytes(postDurangoData) | ||
require.Equal(resultBytes, postDurangoData[DynamicFeeExtraDataSize:]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
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.
what is the cyclic import that prevents us to have these in predicate pkg?
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.
predicates imports params which needs to import predicates again to parse the predicates to make the block context for the precompiles.
I'm somewhat hopeful that we can fix this by finding a better location for the libevm hooks other than "params", which we can address next.
also I mildly dislike that the predicates package needs to know about the length of the dynamic fee window.
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.
If the dynamic fee window is the only reason we're importing params package I think it's fine to copy/move it to predicate pkg and move these util functions there
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.
params in general is a really bad package for constants, and in our case it's even worse.