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

dkg/sync: enforce version #1901

Merged
merged 5 commits into from
Mar 20, 2023
Merged

dkg/sync: enforce version #1901

merged 5 commits into from
Mar 20, 2023

Conversation

corverroos
Copy link
Contributor

Enforce matching peer minor version. DKG only guarantees compatibility with patch versions.

category: bug
ticket: #1895

@codecov
Copy link

codecov bot commented Mar 18, 2023

Codecov Report

Patch coverage: 77.77% and project coverage change: -0.02 ⚠️

Comparison is base (280a764) 55.47% compared to head (eeb12bf) 55.45%.

❗ Current head eeb12bf differs from pull request most recent head 389bc2e. Consider uploading reports for the commit 389bc2e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1901      +/-   ##
==========================================
- Coverage   55.47%   55.45%   -0.02%     
==========================================
  Files         172      173       +1     
  Lines       22073    22128      +55     
==========================================
+ Hits        12244    12271      +27     
- Misses       8253     8278      +25     
- Partials     1576     1579       +3     
Impacted Files Coverage Δ
dkg/dkg.go 57.74% <57.14%> (-0.20%) ⬇️
dkg/sync/server.go 69.94% <75.86%> (+5.87%) ⬆️
app/version/version.go 18.75% <100.00%> (ø)
dkg/sync/client.go 70.14% <100.00%> (+4.24%) ⬆️

... and 6 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

// Minor returns the minor version of the provided version string.
func Minor(version string) (string, error) {
split := strings.Split(version, ".")
if len(split) < 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be

Suggested change
if len(split) < 2 {
if len(split) < 3 {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, it supports v0.1 as input and just returns it.

"github.com/obolnetwork/charon/app/version"
)

func TestMinor(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

also add a case to assert an error from Minor function with error: invalid version string

@@ -73,6 +76,14 @@ func (s *Server) AwaitAllConnected(ctx context.Context) error {
}
}

// isError checks if there was any error in between the server flow.
func (s *Server) setError() {
Copy link
Contributor

Choose a reason for hiding this comment

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

godoc incorrect

log.Error(ctx, "Received mismatching cluster definition hash from peer", nil)
} else if ok && !s.isConnected(pID) {
count := s.setConnected(pID)
log.Info(ctx, fmt.Sprintf("Connected to peer %d of %d", count, s.allCount))
}

// Verify definition hash
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment should be around line number 200

Comment on lines 193 to 204
if msg.Version != s.version {
resp.Error = errInvalidVersion
s.setError()
log.Error(ctx, "Received mismatching charon version from peer", nil,
z.Str("expect", s.version),
z.Str("got", msg.Version),
)
} else if ok, err := pubkey.Verify(s.defHash, msg.HashSignature); err != nil { // Note: libp2p verify does another hash of defHash.
return errors.Wrap(err, "verify sig hash")
} else if !ok {
resp.Error = errInvalidSig

s.mu.Lock()
s.errResponse = true
s.mu.Unlock()

s.setError()
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have this message verification as a separate method to server struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea!

@@ -209,6 +214,29 @@ func (s *Server) handleStream(ctx context.Context, stream network.Stream) error
}
}

// validReq returns an error message and false if the request version or definition hash are invalid.
// Else it returns true or an error.
func (s *Server) validReq(ctx context.Context, pubkey crypto.PubKey, msg *pb.MsgSync) (string, bool, error) {
Copy link
Contributor

@dB2510 dB2510 Mar 20, 2023

Choose a reason for hiding this comment

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

we are reading s.version and s.defHash in this method without locking mutex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they are immutable fields, no need to lock

Copy link
Contributor Author

@corverroos corverroos Mar 20, 2023

Choose a reason for hiding this comment

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

grouped server fields into immutable and mutable groups

@corverroos corverroos added the merge when ready Indicates bulldozer bot may merge when all checks pass label Mar 20, 2023
@obol-bulldozer obol-bulldozer bot merged commit 6bba714 into main Mar 20, 2023
@obol-bulldozer obol-bulldozer bot deleted the corver/dkgversion branch March 20, 2023 09:06
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.

3 participants