-
Notifications
You must be signed in to change notification settings - Fork 111
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
chore(lib/grandpa): integrate scale into grandpa #1811
Conversation
…fe/gossamer into jimmy/fixNetworkScaleIntegration
dot/types/grandpa.go
Outdated
func (v *GrandpaVoter) Encode() ([]byte, error) { | ||
enc := []byte{} | ||
b := v.Key.Encode() | ||
enc = append(enc, b...) |
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.
does the new SCALE package work with custom encodings? for example, if scale.Marshal(*GrandpaVoter)
is called, will this function be called by SCALE?
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.
No it does not. I also do not believe the GrandpaVoter is scale encoded because of the ed25519.PublicKey (Don't think the length is the leading byte of the encoded pubkey)
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.
yeah, it's always a []byte
of length 32. unfortunately the ed25519 has it just as []byte
instead of [32]byte
so we can't directly SCALE encode it. maybe as a next step for SCALE we can add custom type encodings
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.
Yeah I think that could be a good idea
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 method should just be
return scale.Marshal(v)
if you change ed25519.PublicKey
to [32]byte
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 we could just delete it all together and just directly marshal/unmarshal. Would also allow us to get rid of the custom encode and decode functions for GrandpaVoters
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 will look into this now actually. Could be a nice change to include in this PR
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 this is a huge change maybe do it in another PR, since I think the crypto/ed25519 golang lib we're using has some nice functions that we currently use (but maybe it's not a huge change)
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.
Yeah good call, I will do this in a separate PR
lib/grandpa/network.go
Outdated
|
||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("message type not recognised") |
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.
why not ErrInvalidMessageType
?
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.
Will change
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.
looks good!! basically just a question about the decodeMessage
function, I think everything else is fine
…mer into jimmy/grandpaIntegration
"fmt" | ||
"io" | ||
|
||
"github.com/ChainSafe/gossamer/lib/common" | ||
"github.com/ChainSafe/gossamer/lib/crypto/ed25519" | ||
"github.com/ChainSafe/gossamer/lib/scale" | ||
scale2 "github.com/ChainSafe/gossamer/pkg/scale" |
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.
why do we need both scale packages?
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.
Well right now encoding/decoding for the grandpaVoter is using custom logic (since its not scale encoded I do not believe) and its uses the old scale to encode/decode. Dot/types is the integration I will finish after this one is merged so I was planning to fix it then but if you want it in this pr I can do that.
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.
As long as we have an issue for this that's fine.
lib/grandpa/types.go
Outdated
primaryProposal subround = 2 | ||
Prevote Subround | ||
Precommit Subround = 1 | ||
PrimaryProposal Subround = 2 |
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.
why are these public now?
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.
So scale can access them when decoding/encoding. I believe this is necessary but I can change if I am wrong
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.
The values don't need to be public, only the attribute names if they are being used as an attribute in a struct.
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.
looks good, would be nice to either add SCALE custom encoding or change our crypto/ed25519/PublicKey
type to be [32]byte
so that it can be used with new SCALE, maybe wanna open issues for these?
I prefer the latter. If it was a |
dot/types/grandpa.go
Outdated
v.ID = id | ||
return nil | ||
} | ||
|
||
// Encode will encode the GrandpaVoter | ||
func (v *GrandpaVoter) Encode() ([]byte, 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.
nit: can you update all the receiver functions.
func (v *GrandpaVoter) Encode() ([]byte, error) { | |
func (gv *GrandpaVoter) Encode() ([]byte, error) { |
func justificationToCompact(just []*SignedVote) ([]*Vote, []*AuthData) { | ||
precommits := make([]*Vote, len(just)) | ||
authData := make([]*AuthData, len(just)) | ||
func justificationToCompact(just []SignedVote) ([]Vote, []AuthData) { |
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 function name does not correspond to the action IMO, I guess splitJustification
or fromJustificationToVoteAndAuth
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.
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 method should be a receiver function of a new type called type SignedVotes []SignedVote
.
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 named it this way to match substrate's naming, so I think it's ok to leave as is but up to your judgement
…mer into jimmy/grandpaIntegration
🎉 This PR is included in version 0.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes
Tests
Issues
Primary Reviewer