-
Notifications
You must be signed in to change notification settings - Fork 270
Types and refactoring for ACP-77 ValidatorUptime messages #1292
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
Merged
+208
−42
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c2da67d
Bump avalanchego to master
33466ce
always sign uptime messages (testing branch)
964e193
nits
a5cde37
cleanup
c363886
assign to correct `err`
0bf1de6
fix handler
dd66fa7
Merge branches 'always-sign-uptime' and 'master' of github.com:ava-la…
8b3fb1c
move ValidatorUptime type to subnet-evm
008bc37
disable always signing
48f0ab7
implement on the type itself
991ff46
remove unneeded code
fe05d33
fix ut
0747262
Merge branch 'master' into always-sign-uptime-types
c1074a5
Merge branch 'master' into always-sign-uptime-types
2841bdb
Merge branch 'master' into always-sign-uptime-types
ceyonur 17ddf82
Merge branch 'master' into always-sign-uptime-types
ceyonur 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
// (c) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package messages | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ava-labs/avalanchego/codec" | ||
"github.com/ava-labs/avalanchego/codec/linearcodec" | ||
"github.com/ava-labs/avalanchego/utils/units" | ||
) | ||
|
||
const ( | ||
CodecVersion = 0 | ||
|
||
MaxMessageSize = 24 * units.KiB | ||
) | ||
|
||
var Codec codec.Manager | ||
|
||
func init() { | ||
Codec = codec.NewManager(MaxMessageSize) | ||
lc := linearcodec.NewDefault() | ||
|
||
err := errors.Join( | ||
lc.RegisterType(&ValidatorUptime{}), | ||
Codec.RegisterCodec(CodecVersion, lc), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains hidden or 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,45 @@ | ||
// (c) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package messages | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var errWrongType = errors.New("wrong payload type") | ||
|
||
// Payload provides a common interface for all payloads implemented by this | ||
// package. | ||
type Payload interface { | ||
// Bytes returns the binary representation of this payload. | ||
Bytes() []byte | ||
|
||
// initialize the payload with the provided binary representation. | ||
initialize(b []byte) | ||
} | ||
|
||
// Signable is an optional interface that payloads can implement to allow | ||
// on-the-fly signing of incoming messages by the warp backend. | ||
type Signable interface { | ||
ceyonur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VerifyMesssage(sourceAddress []byte) error | ||
ceyonur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func Parse(bytes []byte) (Payload, error) { | ||
var payload Payload | ||
if _, err := Codec.Unmarshal(bytes, &payload); err != nil { | ||
return nil, err | ||
} | ||
payload.initialize(bytes) | ||
return payload, nil | ||
} | ||
|
||
func initialize(p Payload) error { | ||
bytes, err := Codec.Marshal(CodecVersion, &p) | ||
if err != nil { | ||
return fmt.Errorf("couldn't marshal %T payload: %w", p, err) | ||
} | ||
p.initialize(bytes) | ||
return nil | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.