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/consensus: implement qbft component #514

Merged
merged 6 commits into from
May 11, 2022
Merged

Conversation

corverroos
Copy link
Contributor

@corverroos corverroos commented May 10, 2022

Implements a qbft consensus component that integrates qbft into p2p and the core workflow.

Note this isn't wired yet. Tests will also be added in subsequent PR.

category: feature
ticket: #445
feature_flag: qbft_consensus

@codecov
Copy link

codecov bot commented May 10, 2022

Codecov Report

Merging #514 (ab4f84e) into main (22dc97a) will decrease coverage by 2.29%.
The diff coverage is 3.49%.

@@            Coverage Diff             @@
##             main     #514      +/-   ##
==========================================
- Coverage   57.42%   55.12%   -2.30%     
==========================================
  Files          87       90       +3     
  Lines        8032     8318     +286     
==========================================
- Hits         4612     4585      -27     
- Misses       2819     3128     +309     
- Partials      601      605       +4     
Impacted Files Coverage Δ
core/consensus/component.go 0.00% <0.00%> (ø)
core/consensus/transport.go 0.00% <0.00%> (ø)
core/proto.go 72.00% <0.00%> (-28.00%) ⬇️
core/consensus/msg.go 15.38% <15.38%> (ø)
core/qbft/qbft.go 77.32% <0.00%> (-8.40%) ⬇️

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 22dc97a...ab4f84e. Read the comment docs.

@@ -59,7 +60,8 @@ func RandomCorePubKey(t *testing.T) core.PubKey {
// RandomEth2PubKey returns a random eth2 phase0 bls pubkey.
func RandomEth2PubKey(t *testing.T) eth2p0.BLSPubKey {
t.Helper()
pubkey, _, err := tbls.Keygen()
random := rand.New(rand.NewSource(rand.Int63()))
Copy link
Contributor

Choose a reason for hiding this comment

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

is this deterministic?

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, since it uses math.Rand for the seed

tcpNode: tcpNode,
peers: peers,
p2pKey: p2pKey,
recvBuffers: make(map[core.Duty]chan msg),
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need receive buffers for each duty with size 100?
and why 100?

Copy link
Contributor Author

@corverroos corverroos May 11, 2022

Choose a reason for hiding this comment

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

I'll add this comment: Allow receiving some initial messages before this node has started

@corverroos corverroos added the merge when ready Indicates bulldozer bot may merge when all checks pass label May 11, 2022
@obol-bulldozer obol-bulldozer bot merged commit afc71ba into main May 11, 2022
@obol-bulldozer obol-bulldozer bot deleted the corver/qbftintegrate branch May 11, 2022 13:32
Copy link
Contributor

@OisinKyne OisinKyne left a comment

Choose a reason for hiding this comment

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

Apologies I didn't get this finished yesterday. Busy day. Not all of these questions are the most insightful comments and are partly for my benefit. 🙃

const (
recvBuffer = 100
period = time.Second
protocolID = "/charon/consensus/1.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we have only one type of consensus message protocol do you think?

What if:

/charon/consensus/qbft/1.0.0
/charon/consensus/hotstuff/0.1.0
/charon/consensus/tendermint/0.5.0

etc.

)

const (
recvBuffer = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

Same q as dhruv, do we need this to be a parameter? Do we expect this to be a dos vector? Should we slap a prom gauge/metric around it somewhere to keep an eye on the space in the buffer?


// NewComponent returns a new consensus QBFT component.
func NewComponent(tcpNode host.Host, peers []p2p.Peer,
peerIdx int64, p2pKey *ecdsa.PrivateKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

Noob go question, here we're passing only a pointer to the one PrivateKey in memory, not duplicating the value everywhere, right? Is exposing the raw memory address of the PKey to many places encapsulated enough? Do we need any sort of mutex for signing with it or is it all good cause it's all reads no writes? Is this QBFT Component a singleton that does all QBFT or will there be parallel instantiations of it?

t.setValues(msg)

select {
case <-ctx.Done():
Copy link
Contributor

Choose a reason for hiding this comment

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

This is in many places so I take it its intentional, but what's with a select { } block not counting for an extra indentation, the cases aren't tabbed, convention I guess but seems weird to me.

if err != nil {
return errors.Wrap(err, "new stream")
}
defer s.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no scenario where s can be non-nil when err is non-nil, right? Otherwise we could have a memory leak from returning before deferring the close.

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