ledger

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockAndPvtData added in v1.1.0

type BlockAndPvtData struct {
	Block        *common.Block
	BlockPvtData map[uint64]*TxPvtData
	Missing      *MissingPrivateDataList
}

BlockAndPvtData encapsulates the block and a map that contains the tuples <seqInBlock, *TxPvtData> The map is expected to contain the entries only for the transactions that has associated pvt data

type BlockPvtData added in v1.4.0

type BlockPvtData struct {
	BlockNum  uint64
	WriteSets map[uint64]*TxPvtData
}

BlockPvtData contains the private data for a block

type ChaincodeLifecycleDetails added in v1.4.0

type ChaincodeLifecycleDetails struct {
	Updated bool // true, if an existing chaincode is updated (false for newly deployed chaincodes).
	// Following attributes are meaningful only if 'Updated' is true
	HashChanged        bool     // true, if the chaincode code package is changed
	CollectionsUpdated []string // names of the collections that are either added or updated
	CollectionsRemoved []string // names of the collections that are removed
}

ChaincodeLifecycleDetails captures the finer details of chaincode lifecycle event

type ChaincodeLifecycleInfo added in v1.4.0

type ChaincodeLifecycleInfo struct {
	Name    string
	Deleted bool
	Details *ChaincodeLifecycleDetails // Can contain finer details about lifecycle event that can be used for certain optimization
}

ChaincodeLifecycleInfo captures the update info of a chaincode

type CollConfigNotDefinedError added in v1.4.0

type CollConfigNotDefinedError struct {
	Ns string
}

CollConfigNotDefinedError is returned whenever an operation is requested on a collection whose config has not been defined

func (*CollConfigNotDefinedError) Error added in v1.4.0

func (e *CollConfigNotDefinedError) Error() string

type CollectionConfigInfo added in v1.2.0

type CollectionConfigInfo struct {
	CollectionConfig   *common.CollectionConfigPackage
	CommittingBlockNum uint64
}

CollectionConfigInfo encapsulates a collection config for a chaincode and its committing block number

type ConfigHistoryRetriever added in v1.2.0

type ConfigHistoryRetriever interface {
	CollectionConfigAt(blockNum uint64, chaincodeName string) (*CollectionConfigInfo, error)
	MostRecentCollectionConfigBelow(blockNum uint64, chaincodeName string) (*CollectionConfigInfo, error)
}

ConfigHistoryRetriever allow retrieving history of collection configs

type DeployedChaincodeInfo added in v1.4.0

type DeployedChaincodeInfo struct {
	Name                string
	Hash                []byte
	Version             string
	CollectionConfigPkg *common.CollectionConfigPackage
}

DeployedChaincodeInfo encapsulates chaincode information from the deployed chaincodes

type DeployedChaincodeInfoProvider added in v1.4.0

type DeployedChaincodeInfoProvider interface {
	Namespaces() []string
	UpdatedChaincodes(stateUpdates map[string][]*kvrwset.KVWrite) ([]*ChaincodeLifecycleInfo, error)
	ChaincodeInfo(chaincodeName string, qe SimpleQueryExecutor) (*DeployedChaincodeInfo, error)
	CollectionInfo(chaincodeName, collectionName string, qe SimpleQueryExecutor) (*common.StaticCollectionConfig, error)
}

DeployedChaincodeInfoProvider is a dependency that is used by ledger to build collection config history LSCC module is expected to provide an implementation fo this dependencys

type ErrCollectionConfigNotYetAvailable added in v1.2.0

type ErrCollectionConfigNotYetAvailable struct {
	MaxBlockNumCommitted uint64
	Msg                  string
}

ErrCollectionConfigNotYetAvailable is an error which is returned from the function ConfigHistoryRetriever.CollectionConfigAt() if the latest block number committed is lower than the block number specified in the request.

func (*ErrCollectionConfigNotYetAvailable) Error added in v1.2.0

type HistoryQueryExecutor

type HistoryQueryExecutor interface {
	// GetHistoryForKey retrieves the history of values for a key.
	// The returned ResultsIterator contains results of type *KeyModification which is defined in protos/ledger/queryresult.
	GetHistoryForKey(namespace string, key string) (commonledger.ResultsIterator, error)
}

HistoryQueryExecutor executes the history queries

type Initializer added in v1.4.0

type Initializer struct {
	StateListeners                []StateListener
	DeployedChaincodeInfoProvider DeployedChaincodeInfoProvider
	MembershipInfoProvider        MembershipInfoProvider
}

Initializer encapsulates dependencies for PeerLedgerProvider

type InvalidCollNameError added in v1.4.0

type InvalidCollNameError struct {
	Ns, Coll string
}

InvalidCollNameError is returned whenever an operation is requested on a collection whose name is invalid

func (*InvalidCollNameError) Error added in v1.4.0

func (e *InvalidCollNameError) Error() string

type MembershipInfoProvider added in v1.4.0

type MembershipInfoProvider interface {
	// AmMemberOf checks whether the current peer is a member of the given collection
	AmMemberOf(channelName string, collectionPolicyConfig *common.CollectionPolicyConfig) (bool, error)
}

MembershipInfoProvider is a dependency that is used by ledger to determine whether the current peer is a member of a collection. Gossip module is expected to provide the dependency to ledger

type MissingBlockPvtdataInfo added in v1.4.0

type MissingBlockPvtdataInfo map[uint64][]*MissingCollectionPvtDataInfo

MissingBlockPvtdataInfo is a map of transaction number (within the block) to MissingCollectionPvtDataInfo

type MissingCollectionPvtDataInfo added in v1.4.0

type MissingCollectionPvtDataInfo struct {
	Namespace, Collection string
}

MissingCollectionPvtDataInfo includes the name of the chaincode and collection for which private data is missing

type MissingPrivateData added in v1.1.0

type MissingPrivateData struct {
	TxId       string
	SeqInBlock uint64
	Namespace  string
	Collection string
	IsEligible bool
}

MissingPrivateData represents a private RWSet that isn't present among the private data passed to the ledger at the commit of the corresponding block

type MissingPrivateDataList

type MissingPrivateDataList struct {
	List []*MissingPrivateData
}

func (*MissingPrivateDataList) Add

func (missing *MissingPrivateDataList) Add(txId string, txNum uint64, ns, coll string, isEligible bool)

type MissingPvtDataInfo added in v1.4.0

type MissingPvtDataInfo map[uint64]MissingBlockPvtdataInfo

MissingPvtDataInfo is a map of block number to MissingBlockPvtdataInfo

func (MissingPvtDataInfo) Add added in v1.4.0

func (missingPvtDataInfo MissingPvtDataInfo) Add(blkNum, txNum uint64, ns, coll string)

type MissingPvtDataTracker added in v1.4.0

type MissingPvtDataTracker interface {
	GetMissingPvtDataInfoForMostRecentBlocks(maxBlocks int) (MissingPvtDataInfo, error)
}

MissingPvtDataTracker allows getting information about the private data that is not missing on the peer

type NotFoundInIndexErr added in v1.2.0

type NotFoundInIndexErr string

NotFoundInIndexErr is used to indicate missing entry in the index

func (NotFoundInIndexErr) Error added in v1.2.0

func (NotFoundInIndexErr) Error() string

type PeerLedger

type PeerLedger interface {
	commonledger.Ledger
	// GetTransactionByID retrieves a transaction by id
	GetTransactionByID(txID string) (*peer.ProcessedTransaction, error)
	// GetBlockByHash returns a block given it's hash
	GetBlockByHash(blockHash []byte) (*common.Block, error)
	// GetBlockByTxID returns a block which contains a transaction
	GetBlockByTxID(txID string) (*common.Block, error)
	// GetTxValidationCodeByTxID returns reason code of transaction validation
	GetTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error)
	// NewTxSimulator gives handle to a transaction simulator.
	// A client can obtain more than one 'TxSimulator's for parallel execution.
	// Any snapshoting/synchronization should be performed at the implementation level if required
	NewTxSimulator(txid string) (TxSimulator, error)
	// NewQueryExecutor gives handle to a query executor.
	// A client can obtain more than one 'QueryExecutor's for parallel execution.
	// Any synchronization should be performed at the implementation level if required
	NewQueryExecutor() (QueryExecutor, error)
	// NewHistoryQueryExecutor gives handle to a history query executor.
	// A client can obtain more than one 'HistoryQueryExecutor's for parallel execution.
	// Any synchronization should be performed at the implementation level if required
	NewHistoryQueryExecutor() (HistoryQueryExecutor, error)
	// GetPvtDataAndBlockByNum returns the block and the corresponding pvt data.
	// The pvt data is filtered by the list of 'ns/collections' supplied
	// A nil filter does not filter any results and causes retrieving all the pvt data for the given blockNum
	GetPvtDataAndBlockByNum(blockNum uint64, filter PvtNsCollFilter) (*BlockAndPvtData, error)
	// GetPvtDataByNum returns only the pvt data  corresponding to the given block number
	// The pvt data is filtered by the list of 'ns/collections' supplied in the filter
	// A nil filter does not filter any results and causes retrieving all the pvt data for the given blockNum
	GetPvtDataByNum(blockNum uint64, filter PvtNsCollFilter) ([]*TxPvtData, error)
	// CommitWithPvtData commits the block and the corresponding pvt data in an atomic operation
	CommitWithPvtData(blockAndPvtdata *BlockAndPvtData) error
	// Purge removes private read-writes set generated by endorsers at block height lesser than
	// a given maxBlockNumToRetain. In other words, Purge only retains private read-write sets
	// that were generated at block height of maxBlockNumToRetain or higher.
	PurgePrivateData(maxBlockNumToRetain uint64) error
	// PrivateDataMinBlockNum returns the lowest retained endorsement block height
	PrivateDataMinBlockNum() (uint64, error)
	//Prune prunes the blocks/transactions that satisfy the given policy
	Prune(policy commonledger.PrunePolicy) error
	// GetConfigHistoryRetriever returns the ConfigHistoryRetriever
	GetConfigHistoryRetriever() (ConfigHistoryRetriever, error)
	// CommitPvtData commits the private data corresponding to already committed block
	// If hashes for some of the private data supplied in this function does not match
	// the corresponding hash present in the block, the unmatched private data is not
	// committed and instead the mismatch inforation is returned back
	CommitPvtData(blockPvtData []*BlockPvtData) ([]*PvtdataHashMismatch, error)
	// GetMissingPvtDataTracker return the MissingPvtDataTracker
	GetMissingPvtDataTracker() (MissingPvtDataTracker, error)
}

PeerLedger differs from the OrdererLedger in that PeerLedger locally maintain a bitmask that tells apart valid transactions from invalid ones

type PeerLedgerProvider

type PeerLedgerProvider interface {
	Initialize(initializer *Initializer)
	// 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
	Create(genesisBlock *common.Block) (PeerLedger, error)
	// Open opens an already created ledger
	Open(ledgerID string) (PeerLedger, error)
	// Exists tells whether the ledger with given id exists
	Exists(ledgerID string) (bool, error)
	// List lists the ids of the existing ledgers
	List() ([]string, error)
	// Close closes the PeerLedgerProvider
	Close()
}

PeerLedgerProvider provides handle to ledger instances

type PvtCollFilter added in v1.1.0

type PvtCollFilter map[string]bool

PvtCollFilter represents the set of the collection names (as keys of the map with value 'true')

type PvtNsCollFilter added in v1.1.0

type PvtNsCollFilter map[string]PvtCollFilter

PvtNsCollFilter specifies the tuple <namespace, PvtCollFilter>

func NewPvtNsCollFilter added in v1.1.0

func NewPvtNsCollFilter() PvtNsCollFilter

NewPvtNsCollFilter constructs an empty PvtNsCollFilter

func (PvtNsCollFilter) Add added in v1.1.0

func (filter PvtNsCollFilter) Add(ns string, coll string)

Add adds a namespace-collection tuple to the filter

func (PvtNsCollFilter) Has added in v1.1.0

func (filter PvtNsCollFilter) Has(ns string, coll string) bool

Has returns true if the filter has the entry for tuple namespace-collection

type PvtdataHashMismatch added in v1.4.0

type PvtdataHashMismatch struct {
	BlockNum, TxNum               uint64
	ChaincodeName, CollectionName string
	ExpectedHash                  []byte
}

PvtdataHashMismatch is used when the hash of private write-set does not match the corresponding hash present in the block See function `PeerLedger.CommitPvtData` for the usages

type QueryExecutor

type QueryExecutor interface {
	SimpleQueryExecutor
	// GetStateMetadata returns the metadata for given namespace and key
	GetStateMetadata(namespace, key string) (map[string][]byte, error)
	// GetStateMultipleKeys gets the values for multiple keys in a single call
	GetStateMultipleKeys(namespace string, keys []string) ([][]byte, error)
	// GetStateRangeScanIteratorWithMetadata returns an iterator that contains all the key-values between given key ranges.
	// startKey is included in the results and endKey is excluded. An empty startKey refers to the first available key
	// and an empty endKey refers to the last available key. For scanning all the keys, both the startKey and the endKey
	// can be supplied as empty strings. However, a full scan should be used judiciously for performance reasons.
	// metadata is a map of additional query parameters
	// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
	GetStateRangeScanIteratorWithMetadata(namespace string, startKey, endKey string, metadata map[string]interface{}) (QueryResultsIterator, error)
	// ExecuteQuery executes the given query and returns an iterator that contains results of type specific to the underlying data store.
	// Only used for state databases that support query
	// For a chaincode, the namespace corresponds to the chaincodeId
	// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
	ExecuteQuery(namespace, query string) (commonledger.ResultsIterator, error)
	// ExecuteQueryWithMetadata executes the given query and returns an iterator that contains results of type specific to the underlying data store.
	// metadata is a map of additional query parameters
	// Only used for state databases that support query
	// For a chaincode, the namespace corresponds to the chaincodeId
	// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
	ExecuteQueryWithMetadata(namespace, query string, metadata map[string]interface{}) (QueryResultsIterator, error)
	// GetPrivateData gets the value of a private data item identified by a tuple <namespace, collection, key>
	GetPrivateData(namespace, collection, key string) ([]byte, error)
	// GetPrivateDataMetadata gets the metadata of a private data item identified by a tuple <namespace, collection, key>
	GetPrivateDataMetadata(namespace, collection, key string) (map[string][]byte, error)
	// GetPrivateDataMetadataByHash gets the metadata of a private data item identified by a tuple <namespace, collection, keyhash>
	GetPrivateDataMetadataByHash(namespace, collection string, keyhash []byte) (map[string][]byte, error)
	// GetPrivateDataMultipleKeys gets the values for the multiple private data items in a single call
	GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([][]byte, error)
	// GetPrivateDataRangeScanIterator returns an iterator that contains all the key-values between given key ranges.
	// startKey is included in the results and endKey is excluded. An empty startKey refers to the first available key
	// and an empty endKey refers to the last available key. For scanning all the keys, both the startKey and the endKey
	// can be supplied as empty strings. However, a full scan shuold be used judiciously for performance reasons.
	// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
	GetPrivateDataRangeScanIterator(namespace, collection, startKey, endKey string) (commonledger.ResultsIterator, error)
	// ExecuteQuery executes the given query and returns an iterator that contains results of type specific to the underlying data store.
	// Only used for state databases that support query
	// For a chaincode, the namespace corresponds to the chaincodeId
	// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
	ExecuteQueryOnPrivateData(namespace, collection, query string) (commonledger.ResultsIterator, error)
	// Done releases resources occupied by the QueryExecutor
	Done()
}

QueryExecutor executes the queries Get* methods are for supporting KV-based data model. ExecuteQuery method is for supporting a rich datamodel and query support

ExecuteQuery method in the case of a rich data model is expected to support queries on latest state, historical state and on the intersection of state and transactions

type QueryResultsIterator added in v1.4.0

type QueryResultsIterator interface {
	commonledger.ResultsIterator
	// GetBookmarkAndClose returns a paging bookmark and releases resources occupied by the iterator
	GetBookmarkAndClose() string
}

QueryResultsIterator - an iterator for query result set

type SimpleQueryExecutor added in v1.4.0

type SimpleQueryExecutor interface {
	// GetState gets the value for given namespace and key. For a chaincode, the namespace corresponds to the chaincodeId
	GetState(namespace string, key string) ([]byte, error)
	// GetStateRangeScanIterator returns an iterator that contains all the key-values between given key ranges.
	// startKey is included in the results and endKey is excluded. An empty startKey refers to the first available key
	// and an empty endKey refers to the last available key. For scanning all the keys, both the startKey and the endKey
	// can be supplied as empty strings. However, a full scan should be used judiciously for performance reasons.
	// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
	GetStateRangeScanIterator(namespace string, startKey string, endKey string) (commonledger.ResultsIterator, error)
}

SimpleQueryExecutor encapsulates basic functions

type StateListener added in v1.1.0

type StateListener interface {
	InterestedInNamespaces() []string
	HandleStateUpdates(trigger *StateUpdateTrigger) error
	StateCommitDone(channelID string)
}

StateListener allows a custom code for performing additional stuff upon state change for a perticular namespace against which the listener is registered. This helps to perform custom tasks other than the state updates. A ledger implemetation is expected to invoke Function `HandleStateUpdates` once per block and the `stateUpdates` parameter passed to the function captures the state changes caused by the block for the namespace. The actual data type of stateUpdates depends on the data model enabled. For instance, for KV data model, the actual type would be proto message `github.com/hyperledger/fabric/protos/ledger/rwset/kvrwset.KVWrite` Function `HandleStateUpdates` is expected to be invoked before block is committed and if this function returns an error, the ledger implementation is expected to halt block commit operation and result in a panic

type StateUpdateTrigger added in v1.4.0

type StateUpdateTrigger struct {
	LedgerID                    string
	StateUpdates                StateUpdates
	CommittingBlockNum          uint64
	CommittedStateQueryExecutor SimpleQueryExecutor
	PostCommitQueryExecutor     SimpleQueryExecutor
}

StateUpdateTrigger encapsulates the information and helper tools that may be used by a StateListener

type StateUpdates added in v1.1.0

type StateUpdates map[string]interface{}

StateUpdates is the generic type to represent the state updates

type TxPvtData added in v1.1.0

type TxPvtData struct {
	SeqInBlock uint64
	WriteSet   *rwset.TxPvtReadWriteSet
}

TxPvtData encapsulates the transaction number and pvt write-set for a transaction

func (*TxPvtData) Has added in v1.1.0

func (pvtdata *TxPvtData) Has(ns string, coll string) bool

Has returns true if the pvtdata includes the data for collection <ns,coll>

type TxSimulationResults added in v1.1.0

type TxSimulationResults struct {
	PubSimulationResults *rwset.TxReadWriteSet
	PvtSimulationResults *rwset.TxPvtReadWriteSet
}

TxSimulationResults captures the details of the simulation results

func (*TxSimulationResults) ContainsPvtWrites added in v1.1.0

func (txSim *TxSimulationResults) ContainsPvtWrites() bool

ContainsPvtWrites returns true if the simulation results include the private writes

func (*TxSimulationResults) GetPubSimulationBytes added in v1.1.0

func (txSim *TxSimulationResults) GetPubSimulationBytes() ([]byte, error)

GetPubSimulationBytes returns the serialized bytes of public readwrite set

func (*TxSimulationResults) GetPvtSimulationBytes added in v1.1.0

func (txSim *TxSimulationResults) GetPvtSimulationBytes() ([]byte, error)

GetPvtSimulationBytes returns the serialized bytes of private readwrite set

type TxSimulator

type TxSimulator interface {
	QueryExecutor
	// SetState sets the given value for the given namespace and key. For a chaincode, the namespace corresponds to the chaincodeId
	SetState(namespace string, key string, value []byte) error
	// DeleteState deletes the given namespace and key
	DeleteState(namespace string, key string) error
	// SetMultipleKeys sets the values for multiple keys in a single call
	SetStateMultipleKeys(namespace string, kvs map[string][]byte) error
	// SetStateMetadata sets the metadata associated with an existing key-tuple <namespace, key>
	SetStateMetadata(namespace, key string, metadata map[string][]byte) error
	// DeleteStateMetadata deletes the metadata (if any) associated with an existing key-tuple <namespace, key>
	DeleteStateMetadata(namespace, key string) error
	// ExecuteUpdate for supporting rich data model (see comments on QueryExecutor above)
	ExecuteUpdate(query string) error
	// SetPrivateData sets the given value to a key in the private data state represented by the tuple <namespace, collection, key>
	SetPrivateData(namespace, collection, key string, value []byte) error
	// SetPrivateDataMultipleKeys sets the values for multiple keys in the private data space in a single call
	SetPrivateDataMultipleKeys(namespace, collection string, kvs map[string][]byte) error
	// DeletePrivateData deletes the given tuple <namespace, collection, key> from private data
	DeletePrivateData(namespace, collection, key string) error
	// SetPrivateDataMetadata sets the metadata associated with an existing key-tuple <namespace, collection, key>
	SetPrivateDataMetadata(namespace, collection, key string, metadata map[string][]byte) error
	// DeletePrivateDataMetadata deletes the metadata associated with an existing key-tuple <namespace, collection, key>
	DeletePrivateDataMetadata(namespace, collection, key string) error
	// GetTxSimulationResults encapsulates the results of the transaction simulation.
	// This should contain enough detail for
	// - The update in the state that would be caused if the transaction is to be committed
	// - The environment in which the transaction is executed so as to be able to decide the validity of the environment
	//   (at a later time on a different peer) during committing the transactions
	// Different ledger implementation (or configurations of a single implementation) may want to represent the above two pieces
	// of information in different way in order to support different data-models or optimize the information representations.
	// Returned type 'TxSimulationResults' contains the simulation results for both the public data and the private data.
	// The public data simulation results are expected to be used as in V1 while the private data simulation results are expected
	// to be used by the gossip to disseminate this to the other endorsers (in phase-2 of sidedb)
	GetTxSimulationResults() (*TxSimulationResults, error)
}

TxSimulator simulates a transaction on a consistent snapshot of the 'as recent state as possible' Set* methods are for supporting KV-based data model. ExecuteUpdate method is for supporting a rich datamodel and query support

type ValidatedLedger

type ValidatedLedger interface {
	commonledger.Ledger
}

ValidatedLedger represents the 'final ledger' after filtering out invalid transactions from PeerLedger. Post-v1

Jump to

Keyboard shortcuts

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