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

Misc node code fixes #369

Merged
merged 4 commits into from
Mar 22, 2024
Merged

Misc node code fixes #369

merged 4 commits into from
Mar 22, 2024

Conversation

jianoaix
Copy link
Contributor

@jianoaix jianoaix commented Mar 19, 2024

Why are these changes needed?

Checks

  • I've made sure the lint is passing in this PR.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

Copy link
Contributor

@bxue-l2 bxue-l2 left a comment

Choose a reason for hiding this comment

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

lgtm, except the nil

@@ -40,15 +43,15 @@ func GetBlobMessages(in *pb.StoreChunksRequest) ([]*core.BlobMessage, error) {
}

bundles := make(map[core.QuorumID]core.Bundle, len(blob.GetBundles()))
for i, chunks := range blob.GetBundles() {
quorumID := blob.GetHeader().GetQuorumHeaders()[i].QuorumId
for j, chunks := range blob.GetBundles() {
Copy link
Contributor

Choose a reason for hiding this comment

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

On line 41, Since GetHeader() can be nil, GetQuorumHeaders() will evaluate to invalid memory. Similarly for L44

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a node request validation here: #378, to make sure header is non-null

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a comment in L33 that this method assumes the inputs are valid and point to the validation method

for i, chunks := range blob.GetBundles() {
quorumID := blob.GetHeader().GetQuorumHeaders()[i].QuorumId
for j, chunks := range blob.GetBundles() {
quorumID := blob.GetHeader().GetQuorumHeaders()[j].QuorumId
bundles[uint8(quorumID)] = make([]*encoding.Frame, len(chunks.GetChunks()))
Copy link
Contributor

Choose a reason for hiding this comment

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

casting from uint32 to uint8 is a bit dangerous, I think 256 can overwrite 0. I feel I am doing a bit too much on the audit side now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The protobuf doesn't have uint8, that's why it's uint32 from the gRPC request, and we will cast it to uint8 inside golang world

Copy link
Collaborator

Choose a reason for hiding this comment

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

@@ -40,15 +43,15 @@ func GetBlobMessages(in *pb.StoreChunksRequest) ([]*core.BlobMessage, error) {
}

bundles := make(map[core.QuorumID]core.Bundle, len(blob.GetBundles()))
for i, chunks := range blob.GetBundles() {
quorumID := blob.GetHeader().GetQuorumHeaders()[i].QuorumId
for j, chunks := range blob.GetBundles() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a comment in L33 that this method assumes the inputs are valid and point to the validation method

node/node.go Outdated
@@ -318,8 +318,8 @@ func (n *Node) ProcessBatch(ctx context.Context, header *core.BatchHeader, blobs
// revert all the keys for that batch.
result := <-storeChan
if result.keys != nil {
if !n.Store.DeleteKeys(ctx, result.keys) {
log.Error("Failed to delete the invalid batch that should be rolled back", "batchHeaderHash", batchHeaderHash)
if err = n.Store.DeleteKeys(ctx, result.keys); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

assign to a different err variable? The err logged in L322 should be the err in L315, but this overrides that value

@@ -17,6 +17,8 @@ import (
)

// Constructs a core.BatchHeader from a proto of pb.StoreChunksRequest.
// Note the StoreChunksRequest is validated as soon as it enters the node gRPC
// interface, see grpc.Server.validateStoreChunkRequest.
func GetBatchHeader(in *pb.StoreChunksRequest) (*core.BatchHeader, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: start the comment with GetBatchHeader constructs a ...

@jianoaix jianoaix merged commit 5999f23 into Layr-Labs:master Mar 22, 2024
5 checks passed
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