-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Enforce solo machine signature type uniqueness #7394
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7394 +/- ##
==========================================
+ Coverage 54.99% 55.07% +0.07%
==========================================
Files 588 588
Lines 36664 36760 +96
==========================================
+ Hits 20163 20245 +82
- Misses 14409 14417 +8
- Partials 2092 2098 +6 |
Adjusts SignatureAndData proto definition to take in a DataType. Updates misbehaviour basic validation to do checks on the data type. Adds unmarshaling tests.
…n strange error on testing codec.go
Rename CanUnmarshalDataByType -> UnmarshalDataByType. Return a new interface and error. Refactor tests to work. Refactor misbehaviour_handle.go to check unmarshaling of the data and DRY code by separating signature and data checks into its own function. Update godoc.
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.
I think this is the cleanest way of handling DataType
atm. This is one step closer to converting SignBytes
to an interface/Any.
Changing SignBytes
to an Any
would reduce one marshaling layer and isn't too far of a step now that I have added the Data
interface, but it also would make each proto data definition have sequence, timestamp, diversifier, and data type fields which is pretty redundant since we have like 9 types of data definitions. I'm not really sure what is better.
clientPrefixedPath := "clients/" + counterpartyClientIdentifier + "/" + host.ClientStatePath() | ||
path, err := commitmenttypes.ApplyPrefix(prefix, clientPrefixedPath) | ||
suite.Require().NoError(err) | ||
path := suite.solomachine.GetClientStatePath(counterpartyClientIdentifier) |
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.
I think ideally we abstract this in host
for all path type's so the users doesn't need to call ApplyPrefix
. I only abstracted this in solo machine because I started to write dup code and then figured I might as well do it for all path types
// unmarshaled into the specified data type. | ||
func verifySignatureAndData(cdc codec.BinaryMarshaler, clientState ClientState, misbehaviour *Misbehaviour, sigAndData *SignatureAndData) error { | ||
// ensure data can be unmarshaled to the specified data type | ||
if _, err := UnmarshalDataByType(cdc, sigAndData.DataType, sigAndData.Data); err != nil { |
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.
this cannot be done in misbehaviour.validate basic because we need a codec that has registered the client state/consensus state interface
@@ -96,6 +99,29 @@ func ClientStateSignBytes( | |||
diversifier string, | |||
path commitmenttypes.MerklePath, // nolint: interfacer | |||
clientState exported.ClientState, | |||
) ([]byte, error) { | |||
dataBz, err := ClientStateDataBytes(cdc, path, clientState) |
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.
splitting this is useful testing and external callers
) | ||
|
||
// Interface implementation checks. | ||
var _, _, _, _ codectypes.UnpackInterfacesMessage = &ClientState{}, &ConsensusState{}, &Header{}, &HeaderData{} | ||
|
||
// Data is an interface used for all the signature data bytes proto definitions. | ||
type Data interface{} |
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.
this is added just so I can return the unmarshaled data in UnmarshalDataByType
@@ -28,3 +32,13 @@ func (h Header) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { | |||
func (hd HeaderData) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { | |||
return unpacker.UnpackAny(hd.NewPubKey, new(crypto.PubKey)) | |||
} | |||
|
|||
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method | |||
func (csd ClientStateData) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { |
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.
we should do a sweep of all proto structs with Any
to ensure these funcs are there. They are hard to debug we you run into the error
Co-authored-by: Federico Kunze <[email protected]>
apply most of @fedekunze comments.
…-sdk into colin/7277-solo-uniqueness
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.
ACK
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.
ACK 🎉
@colin-axner the async acks PR created some conflicts, can you fix them so it auto merges the PR 🙏 |
currently working on it. It'd be good to double check my diffs, the conflicts are non-trivial |
Description
closes: #7277
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes