Skip to content
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

Feature/#9 test dvoting #16

Merged
merged 29 commits into from
Jun 3, 2024
Merged

Feature/#9 test dvoting #16

merged 29 commits into from
Jun 3, 2024

Conversation

XioZ
Copy link
Collaborator

@XioZ XioZ commented May 30, 2024

  • Closing Test D-Voting with New Mino P2P #9
  • Rewrote Stream() to:
    • have an orchestrator that relays messages among participants (participants can send/receive messages to/from the orchestrator as well as to/from other participants)
    • wrap orchestrator's address to pass equality check by callers against protocol initiator's participant address
  • Passed integration check with d-voting (all actions from Initialize Nodes to See Results completed successfully)
  • Improved benchmark performance to slightly outperform gRPC

image Screenshot 2024-05-30 at 23 29 53 Screenshot 2024-05-31 at 00 32 12

@XioZ XioZ assigned XioZ and unassigned XioZ May 30, 2024
@XioZ XioZ requested a review from ineiti May 30, 2024 23:04
Copy link
Member

@ineiti ineiti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work - I'm happy that it all fits together now. For the final report, please be sure to:

  • comment what you changed to improve the benchmark
  • describe what in the current API description is wrong / confusing

There are too many closures in the code, and it's not clear which closures capture which local variables. This is why I propose to create them as methods on the structure, and then call them like that. If we would have more time, it would also be easier to test them like that.

Comment on lines 148 to 149
} else {
addr, err = newOrchestratorAddr(location, identity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreachable code path: on line 128 you return if len(parts) < 2, and here you check if it equals 2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's reachable. it handles 3 cases: < 2, = 2 and > 2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I see the light. It's /(.*?):(.*?)(:o)?/. So either add that as a comment to FromText, or check for parts[2] == 'o' in the else branch to make this explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added check

"default listen address)",
Required: false,
Value: "",
},
)

cmd := builder.SetCommand("list")
sub := cmd.SetSubCommand("address")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change, only my comment: this could be a command only, w/o a subcommand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address doesn't work as a command in dvoting. it seems to conflict with commands from another controller when i was testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be addresses, listp2p, listAddresses, dumpAddresses, or any other command.

As I said - no change needed, just a random idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok keeping as-is then :)

in: make(chan Packet, MaxUnreadAllowed),
}

fetch := func(decoder *gob.Decoder) (Packet, mino.Address, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor: add this as a method to orchestrator

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? closure is the more idiomatic way to write single-use functions in Go, as it avoids unnecessarily long argument list through variable capture, which makes the code cleaner, shorter and easier to read without having to scroll to another function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, there would be no additional arguments, as all captured variables are available in the orchestrator.

And while I can see the argument for one (short) closure, I wouldn't call three closures in a row cleaner, shorter, and easier to read...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


reply, err := h.Process(mino.Request{Address: from, Message: req})
relay := func(packet Packet, dest address) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor: add this as a method to orchestrator

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

if err != nil {
r.logger.Error().Err(err).Msg("could not reply to call")
return
receive := func(decoder *gob.Decoder) (Packet, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor: add this as a method to orchestrator

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

encoder := gob.NewEncoder(stream)
decoder := gob.NewDecoder(stream)

receive := func() (Packet, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor: add this as a method to participant (and add decoder to its structure)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

// Send is asynchronous and returns immediately an error channel that
// closes when the message has either been sent or errored to each address.
func (s session) Send(msg serde.Message, addrs ...mino.Address) <-chan error {
func (o orchestrator) Send(msg serde.Message, addrs ...mino.Address) <-chan error {
send := func(addr mino.Address) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Make this a method of orchestrator - else it's capturing o here, which is confusing. If it's part of orchestrator, it's clear that it will use the fields of orchestrator
  • Take msg as parameter, else the captured msg will be used both in this closure and be passed to doSend

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

func (p participant) Send(msg serde.Message, addrs ...mino.Address) <-chan error {
send := func(addr mino.Address) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Make this a method of participant - else it's capturing p here, which is confusing. If it's part of participant, it's clear that it will use the fields of participant
  • Take msg as parameter, else the captured msg will be used both in this closure and be passed to doSend

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@XioZ XioZ force-pushed the feature/#9-test-dvoting branch from 227235b to 2a1cc78 Compare May 31, 2024 15:31
@XioZ XioZ merged commit a745f07 into main Jun 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants