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

core/qbft: refactor to use generics #501

Merged
merged 3 commits into from
May 9, 2022
Merged

Conversation

corverroos
Copy link
Contributor

Refactors qbft to use generics. This simplified the integration significantly since an external buffer isn't required and casting and conversion and (errors) isn't required.

category: refactor
ticket: #445
feature_set: alpha

@@ -23,7 +23,7 @@ repos:
exclude: ".pb.go"

- repo: https://github.com/corverroos/fiximports
rev: 496e5392530966aa8f12e88a289c07782075cf91
Copy link
Contributor Author

Choose a reason for hiding this comment

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

had to bump fiximports to support go1.18 generics

@codecov
Copy link

codecov bot commented May 9, 2022

Codecov Report

Merging #501 (daa46a2) into main (e6e0837) will decrease coverage by 0.14%.
The diff coverage is 61.34%.

@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
- Coverage   56.60%   56.46%   -0.15%     
==========================================
  Files          87       87              
  Lines        7976     7979       +3     
==========================================
- Hits         4515     4505      -10     
- Misses       2862     2874      +12     
- Partials      599      600       +1     
Impacted Files Coverage Δ
core/qbft/qbft.go 69.23% <61.34%> (-3.13%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6e0837...daa46a2. Read the comment docs.

// Msg defines the inter process messages.
type Msg struct {
type Msg[I any, V Value[V]] interface {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing message to an interface simplifies explicit justifications, since external buffer of signed messages isn't required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, here it is not clear to me what is I and what is V

Copy link
Contributor

Choose a reason for hiding this comment

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

So, I guess V is the type of the value reaching a consensus on? But I?

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 is the instance of consensus as per the paper

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, then

Base automatically changed from corver/qbftexplicit to main May 9, 2022 11:18
@@ -27,34 +26,42 @@ import (
"github.com/obolnetwork/charon/app/errors"
)

// Value defines the generic value type constraint
// that provides an equality method.
type Value[V any] interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

@corverroos I don't think the name of this interface represents the methods it countais. Something like Equaler is better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but using V Value for the "value" makes a lot more sense than Equaler for "value". In this case, this interface defines what constraints the "value" type. Which is only that it has an equal method.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that this is the interface for the value we are reaching consensus for, it makes sense to have an interface called Value. I was confused because it didn't have other methods, I guess you will need to add it some other method to be able to use it, like something that returns V? In order to use the Value[v] returned by the consensus?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we will use this interface when we integrate it into the core workflow components

// Transport abstracts the transport layer between processes in the consensus system.
//
// Note that broadcasting doesn't return an error. Since this algorithm is idempotent
// it is suggested to just retry broadcasting indefinitely until it succeeds or times out.
type Transport struct {
type Transport[I any, V Value[V]] struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

@corverroos what is I and what is V ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup:

// Instance identifies the consensus instance.
Instance() I

// Value being proposed.
Value() V

@leolara
Copy link
Contributor

leolara commented May 9, 2022

I like that messages changes from public fields to public accessors

@corverroos corverroos added the merge when ready Indicates bulldozer bot may merge when all checks pass label May 9, 2022
@obol-bulldozer obol-bulldozer bot merged commit 1efbfb8 into main May 9, 2022
@obol-bulldozer obol-bulldozer bot deleted the corver/qbftgeneric branch May 9, 2022 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants