...

Package cceventmgmt

import "github.com/hyperledger/fabric/core/ledger/cceventmgmt"
Overview
Index

Overview ▾

func Initialize

func Initialize(ccInfoProvider ChaincodeInfoProvider)

Initialize initializes event mgmt

type ChaincodeDefinition

ChaincodeDefinition captures the info about chaincode

type ChaincodeDefinition struct {
    Name              string
    Hash              []byte
    Version           string
    CollectionConfigs *common.CollectionConfigPackage
}

func (*ChaincodeDefinition) String

func (cdef *ChaincodeDefinition) String() string

type ChaincodeInfoProvider

ChaincodeInfoProvider interface enables event mgr to retrieve chaincode info for a given chaincode

type ChaincodeInfoProvider interface {
    // GetDeployedChaincodeInfo retrieves the details about the deployed chaincode.
    // This function is expected to return nil, if the chaincode with the given name is not deployed
    // or the version or hash of the deployed chaincode does not match with the given version and hash
    GetDeployedChaincodeInfo(chainid string, chaincodeDefinition *ChaincodeDefinition) (*ledger.DeployedChaincodeInfo, error)
    // RetrieveChaincodeArtifacts checks if the given chaincode is installed on the peer and if yes,
    // it extracts the state db specific artifacts from the chaincode package tarball
    RetrieveChaincodeArtifacts(chaincodeDefinition *ChaincodeDefinition) (installed bool, dbArtifactsTar []byte, err error)
}

type ChaincodeLifecycleEventListener

ChaincodeLifecycleEventListener interface enables ledger components (mainly, intended for statedb) to be able to listen to chaincode lifecycle events. 'dbArtifactsTar' represents db specific artifacts (such as index specs) packaged in a tar

type ChaincodeLifecycleEventListener interface {
    // HandleChaincodeDeploy is invoked when chaincode installed + defined becomes true.
    // The expected usage are to creates all the necessary statedb structures (such as indexes) and update
    // service discovery info. This function is invoked immediately before the committing the state changes
    // that contain chaincode definition or when a chaincode install happens
    HandleChaincodeDeploy(chaincodeDefinition *ChaincodeDefinition, dbArtifactsTar []byte) error
    // ChaincodeDeployDone is invoked after the chaincode deployment is finished - `succeeded` indicates
    // whether the deploy finished successfully
    ChaincodeDeployDone(succeeded bool)
}

type KVLedgerLSCCStateListener

KVLedgerLSCCStateListener listens for state changes for chaincode lifecycle

type KVLedgerLSCCStateListener struct {
    DeployedChaincodeInfoProvider ledger.DeployedChaincodeInfoProvider
}

func (*KVLedgerLSCCStateListener) HandleStateUpdates

func (listener *KVLedgerLSCCStateListener) HandleStateUpdates(trigger *ledger.StateUpdateTrigger) error

HandleStateUpdates uses 'DeployedChaincodeInfoProvider' to findout deployment of a chaincode and invokes `HandleChaincodeDeploy` function on chaincode event manager (which in turn is responsible for creation of statedb artifacts for the chaincode statedata)

func (*KVLedgerLSCCStateListener) InterestedInNamespaces

func (listener *KVLedgerLSCCStateListener) InterestedInNamespaces() []string

InterestedInNamespaces implements function from interface `ledger.StateListener`

func (*KVLedgerLSCCStateListener) StateCommitDone

func (listener *KVLedgerLSCCStateListener) StateCommitDone(channelName string)

StateCommitDone implements function from interface `ledger.StateListener`

type Mgr

Mgr encapsulate important interactions for events related to the interest of ledger

type Mgr struct {
    // contains filtered or unexported fields
}

func GetMgr

func GetMgr() *Mgr

GetMgr returns the reference to singleton event manager

func (*Mgr) ChaincodeDeployDone

func (m *Mgr) ChaincodeDeployDone(chainid string)

ChaincodeDeployDone is expected to be called when the deploy transaction state is committed

func (*Mgr) ChaincodeInstallDone

func (m *Mgr) ChaincodeInstallDone(succeeded bool)

ChaincodeInstallDone is expected to get invoked when chaincode install finishes

func (*Mgr) HandleChaincodeDeploy

func (m *Mgr) HandleChaincodeDeploy(chainid string, chaincodeDefinitions []*ChaincodeDefinition) error

HandleChaincodeDeploy is expected to be invoked when a chaincode is deployed via a deploy transaction The `chaincodeDefinitions` parameter contains all the chaincodes deployed in a block We need to store the last received `chaincodeDefinitions` because this function is expected to be invoked after the deploy transactions validation is performed but not committed yet to the ledger. Further, we release the read lock after this function. This leaves a small window when a `chaincode install` can happen before the deploy transaction is committed and hence the function `HandleChaincodeInstall` may miss finding the deployed chaincode. So, in function `HandleChaincodeInstall`, we explicitly check for chaincode deployed in this stored `chaincodeDefinitions`

func (*Mgr) HandleChaincodeInstall

func (m *Mgr) HandleChaincodeInstall(chaincodeDefinition *ChaincodeDefinition, dbArtifacts []byte) error

HandleChaincodeInstall is expected to get invoked during installation of a chaincode package

func (*Mgr) Register

func (m *Mgr) Register(ledgerid string, l ChaincodeLifecycleEventListener)

Register registers a ChaincodeLifecycleEventListener for given ledgerid Since, `Register` is expected to be invoked when creating/opening a ledger instance