Commit 2a16532c authored by manish's avatar manish
Browse files

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: default avatarmanish <manish.sethi@gmail.com>
parent e67a2382
......@@ -21,8 +21,8 @@ import (
"testing"
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/spf13/viper"
)
......
......@@ -20,13 +20,13 @@ import (
"os"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/history/historydb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/stateleveldb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/spf13/viper"
)
......
......@@ -20,8 +20,9 @@ import (
"errors"
"fmt"
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/common/ledger/blkstorage"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/blkstorage"
"github.com/hyperledger/fabric/core/ledger/kvledger/history/historydb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
......@@ -31,7 +32,6 @@ import (
logging "github.com/op/go-logging"
"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
)
var logger = logging.MustGetLogger("kvledger")
......@@ -205,7 +205,7 @@ func (l *kvLedger) GetTransactionByID(txID string) (*common.Envelope, error) {
}
// GetBlockchainInfo returns basic info about blockchain
func (l *kvLedger) GetBlockchainInfo() (*pb.BlockchainInfo, error) {
func (l *kvLedger) GetBlockchainInfo() (*common.BlockchainInfo, error) {
return l.blockStore.GetBlockchainInfo()
}
......@@ -219,7 +219,7 @@ func (l *kvLedger) GetBlockByNumber(blockNumber uint64) (*common.Block, error) {
// GetBlocksIterator returns an iterator that starts from `startBlockNumber`(inclusive).
// The iterator is a blocking iterator i.e., it blocks till the next block gets available in the ledger
// ResultsIterator contains type BlockHolder
func (l *kvLedger) GetBlocksIterator(startBlockNumber uint64) (ledger.ResultsIterator, error) {
func (l *kvLedger) GetBlocksIterator(startBlockNumber uint64) (commonledger.ResultsIterator, error) {
return l.blockStore.RetrieveBlocks(startBlockNumber)
}
......@@ -230,7 +230,7 @@ func (l *kvLedger) GetBlockByHash(blockHash []byte) (*common.Block, error) {
}
//Prune prunes the blocks/transactions that satisfy the given policy
func (l *kvLedger) Prune(policy ledger.PrunePolicy) error {
func (l *kvLedger) Prune(policy commonledger.PrunePolicy) error {
return errors.New("Not yet implemented")
}
......
......@@ -19,16 +19,16 @@ package kvledger
import (
"errors"
"github.com/hyperledger/fabric/common/ledger/blkstorage"
"github.com/hyperledger/fabric/common/ledger/blkstorage/fsblkstorage"
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/blkstorage"
"github.com/hyperledger/fabric/core/ledger/blkstorage/fsblkstorage"
"github.com/hyperledger/fabric/core/ledger/kvledger/history/historydb"
"github.com/hyperledger/fabric/core/ledger/kvledger/history/historydb/historyleveldb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/statecouchdb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/stateleveldb"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/util/leveldbhelper"
)
var (
......
......@@ -20,8 +20,8 @@ import (
"fmt"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
func TestLedgerProvider(t *testing.T) {
......
......@@ -20,10 +20,11 @@ import (
"fmt"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
ledgerpackage "github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/testutil"
pb "github.com/hyperledger/fabric/protos/peer"
ledgertestutil "github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/hyperledger/fabric/protos/common"
"github.com/stretchr/testify/assert"
)
......@@ -36,7 +37,7 @@ func TestKVLedgerBlockStorage(t *testing.T) {
defer ledger.Close()
bcInfo, _ := ledger.GetBlockchainInfo()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 0, CurrentBlockHash: nil, PreviousBlockHash: nil})
simulator, _ := ledger.NewTxSimulator()
......@@ -51,7 +52,7 @@ func TestKVLedgerBlockStorage(t *testing.T) {
bcInfo, _ = ledger.GetBlockchainInfo()
block1Hash := block1.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 1, CurrentBlockHash: block1Hash, PreviousBlockHash: []byte{}})
simulator, _ = ledger.NewTxSimulator()
......@@ -65,7 +66,7 @@ func TestKVLedgerBlockStorage(t *testing.T) {
bcInfo, _ = ledger.GetBlockchainInfo()
block2Hash := block2.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 2, CurrentBlockHash: block2Hash, PreviousBlockHash: block1.Header.Hash()})
b1, _ := ledger.GetBlockByHash(block1Hash)
......@@ -82,7 +83,7 @@ func TestKVLedgerBlockStorage(t *testing.T) {
}
func TestKVLedgerDBRecovery(t *testing.T) {
testutil.SetupCoreYAMLConfig("./../../../peer")
ledgertestutil.SetupCoreYAMLConfig("./../../../peer")
env := newTestEnv(t)
defer env.cleanup()
provider, _ := NewProvider()
......@@ -91,7 +92,7 @@ func TestKVLedgerDBRecovery(t *testing.T) {
defer ledger.Close()
bcInfo, _ := ledger.GetBlockchainInfo()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 0, CurrentBlockHash: nil, PreviousBlockHash: nil})
//creating and committing the first block
simulator, _ := ledger.NewTxSimulator()
......@@ -108,7 +109,7 @@ func TestKVLedgerDBRecovery(t *testing.T) {
ledger.Commit(block1)
bcInfo, _ = ledger.GetBlockchainInfo()
block1Hash := block1.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 1, CurrentBlockHash: block1Hash, PreviousBlockHash: []byte{}})
//======================================================================================
......@@ -134,7 +135,7 @@ func TestKVLedgerDBRecovery(t *testing.T) {
bcInfo, _ = ledger.GetBlockchainInfo()
block2Hash := block2.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 2, CurrentBlockHash: block2Hash, PreviousBlockHash: block1.Header.Hash()})
simulator, _ = ledger.NewTxSimulator()
......@@ -234,7 +235,7 @@ func TestKVLedgerDBRecovery(t *testing.T) {
bcInfo, _ = ledger.GetBlockchainInfo()
block3Hash := block3.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 3, CurrentBlockHash: block3Hash, PreviousBlockHash: block2.Header.Hash()})
simulator, _ = ledger.NewTxSimulator()
......@@ -325,7 +326,7 @@ func TestKVLedgerDBRecovery(t *testing.T) {
bcInfo, _ = ledger.GetBlockchainInfo()
block4Hash := block4.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 4, CurrentBlockHash: block4Hash, PreviousBlockHash: block3.Header.Hash()})
simulator, _ = ledger.NewTxSimulator()
......@@ -385,7 +386,7 @@ func TestKVLedgerDBRecovery(t *testing.T) {
func TestLedgerWithCouchDbEnabledWithBinaryAndJSONData(t *testing.T) {
//call a helper method to load the core.yaml
testutil.SetupCoreYAMLConfig("./../../../peer")
ledgertestutil.SetupCoreYAMLConfig("./../../../peer")
logger.Debugf("TestLedgerWithCouchDbEnabledWithBinaryAndJSONData IsCouchDBEnabled()value: %v , IsHistoryDBEnabled()value: %v\n",
ledgerconfig.IsCouchDBEnabled(), ledgerconfig.IsHistoryDBEnabled())
......@@ -398,7 +399,7 @@ func TestLedgerWithCouchDbEnabledWithBinaryAndJSONData(t *testing.T) {
defer ledger.Close()
bcInfo, _ := ledger.GetBlockchainInfo()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 0, CurrentBlockHash: nil, PreviousBlockHash: nil})
simulator, _ := ledger.NewTxSimulator()
......@@ -415,7 +416,7 @@ func TestLedgerWithCouchDbEnabledWithBinaryAndJSONData(t *testing.T) {
bcInfo, _ = ledger.GetBlockchainInfo()
block1Hash := block1.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 1, CurrentBlockHash: block1Hash, PreviousBlockHash: []byte{}})
simulationResults := [][]byte{}
......@@ -442,7 +443,7 @@ func TestLedgerWithCouchDbEnabledWithBinaryAndJSONData(t *testing.T) {
bcInfo, _ = ledger.GetBlockchainInfo()
block2Hash := block2.Header.Hash()
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
Height: 2, CurrentBlockHash: block2Hash, PreviousBlockHash: block1.Header.Hash()})
b1, _ := ledger.GetBlockByHash(block1Hash)
......
......@@ -19,8 +19,8 @@ package rwset
import (
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
func TestRWSetHolder(t *testing.T) {
......
......@@ -21,8 +21,8 @@ import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
func TestNilTxRWSet(t *testing.T) {
......
......@@ -20,9 +20,9 @@ import (
"strings"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
// TestBasicRW tests basic read-write
......
......@@ -20,18 +20,19 @@ import (
"os"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/commontests"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/testutil"
ledgertestutil "github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/spf13/viper"
)
func TestMain(m *testing.M) {
//call a helper method to load the core.yaml, will be used to detect if CouchDB is enabled
testutil.SetupCoreYAMLConfig("./../../../../../../peer")
ledgertestutil.SetupCoreYAMLConfig("./../../../../../../peer")
viper.Set("ledger.state.couchDBConfig.couchDBAddress", "127.0.0.1:5984")
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/kvledger/txmgmt/statedb/statecouchdb")
......
......@@ -19,8 +19,8 @@ package statedb
import (
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
func TestUpdateBatchIterator(t *testing.T) {
......
......@@ -21,10 +21,10 @@ import (
"errors"
"fmt"
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/util/leveldbhelper"
logging "github.com/op/go-logging"
"github.com/syndtr/goleveldb/leveldb/iterator"
)
......
......@@ -20,10 +20,10 @@ import (
"os"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/commontests"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/spf13/viper"
)
......
......@@ -19,8 +19,8 @@ package statedb
import (
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
// TestEncodeString tests encoding and decoding a string value
......
......@@ -19,13 +19,14 @@ package commontests
import (
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/statecouchdb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/stateleveldb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/testutil"
ledgertestutil "github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric/protos/common"
"github.com/spf13/viper"
......@@ -47,7 +48,7 @@ var testEnvs = []testEnv{}
func init() {
//call a helper method to load the core.yaml so that we can detect whether couch is configured
testutil.SetupCoreYAMLConfig("./../../../../../../peer")
ledgertestutil.SetupCoreYAMLConfig("./../../../../../../peer")
//Only run the tests if CouchDB is explitily enabled in the code,
//otherwise CouchDB may not be installed and all the tests would fail
......
......@@ -21,10 +21,10 @@ import (
"fmt"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
func TestTxSimulatorWithNoExistingData(t *testing.T) {
......
......@@ -17,6 +17,7 @@ limitations under the License.
package lockbasedtxmgr
import (
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwset"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
......@@ -60,7 +61,7 @@ func (h *queryHelper) getStateMultipleKeys(namespace string, keys []string) ([][
return values, nil
}
func (h *queryHelper) getStateRangeScanIterator(namespace string, startKey string, endKey string) (ledger.ResultsIterator, error) {
func (h *queryHelper) getStateRangeScanIterator(namespace string, startKey string, endKey string) (commonledger.ResultsIterator, error) {
h.checkDone()
itr, err := newResultsItr(namespace, startKey, endKey, h.txmgr.db, h.rwset)
if err != nil {
......@@ -70,7 +71,7 @@ func (h *queryHelper) getStateRangeScanIterator(namespace string, startKey strin
return itr, nil
}
func (h *queryHelper) executeQuery(query string) (ledger.ResultsIterator, error) {
func (h *queryHelper) executeQuery(query string) (commonledger.ResultsIterator, error) {
dbItr, err := h.txmgr.db.ExecuteQuery(query)
if err != nil {
return nil, err
......@@ -128,7 +129,7 @@ func newResultsItr(ns string, startKey string, endKey string, db statedb.Version
// caller decides to stop iterating at some intermidiate point. Alternatively, we could have
// set the EndKey and ItrExhausted in the Close() function but it may not be desirable to change
// transactional behaviour based on whether the Close() was invoked or not
func (itr *resultsItr) Next() (ledger.QueryResult, error) {
func (itr *resultsItr) Next() (commonledger.QueryResult, error) {
queryResult, err := itr.dbItr.Next()
if err != nil {
return nil, err
......@@ -176,7 +177,7 @@ type queryResultsItr struct {
}
// Next implements method in interface ledger.ResultsIterator
func (itr *queryResultsItr) Next() (ledger.QueryResult, error) {
func (itr *queryResultsItr) Next() (commonledger.QueryResult, error) {
queryResult, err := itr.DBItr.Next()
if err != nil {
......
......@@ -17,8 +17,8 @@ limitations under the License.
package lockbasedtxmgr
import (
"github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/ledger"
)
// LockBasedQueryExecutor is a query executor used in `LockBasedTxMgr`
......
......@@ -19,10 +19,10 @@ package statebasedval
import (
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/stateleveldb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
)
func TestCombinedIterator(t *testing.T) {
......
......@@ -20,11 +20,11 @@ import (
"os"
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwset"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/stateleveldb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric/protos/common"
"github.com/spf13/viper"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment