lifecycle

package
v2.0.0-beta+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2019 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NamespacesName is the prefix (or namespace) of the DB which will be used to store
	// the information about other namespaces (for things like chaincodes) in the DB.
	// We want a sub-namespaces within lifecycle in case other information needs to be stored here
	// in the future.
	NamespacesName = "namespaces"

	// ChaincodeSourcesName is the namespace reserved for storing the information about where
	// to find the chaincode (such as as a package on the local filesystem, or in the future,
	// at some network resource).  This namespace is only populated in the org implicit collection.
	ChaincodeSourcesName = "chaincode-sources"

	// ChaincodeDefinitionType is the name of the type used to store defined chaincodes
	ChaincodeDefinitionType = "ChaincodeDefinition"

	// FriendlyChaincodeDefinitionType is the name exposed to the outside world for the chaincode namespace
	FriendlyChaincodeDefinitionType = "Chaincode"

	// DefaultEndorsementPolicyRef is the name of the default endorsement policy for this channel
	DefaultEndorsementPolicyRef = "/Channel/Application/Endorsement"
)
View Source
const (
	// LifecycleNamespace is the namespace in the statedb where lifecycle
	// information is stored
	LifecycleNamespace = "_lifecycle"

	// InstallChaincodeFuncName is the chaincode function name used to install
	// a chaincode
	InstallChaincodeFuncName = "InstallChaincode"

	// QueryInstalledChaincodeFuncName is the chaincode function name used to
	// query an installed chaincode
	QueryInstalledChaincodeFuncName = "QueryInstalledChaincode"

	// QueryInstalledChaincodesFuncName is the chaincode function name used to
	// query all installed chaincodes
	QueryInstalledChaincodesFuncName = "QueryInstalledChaincodes"

	// ApproveChaincodeDefinitionForMyOrgFuncName is the chaincode function name
	// used to approve a chaincode definition for execution by the user's own org
	ApproveChaincodeDefinitionForMyOrgFuncName = "ApproveChaincodeDefinitionForMyOrg"

	// CheckCommitReadinessFuncName is the chaincode function name used to check
	// a specified chaincode definition is ready to be committed. It returns the
	// approval status for a given definition over a given set of orgs
	CheckCommitReadinessFuncName = "CheckCommitReadiness"

	// CommitChaincodeDefinitionFuncName is the chaincode function name used to
	// 'commit' (previously 'instantiate') a chaincode in a channel.
	CommitChaincodeDefinitionFuncName = "CommitChaincodeDefinition"

	// QueryChaincodeDefinitionFuncName is the chaincode function name used to
	// query a committed chaincode definition in a channel.
	QueryChaincodeDefinitionFuncName = "QueryChaincodeDefinition"

	// QueryChaincodeDefinitionsFuncName is the chaincode function name used to
	// query the committed chaincode definitions in a channel.
	QueryChaincodeDefinitionsFuncName = "QueryChaincodeDefinitions"
)
View Source
const (
	MetadataInfix = "metadata"
	FieldsInfix   = "fields"
)
View Source
const (
	LifecycleEndorsementPolicyRef = "/Channel/Application/LifecycleEndorsement"
)

Variables

View Source
var (
	// NOTE the chaincode name/version regular expressions should stay in sync
	// with those defined in core/scc/lscc/lscc.go until LSCC has been removed.
	ChaincodeNameRegExp    = regexp.MustCompile("^[a-zA-Z0-9]+([-_][a-zA-Z0-9]+)*$")
	ChaincodeVersionRegExp = regexp.MustCompile("^[A-Za-z0-9_.+-]+$")
)
View Source
var (
	DefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&pb.ApplicationPolicy{
		Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
			ChannelConfigPolicyReference: DefaultEndorsementPolicyRef,
		},
	})
)
View Source
var ImplicitCollectionMatcher = regexp.MustCompile("^" + ImplicitCollectionNameForOrg("(.+)") + "$")
View Source
var (
	// This is a channel which was created with a lifecycle endorsement policy
	LifecycleDefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&cb.ApplicationPolicy{
		Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
			ChannelConfigPolicyReference: LifecycleEndorsementPolicyRef,
		},
	})
)
View Source
var ProtoMessageType = reflect.TypeOf((*proto.Message)(nil)).Elem()
View Source
var SequenceMatcher = regexp.MustCompile("^" + NamespacesName + "/fields/([^/]+)/Sequence$")

Functions

func FieldKey

func FieldKey(namespace, name, field string) string

func GenerateImplicitCollectionForOrg

func GenerateImplicitCollectionForOrg(mspid string) *pb.StaticCollectionConfig

func ImplicitCollectionNameForOrg

func ImplicitCollectionNameForOrg(mspid string) string

func MetadataKey

func MetadataKey(namespace, name string) string

func OrgFromImplicitCollectionName

func OrgFromImplicitCollectionName(name string) string

func StateIteratorToMap

func StateIteratorToMap(itr StateIterator) (map[string][]byte, error)

StateIteratorToMap takes an iterator, and iterates over the entire thing, encoding the KVs into a map, and then closes it.

Types

type Cache

type Cache struct {
	Resources  *Resources
	MyOrgMSPID string

	MetadataHandler MetadataHandler
	// contains filtered or unexported fields
}

func NewCache

func NewCache(resources *Resources, myOrgMSPID string, metadataManager MetadataHandler, custodian *ChaincodeCustodian, ebMetadata *externalbuilder.MetadataProvider) *Cache

func (*Cache) ChaincodeInfo

func (c *Cache) ChaincodeInfo(channelID, name string) (*LocalChaincodeInfo, error)

ChaincodeInfo returns the chaincode definition and its install info. An error is returned only if either the channel or the chaincode do not exist.

func (*Cache) GetInstalledChaincode

func (c *Cache) GetInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)

GetInstalledChaincode returns all of the information about a specific installed chaincode.

func (*Cache) HandleChaincodeInstalled

func (c *Cache) HandleChaincodeInstalled(md *persistence.ChaincodePackageMetadata, packageID string)

HandleChaincodeInstalled should be invoked whenever a new chaincode is installed

func (*Cache) HandleStateUpdates

func (c *Cache) HandleStateUpdates(trigger *ledger.StateUpdateTrigger) error

HandleStateUpdates is required to implement the ledger state listener interface. It applies any state updates to the cache.

func (*Cache) Initialize

func (c *Cache) Initialize(channelID string, qe ledger.SimpleQueryExecutor) error

Initialize will populate the set of currently committed chaincode definitions for a channel into the cache. Note, it this looks like a bit of a DRY violation with respect to 'Update', but, the error handling is quite different and attempting to factor out the common pieces results in a net total of more code.

func (*Cache) InitializeLocalChaincodes

func (c *Cache) InitializeLocalChaincodes() error

InitializeLocalChaincodes should be called once after cache creation (timing doesn't matter, though already installed chaincodes will not be invokable until it it completes). Ideally, this would be part of the constructor, but, we cannot rely on the chaincode store being created before the cache is created.

func (*Cache) InitializeMetadata

func (c *Cache) InitializeMetadata(channel string)

func (*Cache) InterestedInNamespaces

func (c *Cache) InterestedInNamespaces() []string

InterestedInNamespaces is required to implement the ledger state listener interface

func (*Cache) ListInstalledChaincodes

func (c *Cache) ListInstalledChaincodes() []*chaincode.InstalledChaincode

ListInstalledChaincodes returns a slice containing all of the information about the installed chaincodes.

func (*Cache) RegisterListener

func (c *Cache) RegisterListener(channelID string, listener ledger.ChaincodeLifecycleEventListener)

RegisterListener registers an event listener for recieving an event when a chaincode becomes invokable

func (*Cache) StateCommitDone

func (c *Cache) StateCommitDone(channelName string)

StateCommitDone is required to implement the ledger state listener interface

type CachedChaincodeDefinition

type CachedChaincodeDefinition struct {
	Definition  *ChaincodeDefinition
	Approved    bool
	InstallInfo *ChaincodeInstallInfo

	// Hashes is the list of hashed keys in the implicit collection referring to this definition.
	// These hashes are determined by the current sequence number of chaincode definition.  When dirty,
	// these hashes will be empty, and when not, they will be populated.
	Hashes []string
}

type ChaincodeBuilder

type ChaincodeBuilder interface {
	Build(ccid string) error
}

type ChaincodeCustodian

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

ChaincodeCustodian is responsible for enqueuing builds and launches of chaincodes as they become available.

func NewChaincodeCustodian

func NewChaincodeCustodian() *ChaincodeCustodian

NewChaincodeCustodian creates an instance of a chaincode custodian. It is the instantiator's responsibility to spawn a go routine to service the Work routine along with the appropriate dependencies.

func (*ChaincodeCustodian) Close

func (cc *ChaincodeCustodian) Close()

func (*ChaincodeCustodian) NotifyInstalled

func (cc *ChaincodeCustodian) NotifyInstalled(chaincodeID string)

func (*ChaincodeCustodian) NotifyInstalledAndRunnable

func (cc *ChaincodeCustodian) NotifyInstalledAndRunnable(chaincodeID string)

func (*ChaincodeCustodian) Work

func (cc *ChaincodeCustodian) Work(buildRegistry *container.BuildRegistry, builder ChaincodeBuilder, launcher ChaincodeLauncher)

type ChaincodeDefinition

type ChaincodeDefinition struct {
	Sequence        int64
	EndorsementInfo *lb.ChaincodeEndorsementInfo
	ValidationInfo  *lb.ChaincodeValidationInfo
	Collections     *pb.CollectionConfigPackage
}

ChaincodeDefinition contains the chaincode parameters, as well as the sequence number of the definition. Note, it does not embed ChaincodeParameters so as not to complicate the serialization. It is expected that any instance will have no nil fields once initialized. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.

func (*ChaincodeDefinition) Parameters

func (cd *ChaincodeDefinition) Parameters() *ChaincodeParameters

Parameters returns the non-sequence info of the chaincode definition

func (*ChaincodeDefinition) String

func (cd *ChaincodeDefinition) String() string

type ChaincodeEndorsementInfo

type ChaincodeEndorsementInfo struct {
	// Version is the version from the definition in this particular channel and namespace context.
	Version string

	// EnforceInit is set to true for definitions which require the chaincode package to enforce
	// 'init exactly once' semantics.
	EnforceInit bool

	// ChaincodeID is the name by which to look up or launch the underlying chaincode.
	ChaincodeID string

	// EndorsementPlugin is the name of the plugin to use when endorsing.
	EndorsementPlugin string
}

ChaincodeEndorsementInfo contains the information necessary to handle a chaincode invoke request.

type ChaincodeEndorsementInfoSource

type ChaincodeEndorsementInfoSource struct {
	Resources   *Resources
	Cache       ChaincodeInfoCache
	LegacyImpl  Lifecycle
	BuiltinSCCs scc.BuiltinSCCs
}

func (*ChaincodeEndorsementInfoSource) CachedChaincodeInfo

func (cei *ChaincodeEndorsementInfoSource) CachedChaincodeInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*LocalChaincodeInfo, bool, error)

func (*ChaincodeEndorsementInfoSource) ChaincodeEndorsementInfo

func (cei *ChaincodeEndorsementInfoSource) ChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ChaincodeEndorsementInfo, error)

ChaincodeEndorsementInfo returns the information necessary to handle a chaincode invocation request, as well as a function to enforce security checks on the chaincode (in case the definition is from the legacy lscc).

type ChaincodeInfoCache

type ChaincodeInfoCache interface {
	ChaincodeInfo(channelID, chaincodeName string) (definition *LocalChaincodeInfo, err error)
}

type ChaincodeInfoProvider

type ChaincodeInfoProvider interface {
	// ChaincodeInfo returns the chaincode definition and its install info.
	// An error is returned only if either the channel or the chaincode do not exist.
	ChaincodeInfo(channelID, name string) (*LocalChaincodeInfo, error)
}

ChaincodeInfoProvider provides metadata for a _lifecycle-defined chaincode on a specific channel

type ChaincodeInstallInfo

type ChaincodeInstallInfo struct {
	PackageID string
	Type      string
	Path      string
	Label     string
}

type ChaincodeLauncher

type ChaincodeLauncher interface {
	Launch(ccid string) error
}

type ChaincodeLocalPackage

type ChaincodeLocalPackage struct {
	PackageID string
}

ChaincodeLocalPackage is a type of chaincode-source which may be serialized into the org's private data collection. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.

type ChaincodeParameters

type ChaincodeParameters struct {
	EndorsementInfo *lb.ChaincodeEndorsementInfo
	ValidationInfo  *lb.ChaincodeValidationInfo
	Collections     *pb.CollectionConfigPackage
}

ChaincodeParameters are the parts of the chaincode definition which are serialized as values in the statedb. It is expected that any instance will have no nil fields once initialized. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.

func (*ChaincodeParameters) Equal

type ChaincodePrivateLedgerShim

type ChaincodePrivateLedgerShim struct {
	Stub       shim.ChaincodeStubInterface
	Collection string
}

ChaincodePrivateLedgerShim wraps the chaincode shim to make access to keys in a collection have the same semantics as normal public keys.

func (*ChaincodePrivateLedgerShim) CollectionName

func (cls *ChaincodePrivateLedgerShim) CollectionName() string

func (*ChaincodePrivateLedgerShim) DelState

func (cls *ChaincodePrivateLedgerShim) DelState(key string) error

DelState deletes the key in the configured collection.

func (*ChaincodePrivateLedgerShim) GetState

func (cls *ChaincodePrivateLedgerShim) GetState(key string) ([]byte, error)

GetState returns the value for the key in the configured collection.

func (*ChaincodePrivateLedgerShim) GetStateHash

func (cls *ChaincodePrivateLedgerShim) GetStateHash(key string) ([]byte, error)

GetStateHash return the hash of the pre-image for the key in the configured collection.

func (*ChaincodePrivateLedgerShim) GetStateRange

func (cls *ChaincodePrivateLedgerShim) GetStateRange(prefix string) (map[string][]byte, error)

GetStateRange performs a range query in the configured collection for all keys beginning with a particular prefix. This function assumes that keys contain only ascii chars from \x00 to \x7e.

func (*ChaincodePrivateLedgerShim) PutState

func (cls *ChaincodePrivateLedgerShim) PutState(key string, value []byte) error

PutState sets the value for the key in the configured collection.

type ChaincodePublicLedgerShim

type ChaincodePublicLedgerShim struct {
	shim.ChaincodeStubInterface
}

ChaincodePublicLedgerShim decorates the chaincode shim to support the state interfaces required by the serialization code.

func (*ChaincodePublicLedgerShim) GetStateRange

func (cls *ChaincodePublicLedgerShim) GetStateRange(prefix string) (map[string][]byte, error)

GetStateRange performs a range query for keys beginning with a particular prefix, and returns it as a map. This function assumes that keys contain only ascii chars from \x00 to \x7e.

type ChaincodeResultIteratorShim

type ChaincodeResultIteratorShim struct {
	ResultsIterator shim.StateQueryIteratorInterface
}

func (*ChaincodeResultIteratorShim) Close

func (cris *ChaincodeResultIteratorShim) Close() error

func (*ChaincodeResultIteratorShim) Next

type ChaincodeStore

type ChaincodeStore interface {
	Save(label string, ccInstallPkg []byte) (string, error)
	ListInstalledChaincodes() ([]chaincode.InstalledChaincode, error)
	Load(packageID string) (ccInstallPkg []byte, err error)
	Delete(packageID string) error
}

ChaincodeStore provides a way to persist chaincodes

type ChannelCache

type ChannelCache struct {
	Chaincodes map[string]*CachedChaincodeDefinition

	// InterestingHashes is a map of hashed key names to the chaincode name which they affect.
	// These are to be used for the state listener, to mark chaincode definitions dirty when
	// a write is made into the implicit collection for this org.  Interesting hashes are
	// added when marking a definition clean, and deleted when marking it dirty.
	InterestingHashes map[string]string
}

type ChannelConfigSource

type ChannelConfigSource interface {
	// GetStableChannelConfig returns the channel config for a given channel id.
	// Note, it is a stable bundle, which means it will not be updated, even if
	// the channel is, so it should be discarded after use.
	GetStableChannelConfig(channelID string) channelconfig.Resources
}

ChannelConfigSource provides a way to retrieve the channel config for a given channel ID.

type ChannelPolicyReferenceProvider

type ChannelPolicyReferenceProvider interface {
	// NewPolicy creates a new policy based on the policy bytes
	NewPolicy(channelID, channelConfigPolicyReference string) (policies.Policy, error)
}

ChannelPolicyReferenceProvider is used to determine if a set of signature is valid and complies with a policy

type DummyQueryExecutorShim

type DummyQueryExecutorShim struct {
}

DummyQueryExecutorShim implements the ReadableState interface. It is used to ensure channel-less system chaincode calls don't panic and return and error when an invalid operation is attempted (i.e. an InstallChaincode invocation against a chaincode other than _lifecycle)

func (*DummyQueryExecutorShim) GetState

func (*DummyQueryExecutorShim) GetState(key string) ([]byte, error)

type ErrNamespaceNotDefined

type ErrNamespaceNotDefined struct {
	Namespace string
}

ErrNamespaceNotDefined is the error returned when a namespace is not defined. This indicates that the chaincode definition has not been committed.

func (ErrNamespaceNotDefined) Error

func (e ErrNamespaceNotDefined) Error() string

type EventBroker

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

EventBroker receives events from lifecycle cache and in turn invokes the registered listeners

func NewEventBroker

func NewEventBroker(chaincodeStore ChaincodeStore, pkgParser PackageParser, ebMetadata *externalbuilder.MetadataProvider) *EventBroker

func (*EventBroker) ApproveOrDefineCommitted

func (b *EventBroker) ApproveOrDefineCommitted(channelID string)

ApproveOrDefineCommitted gets invoked after the commit of state updates that triggered the invocaiton of "ProcessApproveOrDefineEvent" function

func (*EventBroker) ProcessApproveOrDefineEvent

func (b *EventBroker) ProcessApproveOrDefineEvent(channelID string, chaincodeName string, cachedChaincode *CachedChaincodeDefinition)

ProcessApproveOrDefineEvent gets invoked by an event that makes approve and define to be true This should be OK even if this function gets invoked on defined and approved events separately because the first check in this fucntion evaluates the final condition. However, the current cache implementation invokes this function when approve and define both become true.

func (*EventBroker) ProcessInstallEvent

func (b *EventBroker) ProcessInstallEvent(localChaincode *LocalChaincode)

ProcessInstallEvent gets invoked when a chaincode is installed

func (*EventBroker) RegisterListener

func (b *EventBroker) RegisterListener(channelID string, listener ledger.ChaincodeLifecycleEventListener)

type ExternalFunctions

type ExternalFunctions struct {
	Resources                 *Resources
	InstallListener           InstallListener
	InstalledChaincodesLister InstalledChaincodesLister
	ChaincodeBuilder          ChaincodeBuilder
	BuildRegistry             *container.BuildRegistry
}

ExternalFunctions is intended primarily to support the SCC functions. In general, its methods signatures produce writes (which must be commmitted as part of an endorsement flow), or return human readable errors (for instance indicating a chaincode is not found) rather than sentinals. Instead, use the utility functions attached to the lifecycle Resources when needed.

func (*ExternalFunctions) ApproveChaincodeDefinitionForOrg

func (ef *ExternalFunctions) ApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID string, publicState ReadableState, orgState ReadWritableState) error

ApproveChaincodeDefinitionForOrg adds a chaincode definition entry into the passed in Org state. The definition must be for either the currently defined sequence number or the next sequence number. If the definition is for the current sequence number, then it must match exactly the current definition or it will be rejected.

func (*ExternalFunctions) CheckCommitReadiness

func (ef *ExternalFunctions) CheckCommitReadiness(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)

CheckCommitReadiness takes a chaincode definition, checks that its sequence number is the next allowable sequence number and checks which organizations have approved the definition.

func (*ExternalFunctions) CommitChaincodeDefinition

func (ef *ExternalFunctions) CommitChaincodeDefinition(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)

CommitChaincodeDefinition takes a chaincode definition, checks that its sequence number is the next allowable sequence number, checks which organizations have approved the definition, and applies the definition to the public world state. It is the responsibility of the caller to check the approvals to determine if the result is valid (typically, this means checking that the peer's own org has approved the definition).

func (*ExternalFunctions) DefaultEndorsementPolicyAsBytes

func (ef *ExternalFunctions) DefaultEndorsementPolicyAsBytes(channelID string) ([]byte, error)

DefaultEndorsementPolicyAsBytes returns a marshalled version of the default chaincode endorsement policy in the supplied channel

func (*ExternalFunctions) GetInstalledChaincodePackage

func (ef *ExternalFunctions) GetInstalledChaincodePackage(packageID string) ([]byte, error)

GetInstalledChaincodePakcage retreives the installed chaincode with the given package ID from the peer's chaincode store.

func (*ExternalFunctions) InstallChaincode

func (ef *ExternalFunctions) InstallChaincode(chaincodeInstallPackage []byte) (*chaincode.InstalledChaincode, error)

InstallChaincode installs a given chaincode to the peer's chaincode store. It returns the hash to reference the chaincode by or an error on failure.

func (*ExternalFunctions) QueryChaincodeDefinition

func (ef *ExternalFunctions) QueryChaincodeDefinition(name string, publicState ReadableState) (*ChaincodeDefinition, error)

QueryChaincodeDefinition returns the defined chaincode by the given name (if it is committed, and a chaincode) or otherwise returns an error.

func (*ExternalFunctions) QueryInstalledChaincode

func (ef *ExternalFunctions) QueryInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)

QueryInstalledChaincode returns metadata for the chaincode with the supplied package ID.

func (*ExternalFunctions) QueryInstalledChaincodes

func (ef *ExternalFunctions) QueryInstalledChaincodes() []*chaincode.InstalledChaincode

QueryInstalledChaincodes returns a list of installed chaincodes

func (*ExternalFunctions) QueryNamespaceDefinitions

func (ef *ExternalFunctions) QueryNamespaceDefinitions(publicState RangeableState) (map[string]string, error)

QueryNamespaceDefinitions lists the publicly defined namespaces in a channel. Today it should only ever find Datatype encodings of 'ChaincodeDefinition'.

func (*ExternalFunctions) QueryOrgApprovals

func (ef *ExternalFunctions) QueryOrgApprovals(name string, cd *ChaincodeDefinition, orgStates []OpaqueState) (map[string]bool, error)

QueryOrgApprovals returns a map containing the orgs whose orgStates were provided and whether or not they have approved a chaincode definition with the specified parameters.

func (*ExternalFunctions) SetChaincodeDefinitionDefaults

func (ef *ExternalFunctions) SetChaincodeDefinitionDefaults(chname string, cd *ChaincodeDefinition) error

SetChaincodeDefinitionDefaults fills any empty fields in the supplied ChaincodeDefinition with the supplied channel's defaults

type HandleMetadataUpdateFunc

type HandleMetadataUpdateFunc func(channel string, metadata chaincode.MetadataSet)

HandleMetadataUpdateFunc is triggered upon a change in the chaincode lifecycle.

func (HandleMetadataUpdateFunc) HandleMetadataUpdate

func (handleMetadataUpdate HandleMetadataUpdateFunc) HandleMetadataUpdate(channel string, metadata chaincode.MetadataSet)

HandleMetadataUpdate runs whenever there is a change to the metadata of a chaincode in the context of a specific channel.

type InstallListener

type InstallListener interface {
	HandleChaincodeInstalled(md *persistence.ChaincodePackageMetadata, packageID string)
}

type InstalledChaincodesLister

type InstalledChaincodesLister interface {
	ListInstalledChaincodes() []*chaincode.InstalledChaincode
	GetInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)
}

type Invocation

type Invocation struct {
	ChannelID         string
	ApplicationConfig channelconfig.Application // Note this may be nil
	Stub              shim.ChaincodeStubInterface
	SCC               *SCC
}

func (*Invocation) ApproveChaincodeDefinitionForMyOrg

func (i *Invocation) ApproveChaincodeDefinitionForMyOrg(input *lb.ApproveChaincodeDefinitionForMyOrgArgs) (proto.Message, error)

ApproveChaincodeDefinitionForMyOrg is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) CheckCommitReadiness

func (i *Invocation) CheckCommitReadiness(input *lb.CheckCommitReadinessArgs) (proto.Message, error)

CheckCommitReadiness is a SCC function that may be dispatched to the underlying lifecycle implementation.

func (*Invocation) CommitChaincodeDefinition

func (i *Invocation) CommitChaincodeDefinition(input *lb.CommitChaincodeDefinitionArgs) (proto.Message, error)

CommitChaincodeDefinition is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) GetInstalledChaincodePackage

func (i *Invocation) GetInstalledChaincodePackage(input *lb.GetInstalledChaincodePackageArgs) (proto.Message, error)

GetInstalledChaincodePackage is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) InstallChaincode

func (i *Invocation) InstallChaincode(input *lb.InstallChaincodeArgs) (proto.Message, error)

InstallChaincode is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryChaincodeDefinition

func (i *Invocation) QueryChaincodeDefinition(input *lb.QueryChaincodeDefinitionArgs) (proto.Message, error)

QueryChaincodeDefinition is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryChaincodeDefinitions

func (i *Invocation) QueryChaincodeDefinitions(input *lb.QueryChaincodeDefinitionsArgs) (proto.Message, error)

QueryChaincodeDefinitions is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryInstalledChaincode

func (i *Invocation) QueryInstalledChaincode(input *lb.QueryInstalledChaincodeArgs) (proto.Message, error)

QueryInstalledChaincode is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryInstalledChaincodes

func (i *Invocation) QueryInstalledChaincodes(input *lb.QueryInstalledChaincodesArgs) (proto.Message, error)

QueryInstalledChaincodes is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

type LegacyDeployedCCInfoProvider

type LegacyDeployedCCInfoProvider interface {
	ledger.DeployedChaincodeInfoProvider
}

type LegacyMetadataProvider

type LegacyMetadataProvider interface {
	Metadata(channel string, cc string, includeCollections bool) *chaincode.Metadata
}

LegacyMetadataProvider provides metadata for a lscc-defined chaincode on a specific channel.

type Lifecycle

type Lifecycle interface {
	ChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ChaincodeEndorsementInfo, error)
}

Lifecycle is the interface which the core/chaincode package and core/endorser package requires that lifecycle satisfy.

type LocalChaincode

type LocalChaincode struct {
	Info       *ChaincodeInstallInfo
	References map[string]map[string]*CachedChaincodeDefinition
}

func (*LocalChaincode) ToInstalledChaincode

func (l *LocalChaincode) ToInstalledChaincode() *chaincode.InstalledChaincode

ToInstalledChaincode converts a LocalChaincode to an InstalledChaincode, which is returned by lifecycle queries.

type LocalChaincodeInfo

type LocalChaincodeInfo struct {
	Definition  *ChaincodeDefinition
	Approved    bool
	InstallInfo *ChaincodeInstallInfo
}

type Marshaler

type Marshaler func(proto.Message) ([]byte, error)

func (Marshaler) Marshal

func (m Marshaler) Marshal(msg proto.Message) ([]byte, error)

type MetadataHandler

type MetadataHandler interface {
	InitializeMetadata(channel string, chaincodes chaincode.MetadataSet)
	UpdateMetadata(channel string, chaincodes chaincode.MetadataSet)
}

MetadataHandler is the interface through which the cache drives metadata updates for listeners such as gossip and service discovery

type MetadataManager

type MetadataManager struct {
	LegacyMetadataSet map[string]chaincode.MetadataSet
	MetadataSet       map[string]chaincode.MetadataSet
	// contains filtered or unexported fields
}

MetadataManager stores metadata about the chaincodes installed/deployed via _lifecycle (Metadaset) and lscc (LegacyMetadataSet) and updates any registered listeners upon a change in the metadata.

func NewMetadataManager

func NewMetadataManager() *MetadataManager

func (*MetadataManager) AddListener

func (m *MetadataManager) AddListener(listener MetadataUpdateListener)

AddListener registers the given listener to be triggered upon a lifecycle change

func (*MetadataManager) HandleMetadataUpdate

func (m *MetadataManager) HandleMetadataUpdate(channel string, metadata chaincode.MetadataSet)

HandleMetadataUpdate implements the function of the same name in the cclifecycle.LifecycleChangeListener interface. This function is called by the legacy lifecycle (lscc) to deliver updates so we aggregate them and propagate them to our listeners. This function is also called to initialise data structures right at peer startup time.

func (*MetadataManager) InitializeMetadata

func (m *MetadataManager) InitializeMetadata(channel string, metadata chaincode.MetadataSet)

InitializeMetadata implements the function of the same name in the lifecycle.MetadataManager interface. This function is called by _lifecycle to initialize metadata for the given channel.

func (*MetadataManager) UpdateMetadata

func (m *MetadataManager) UpdateMetadata(channel string, metadata chaincode.MetadataSet)

UpdateMetadata implements the function of the same name in the lifecycle.MetadataManager interface. This function is called by _lifecycle to deliver updates so we aggregate them and propagate them to our listeners.

type MetadataProvider

type MetadataProvider struct {
	ChaincodeInfoProvider          ChaincodeInfoProvider
	LegacyMetadataProvider         LegacyMetadataProvider
	ChannelPolicyReferenceProvider ChannelPolicyReferenceProvider
}

func NewMetadataProvider

NewMetadataProvider returns a new MetadataProvider instance

func (*MetadataProvider) Metadata

func (mp *MetadataProvider) Metadata(channel string, ccName string, includeCollections bool) *chaincode.Metadata

Metadata implements the metadata retriever support interface for service discovery

type MetadataUpdateListener

type MetadataUpdateListener interface {
	HandleMetadataUpdate(channel string, metadata chaincode.MetadataSet)
}

MetadataUpdateListener runs whenever there is a change to the metadata of a chaincode in the context of a specific channel.

type OpaqueState

type OpaqueState interface {
	GetStateHash(key string) (value []byte, err error)
	CollectionName() string
}

type PackageParser

type PackageParser interface {
	Parse(data []byte) (*persistence.ChaincodePackage, error)
}

type PrivateQueryExecutor

type PrivateQueryExecutor interface {
	GetPrivateDataHash(namespace, collection, key string) (value []byte, err error)
}

type PrivateQueryExecutorShim

type PrivateQueryExecutorShim struct {
	Namespace  string
	Collection string
	State      PrivateQueryExecutor
}

func (*PrivateQueryExecutorShim) CollectionName

func (pqes *PrivateQueryExecutorShim) CollectionName() string

func (*PrivateQueryExecutorShim) GetStateHash

func (pqes *PrivateQueryExecutorShim) GetStateHash(key string) ([]byte, error)

type QueryExecutorProvider

type QueryExecutorProvider interface {
	TxQueryExecutor(channelID, txID string) ledger.SimpleQueryExecutor
}

QueryExecutorProvider provides a way to retrieve the query executor assosciated with an invocation

type RangeableState

type RangeableState interface {
	GetStateRange(prefix string) (map[string][]byte, error)
}

type ReadWritableState

type ReadWritableState interface {
	ReadableState
	PutState(key string, value []byte) error
	DelState(key string) error
}

type ReadableState

type ReadableState interface {
	GetState(key string) (value []byte, err error)
}

type Resources

type Resources struct {
	ChannelConfigSource ChannelConfigSource
	ChaincodeStore      ChaincodeStore
	PackageParser       PackageParser
	Serializer          *Serializer
}

Resources stores the common functions needed by all components of the lifecycle by the SCC as well as internally. It also has some utility methods attached to it for querying the lifecycle definitions.

func (*Resources) ChaincodeDefinitionIfDefined

func (r *Resources) ChaincodeDefinitionIfDefined(chaincodeName string, state ReadableState) (bool, *ChaincodeDefinition, error)

ChaincodeDefinitionIfDefined returns whether the chaincode name is defined in the new lifecycle, a shim around the SimpleQueryExecutor to work with the serializer, or an error. If the namespace is defined, but it is not a chaincode, this is considered an error.

type ResultsIteratorShim

type ResultsIteratorShim struct {
	ResultsIterator commonledger.ResultsIterator
}

func (*ResultsIteratorShim) Close

func (ris *ResultsIteratorShim) Close() error

func (*ResultsIteratorShim) Next

func (ris *ResultsIteratorShim) Next() (*queryresult.KV, error)

type SCC

type SCC struct {
	OrgMSPID string

	ACLProvider aclmgmt.ACLProvider

	ChannelConfigSource ChannelConfigSource

	DeployedCCInfoProvider ledger.DeployedChaincodeInfoProvider
	QueryExecutorProvider  QueryExecutorProvider

	// Functions provides the backing implementation of lifecycle.
	Functions SCCFunctions

	// Dispatcher handles the rote protobuf boilerplate for unmarshaling/marshaling
	// the inputs and outputs of the SCC functions.
	Dispatcher *dispatcher.Dispatcher
}

SCC implements the required methods to satisfy the chaincode interface. It routes the invocation calls to the backing implementations.

func (*SCC) Chaincode

func (scc *SCC) Chaincode() shim.Chaincode

Chaincode returns a reference to itself

func (*SCC) Init

func (scc *SCC) Init(stub shim.ChaincodeStubInterface) pb.Response

Init is mostly useless for system chaincodes and always returns success

func (*SCC) Invoke

func (scc *SCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response

Invoke takes chaincode invocation arguments and routes them to the correct underlying lifecycle operation. All functions take a single argument of type marshaled lb.<FunctionName>Args and return a marshaled lb.<FunctionName>Result

func (*SCC) Name

func (scc *SCC) Name() string

Name returns "_lifecycle"

type SCCFunctions added in v1.4.1

type SCCFunctions interface {
	// InstallChaincode persists a chaincode definition to disk
	InstallChaincode([]byte) (*chaincode.InstalledChaincode, error)

	// QueryInstalledChaincode returns metadata for the chaincode with the supplied package ID.
	QueryInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)

	// GetInstalledChaincodePackage returns the chaincode package
	// installed on the peer as bytes.
	GetInstalledChaincodePackage(packageID string) ([]byte, error)

	// QueryInstalledChaincodes returns the currently installed chaincodes
	QueryInstalledChaincodes() []*chaincode.InstalledChaincode

	// ApproveChaincodeDefinitionForOrg records a chaincode definition into this org's implicit collection.
	ApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID string, publicState ReadableState, orgState ReadWritableState) error

	// CheckCommitReadiness returns a map containing the orgs
	// whose orgStates were supplied and whether or not they have approved
	// the specified definition.
	CheckCommitReadiness(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)

	// CommitChaincodeDefinition records a new chaincode definition into the
	// public state and returns a map containing the orgs whose orgStates
	// were supplied and whether or not they have approved the definition.
	CommitChaincodeDefinition(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)

	// QueryChaincodeDefinition returns a chaincode definition from the public
	// state.
	QueryChaincodeDefinition(name string, publicState ReadableState) (*ChaincodeDefinition, error)

	// QueryOrgApprovals returns a map containing the orgs whose orgStates were
	// supplied and whether or not they have approved a chaincode definition with
	// the specified parameters.
	QueryOrgApprovals(name string, cd *ChaincodeDefinition, orgStates []OpaqueState) (map[string]bool, error)

	// QueryNamespaceDefinitions returns all defined namespaces
	QueryNamespaceDefinitions(publicState RangeableState) (map[string]string, error)
}

SCCFunctions provides a backing implementation with concrete arguments for each of the SCC functions

type Serializer

type Serializer struct {
	// Marshaler, when nil uses the standard protobuf impl.
	// Can be overridden for test.
	Marshaler Marshaler
}

Serializer is used to write structures into the db and to read them back out. Although it's unfortunate to write a custom serializer, rather than to use something pre-written, like protobuf or JSON, in order to produce precise readwrite sets which only perform state updates for keys which are actually updated (and not simply set to the same value again) custom serialization is required.

func (*Serializer) Deserialize

func (s *Serializer) Deserialize(namespace, name string, metadata *lb.StateMetadata, structure interface{}, state ReadableState) error

Deserialize accepts a struct (of a type previously serialized) and populates it with the values from the db. Note: The struct names for the serialization and deserialization must match exactly. Unencoded fields are not populated, and the extraneous keys are ignored. The metadata provided should have been returned by a DeserializeMetadata call for the same namespace and name.

func (*Serializer) DeserializeAllMetadata

func (s *Serializer) DeserializeAllMetadata(namespace string, state RangeableState) (map[string]*lb.StateMetadata, error)

func (*Serializer) DeserializeField

func (s *Serializer) DeserializeField(namespace, name, field string, state ReadableState) (*lb.StateData, error)

func (*Serializer) DeserializeFieldAsBytes

func (s *Serializer) DeserializeFieldAsBytes(namespace, name, field string, state ReadableState) ([]byte, error)

func (*Serializer) DeserializeFieldAsInt64

func (s *Serializer) DeserializeFieldAsInt64(namespace, name, field string, state ReadableState) (int64, error)

func (*Serializer) DeserializeFieldAsProto

func (s *Serializer) DeserializeFieldAsProto(namespace, name, field string, state ReadableState, msg proto.Message) error

func (*Serializer) DeserializeFieldAsString

func (s *Serializer) DeserializeFieldAsString(namespace, name, field string, state ReadableState) (string, error)

func (*Serializer) DeserializeMetadata

func (s *Serializer) DeserializeMetadata(namespace, name string, state ReadableState) (*lb.StateMetadata, bool, error)

func (*Serializer) IsMetadataSerialized

func (s *Serializer) IsMetadataSerialized(namespace, name string, structure interface{}, state OpaqueState) (bool, error)

func (*Serializer) IsSerialized

func (s *Serializer) IsSerialized(namespace, name string, structure interface{}, state OpaqueState) (bool, error)

IsSerialized essentially checks if the hashes of a serialized version of a structure matches the hashes of the pre-image of some struct serialized into the database.

func (*Serializer) SerializableChecks

func (s *Serializer) SerializableChecks(structure interface{}) (reflect.Value, []string, error)

SerializableChecks performs some boilerplate checks to make sure the given structure is serializable. It returns the reflected version of the value and a slice of all field names, or an error.

func (*Serializer) Serialize

func (s *Serializer) Serialize(namespace, name string, structure interface{}, state ReadWritableState) error

Serialize takes a pointer to a struct, and writes each of its fields as keys into a namespace. It also writes the struct metadata (if it needs updating) and, deletes any keys in the namespace which are not found in the struct. Note: If a key already exists for the field, and the value is unchanged, then the key is _not_ written to.

type SimpleQueryExecutorShim

type SimpleQueryExecutorShim struct {
	Namespace           string
	SimpleQueryExecutor ledger.SimpleQueryExecutor
}

SimpleQueryExecutorShim implements the ReadableState and RangeableState interfaces based on an underlying ledger.SimpleQueryExecutor

func (*SimpleQueryExecutorShim) GetState

func (sqes *SimpleQueryExecutorShim) GetState(key string) ([]byte, error)

func (*SimpleQueryExecutorShim) GetStateRange

func (sqes *SimpleQueryExecutorShim) GetStateRange(prefix string) (map[string][]byte, error)

type StateIterator

type StateIterator interface {
	Close() error
	Next() (*queryresult.KV, error)
}

type ValidatorCommitter

type ValidatorCommitter struct {
	Resources                    *Resources
	LegacyDeployedCCInfoProvider LegacyDeployedCCInfoProvider
}

func (*ValidatorCommitter) AllCollectionsConfigPkg

func (vc *ValidatorCommitter) AllCollectionsConfigPkg(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) (*pb.CollectionConfigPackage, error)

AllCollectionsConfigPkg implements function in interface ledger.DeployedChaincodeInfoProvider this implementation returns a combined collection config pkg that contains both explicit and implicit collections

func (*ValidatorCommitter) ChaincodeImplicitCollections

func (vc *ValidatorCommitter) ChaincodeImplicitCollections(channelName string) ([]*pb.StaticCollectionConfig, error)

ChaincodeImplicitCollections assumes the chaincode exists in the new lifecycle and returns the implicit collections

func (*ValidatorCommitter) ChaincodeInfo

func (vc *ValidatorCommitter) ChaincodeInfo(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ledger.DeployedChaincodeInfo, error)

func (*ValidatorCommitter) CollectionInfo

func (vc *ValidatorCommitter) CollectionInfo(channelName, chaincodeName, collectionName string, qe ledger.SimpleQueryExecutor) (*pb.StaticCollectionConfig, error)

CollectionInfo implements function in interface ledger.DeployedChaincodeInfoProvider, it returns config for both static and implicit collections.

func (*ValidatorCommitter) CollectionValidationInfo

func (vc *ValidatorCommitter) CollectionValidationInfo(channelID, chaincodeName, collectionName string, state validationState.State) (args []byte, unexpectedErr, validationErr error)

CollectionValidationInfo returns information about collections to the validation component

func (*ValidatorCommitter) ImplicitCollectionEndorsementPolicyAsBytes

func (vc *ValidatorCommitter) ImplicitCollectionEndorsementPolicyAsBytes(channelID, orgMSPID string) (policy []byte, unexpectedErr, validationErr error)

func (*ValidatorCommitter) ImplicitCollections

func (vc *ValidatorCommitter) ImplicitCollections(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) ([]*pb.StaticCollectionConfig, error)

ImplicitCollections implements function in interface ledger.DeployedChaincodeInfoProvider. It returns a slice that contains one proto msg for each of the implicit collections

func (*ValidatorCommitter) LifecycleEndorsementPolicyAsBytes

func (vc *ValidatorCommitter) LifecycleEndorsementPolicyAsBytes(channelID string) ([]byte, error)

func (*ValidatorCommitter) Namespaces

func (vc *ValidatorCommitter) Namespaces() []string

Namespaces returns the list of namespaces which are relevant to chaincode lifecycle

func (*ValidatorCommitter) UpdatedChaincodes

func (vc *ValidatorCommitter) UpdatedChaincodes(stateUpdates map[string][]*kvrwset.KVWrite) ([]*ledger.ChaincodeLifecycleInfo, error)

UpdatedChaincodes returns the chaincodes that are getting updated by the supplied 'stateUpdates'

func (*ValidatorCommitter) ValidationInfo

func (vc *ValidatorCommitter) ValidationInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (plugin string, args []byte, unexpectedErr error, validationErr error)

ValidationInfo returns the name and arguments of the validation plugin for the supplied chaincode. The function returns two types of errors, unexpected errors and validation errors. The reason for this is that this function is called from the validation code, which needs to differentiate the two types of error to halt processing on the channel if the unexpected error is not nil and mark the transaction as invalid if the validation error is not nil.

type ValidatorStateShim

type ValidatorStateShim struct {
	ValidatorState validatorstate.State
	Namespace      string
}

func (*ValidatorStateShim) GetState

func (vss *ValidatorStateShim) GetState(key string) ([]byte, error)

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL