Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Jul 12, 2024
1 parent c7b0de7 commit b13fb4f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 1 addition & 4 deletions node/grpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ func GetBlobMessages(in *pb.StoreChunksRequest, numWorkers int) ([]*core.BlobMes
resultChan <- err
return
}
bundles[uint8(quorumID)] = make([]*encoding.Frame, len(bundleMsg))
for k := 0; k < len(bundleMsg); k++ {
bundles[uint8(quorumID)][k] = bundleMsg[k]
}
bundles[uint8(quorumID)] = bundleMsg
} else {
bundles[uint8(quorumID)] = make([]*encoding.Frame, len(bundle.GetChunks()))
for k, data := range bundle.GetChunks() {
Expand Down
14 changes: 7 additions & 7 deletions node/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,8 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs
if len(bundle.GetChunks()) > 0 && len(bundle.GetChunks()[0]) > 0 {
return nil, errors.New("chunks of a bundle are encoded together already")
}
// The bundle may be empty if the operator is not in a quorum (operators can
// be in just a subset of quorums). We need to store only the non-empty
// quorums.
if len(bundle.GetBundle()) > 0 {
rawBundles[quorumID] = bundle.GetBundle()
}
} else if len(bundle.GetChunks()) > 0 {
rawBundles[quorumID] = bundle.GetBundle()
} else {
rawChunks[quorumID] = make([][]byte, len(bundle.GetChunks()))
for j, chunk := range bundle.GetChunks() {
rawChunks[quorumID][j] = chunk
Expand Down Expand Up @@ -300,6 +295,7 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs
}
chunksBytes, ok := rawChunks[quorumID]
if ok {

bundleRaw := make([][]byte, len(bundle))
for i := 0; i < len(bundle); i++ {
bundleRaw[i] = chunksBytes[i]
Expand Down Expand Up @@ -458,6 +454,10 @@ func DecodeGobChunks(data []byte) ([][]byte, error) {
// Converts a flattened array of chunks into an array of its constituent chunks,
// throwing an error in case the chunks were not serialized correctly.
func DecodeChunks(data []byte) ([][]byte, node.ChunkEncoding, error) {
// Empty chunk is valid, but there is nothing to decode.
if len(data) == 0 {
return [][]byte{}, node.ChunkEncoding_UNKNOWN, nil
}
if len(data) < 8 {
return nil, node.ChunkEncoding_UNKNOWN, errors.New("data must have at least 8 bytes")
}
Expand Down
5 changes: 5 additions & 0 deletions node/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ func createStore(t *testing.T) *node.Store {
}

func TestEncodeDecodeChunks(t *testing.T) {
decoded, format, err := node.DecodeChunks([]byte{})
assert.Nil(t, err)
assert.Equal(t, pb.ChunkEncoding_UNKNOWN, format)
assert.Equal(t, 0, len(decoded))

numSamples := 32
numChunks := 10
chunkSize := 2 * 1024
Expand Down

0 comments on commit b13fb4f

Please sign in to comment.