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

BFT: orderer deliver headers on cache #4455

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions common/deliver/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion common/deliver/deliver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -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())

Expand All @@ -538,6 +540,10 @@ var _ = Describe("Deliver", func() {
Metadata: &cb.BlockMetadata{Metadata: [][]byte{{3}, {4}}},
}))
}

for _, b := range cachedBlocks {
Expect(b.Data).ToNot(BeNil())
}
})
})

Expand Down