diff --git a/common/deliver/deliver.go b/common/deliver/deliver.go index e87a85e2548..c6b16a4a868 100644 --- a/common/deliver/deliver.go +++ b/common/deliver/deliver.go @@ -328,12 +328,18 @@ func (h *Handler) deliverBlocks(ctx context.Context, srv *Server, envelope *cb.E logger.Debugf("[channel: %s] Delivering block [%d] for (%p) for %s", chdr.ChannelId, block.Header.Number, seekInfo, addr) + // Data blocks carry nil data for block attestations. + // Never mutate the block received from the iterator as it is from a cache. + block2send := block if seekInfo.ContentType == ab.SeekInfo_HEADER_WITH_SIG && !protoutil.IsConfigBlock(block) { - block.Data = nil + block2send = &cb.Block{ + Header: block.Header, + Metadata: block.Metadata, + } } signedData := &protoutil.SignedData{Data: envelope.Payload, Identity: shdr.Creator, Signature: envelope.Signature} - if err := srv.SendBlockResponse(block, chdr.ChannelId, chain, signedData); err != nil { + if err := srv.SendBlockResponse(block2send, chdr.ChannelId, chain, signedData); err != nil { logger.Warningf("[channel: %s] Error sending to %s: %s", chdr.ChannelId, addr, err) return cb.Status_INTERNAL_SERVER_ERROR, err } diff --git a/common/deliver/deliver_test.go b/common/deliver/deliver_test.go index f3c67d570ae..12c55cfb16e 100644 --- a/common/deliver/deliver_test.go +++ b/common/deliver/deliver_test.go @@ -502,6 +502,7 @@ var _ = Describe("Deliver", func() { }) Context("when seek info is configured to header with sig content type", func() { + var cachedBlocks []*cb.Block BeforeEach(func() { seekInfo = &ab.SeekInfo{ Start: &ab.SeekPosition{}, @@ -516,11 +517,12 @@ var _ = Describe("Deliver", func() { Data: &cb.BlockData{Data: [][]byte{{1}, {2}}}, Metadata: &cb.BlockMetadata{Metadata: [][]byte{{3}, {4}}}, } + cachedBlocks = append(cachedBlocks, blk) return blk, cb.Status_SUCCESS } }) - It("sends blocks with nil Data", func() { + It("sends blocks with nil Data, but does not mutate cached blocks", func() { err := handler.Handle(context.Background(), server) Expect(err).NotTo(HaveOccurred()) @@ -538,6 +540,10 @@ var _ = Describe("Deliver", func() { Metadata: &cb.BlockMetadata{Metadata: [][]byte{{3}, {4}}}, })) } + + for _, b := range cachedBlocks { + Expect(b.Data).ToNot(BeNil()) + } }) })