-
Notifications
You must be signed in to change notification settings - Fork 110
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
Added checks to avoid decoding messages as handshakes #2681
Added checks to avoid decoding messages as handshakes #2681
Conversation
Codecov Report
@@ Coverage Diff @@
## development #2681 +/- ##
===============================================
+ Coverage 62.93% 62.98% +0.05%
===============================================
Files 212 212
Lines 27020 27038 +18
===============================================
+ Hits 17004 17029 +25
+ Misses 8472 8461 -11
- Partials 1544 1548 +4 |
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
…afe/gossamer into kishan/chore/quick-network-checks
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Making roles enum does not fix the problem, i still have to check if it is 1, 2 or 4. |
…afe/gossamer into kishan/chore/quick-network-checks
For sure, you can have them as typed byte set to those values (1,2,4), enums won't work (especially since 3 is missing lol) |
dot/services.go
Outdated
@@ -280,7 +280,7 @@ func (nodeBuilder) createNetworkService(cfg *Config, stateSrvc *state.Service, | |||
LogLvl: cfg.Log.NetworkLvl, | |||
BlockState: stateSrvc.Block, | |||
BasePath: cfg.Global.BasePath, | |||
Roles: cfg.Core.Roles, | |||
Roles: common.Roles(cfg.Core.Roles), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit do you think we could have the cfg.Core.Roles
directly as common.Roles
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with latest commit, roles are getting used everywhere instead of byte. I have propagated these changes til toml config. I would not like to change toml config, since that's what deals with marshalling and marshalling config. I don't want to disturb any behaviour there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a byte alias probably won't change config parsing. Don't we have unit tests to verify this?
dot/network/notifications.go
Outdated
// this error will never happen. | ||
// Handshake interface and NotificationMessage interfaces are same. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we then remove the , ok
in hs, ok := msg.(Handshake)
so it panics in case it ever happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arhhmm, I am not really sure about that. I would prefer not to remove this.
I feel like NotificationMessage and Handshake happens to have the same interface at the moment, but they don't have to. Also, not a big fan of panicking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's remove that comment.
Panicing is useful for programming errors, so it doesn't go unnoticed in some error log line.
I also was team anti-panic, but it really has its use for programming errors (not from user/IO of course)
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
…afe/gossamer into kishan/chore/quick-network-checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Just so you know, you could use const (
enum1 uint8 = iota // that's 0
_
enum2 // that's 2
) But I prefer to just hardcode the constant as it is now, so really just a shower thought |
🎉 This PR is included in version 0.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes
These changes would show the appropriate error messages instead of genesis mismatch and also avoid banning the other peer.
Tests
go test -tags integration github.com/ChainSafe/gossamer
Issues
#2636
Primary Reviewer
@timwu20