Skip to content

Commit 001b8e3

Browse files
committed
[FAB-3673] remove blockhoder interface/struct
This CR removes Blockholder interface/struct and uses common.Block everywhere in common ledger. Change-Id: I66de25a603c61c4c8131c6fb53b5545f5717fb4c Signed-off-by: manish <[email protected]>
1 parent add0af3 commit 001b8e3

File tree

5 files changed

+5
-36
lines changed

5 files changed

+5
-36
lines changed

common/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr,
124124
for {
125125
block, err := itr.Next()
126126
testutil.AssertNoError(t, err, fmt.Sprintf("Error while getting block number [%d] from iterator", numBlocksItrated))
127-
testutil.AssertEquals(t, block.(*blockHolder).GetBlock(), expectedBlocks[numBlocksItrated])
127+
testutil.AssertEquals(t, block, expectedBlocks[numBlocksItrated])
128128
numBlocksItrated++
129129
if numBlocksItrated == lastBlockNum-firstBlockNum+1 {
130130
break

common/ledger/blkstorage/fsblkstorage/blocks_itr.go

+1-23
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,11 @@ limitations under the License.
1717
package fsblkstorage
1818

1919
import (
20-
"fmt"
2120
"sync"
2221

2322
"github.com/hyperledger/fabric/common/ledger"
24-
25-
"github.com/hyperledger/fabric/protos/common"
2623
)
2724

28-
// blockHolder holds block bytes
29-
type blockHolder struct {
30-
blockBytes []byte
31-
}
32-
33-
// GetBlock serializes Block from block bytes
34-
func (bh *blockHolder) GetBlock() *common.Block {
35-
block, err := deserializeBlock(bh.blockBytes)
36-
if err != nil {
37-
panic(fmt.Errorf("Problem in deserialzing block: %s", err))
38-
}
39-
return block
40-
}
41-
42-
// GetBlockBytes returns block bytes
43-
func (bh *blockHolder) GetBlockBytes() []byte {
44-
return bh.blockBytes
45-
}
46-
4725
// blocksItr - an iterator for iterating over a sequence of blocks
4826
type blocksItr struct {
4927
mgr *blockfileMgr
@@ -108,7 +86,7 @@ func (itr *blocksItr) Next() (ledger.QueryResult, error) {
10886
return nil, err
10987
}
11088
itr.blockNumToRetrieve++
111-
return &blockHolder{nextBlockBytes}, nil
89+
return deserializeBlock(nextBlockBytes)
11290
}
11391

11492
// Close releases any resources held by the iterator

common/ledger/blkstorage/fsblkstorage/blocks_itr_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func testIterateAndVerify(t *testing.T, itr *blocksItr, blocks []*common.Block,
7878
blocksIterated := 0
7979
for {
8080
t.Logf("blocksIterated: %v", blocksIterated)
81-
bh, err := itr.Next()
81+
block, err := itr.Next()
8282
testutil.AssertNoError(t, err, "")
83-
testutil.AssertEquals(t, bh.(*blockHolder).GetBlock(), blocks[blocksIterated])
83+
testutil.AssertEquals(t, block, blocks[blocksIterated])
8484
blocksIterated++
8585
if blocksIterated == len(blocks) {
8686
break

common/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"fmt"
2323

24-
"github.com/hyperledger/fabric/common/ledger"
2524
"github.com/hyperledger/fabric/common/ledger/blkstorage"
2625
"github.com/hyperledger/fabric/common/ledger/testutil"
2726
"github.com/hyperledger/fabric/core/ledger/util"
@@ -63,8 +62,7 @@ func checkBlocks(t *testing.T, expectedBlocks []*common.Block, store blkstorage.
6362

6463
itr, _ := store.RetrieveBlocks(0)
6564
for i := 0; i < len(expectedBlocks); i++ {
66-
blockHolder, _ := itr.Next()
67-
block := blockHolder.(ledger.BlockHolder).GetBlock()
65+
block, _ := itr.Next()
6866
testutil.AssertEquals(t, block, expectedBlocks[i])
6967
}
7068

common/ledger/ledger_interface.go

-7
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,5 @@ type ResultsIterator interface {
4949
// QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries
5050
type QueryResult interface{}
5151

52-
// BlockHolder holds block returned by the iterator in GetBlocksIterator.
53-
// The sole purpose of this holder is to avoid desrialization if block is desired in raw bytes form (e.g., for transfer)
54-
type BlockHolder interface {
55-
GetBlock() *common.Block
56-
GetBlockBytes() []byte
57-
}
58-
5952
// PrunePolicy - a general interface for supporting different pruning policies
6053
type PrunePolicy interface{}

0 commit comments

Comments
 (0)