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

message validation #1289

Merged
merged 14 commits into from Sep 22, 2021
Merged

message validation #1289

merged 14 commits into from Sep 22, 2021

Conversation

synzhu
Copy link
Contributor

@synzhu synzhu commented Sep 13, 2021

  • Implements a single topic validator that handles deserializing the message, extracting the sender ID, and then runs all application level MessageValidators on the message.
  • Deprecates the OriginID field on the Message struct. Instead, the network layer, upon receiving a message, can simply deduce the OriginID based on the sender's peer ID.

closes https://github.com/dapperlabs/flow-go/issues/5804

@synzhu synzhu changed the title Smnzhu/validation consolidation message validation Sep 13, 2021
@synzhu synzhu marked this pull request as ready for review September 13, 2021 23:34
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

Thanks! I like that TopicValidator is called systematically. I think there's a small "bug" in calling the inner validators, see inline.

string Type = 6;
string ChannelID = 1;
bytes EventID = 2;
bytes OriginID = 3 [deprecated = true];
Copy link
Contributor

Choose a reason for hiding this comment

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

If we just deprecate this, we're not removing the field and are still allowing its use.

Which means, technically, that we could still have OriginID claims in this field, which would still be ser/deser-ialized, and that we should still report if different from the result of the validation logic.

Is it possible to just remove this field and mark the release that would include this PR as breaking? I think it's worth it.

/cc @ramtinms @vishalchangrani for advice on the Message format change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, although I'm hoping we can eventually remove all of these fields except Payload, and I think this is something that can wait until later and we can remove them all in one fell swoop.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Do we have an issue for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly, but it is part of https://github.com/dapperlabs/flow-go/issues/5847

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as the network layer is passing the application layer the origin ID (which we are), it doesn't matter if we remove the field now or later.

network/validator/pubsub/validator.go Show resolved Hide resolved
network/p2p/middleware.go Outdated Show resolved Hide resolved
Comment on lines 83 to 84
if !ok {
r.log.Fatal().Str("raw_msg", rawMsg.String()).Msg("validator data missing")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of the log fatal here.

This would be triggered by an independent modification of TopicValidator that e.g. made it return before populating the data in some cases. We should definitely log a spectacular Error, but why not behave like the above failure cases and return?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can, but personally I would consider it a bug if the validator returned ValidationAccept without populating the data. At the bare minimum, the validator should check that the message can be deserialized properly and that the origin id can be extracted. If it cannot do even this, then we should definitely reject the message.

Copy link
Contributor

Choose a reason for hiding this comment

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

My issue is neither with checking that the validation data is here, nor with considering this a bug. We should certainly transmit the message that "something is rotten in the state of Denmark" far and wide.

My issue is with crashing the node based on the input of one (externally controlled) message. A validator that accepts without populating the data has a bug, yes, but should its impact be to lose the entire blockchain?

network/validator/pubsub/validator.go Show resolved Hide resolved
network/validator/pubsub/validator.go Show resolved Hide resolved
network/validator/pubsub/staked_validator.go Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2021

Codecov Report

Merging #1289 (abc4ae0) into master (a783037) will increase coverage by 0.02%.
The diff coverage is 45.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1289      +/-   ##
==========================================
+ Coverage   54.70%   54.73%   +0.02%     
==========================================
  Files         502      501       -1     
  Lines       31769    31743      -26     
==========================================
- Hits        17380    17373       -7     
+ Misses      12026    12011      -15     
+ Partials     2363     2359       -4     
Flag Coverage Δ
unittests 54.73% <45.45%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
network/p2p/libp2pUtils.go 59.74% <ø> (+5.48%) ⬆️
network/p2p/middleware.go 0.00% <0.00%> (ø)
network/p2p/readSubscription.go 0.00% <0.00%> (ø)
network/p2p/libp2pNode.go 67.08% <71.42%> (-0.01%) ⬇️
engine/collection/synchronization/engine.go 62.90% <0.00%> (ø)

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 a783037...abc4ae0. Read the comment docs.

Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

This is swallowing the immediate return that should happen on absence of validation data. Otherwise looks good.

network/validator/pubsub/validator.go Show resolved Hide resolved
network/p2p/readSubscription.go Outdated Show resolved Hide resolved
Co-authored-by: François Garillot <4142+huitseeker@users.noreply.github.com>
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

Thanks a bunch for all your work on this, it looks great!

@vishalchangrani
Copy link
Contributor

Since we only care about Accept or Reject, we will be better served with this Validator function instead of the Extended version.

@synzhu
Copy link
Contributor Author

synzhu commented Sep 21, 2021

Since we only care about Accept or Reject, we will be better served with this Validator function instead of the Extended version.

We actually do care about Ignore as well. Currently there is no usecase which simply Ignore, but there could be in the future.

The topic validator should take the validation result from multiple MessageValidators and compute an "aggregate" result which is then returned to Libp2p.

@vishalchangrani
Copy link
Contributor

Since we only care about Accept or Reject, we will be better served with this Validator function instead of the Extended version.

We actually do care about Ignore as well. Currently there is no usecase which simply Ignore, but there could be in the future.

The topic validator should take the validation result from multiple MessageValidators and compute an "aggregate" result which is then returned to Libp2p.

Since we only care about Accept or Reject, we will be better served with this Validator function instead of the Extended version.

We actually do care about Ignore as well. Currently there is no usecase which simply Ignore, but there could be in the future.

The topic validator should take the validation result from multiple MessageValidators and compute an "aggregate" result which is then returned to Libp2p.

correct - and when we do have a use case in the future we can then switch over to the extended version. This seems like a premature generalization. But I went ahead and approved since that is not a big deal one way or the other.

@synzhu
Copy link
Contributor Author

synzhu commented Sep 22, 2021

bors merge

@bors
Copy link
Contributor

bors bot commented Sep 22, 2021

@bors bors bot merged commit 2569fa4 into master Sep 22, 2021
@bors bors bot deleted the smnzhu/validation-consolidation branch September 22, 2021 06:19
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.

None yet

4 participants