-
Notifications
You must be signed in to change notification settings - Fork 232
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
Add handshake codec #762
Draft
nytzuga
wants to merge
57
commits into
master
Choose a base branch
from
handshake-codec
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,363
−9
Draft
Add handshake codec #762
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
0f72644
Add handshake codec
nytzuga 89bf82c
Use 8 bytes to hash UpgradeConfig
nytzuga 19e0d18
Fixed linting issues
nytzuga 30b8aaa
Addressed PR comments
nytzuga 4a59b8a
Improve API usage
nytzuga acc8195
Rewrote configs
nytzuga a0ceae8
WIP: Optional upgrades tests
nytzuga c5d86a4
Upgrade to the latest version
nytzuga b6f8a33
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga 453c84d
Remove unknown field
nytzuga 7c507ac
Address comments from PR
nytzuga 9c954d5
Update precompile template
nytzuga a27ecc8
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga 771d511
Improve template
nytzuga c261ce2
Add more test cases
nytzuga 6fff967
Linting
nytzuga e3601b0
Remove Test config
nytzuga cade28f
Use whole hash instead of the first 8 bytes
nytzuga 6b96e44
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga a2848d7
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga d996f99
Update how optional upgrades are going to be represented internally
nytzuga 758441f
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga 634e9b5
Add ToBytes() and FromBytes() to the Config interface
nytzuga d1b37c4
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga eef61dd
Update template
nytzuga 541acd7
Update mocks
nytzuga 2309af5
Remove serialize tag
nytzuga 74e25d5
Implement custom marshal/unmarshal for all types
nytzuga f1d3d07
Use standard Marshal/Unmarshaller
nytzuga 55f4b95
Implement UpgradeConfig Marshal/Unmarshal
nytzuga d9851ca
Added Marshal / Unmarshal to OptionalNetworkUpgrades
nytzuga 1946de4
Remove sorting from AllowListConfig
nytzuga 2efae3d
Move tests to their own file
nytzuga 6785dd9
Remove all custom serializers
nytzuga 32486fe
WIP
nytzuga 8bc4f87
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga 2de9095
Do not use double pointers
nytzuga 3a1bd28
Apply suggestions from code review
nytzuga b2020cb
Update precompile/allowlist/config.go
nytzuga beb7ab8
Update precompile/allowlist/config.go
nytzuga 8192cb2
Bring back getBigIntToSerialize() until a better solution can be found
nytzuga b86226d
Merge remote-tracking branch 'origin/handshake-codec' into handshake-…
nytzuga 8935259
Remove all magic bytes
nytzuga 5c88c08
Use fixed bytes for addresses
nytzuga 1819327
Improve serialization and testing
nytzuga e079719
Use fixed bytes for addresses
nytzuga 17bf11e
Minor changes
nytzuga 91bdff5
Move UnpackAddresses/PackAddresses to utils
nytzuga a593a68
Fix typo
nytzuga 987017b
Update template
nytzuga 19b3073
Move serialization to utils
nytzuga e8ffb13
Fixed typo
nytzuga 550f7c0
Fixed typo
nytzuga a08d746
Fix typo
nytzuga e0b4b61
Merge remote-tracking branch 'origin/master' into handshake-codec
nytzuga 1bf4664
Rebase with master
nytzuga ac0e945
Add comments back
nytzuga 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ import ( | |
"fmt" | ||
"math/big" | ||
|
||
"github.com/ava-labs/avalanchego/utils/wrappers" | ||
"github.com/ava-labs/subnet-evm/utils" | ||
"github.com/docker/docker/pkg/units" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
|
@@ -144,6 +146,98 @@ func (f *FeeConfig) checkByteLens() error { | |
return nil | ||
} | ||
|
||
func (c *FeeConfig) MarshalBinary() ([]byte, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the following test cases for the serialization of
|
||
p := wrappers.Packer{ | ||
Bytes: []byte{}, | ||
MaxSize: 1 * units.MiB, | ||
} | ||
|
||
if err := utils.PackBigInt(&p, c.GasLimit); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := utils.PackBigInt(&p, c.MinBaseFee); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := utils.PackBigInt(&p, c.TargetGas); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := utils.PackBigInt(&p, c.BaseFeeChangeDenominator); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := utils.PackBigInt(&p, c.MinBlockGasCost); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := utils.PackBigInt(&p, c.MaxBlockGasCost); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := utils.PackBigInt(&p, c.BlockGasCostStep); err != nil { | ||
return nil, err | ||
} | ||
|
||
p.PackLong(c.TargetBlockRate) | ||
if p.Err != nil { | ||
return nil, p.Err | ||
} | ||
|
||
return p.Bytes, nil | ||
} | ||
|
||
func (c *FeeConfig) UnmarshalBinary(data []byte) error { | ||
p := wrappers.Packer{ | ||
Bytes: data, | ||
} | ||
|
||
var err error | ||
|
||
c.GasLimit, err = utils.UnpackBigInt(&p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.MinBaseFee, err = utils.UnpackBigInt(&p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.TargetGas, err = utils.UnpackBigInt(&p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.BaseFeeChangeDenominator, err = utils.UnpackBigInt(&p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.MinBlockGasCost, err = utils.UnpackBigInt(&p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.MaxBlockGasCost, err = utils.UnpackBigInt(&p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.BlockGasCostStep, err = utils.UnpackBigInt(&p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.TargetBlockRate = p.UnpackLong() | ||
if p.Err != nil { | ||
return p.Err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func isBiggerThanHashLen(bigint *big.Int) bool { | ||
buf := bigint.Bytes() | ||
isBigger := len(buf) > common.HashLength | ||
|
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.
can we add some comments here why these are important, how these can be implemented etc?