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

Added checks to avoid decoding messages as handshakes #2681

Merged
merged 22 commits into from
Aug 8, 2022

Conversation

kishansagathiya
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Merging #2681 (b76420f) into development (4f311a5) will increase coverage by 0.05%.
The diff coverage is 78.57%.

@@               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     

dot/network/notifications.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/notifications.go Outdated Show resolved Hide resolved
dot/network/transaction.go Outdated Show resolved Hide resolved
dot/network/transaction.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
kishansagathiya and others added 3 commits July 20, 2022 09:22
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
…afe/gossamer into kishan/chore/quick-network-checks
dot/network/notifications.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/service.go Outdated Show resolved Hide resolved
dot/network/transaction.go Outdated Show resolved Hide resolved
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
@kishansagathiya
Copy link
Contributor Author

Making roles enum does not fix the problem, i still have to check if it is 1, 2 or 4.

@qdm12
Copy link
Contributor

qdm12 commented Jul 26, 2022

Making roles enum does not fix the problem, i still have to check if it is 1, 2 or 4.

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)

@kishansagathiya kishansagathiya changed the title Added checks to avoid decoding handshakes as messages Added checks to avoid decoding messages as handshakes Aug 1, 2022
dot/network/host_test.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
dot/network/block_announce.go Outdated Show resolved Hide resolved
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),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Comment on lines 161 to 162
// this error will never happen.
// Handshake interface and NotificationMessage interfaces are same.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Member

@EclesioMeloJunior EclesioMeloJunior left a comment

Choose a reason for hiding this comment

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

LGTM!

@qdm12
Copy link
Contributor

qdm12 commented Aug 6, 2022

Making roles enum does not fix the problem, i still have to check if it is 1, 2 or 4.

Just so you know, you could use _ to skip 3 and have enums using iota.

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

@kishansagathiya kishansagathiya merged commit b21a8a1 into development Aug 8, 2022
@kishansagathiya kishansagathiya deleted the kishan/chore/quick-network-checks branch August 8, 2022 13:02
@github-actions
Copy link

🎉 This PR is included in version 0.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants