Skip to content

Commit

Permalink
[FAB-3673] remove blockhoder interface/struct
Browse files Browse the repository at this point in the history
This CR removes Blockholder interface/struct and uses common.Block
everywhere in common ledger.

Change-Id: I66de25a603c61c4c8131c6fb53b5545f5717fb4c
Signed-off-by: manish <manish.sethi@gmail.com>
  • Loading branch information
manish-sethi committed May 5, 2017
1 parent add0af3 commit 001b8e3
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 1 addition & 23 deletions common/ledger/blkstorage/fsblkstorage/blocks_itr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions common/ledger/blkstorage/fsblkstorage/blocks_itr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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])
}

Expand Down
7 changes: 0 additions & 7 deletions common/ledger/ledger_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

0 comments on commit 001b8e3

Please sign in to comment.