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

Start validating blobs closer to RPC response reader #13511

Merged
merged 1 commit into from
Jan 23, 2024
Merged

Conversation

kasey
Copy link
Contributor

@kasey kasey commented Jan 23, 2024

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.

@kasey kasey requested a review from a team as a code owner January 23, 2024 18:56
terencechain
terencechain previously approved these changes Jan 23, 2024
Copy link
Contributor

@jtraglia jtraglia left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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 😄

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, ptal

Copy link
Contributor Author

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.

@kasey kasey force-pushed the blob-rpc-opt branch 2 times, most recently from 3050e60 to e9e4d49 Compare January 23, 2024 21:00
Copy link
Contributor

@jtraglia jtraglia 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 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")
Copy link
Contributor

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.

@kasey kasey added this pull request to the merge queue Jan 23, 2024
Comment on lines +213 to +215
if err := vf[i](blob); err != nil {
return err
}
Copy link
Member

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?

Copy link
Member

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

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 23, 2024
@kasey kasey added this pull request to the merge queue Jan 23, 2024
Merged via the queue into develop with commit dbcf5c2 Jan 23, 2024
17 checks passed
@kasey kasey deleted the blob-rpc-opt branch January 23, 2024 23:15
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.

4 participants