Skip to content

Commit

Permalink
[FAB-12508] Add Block(seq) to consenter support
Browse files Browse the repository at this point in the history
This change set adds a method that retrieves a block from
the ledger in the consenter support.

Change-Id: Id088ec688e169d306c242352b485a8e47809b7db
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Oct 25, 2018
1 parent 319ca36 commit 41da334
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/ledger/blockledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Writer interface {
Append(block *cb.Block) error
}

//go:generate mockery -dir . -name ReadWriter -case underscore -output mocks/

// ReadWriter encapsulates the read/write functions of the ledger
type ReadWriter interface {
Reader
Expand Down
63 changes: 63 additions & 0 deletions common/ledger/blockledger/mocks/read_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions orderer/common/multichannel/chainsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func newChainSupport(
return cs
}

// Block returns a block with the following number,
// or nil if such a block doesn't exist.
func (cs *ChainSupport) Block(number uint64) *cb.Block {
if cs.Height() <= number {
return nil
}
return blockledger.GetBlock(cs.Reader(), number)
}

func (cs *ChainSupport) Reader() blockledger.Reader {
return cs
}
Expand Down
33 changes: 33 additions & 0 deletions orderer/common/multichannel/chainsupprt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package multichannel

import (
"testing"

"github.com/hyperledger/fabric/common/deliver/mock"
"github.com/hyperledger/fabric/common/ledger/blockledger/mocks"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/orderer"
"github.com/stretchr/testify/assert"
)

func TestChainSupportBlock(t *testing.T) {
ledger := &mocks.ReadWriter{}
ledger.On("Height").Return(uint64(100))
iterator := &mock.BlockIterator{}
iterator.NextReturns(&common.Block{Header: &common.BlockHeader{Number: 99}}, common.Status_SUCCESS)
ledger.On("Iterator", &orderer.SeekPosition{
Type: &orderer.SeekPosition_Specified{
Specified: &orderer.SeekSpecified{Number: 99},
},
}).Return(iterator, uint64(99))
cs := &ChainSupport{ledgerResources: &ledgerResources{ReadWriter: ledger}}

assert.Nil(t, cs.Block(100))
assert.Equal(t, uint64(99), cs.Block(99).Header.Number)
}
4 changes: 4 additions & 0 deletions orderer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ type ConsenterSupport interface {
// Note that either WriteBlock or WriteConfigBlock must be called before invoking this method a second time.
CreateNextBlock(messages []*cb.Envelope) *cb.Block

// Block returns a block with the following number,
// or nil if such a block doesn't exist.
Block(number uint64) *cb.Block

// WriteBlock commits a block to the ledger.
WriteBlock(block *cb.Block, encodedMetadataValue []byte)

Expand Down
5 changes: 5 additions & 0 deletions orderer/consensus/kafka/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,11 @@ type mockConsenterSupport struct {
mock.Mock
}

func (c *mockConsenterSupport) Block(seq uint64) *cb.Block {
// TODO: implement this
return nil
}

func (c *mockConsenterSupport) NewSignatureHeader() (*cb.SignatureHeader, error) {
args := c.Called()
return args.Get(0).(*cb.SignatureHeader), args.Error(1)
Expand Down
61 changes: 61 additions & 0 deletions orderer/consensus/mocks/mock_consenter_support.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions orderer/mocks/common/multichannel/multichannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ type ConsenterSupport struct {
SequenceVal uint64
}

func (mcs *ConsenterSupport) Block(seq uint64) *cb.Block {
// TODO: implement this
return nil
}

// BlockCutter returns BlockCutterVal
func (mcs *ConsenterSupport) BlockCutter() blockcutter.Receiver {
return mcs.BlockCutterVal
Expand Down

0 comments on commit 41da334

Please sign in to comment.