Skip to content

Commit 41da334

Browse files
committed
[FAB-12508] Add Block(seq) to consenter support
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>
1 parent 319ca36 commit 41da334

File tree

8 files changed

+182
-0
lines changed

8 files changed

+182
-0
lines changed

common/ledger/blockledger/ledger.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type Writer interface {
4848
Append(block *cb.Block) error
4949
}
5050

51+
//go:generate mockery -dir . -name ReadWriter -case underscore -output mocks/
52+
5153
// ReadWriter encapsulates the read/write functions of the ledger
5254
type ReadWriter interface {
5355
Reader

common/ledger/blockledger/mocks/read_writer.go

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orderer/common/multichannel/chainsupport.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ func newChainSupport(
7373
return cs
7474
}
7575

76+
// Block returns a block with the following number,
77+
// or nil if such a block doesn't exist.
78+
func (cs *ChainSupport) Block(number uint64) *cb.Block {
79+
if cs.Height() <= number {
80+
return nil
81+
}
82+
return blockledger.GetBlock(cs.Reader(), number)
83+
}
84+
7685
func (cs *ChainSupport) Reader() blockledger.Reader {
7786
return cs
7887
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package multichannel
8+
9+
import (
10+
"testing"
11+
12+
"github.com/hyperledger/fabric/common/deliver/mock"
13+
"github.com/hyperledger/fabric/common/ledger/blockledger/mocks"
14+
"github.com/hyperledger/fabric/protos/common"
15+
"github.com/hyperledger/fabric/protos/orderer"
16+
"github.com/stretchr/testify/assert"
17+
)
18+
19+
func TestChainSupportBlock(t *testing.T) {
20+
ledger := &mocks.ReadWriter{}
21+
ledger.On("Height").Return(uint64(100))
22+
iterator := &mock.BlockIterator{}
23+
iterator.NextReturns(&common.Block{Header: &common.BlockHeader{Number: 99}}, common.Status_SUCCESS)
24+
ledger.On("Iterator", &orderer.SeekPosition{
25+
Type: &orderer.SeekPosition_Specified{
26+
Specified: &orderer.SeekSpecified{Number: 99},
27+
},
28+
}).Return(iterator, uint64(99))
29+
cs := &ChainSupport{ledgerResources: &ledgerResources{ReadWriter: ledger}}
30+
31+
assert.Nil(t, cs.Block(100))
32+
assert.Equal(t, uint64(99), cs.Block(99).Header.Number)
33+
}

orderer/consensus/consensus.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ type ConsenterSupport interface {
8484
// Note that either WriteBlock or WriteConfigBlock must be called before invoking this method a second time.
8585
CreateNextBlock(messages []*cb.Envelope) *cb.Block
8686

87+
// Block returns a block with the following number,
88+
// or nil if such a block doesn't exist.
89+
Block(number uint64) *cb.Block
90+
8791
// WriteBlock commits a block to the ledger.
8892
WriteBlock(block *cb.Block, encodedMetadataValue []byte)
8993

orderer/consensus/kafka/chain_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,6 +3634,11 @@ type mockConsenterSupport struct {
36343634
mock.Mock
36353635
}
36363636

3637+
func (c *mockConsenterSupport) Block(seq uint64) *cb.Block {
3638+
// TODO: implement this
3639+
return nil
3640+
}
3641+
36373642
func (c *mockConsenterSupport) NewSignatureHeader() (*cb.SignatureHeader, error) {
36383643
args := c.Called()
36393644
return args.Get(0).(*cb.SignatureHeader), args.Error(1)

orderer/consensus/mocks/mock_consenter_support.go

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orderer/mocks/common/multichannel/multichannel.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ type ConsenterSupport struct {
6262
SequenceVal uint64
6363
}
6464

65+
func (mcs *ConsenterSupport) Block(seq uint64) *cb.Block {
66+
// TODO: implement this
67+
return nil
68+
}
69+
6570
// BlockCutter returns BlockCutterVal
6671
func (mcs *ConsenterSupport) BlockCutter() blockcutter.Receiver {
6772
return mcs.BlockCutterVal

0 commit comments

Comments
 (0)