Beispiel #1
0
// NewKVLedger constructs new `KVLedger`
func NewKVLedger(conf *Conf) (*KVLedger, error) {

	logger.Debugf("Creating KVLedger using config: ", conf)

	attrsToIndex := []blkstorage.IndexableAttr{
		blkstorage.IndexableAttrBlockHash,
		blkstorage.IndexableAttrBlockNum,
		blkstorage.IndexableAttrTxID,
		blkstorage.IndexableAttrBlockNumTranNum,
	}
	indexConfig := &blkstorage.IndexConfig{AttrsToIndex: attrsToIndex}
	blockStorageConf := fsblkstorage.NewConf(conf.blockStorageDir, conf.maxBlockfileSize)
	blockStore := fsblkstorage.NewFsBlockStore(blockStorageConf, indexConfig)

	//State and History database managers
	var txmgmt txmgr.TxMgr
	var historymgmt history.HistMgr

	if ledgerconfig.IsCouchDBEnabled() == true {
		//By default we can talk to CouchDB with empty id and pw (""), or you can add your own id and password to talk to a secured CouchDB
		logger.Debugf("===COUCHDB=== NewKVLedger() Using CouchDB instead of RocksDB...hardcoding and passing connection config for now")

		couchDBDef := ledgerconfig.GetCouchDBDefinition()

		//create new transaction manager based on couchDB
		txmgmt = couchdbtxmgmt.NewCouchDBTxMgr(&couchdbtxmgmt.Conf{DBPath: conf.txMgrDBPath},
			couchDBDef.URL,      //couchDB connection URL
			"system",            //couchDB db name matches ledger name, TODO for now use system ledger, eventually allow passing in subledger name
			couchDBDef.Username, //enter couchDB id here
			couchDBDef.Password) //enter couchDB pw here
	} else {
		// Fall back to using goleveldb lockbased transaction manager
		db := stateleveldb.NewVersionedDBProvider(&stateleveldb.Conf{DBPath: conf.txMgrDBPath}).GetDBHandle("Default")
		txmgmt = lockbasedtxmgr.NewLockBasedTxMgr(db)
	}

	if ledgerconfig.IsHistoryDBEnabled() == true {
		logger.Debugf("===HISTORYDB=== NewKVLedger() Using CouchDB for transaction history database")

		couchDBDef := ledgerconfig.GetCouchDBDefinition()

		historymgmt = history.NewCouchDBHistMgr(
			couchDBDef.URL,      //couchDB connection URL
			"system_history",    //couchDB db name matches ledger name, TODO for now use system_history ledger, eventually allow passing in subledger name
			couchDBDef.Username, //enter couchDB id here
			couchDBDef.Password) //enter couchDB pw here
	}

	l := &KVLedger{blockStore, txmgmt, historymgmt}

	if err := recoverStateDB(l); err != nil {
		panic(fmt.Errorf(`Error during state DB recovery:%s`, err))
	}

	return l, nil
}
Beispiel #2
0
func newTestEnvHistoryCouchDB(t testing.TB, dbName string) *testEnvHistoryCouchDB {

	couchDBDef := ledgerconfig.GetCouchDBDefinition()

	return &testEnvHistoryCouchDB{
		couchDBAddress:    couchDBDef.URL,
		couchDatabaseName: dbName,
		couchUsername:     couchDBDef.Username,
		couchPassword:     couchDBDef.Password,
	}
}
func newTestEnv(t testing.TB) *testEnv {

	//call a helper method to load the core.yaml
	testutil.SetupCoreYAMLConfig("./../../../../../peer")

	couchDBDef := ledgerconfig.GetCouchDBDefinition()

	conf := &Conf{"/tmp/tests/ledger/kvledger/txmgmt/couchdbtxmgmt"}
	os.RemoveAll(conf.DBPath)
	return &testEnv{
		conf:              conf,
		couchDBAddress:    couchDBDef.URL,
		couchDatabaseName: "system_test",
		couchUsername:     couchDBDef.Username,
		couchPassword:     couchDBDef.Password,
	}
}