Skip to content

Commit d85251d

Browse files
committed
Use a local copy of last batch
SBFT used the ledger and an iterator to get the last batch. This commit changes this and tries to use a "local copy" that is generally a field in the backend struct. There are two cases: - backend (System implementation) only knows about Genesis, we can assume that the last batch is one with an empty header, empty signatures and empty payload batch - backend's Deliver is called on (re)connection or at batch delivery - here we can use the argument (batch of type Batch) to update the last batch Change-Id: Ibd381347df832643a547a3b05bdc7331f4fb1382 Signed-off-by: Gabor Hosszu <[email protected]>
1 parent cfbe227 commit d85251d

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

orderer/sbft/backend/backend.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"github.com/hyperledger/fabric/orderer/sbft/persist"
4646
s "github.com/hyperledger/fabric/orderer/sbft/simplebft"
4747
cb "github.com/hyperledger/fabric/protos/common"
48-
ab "github.com/hyperledger/fabric/protos/orderer"
4948
"github.com/op/go-logging"
5049
)
5150

@@ -69,6 +68,8 @@ type Backend struct {
6968

7069
persistence *persist.Persist
7170
ledger rawledger.ReadWriter
71+
72+
lastBatch *s.Batch
7273
}
7374

7475
type consensusConn Backend
@@ -134,6 +135,7 @@ func NewBackend(peers map[string][]byte, conn *connection.Manager, rl rawledger.
134135
}
135136
RegisterConsensusServer(conn.Server, (*consensusConn)(c))
136137
c.persistence = persist
138+
c.lastBatch = &s.Batch{Header: nil, Signatures: nil, Payloads: [][]byte{}}
137139
c.queue = make(chan Executable)
138140
go c.run()
139141
return c, nil
@@ -313,6 +315,7 @@ func (t *Backend) Deliver(batch *s.Batch) {
313315
// SBFT needs to use Rawledger's structures and signatures over the Block.
314316
block.Metadata.Metadata[headerIndex] = batch.Header
315317
block.Metadata.Metadata[signaturesIndex] = encodeSignatures(batch.Signatures)
318+
t.lastBatch = batch
316319
t.ledger.Append(block)
317320
}
318321

@@ -338,16 +341,7 @@ func (t *Backend) Restore(key string, out proto.Message) bool {
338341
}
339342

340343
func (t *Backend) LastBatch() *s.Batch {
341-
it, _ := t.ledger.Iterator(&ab.SeekPosition{Type: &ab.SeekPosition_Newest{}})
342-
block, status := it.Next()
343-
data := block.Data.Data
344-
if status != cb.Status_SUCCESS {
345-
panic("Fatal ledger error: unable to get last block.")
346-
}
347-
header := getHeader(block.Metadata)
348-
sgns := decodeSignatures(getEncodedSignatures(block.Metadata))
349-
batch := s.Batch{Header: header, Payloads: data, Signatures: sgns}
350-
return &batch
344+
return t.lastBatch
351345
}
352346

353347
func (t *Backend) Sign(data []byte) []byte {

0 commit comments

Comments
 (0)