From 001b8e3ea69df786cb3c1feef27f6ad57afb5eb3 Mon Sep 17 00:00:00 2001 From: manish Date: Fri, 5 May 2017 15:15:16 +0530 Subject: [PATCH] [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 --- .../fsblkstorage/blockfile_mgr_test.go | 2 +- .../blkstorage/fsblkstorage/blocks_itr.go | 24 +------------------ .../fsblkstorage/blocks_itr_test.go | 4 ++-- .../fs_blockstore_provider_test.go | 4 +--- common/ledger/ledger_interface.go | 7 ------ 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/common/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go b/common/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go index 25b732f2911..4fd4781ac14 100644 --- a/common/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go +++ b/common/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go @@ -124,7 +124,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr, for { block, err := itr.Next() testutil.AssertNoError(t, err, fmt.Sprintf("Error while getting block number [%d] from iterator", numBlocksItrated)) - testutil.AssertEquals(t, block.(*blockHolder).GetBlock(), expectedBlocks[numBlocksItrated]) + testutil.AssertEquals(t, block, expectedBlocks[numBlocksItrated]) numBlocksItrated++ if numBlocksItrated == lastBlockNum-firstBlockNum+1 { break diff --git a/common/ledger/blkstorage/fsblkstorage/blocks_itr.go b/common/ledger/blkstorage/fsblkstorage/blocks_itr.go index 566e807ad55..52cee7a5d8e 100644 --- a/common/ledger/blkstorage/fsblkstorage/blocks_itr.go +++ b/common/ledger/blkstorage/fsblkstorage/blocks_itr.go @@ -17,33 +17,11 @@ limitations under the License. package fsblkstorage import ( - "fmt" "sync" "github.com/hyperledger/fabric/common/ledger" - - "github.com/hyperledger/fabric/protos/common" ) -// blockHolder holds block bytes -type blockHolder struct { - blockBytes []byte -} - -// GetBlock serializes Block from block bytes -func (bh *blockHolder) GetBlock() *common.Block { - block, err := deserializeBlock(bh.blockBytes) - if err != nil { - panic(fmt.Errorf("Problem in deserialzing block: %s", err)) - } - return block -} - -// GetBlockBytes returns block bytes -func (bh *blockHolder) GetBlockBytes() []byte { - return bh.blockBytes -} - // blocksItr - an iterator for iterating over a sequence of blocks type blocksItr struct { mgr *blockfileMgr @@ -108,7 +86,7 @@ func (itr *blocksItr) Next() (ledger.QueryResult, error) { return nil, err } itr.blockNumToRetrieve++ - return &blockHolder{nextBlockBytes}, nil + return deserializeBlock(nextBlockBytes) } // Close releases any resources held by the iterator diff --git a/common/ledger/blkstorage/fsblkstorage/blocks_itr_test.go b/common/ledger/blkstorage/fsblkstorage/blocks_itr_test.go index 1f9ddf3b3ed..4cb804674ac 100644 --- a/common/ledger/blkstorage/fsblkstorage/blocks_itr_test.go +++ b/common/ledger/blkstorage/fsblkstorage/blocks_itr_test.go @@ -78,9 +78,9 @@ func testIterateAndVerify(t *testing.T, itr *blocksItr, blocks []*common.Block, blocksIterated := 0 for { t.Logf("blocksIterated: %v", blocksIterated) - bh, err := itr.Next() + block, err := itr.Next() testutil.AssertNoError(t, err, "") - testutil.AssertEquals(t, bh.(*blockHolder).GetBlock(), blocks[blocksIterated]) + testutil.AssertEquals(t, block, blocks[blocksIterated]) blocksIterated++ if blocksIterated == len(blocks) { break diff --git a/common/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go b/common/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go index 8ded0cec697..79a49bd276c 100644 --- a/common/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go +++ b/common/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go @@ -21,7 +21,6 @@ import ( "fmt" - "github.com/hyperledger/fabric/common/ledger" "github.com/hyperledger/fabric/common/ledger/blkstorage" "github.com/hyperledger/fabric/common/ledger/testutil" "github.com/hyperledger/fabric/core/ledger/util" @@ -63,8 +62,7 @@ func checkBlocks(t *testing.T, expectedBlocks []*common.Block, store blkstorage. itr, _ := store.RetrieveBlocks(0) for i := 0; i < len(expectedBlocks); i++ { - blockHolder, _ := itr.Next() - block := blockHolder.(ledger.BlockHolder).GetBlock() + block, _ := itr.Next() testutil.AssertEquals(t, block, expectedBlocks[i]) } diff --git a/common/ledger/ledger_interface.go b/common/ledger/ledger_interface.go index 6a9d92f1484..f6d0bbb9561 100644 --- a/common/ledger/ledger_interface.go +++ b/common/ledger/ledger_interface.go @@ -49,12 +49,5 @@ type ResultsIterator interface { // QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries type QueryResult interface{} -// BlockHolder holds block returned by the iterator in GetBlocksIterator. -// The sole purpose of this holder is to avoid desrialization if block is desired in raw bytes form (e.g., for transfer) -type BlockHolder interface { - GetBlock() *common.Block - GetBlockBytes() []byte -} - // PrunePolicy - a general interface for supporting different pruning policies type PrunePolicy interface{}