Skip to content

Commit 2a16532

Browse files
committed
Move Blockstorage code under /fabric/common package
https://jira.hyperledger.org/browse/FAB-2022 This changes introduced by this CR - Moves the block storage code from package core/ledger/blkstorage to common/ledger/blkstorage - Splits the ledger_interface.go so as to move common interfaces and data type to common/ledger package - Moves some of the util functions to common/ledger package - Moves core/ledger/ordererledger package to orderer/ledger/fsledger orderer folks can futher rename/refactor this as seems suitable to them Change-Id: I759e16f00dc2ec9bb62196121083cf48eae76948 Signed-off-by: manish <[email protected]>
1 parent e67a238 commit 2a16532

File tree

82 files changed

+626
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+626
-490
lines changed

core/ledger/blkstorage/blockstorage.go common/ledger/blkstorage/blockstorage.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ package blkstorage
1919
import (
2020
"errors"
2121

22-
"github.com/hyperledger/fabric/core/ledger"
23-
22+
"github.com/hyperledger/fabric/common/ledger"
2423
"github.com/hyperledger/fabric/protos/common"
25-
pb "github.com/hyperledger/fabric/protos/peer"
2624
)
2725

2826
// IndexableAttr represents an indexable attribute
@@ -62,7 +60,7 @@ type BlockStoreProvider interface {
6260
// of type `IndexConfig` which configures the block store on what items should be indexed
6361
type BlockStore interface {
6462
AddBlock(block *common.Block) error
65-
GetBlockchainInfo() (*pb.BlockchainInfo, error)
63+
GetBlockchainInfo() (*common.BlockchainInfo, error)
6664
RetrieveBlocks(startNum uint64) (ledger.ResultsIterator, error)
6765
RetrieveBlockByHash(blockHash []byte) (*common.Block, error)
6866
RetrieveBlockByNumber(blockNum uint64) (*common.Block, error) // blockNum of math.MaxUint64 will return last block

core/ledger/blkstorage/fsblkstorage/block_serialization.go common/ledger/blkstorage/fsblkstorage/block_serialization.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121

2222
"github.com/golang/protobuf/proto"
23-
ledgerutil "github.com/hyperledger/fabric/core/ledger/util"
23+
ledgerutil "github.com/hyperledger/fabric/common/ledger/util"
2424
"github.com/hyperledger/fabric/protos/common"
2525
"github.com/hyperledger/fabric/protos/utils"
2626
)

core/ledger/blkstorage/fsblkstorage/block_serialization_test.go common/ledger/blkstorage/fsblkstorage/block_serialization_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121

2222
"github.com/golang/protobuf/proto"
23-
"github.com/hyperledger/fabric/core/ledger/testutil"
23+
"github.com/hyperledger/fabric/common/ledger/testutil"
2424
putils "github.com/hyperledger/fabric/protos/utils"
2525
)
2626

core/ledger/blkstorage/fsblkstorage/block_stream_test.go common/ledger/blkstorage/fsblkstorage/block_stream_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121

2222
"github.com/golang/protobuf/proto"
23-
"github.com/hyperledger/fabric/core/ledger/testutil"
23+
"github.com/hyperledger/fabric/common/ledger/testutil"
2424
)
2525

2626
func TestBlockfileStream(t *testing.T) {

core/ledger/blkstorage/fsblkstorage/blockfile_mgr.go common/ledger/blkstorage/fsblkstorage/blockfile_mgr.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import (
2323
"sync/atomic"
2424

2525
"github.com/golang/protobuf/proto"
26-
"github.com/hyperledger/fabric/core/ledger/blkstorage"
27-
"github.com/hyperledger/fabric/core/ledger/util"
28-
"github.com/hyperledger/fabric/core/ledger/util/leveldbhelper"
26+
"github.com/hyperledger/fabric/common/ledger/blkstorage"
27+
"github.com/hyperledger/fabric/common/ledger/util"
28+
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
2929
"github.com/hyperledger/fabric/protos/common"
30-
pb "github.com/hyperledger/fabric/protos/peer"
3130
putil "github.com/hyperledger/fabric/protos/utils"
3231
"github.com/op/go-logging"
3332
)
@@ -153,7 +152,7 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
153152
mgr.syncIndex()
154153

155154
// init BlockchainInfo for external API's
156-
bcInfo := &pb.BlockchainInfo{
155+
bcInfo := &common.BlockchainInfo{
157156
Height: 0,
158157
CurrentBlockHash: nil,
159158
PreviousBlockHash: nil}
@@ -166,7 +165,7 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
166165
}
167166
lastBlockHash := lastBlockHeader.Hash()
168167
previousBlockHash := lastBlockHeader.PreviousHash
169-
bcInfo = &pb.BlockchainInfo{
168+
bcInfo = &common.BlockchainInfo{
170169
Height: cpInfo.lastBlockNumber,
171170
CurrentBlockHash: lastBlockHash,
172171
PreviousBlockHash: previousBlockHash}
@@ -373,8 +372,8 @@ func (mgr *blockfileMgr) syncIndex() error {
373372
return nil
374373
}
375374

376-
func (mgr *blockfileMgr) getBlockchainInfo() *pb.BlockchainInfo {
377-
return mgr.bcInfo.Load().(*pb.BlockchainInfo)
375+
func (mgr *blockfileMgr) getBlockchainInfo() *common.BlockchainInfo {
376+
return mgr.bcInfo.Load().(*common.BlockchainInfo)
378377
}
379378

380379
func (mgr *blockfileMgr) updateCheckpoint(cpInfo *checkpointInfo) {
@@ -387,7 +386,7 @@ func (mgr *blockfileMgr) updateCheckpoint(cpInfo *checkpointInfo) {
387386

388387
func (mgr *blockfileMgr) updateBlockchainInfo(latestBlockHash []byte, latestBlock *common.Block) {
389388
currentBCInfo := mgr.getBlockchainInfo()
390-
newBCInfo := &pb.BlockchainInfo{
389+
newBCInfo := &common.BlockchainInfo{
391390
Height: currentBCInfo.Height + 1,
392391
CurrentBlockHash: latestBlockHash,
393392
PreviousBlockHash: latestBlock.Header.PreviousHash}

core/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go common/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ import (
2121
"testing"
2222

2323
"github.com/golang/protobuf/proto"
24-
"github.com/hyperledger/fabric/core/ledger/testutil"
24+
"github.com/hyperledger/fabric/common/ledger/testutil"
2525

2626
"github.com/hyperledger/fabric/protos/common"
27-
pb "github.com/hyperledger/fabric/protos/peer"
2827
putil "github.com/hyperledger/fabric/protos/utils"
2928
)
3029

@@ -127,7 +126,7 @@ func TestBlockfileMgrBlockchainInfo(t *testing.T) {
127126
defer blkfileMgrWrapper.close()
128127

129128
bcInfo := blkfileMgrWrapper.blockfileMgr.getBlockchainInfo()
130-
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{Height: 0, CurrentBlockHash: nil, PreviousBlockHash: nil})
129+
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{Height: 0, CurrentBlockHash: nil, PreviousBlockHash: nil})
131130

132131
blocks := testutil.ConstructTestBlocks(t, 10)
133132
blkfileMgrWrapper.addBlocks(blocks)

core/ledger/blkstorage/fsblkstorage/blockfile_scan_test.go common/ledger/blkstorage/fsblkstorage/blockfile_scan_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"os"
2121
"testing"
2222

23-
"github.com/hyperledger/fabric/core/ledger/testutil"
24-
"github.com/hyperledger/fabric/core/ledger/util"
23+
"github.com/hyperledger/fabric/common/ledger/testutil"
24+
"github.com/hyperledger/fabric/common/ledger/util"
2525

2626
"github.com/hyperledger/fabric/protos/common"
2727
)

core/ledger/blkstorage/fsblkstorage/blockindex.go common/ledger/blkstorage/fsblkstorage/blockindex.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"fmt"
2121

2222
"github.com/golang/protobuf/proto"
23-
"github.com/hyperledger/fabric/core/ledger/blkstorage"
24-
"github.com/hyperledger/fabric/core/ledger/util"
25-
"github.com/hyperledger/fabric/core/ledger/util/leveldbhelper"
23+
"github.com/hyperledger/fabric/common/ledger/blkstorage"
24+
"github.com/hyperledger/fabric/common/ledger/util"
25+
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
2626
)
2727

2828
const (

core/ledger/blkstorage/fsblkstorage/blockindex_test.go common/ledger/blkstorage/fsblkstorage/blockindex_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"fmt"
2121
"testing"
2222

23-
"github.com/hyperledger/fabric/core/ledger/blkstorage"
24-
"github.com/hyperledger/fabric/core/ledger/testutil"
23+
"github.com/hyperledger/fabric/common/ledger/blkstorage"
24+
"github.com/hyperledger/fabric/common/ledger/testutil"
2525
putil "github.com/hyperledger/fabric/protos/utils"
2626
)
2727

core/ledger/blkstorage/fsblkstorage/blocks_itr.go common/ledger/blkstorage/fsblkstorage/blocks_itr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"sync"
2222

23-
"github.com/hyperledger/fabric/core/ledger"
23+
"github.com/hyperledger/fabric/common/ledger"
2424

2525
"github.com/hyperledger/fabric/protos/common"
2626
)

core/ledger/blkstorage/fsblkstorage/blocks_itr_test.go common/ledger/blkstorage/fsblkstorage/blocks_itr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121
"time"
2222

23-
"github.com/hyperledger/fabric/core/ledger/testutil"
23+
"github.com/hyperledger/fabric/common/ledger/testutil"
2424
"github.com/hyperledger/fabric/protos/common"
2525
)
2626

core/ledger/blkstorage/fsblkstorage/fs_blockstore.go common/ledger/blkstorage/fsblkstorage/fs_blockstore.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ limitations under the License.
1717
package fsblkstorage
1818

1919
import (
20-
"github.com/hyperledger/fabric/core/ledger"
21-
"github.com/hyperledger/fabric/core/ledger/blkstorage"
22-
"github.com/hyperledger/fabric/core/ledger/util/leveldbhelper"
20+
"github.com/hyperledger/fabric/common/ledger"
21+
"github.com/hyperledger/fabric/common/ledger/blkstorage"
22+
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
2323

2424
"github.com/hyperledger/fabric/protos/common"
25-
pb "github.com/hyperledger/fabric/protos/peer"
2625
)
2726

2827
// fsBlockStore - filesystem based implementation for `BlockStore`
@@ -44,7 +43,7 @@ func (store *fsBlockStore) AddBlock(block *common.Block) error {
4443
}
4544

4645
// GetBlockchainInfo returns the current info about blockchain
47-
func (store *fsBlockStore) GetBlockchainInfo() (*pb.BlockchainInfo, error) {
46+
func (store *fsBlockStore) GetBlockchainInfo() (*common.BlockchainInfo, error) {
4847
return store.fileMgr.getBlockchainInfo(), nil
4948
}
5049

core/ledger/blkstorage/fsblkstorage/fs_blockstore_provider.go common/ledger/blkstorage/fsblkstorage/fs_blockstore_provider.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package fsblkstorage
1818

1919
import (
20-
"github.com/hyperledger/fabric/core/ledger/blkstorage"
21-
"github.com/hyperledger/fabric/core/ledger/util"
22-
"github.com/hyperledger/fabric/core/ledger/util/leveldbhelper"
20+
"github.com/hyperledger/fabric/common/ledger/blkstorage"
21+
"github.com/hyperledger/fabric/common/ledger/util"
22+
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
2323
)
2424

2525
// FsBlockstoreProvider provides handle to block storage - this is not thread-safe

core/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go common/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121

2222
"fmt"
2323

24-
"github.com/hyperledger/fabric/core/ledger"
25-
"github.com/hyperledger/fabric/core/ledger/blkstorage"
26-
"github.com/hyperledger/fabric/core/ledger/testutil"
24+
"github.com/hyperledger/fabric/common/ledger"
25+
"github.com/hyperledger/fabric/common/ledger/blkstorage"
26+
"github.com/hyperledger/fabric/common/ledger/testutil"
2727
"github.com/hyperledger/fabric/protos/common"
2828
)
2929

core/ledger/blkstorage/fsblkstorage/pkg_test.go common/ledger/blkstorage/fsblkstorage/pkg_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"os"
2323
"testing"
2424

25-
"github.com/hyperledger/fabric/core/ledger/blkstorage"
26-
"github.com/hyperledger/fabric/core/ledger/testutil"
25+
"github.com/hyperledger/fabric/common/ledger/blkstorage"
26+
"github.com/hyperledger/fabric/common/ledger/testutil"
2727

2828
"github.com/hyperledger/fabric/protos/common"
2929
)

common/ledger/ledger_interface.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package ledger
18+
19+
import (
20+
"github.com/hyperledger/fabric/protos/common"
21+
)
22+
23+
// Ledger captures the methods that are common across the 'PeerLedger', 'OrdererLedger', and 'ValidatedLedger'
24+
type Ledger interface {
25+
// GetBlockchainInfo returns basic info about blockchain
26+
GetBlockchainInfo() (*common.BlockchainInfo, error)
27+
// GetBlockByNumber returns block at a given height
28+
// blockNumber of math.MaxUint64 will return last block
29+
GetBlockByNumber(blockNumber uint64) (*common.Block, error)
30+
// GetBlocksIterator returns an iterator that starts from `startBlockNumber`(inclusive).
31+
// The iterator is a blocking iterator i.e., it blocks till the next block gets available in the ledger
32+
// ResultsIterator contains type BlockHolder
33+
GetBlocksIterator(startBlockNumber uint64) (ResultsIterator, error)
34+
// Close closes the ledger
35+
Close()
36+
// Commit adds a new block
37+
Commit(block *common.Block) error
38+
}
39+
40+
// ResultsIterator - an iterator for query result set
41+
type ResultsIterator interface {
42+
// Next returns the next item in the result set. The `QueryResult` is expected to be nil when
43+
// the iterator gets exhausted
44+
Next() (QueryResult, error)
45+
// Close releases resources occupied by the iterator
46+
Close()
47+
}
48+
49+
// QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries
50+
type QueryResult interface{}
51+
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+
59+
// PrunePolicy - a general interface for supporting different pruning policies
60+
type PrunePolicy interface{}

core/ledger/testutil/test_helper.go common/ledger/testutil/test_helper.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/golang/protobuf/proto"
2323
"github.com/hyperledger/fabric/common/util"
2424
"github.com/hyperledger/fabric/protos/common"
25-
pb "github.com/hyperledger/fabric/protos/peer"
2625
ptestutils "github.com/hyperledger/fabric/protos/testutils"
2726
)
2827

@@ -93,14 +92,14 @@ func ConstructTestBlocks(t *testing.T, numBlocks int) []*common.Block {
9392
// ConstructTransaction constructs a transaction for testing
9493
func ConstructTransaction(t *testing.T, simulationResults []byte, sign bool) (*common.Envelope, string, error) {
9594
ccName := "foo"
96-
response := &pb.Response{Status: 200}
95+
//response := &pb.Response{Status: 200}
9796
txID := util.GenerateUUID()
9897
var txEnv *common.Envelope
9998
var err error
10099
if sign {
101-
txEnv, err = ptestutils.ConstructSingedTxEnvWithDefaultSigner(txID, util.GetTestChainID(), ccName, response, simulationResults, nil, nil)
100+
txEnv, err = ptestutils.ConstructSingedTxEnvWithDefaultSigner(txID, util.GetTestChainID(), ccName, nil, simulationResults, nil, nil)
102101
} else {
103-
txEnv, err = ptestutils.ConstructUnsingedTxEnv(txID, util.GetTestChainID(), ccName, response, simulationResults, nil, nil)
102+
txEnv, err = ptestutils.ConstructUnsingedTxEnv(txID, util.GetTestChainID(), ccName, nil, simulationResults, nil, nil)
104103
}
105104
return txEnv, txID, err
106105
}

0 commit comments

Comments
 (0)