Who let the DKGs out: Move DKG to new net interfaces - #76
Conversation
|
|
||
| func (channel *localChannel) RegisterUnmarshaler( | ||
| tpe string, | ||
| unmarshaler func() proto.Unmarshaler) (err error) { |
There was a problem hiding this comment.
This style of breaks between params is tough to read for me (personally). Not something that I've seen before. Maybe if the last param was on a new line?
| channel.unmarshalersByType[tpe] = unmarshaler | ||
| } | ||
| channel.unmarshalersMutex.Unlock() | ||
| return |
There was a problem hiding this comment.
Consider rewriting this as:
+ channel.unmarshalersMutex.Lock()
+ if _, exists := channel.unmarshalersByType[tpe]; !exists {
+ channel.unmarshalersByType[tpe] = unmarshaler
return nil
+ }
+ channel.unmarshalersMutex.Unlock()
+ return fmt.Errorf("type %s already has an associated unmarshaler", tpe)
or change it to error first and then return nil
The above is an example. Of note, it's preferable to return something concrete (ie. nil) rather than a naked return (can be seen as a code smell under some linters).
| // Message corresponds with our proto Envelope type. | ||
| type Message struct{} | ||
| // ClientIdentifier represents the identity of a recipient for a message. | ||
| type ClientIdentifier string |
There was a problem hiding this comment.
Given what we talked about today is this the right abstraction level / type?
|
Going to ignore comments on this PR as I believe they're all supposed to be on the #75 dependency. |
69ef6c2 to
66a450c
Compare
|
This guy is good for review now that #75 is in. |
|
Just realized there are actually no chain-related changes here <_< |
This will let us use them directly for sending through the net.BroadcastChannel interface.
The new DKG code has been adapted to work with net.BroadcastChannel and the new protobuf-based messages in the dkg package. We also adapt main to invoke the new DKG code instead of the old one.
Since the old DKG code is gone, we no longer need this; local.Channel should be used instead.
Even though it isn't live, we bring it back since we've resolved circular package dependency issues.
This fixes our docker build, which was failing because the Go compile wasn't finding the Go files we failed to generate for the DKG messages.
66a450c to
09e5928
Compare
| localMember := thresholdgroup.NewMember(memberID, threshold) | ||
|
|
||
| recvChan := channel.RecvChan() | ||
| recvChan := make(chan interface{}) |
There was a problem hiding this comment.
This is in the critical path: will we rework this or is it worth putting a note to buffering this channel?
There was a problem hiding this comment.
We will be reworking this yeah. Huge refactoring needed here... later. :D
| channel.Send(broadcast.NewPrivateMessage(member.BlsID, receiverID, MemberShareMessage{share})) | ||
| channel.SendTo( | ||
| net.ClientIdentifier(receiverID.GetHexString()), | ||
| &MemberShareMessage{&member.BlsID, &receiverID, &share}) |
There was a problem hiding this comment.
Go allows for trailing commas as the last items delimiter. Could you add one after &share}, and then move the ) to the next line. Do that wherever possible. Thanks.
There was a problem hiding this comment.
I’m aware, and do use that in a few places, particularly with multi line function declarations where avoiding it makes things harder to read. Here it seems to add little in legibility and additional vertical space, so I’ve avoided it.
Is your concern consistency with the rest of the code, consistency with common Go style, or something else entirely?
There was a problem hiding this comment.
Both of the first two + the way it looks.
| justifyingMember.RecordJustificationFromID( | ||
| *justificationsMsg.id, | ||
| accuserID, | ||
| justification) |
There was a problem hiding this comment.
last item with a comma to pop the ) to the \n
| // key generation interactions. | ||
| func Init(channel net.BroadcastChannel) { | ||
| channel.RegisterUnmarshaler( | ||
| "dkg/join", |
There was a problem hiding this comment.
Wouldn't this be a great opportunity to use Type()? Though I like the way this code flows and see why you made the decision you did. Would be nice to have to only remember to update the Type() in a protocol message rather than in the init as well!
There was a problem hiding this comment.
Excellent point!
The main goal of this is to make it so BroadcastChannel's RegisterIdentifier function only needs to take one parameter, and can derive the type from that parameter.
Depends on #75, implements the DKG code on top of the new
netinterfaces. Some tweaks throughout to make everything fit together
right.