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

Finalization of the roster change #43

Merged
merged 9 commits into from
May 13, 2020
Merged

Finalization of the roster change #43

merged 9 commits into from
May 13, 2020

Conversation

Gilthoniel
Copy link
Contributor

  • Implements a catch up process for new joining participant
  • Implements roster change including new players
  • Unit tests

@Gilthoniel Gilthoniel self-assigned this May 11, 2020
@Gilthoniel Gilthoniel added the R4M 🚀 The PR is ready to be reviewed and merged label May 12, 2020
@Gilthoniel Gilthoniel requested a review from nkcr May 12, 2020 12:30
Copy link
Contributor

@nkcr nkcr left a comment

Choose a reason for hiding this comment

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

Very few comments 👍

"golang.org/x/xerrors"
)

type operations struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a small explanation about what an operation is responsible for and what it does.


err = ops.commitBlock(block)
if err != nil {
// No wrapping to avoid redundancy.
Copy link
Contributor

Choose a reason for hiding this comment

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

it is becoming harder and harder to find review's comments 😄

Comment on lines 123 to 137
for _, link := range chain.links {
if last == nil || bytes.Equal(last.To, link.from[:]) {
linkpb, err := c.encoder.Pack(link)
if err != nil {
return xerrors.Errorf("couldn't pack link: %v", err)
}

err = c.storage.Store(linkpb.(*ForwardLinkProto))
if err != nil {
return xerrors.Errorf("couldn't store link: %v", err)
}

last = nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally dislike the way last has a double purpose: first holding the last stored block and then indicating if we started storing new blocks. I would find it easier to understand if using a separate variable for that:

Suggested change
for _, link := range chain.links {
if last == nil || bytes.Equal(last.To, link.from[:]) {
linkpb, err := c.encoder.Pack(link)
if err != nil {
return xerrors.Errorf("couldn't pack link: %v", err)
}
err = c.storage.Store(linkpb.(*ForwardLinkProto))
if err != nil {
return xerrors.Errorf("couldn't store link: %v", err)
}
last = nil
}
}
store := false
for _, link := range chain.links {
store := store || bytes.Equal(last.To, link.from[:])
if store {
linkpb, err := c.encoder.Pack(link)
if err != nil {
return xerrors.Errorf("couldn't pack link: %v", err)
}
err = c.storage.Store(linkpb.(*ForwardLinkProto))
if err != nil {
return xerrors.Errorf("couldn't store link: %v", err)
}
}
}

if removals[i] == removals[i+1] {
removals = append(removals[:i], removals[i+1:]...)
} else {
// Only moves to the next when all occurances of the same index are
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Only moves to the next when all occurances of the same index are
// Only moves to the next when all occurences of the same index are

player, err := f.unpackPlayer(pb.GetAddr(), pb.GetPublicKey())
if err != nil {
// The error is not wrap to avoid redundancy with the private function.
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure why this would be redundant.

For example without wrap you could have

couldn't decode public key

and if you add one:

failed to unpack player: couldn't decode public key

If I had to choose I would go for the second one. IMO no wrap should be an extreme exception where there is no other way around, because there is often a good reason to avoid a wrap but it is not in our interest when something bad happens. Having more and more exceptions is a slippery slope, (I feel this PR as an unusual number of no-wrap error).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have the tendency to use private functions to reduce the code block sizes because I don't like big blocks but I assume it will be redundant when doing that. But it's true it's not always a benefit.

@Gilthoniel Gilthoniel requested a review from nkcr May 13, 2020 06:53
@nkcr nkcr merged commit 380d814 into master May 13, 2020
@Gilthoniel Gilthoniel deleted the roster_change_full branch May 13, 2020 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R4M 🚀 The PR is ready to be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants