-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Start validating blobs closer to RPC response reader #13511
Conversation
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.
Looking good! A couple minor suggestions.
|
||
func (sbv *seqBlobValid) nextValid(blob blocks.ROBlob) error { | ||
if sbv.prev == nil { | ||
sbv.prev = &blob |
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.
If there isn't a previous blob, we need to check that the blob index is zero.
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.
done
return ErrBlobIndexOutOfBounds | ||
} | ||
} else { | ||
if sbv.prev.Slot() >= blob.Slot() { |
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.
We also need to check that blob index is zero here.
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.
done
} | ||
} else { | ||
if sbv.prev.Slot() >= blob.Slot() { | ||
return errChunkResponseSlotNotAsc |
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.
Before this, we should check that the prev.BlockRoot()
matches blob.ParentBlockRoot()
. It's a cheap check that ensures it's a connected chain 😄
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.
done
sbv.prev = &blob | ||
return nil | ||
} | ||
if sbv.prev.BlockRoot() == blob.BlockRoot() { |
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.
Another thing. If the block root is the same, it won't check the blob's slot and parentBlockRoot. It might be useful to have another function which ensures blockRoot, parentBlockRoot, and slot are equal.
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.
done, ptal
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.
checking slot first since that's a minutely cheaper check, then roots & parent root.
3050e60
to
e9e4d49
Compare
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.
This is great! Thanks. Just the smallest of nits.
var ( | ||
// ErrInvalidFetchedData is used to signal that an error occurred which should result in peer downscoring. | ||
ErrInvalidFetchedData = errors.New("invalid data returned from peer") | ||
ErrBlobIndexOutOfBounds = errors.Wrap(ErrInvalidFetchedData, "blob index out of range") |
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.
I think this should be private, ie errBlobIndexOutOfBounds
.
if err := vf[i](blob); err != nil { | ||
return err | ||
} |
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.
maybe over-engineering here, but could these be processed in parallel?
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.
discussed offline, these checks are too trivial to justify parallelization
We already perform sufficient checks to ensure that we safely handle RPC responses, but we can improve efficiency by performing some checks closer to the rpc network reads. This is a proof of concept to show the direction we can move, more refactoring is needed to move the entire blob validation chain to this point.