diff --git a/node/store.go b/node/store.go index 9768da8ec1..d5bf8f68d8 100644 --- a/node/store.go +++ b/node/store.go @@ -233,6 +233,20 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs keys = append(keys, blobHeaderKey) values = append(values, blobHeaderBytes) + // Get raw chunks + rawBlob := blobsProto[idx] + if len(rawBlob.GetBundles()) != len(blob.Bundles) { + return nil, errors.New("internal error: the number of bundles in parsed blob must be the same as in raw blob") + } + rawChunks := make(map[core.QuorumID][][]byte) + for i, chunks := range rawBlob.GetBundles() { + quorumID := uint8(rawBlob.GetHeader().GetQuorumHeaders()[i].GetQuorumId()) + rawChunks[quorumID] = make([][]byte, len(chunks.GetChunks())) + for j, chunk := range chunks.GetChunks() { + rawChunks[quorumID][j] = chunk + } + } + // blob chunks for quorumID, bundle := range blob.Bundles { key, err := EncodeBlobKey(batchHeaderHash, idx, quorumID) @@ -242,12 +256,8 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs } bundleRaw := make([][]byte, len(bundle)) - for i, chunk := range bundle { - bundleRaw[i], err = chunk.Serialize() - if err != nil { - log.Error("Cannot serialize chunk:", "err", err) - return nil, err - } + for i := 0; i < len(bundle); i++ { + bundleRaw[i] = rawChunks[quorumID][i] } chunkBytes, err := encodeChunks(bundleRaw) if err != nil { @@ -257,7 +267,6 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs keys = append(keys, key) values = append(values, chunkBytes) - } } diff --git a/node/store_test.go b/node/store_test.go index 176345dd93..552e116863 100644 --- a/node/store_test.go +++ b/node/store_test.go @@ -74,6 +74,8 @@ func CreateBatch(t *testing.T) (*core.BatchHeader, []*core.BlobMessage, []*pb.Bl Proof: commitment, Coeffs: []encoding.Symbol{encoding.ONE}, } + chunk1bytes, err := chunk1.Serialize() + assert.Nil(t, err) blobMessage := []*core.BlobMessage{ { @@ -163,12 +165,21 @@ func CreateBatch(t *testing.T) (*core.BatchHeader, []*core.BlobMessage, []*pb.Bl Length: uint32(50), QuorumHeaders: []*pb.BlobQuorumInfo{quorumHeaderProto}, } + bundles := []*pb.Bundle{ + { + Chunks: [][]byte{ + chunk1bytes, + }, + }, + } blobs := []*pb.Blob{ { - Header: blobHeaderProto0, + Header: blobHeaderProto0, + Bundles: bundles, }, { - Header: blobHeaderProto1, + Header: blobHeaderProto1, + Bundles: bundles, }, } return &batchHeader, blobMessage, blobs