Skip to content

Commit

Permalink
FAB-12866 - Refactor NewProvider for ledger
Browse files Browse the repository at this point in the history
The metrics provider will be provided by the initializer which is passed
into Initialize function. The NewCommonStorageDBProvider will require the
metrics provider be passed into it. Thus moving the call to
NewCommonStorageDBProvider into initialize function.

Change-Id: I1c23d5cf261719cae0725a09c3ededaafbb8aef8
Signed-off-by: Saad Karim <skarim@us.ibm.com>
  • Loading branch information
Saad Karim committed Nov 14, 2018
1 parent 7cbf47a commit 73bdfc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions core/ledger/kvledger/kv_ledger_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,17 @@ func NewProvider() (ledger.PeerLedgerProvider, error) {
// Initialize the ID store (inventory of chainIds/ledgerIds)
idStore := openIDStore(ledgerconfig.GetLedgerProviderPath())
ledgerStoreProvider := ledgerstorage.NewProvider()
bookkeepingProvider := bookkeeping.NewProvider()
// Initialize the versioned database (state database)
vdbProvider, err := privacyenabledstate.NewCommonStorageDBProvider(bookkeepingProvider)
if err != nil {
return nil, err
}
// Initialize the history database (index for history of values by key)
historydbProvider := historyleveldb.NewHistoryDBProvider()
logger.Info("ledger provider Initialized")
provider := &Provider{idStore, ledgerStoreProvider,
vdbProvider, historydbProvider, nil, nil, bookkeepingProvider, nil, nil}
nil, historydbProvider, nil, nil, nil, nil, nil}
return provider, nil
}

// Initialize implements the corresponding method from interface ledger.PeerLedgerProvider
func (provider *Provider) Initialize(initializer *ledger.Initializer) {
func (provider *Provider) Initialize(initializer *ledger.Initializer) error {
var err error
configHistoryMgr := confighistory.NewMgr(initializer.DeployedChaincodeInfoProvider)
collElgNotifier := &collElgNotifier{
initializer.DeployedChaincodeInfoProvider,
Expand All @@ -91,7 +86,13 @@ func (provider *Provider) Initialize(initializer *ledger.Initializer) {
provider.configHistoryMgr = configHistoryMgr
provider.stateListeners = stateListeners
provider.collElgNotifier = collElgNotifier
provider.bookkeepingProvider = bookkeeping.NewProvider()
provider.vdbProvider, err = privacyenabledstate.NewCommonStorageDBProvider(provider.bookkeepingProvider)
if err != nil {
return err
}
provider.recoverUnderConstructionLedger()
return nil
}

// Create implements the corresponding method from interface ledger.PeerLedgerProvider
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/ledger_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Initializer struct {

// PeerLedgerProvider provides handle to ledger instances
type PeerLedgerProvider interface {
Initialize(initializer *Initializer)
Initialize(initializer *Initializer) error
// Create creates a new ledger with the given genesis block.
// This function guarantees that the creation of ledger and committing the genesis block would an atomic action
// The chain id retrieved from the genesis block is treated as a ledger id
Expand Down

0 comments on commit 73bdfc5

Please sign in to comment.