Skip to content

Commit

Permalink
Use a local copy of last batch
Browse files Browse the repository at this point in the history
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 <gabor@digitalasset.com>
  • Loading branch information
gaborh-da committed Jan 13, 2017
1 parent cfbe227 commit d85251d
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions orderer/sbft/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"github.com/hyperledger/fabric/orderer/sbft/persist"
s "github.com/hyperledger/fabric/orderer/sbft/simplebft"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
"github.com/op/go-logging"
)

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

persistence *persist.Persist
ledger rawledger.ReadWriter

lastBatch *s.Batch
}

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

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

func (t *Backend) LastBatch() *s.Batch {
it, _ := t.ledger.Iterator(&ab.SeekPosition{Type: &ab.SeekPosition_Newest{}})
block, status := it.Next()
data := block.Data.Data
if status != cb.Status_SUCCESS {
panic("Fatal ledger error: unable to get last block.")
}
header := getHeader(block.Metadata)
sgns := decodeSignatures(getEncodedSignatures(block.Metadata))
batch := s.Batch{Header: header, Payloads: data, Signatures: sgns}
return &batch
return t.lastBatch
}

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

0 comments on commit d85251d

Please sign in to comment.