privacyenabledstate

package
v0.0.0-...-9b7ba46 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PubStateDataFileName           = "public_state.data"
	PubStateMetadataFileName       = "public_state.metadata"
	PvtStateHashesFileName         = "private_state_hashes.data"
	PvtStateHashesMetadataFileName = "private_state_hashes.metadata"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CouchDBTestEnv

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

CouchDBTestEnv implements TestEnv interface for couchdb based storage

func (*CouchDBTestEnv) Cleanup

func (env *CouchDBTestEnv) Cleanup()

Cleanup implements corresponding function from interface TestEnv

func (*CouchDBTestEnv) GetDBHandle

func (env *CouchDBTestEnv) GetDBHandle(id string) *DB

GetDBHandle implements corresponding function from interface TestEnv

func (*CouchDBTestEnv) GetName

func (env *CouchDBTestEnv) GetName() string

GetName implements corresponding function from interface TestEnv

func (*CouchDBTestEnv) GetProvider

func (env *CouchDBTestEnv) GetProvider() *DBProvider

GetProvider returns DBProvider

func (*CouchDBTestEnv) Init

func (env *CouchDBTestEnv) Init(t testing.TB)

Init implements corresponding function from interface TestEnv

func (*CouchDBTestEnv) StartExternalResource

func (env *CouchDBTestEnv) StartExternalResource()

StartExternalResource starts external couchDB resources.

func (*CouchDBTestEnv) StopExternalResource

func (env *CouchDBTestEnv) StopExternalResource()

StopExternalResource stops external couchDB resources.

type DB

type DB struct {
	statedb.VersionedDB
	// contains filtered or unexported fields
}

DB uses a single database to maintain both the public and private data

func NewDB

func NewDB(vdb statedb.VersionedDB, ledgerid string, metadataHint *metadataHint) (*DB, error)

NewDB wraps a VersionedDB instance. The public data is managed directly by the wrapped versionedDB. For managing the hashed data and private data, this implementation creates separate namespaces in the wrapped db

func (*DB) ApplyPrivacyAwareUpdates

func (s *DB) ApplyPrivacyAwareUpdates(updates *UpdateBatch, height *version.Height) error

ApplyPrivacyAwareUpdates applies the batch to the underlying db

func (*DB) ApplyUpdates

func (s *DB) ApplyUpdates(batch *statedb.UpdateBatch, height *version.Height) error

ApplyUpdates overrides the function in statedb.VersionedDB and throws appropriate error message Otherwise, somewhere in the code, usage of this function could lead to updating only public data.

func (*DB) ChaincodeDeployDone

func (s *DB) ChaincodeDeployDone(succeeded bool)

ChaincodeDeployDone is a noop for couchdb state impl

func (*DB) ClearCachedVersions

func (s *DB) ClearCachedVersions()

ClearCachedVersions clears the version cache

func (DB) ExecuteQueryOnPrivateData

func (s DB) ExecuteQueryOnPrivateData(namespace, collection, query string) (statedb.ResultsIterator, error)

ExecuteQueryOnPrivateData executes the given query and returns an iterator that contains results of type specific to the underlying data store.

func (*DB) ExportPubStateAndPvtStateHashes

func (s *DB) ExportPubStateAndPvtStateHashes(dir string, newHashFunc snapshot.NewHashFunc) (map[string][]byte, error)

ExportPubStateAndPvtStateHashes generates four files in the specified dir. The files, public_state.data and public_state.metadata contains the exported public state and the files private_state_hashes.data and private_state_hashes.metadata contain the exported private state hashes. The file format for public state and the private state hashes are the same. The data files contains a series serialized proto message SnapshotRecord and the metadata files contains a series of tuple <namespace, num entries for the namespace in the data file>.

func (*DB) GetCachedKeyHashVersion

func (s *DB) GetCachedKeyHashVersion(namespace, collection string, keyHash []byte) (*version.Height, bool)

GetCachedKeyHashVersion retrieves the keyhash version from cache

func (*DB) GetChaincodeEventListener

func (s *DB) GetChaincodeEventListener() cceventmgmt.ChaincodeLifecycleEventListener

GetChaincodeEventListener returns a struct that implements cceventmgmt.ChaincodeLifecycleEventListener if the underlying statedb implements statedb.IndexCapable.

func (*DB) GetKeyHashVersion

func (s *DB) GetKeyHashVersion(namespace, collection string, keyHash []byte) (*version.Height, error)

GetKeyHashVersion gets the version of a private data item identified by a tuple <namespace, collection, keyHash>

func (*DB) GetPrivateData

func (s *DB) GetPrivateData(namespace, collection, key string) (*statedb.VersionedValue, error)

GetPrivateData gets the value of a private data item identified by a tuple <namespace, collection, key>

func (*DB) GetPrivateDataHash

func (s *DB) GetPrivateDataHash(namespace, collection, key string) (*statedb.VersionedValue, error)

GetPrivateDataHash gets the hash of the value of a private data item identified by a tuple <namespace, collection, key>

func (*DB) GetPrivateDataMetadataByHash

func (s *DB) GetPrivateDataMetadataByHash(namespace, collection string, keyHash []byte) ([]byte, error)

GetPrivateDataMetadataByHash implements corresponding function in interface DB. For additional details, see description of the similar function 'GetStateMetadata'

func (*DB) GetPrivateDataMultipleKeys

func (s *DB) GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([]*statedb.VersionedValue, error)

GetPrivateDataMultipleKeys gets the values for the multiple private data items in a single call

func (*DB) GetPrivateDataRangeScanIterator

func (s *DB) GetPrivateDataRangeScanIterator(namespace, collection, startKey, endKey string) (statedb.ResultsIterator, 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.

func (*DB) GetStateMetadata

func (s *DB) GetStateMetadata(namespace, key string) ([]byte, error)

GetStateMetadata implements corresponding function in interface DB. This implementation provides an optimization such that it keeps track if a namespaces has never stored metadata for any of its items, the value 'nil' is returned without going to the db. This is intended to be invoked in the validation and commit path. This saves the chaincodes from paying unnecessary performance penalty if they do not use features that leverage metadata (such as key-level endorsement),

func (*DB) GetValueHash

func (s *DB) GetValueHash(namespace, collection string, keyHash []byte) (*statedb.VersionedValue, error)

GetValueHash gets the value hash of a private data item identified by a tuple <namespace, collection, keyHash>

func (*DB) HandleChaincodeDeploy

func (s *DB) HandleChaincodeDeploy(chaincodeDefinition *cceventmgmt.ChaincodeDefinition, dbArtifactsTar []byte) error

HandleChaincodeDeploy initializes database artifacts for the database associated with the namespace This function deliberately suppresses the errors that occur during the creation of the indexes on couchdb. This is because, in the present code, we do not differentiate between the errors because of couchdb interaction and the errors because of bad index files - the later being unfixable by the admin. Note that the error suppression is acceptable since peer can continue in the committing role without the indexes. However, executing chaincode queries may be affected, until a new chaincode with fixed indexes is installed and instantiated

func (*DB) IsBulkOptimizable

func (s *DB) IsBulkOptimizable() bool

IsBulkOptimizable checks whether the underlying statedb implements statedb.BulkOptimizable

func (*DB) LoadCommittedVersionsOfPubAndHashedKeys

func (s *DB) LoadCommittedVersionsOfPubAndHashedKeys(pubKeys []*statedb.CompositeKey,
	hashedKeys []*HashedCompositeKey) error

LoadCommittedVersionsOfPubAndHashedKeys loads committed version of given public and hashed states

type DBProvider

type DBProvider struct {
	VersionedDBProvider statedb.VersionedDBProvider
	HealthCheckRegistry ledger.HealthCheckRegistry
	// contains filtered or unexported fields
}

DBProvider encapsulates other providers such as VersionedDBProvider and BookeepingProvider which are required to create DB for a channel

func NewDBProvider

func NewDBProvider(
	bookkeeperProvider *bookkeeping.Provider,
	metricsProvider metrics.Provider,
	healthCheckRegistry ledger.HealthCheckRegistry,
	stateDBConf *StateDBConfig,
	sysNamespaces []string,
) (*DBProvider, error)

NewDBProvider constructs an instance of DBProvider

func (*DBProvider) Close

func (p *DBProvider) Close()

Close closes all the VersionedDB instances and releases any resources held by VersionedDBProvider

func (*DBProvider) Drop

func (p *DBProvider) Drop(ledgerid string) error

Drop drops channel-specific data from the statedb

func (*DBProvider) GetDBHandle

func (p *DBProvider) GetDBHandle(id string, chInfoProvider channelInfoProvider) (*DB, error)

GetDBHandle gets a handle to DB for a given id, i.e., a channel

func (*DBProvider) ImportFromSnapshot

func (p *DBProvider) ImportFromSnapshot(
	dbname string,
	savepoint *version.Height,
	snapshotDir string,
	pvtdataHashesConsumers ...SnapshotPvtdataHashesConsumer,
) error

ImportFromSnapshot imports the public state and private state hashes from the corresponding files in the snapshotDir

func (*DBProvider) RegisterHealthChecker

func (p *DBProvider) RegisterHealthChecker() error

RegisterHealthChecker registers the underlying stateDB with the healthChecker. For now, we register only the CouchDB as it runs as a separate process but not for the GoLevelDB as it is an embedded database.

type HashedCompositeKey

type HashedCompositeKey struct {
	Namespace      string
	CollectionName string
	KeyHash        string
}

HashedCompositeKey encloses Namespace, CollectionName and KeyHash components

func (*HashedCompositeKey) String

func (hck *HashedCompositeKey) String() string

String returns a print friendly form of HashedCompositeKey

type HashedUpdateBatch

type HashedUpdateBatch struct {
	UpdateMap
}

HashedUpdateBatch contains updates for the hashes of the private data

func NewHashedUpdateBatch

func NewHashedUpdateBatch() *HashedUpdateBatch

NewHashedUpdateBatch creates an empty HashedUpdateBatch

func (HashedUpdateBatch) Contains

func (h HashedUpdateBatch) Contains(ns, coll string, keyHash []byte) bool

Contains returns true if the given <ns,coll,keyHash> tuple is present in the batch

func (HashedUpdateBatch) Delete

func (h HashedUpdateBatch) Delete(ns, coll string, key []byte, version *version.Height)

Delete overrides the function in UpdateMap for allowing the key to be a []byte instead of a string

func (HashedUpdateBatch) Put

func (h HashedUpdateBatch) Put(ns, coll string, key []byte, value []byte, version *version.Height)

Put overrides the function in UpdateMap for allowing the key to be a []byte instead of a string

func (HashedUpdateBatch) PutValHashAndMetadata

func (h HashedUpdateBatch) PutValHashAndMetadata(ns, coll string, key []byte, value []byte, metadata []byte, version *version.Height)

PutValHashAndMetadata adds a key with value and metadata TODO introducing a new function to limit the refactoring. Later in a separate CR, the 'Put' function above should be removed

func (HashedUpdateBatch) ToCompositeKeyMap

func (h HashedUpdateBatch) ToCompositeKeyMap() map[HashedCompositeKey]*statedb.VersionedValue

ToCompositeKeyMap rearranges the update batch data in the form of a single map

type LevelDBTestEnv

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

LevelDBTestEnv implements TestEnv interface for leveldb based storage

func (*LevelDBTestEnv) Cleanup

func (env *LevelDBTestEnv) Cleanup()

Cleanup implements corresponding function from interface TestEnv

func (*LevelDBTestEnv) GetDBHandle

func (env *LevelDBTestEnv) GetDBHandle(id string) *DB

GetDBHandle implements corresponding function from interface TestEnv

func (*LevelDBTestEnv) GetName

func (env *LevelDBTestEnv) GetName() string

GetName implements corresponding function from interface TestEnv

func (*LevelDBTestEnv) GetProvider

func (env *LevelDBTestEnv) GetProvider() *DBProvider

GetProvider returns DBProvider

func (*LevelDBTestEnv) Init

func (env *LevelDBTestEnv) Init(t testing.TB)

Init implements corresponding function from interface TestEnv

func (*LevelDBTestEnv) StartExternalResource

func (env *LevelDBTestEnv) StartExternalResource()

StartExternalResource will be an empty implementation for levelDB test environment.

func (*LevelDBTestEnv) StopExternalResource

func (env *LevelDBTestEnv) StopExternalResource()

StopExternalResource will be an empty implementation for levelDB test environment.

type NsBatch

type NsBatch struct {
	*statedb.UpdateBatch
}

NsBatch contains updates related to one namespace

func (NsBatch) GetCollectionNames

func (nsb NsBatch) GetCollectionNames() []string

GetCollectionNames returns collections in the namespcae batch

func (NsBatch) GetCollectionUpdates

func (nsb NsBatch) GetCollectionUpdates(collName string) map[string]*statedb.VersionedValue

GetCollectionUpdates returns updates for a specific collection in the namespace batch

type PubUpdateBatch

type PubUpdateBatch struct {
	*statedb.UpdateBatch
}

PubUpdateBatch contains update for the public data

func NewPubUpdateBatch

func NewPubUpdateBatch() *PubUpdateBatch

NewPubUpdateBatch creates an empty PubUpdateBatch

type PvtKVWrite

type PvtKVWrite struct {
	Key      string
	IsDelete bool
	Value    []byte
	Version  *version.Height
}

PvtKVWrite encloses Key, IsDelete, Value, and Version components

type PvtUpdateBatch

type PvtUpdateBatch struct {
	UpdateMap
}

PvtUpdateBatch contains updates for the private data

func NewPvtUpdateBatch

func NewPvtUpdateBatch() *PvtUpdateBatch

NewPvtUpdateBatch creates an empty PvtUpdateBatch

func (PvtUpdateBatch) ToCompositeKeyMap

func (p PvtUpdateBatch) ToCompositeKeyMap() PvtdataCompositeKeyMap

ToCompositeKeyMap rearranges the update batch data in the form of a single map

type PvtdataCompositeKey

type PvtdataCompositeKey struct {
	Namespace      string
	CollectionName string
	Key            string
}

PvtdataCompositeKey encloses Namespace, CollectionName and Key components

type PvtdataCompositeKeyMap

type PvtdataCompositeKeyMap map[PvtdataCompositeKey]*statedb.VersionedValue

PvtdataCompositeKeyMap is a map of PvtdataCompositeKey to VersionedValue

type SnapshotPvtdataHashesConsumer

type SnapshotPvtdataHashesConsumer interface {
	ConsumeSnapshotData(namespace, coll string, keyHash []byte, valueHash []byte, version *version.Height) error
	Done() error
}

type SnapshotReader

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

SnapshotReader reads data from a pair of files (a data file and the corresponding metadata file)

func NewSnapshotReader

func NewSnapshotReader(dir, dataFileName, metadataFileName string) (*SnapshotReader, error)

func (*SnapshotReader) Close

func (r *SnapshotReader) Close()

func (*SnapshotReader) Next

func (r *SnapshotReader) Next() (string, *SnapshotRecord, error)

type SnapshotRecord

type SnapshotRecord struct {
	Key                  []byte   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value                []byte   `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	Metadata             []byte   `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"`
	Version              []byte   `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*SnapshotRecord) Descriptor

func (*SnapshotRecord) Descriptor() ([]byte, []int)

func (*SnapshotRecord) GetKey

func (m *SnapshotRecord) GetKey() []byte

func (*SnapshotRecord) GetMetadata

func (m *SnapshotRecord) GetMetadata() []byte

func (*SnapshotRecord) GetValue

func (m *SnapshotRecord) GetValue() []byte

func (*SnapshotRecord) GetVersion

func (m *SnapshotRecord) GetVersion() []byte

func (*SnapshotRecord) ProtoMessage

func (*SnapshotRecord) ProtoMessage()

func (*SnapshotRecord) Reset

func (m *SnapshotRecord) Reset()

func (*SnapshotRecord) String

func (m *SnapshotRecord) String() string

func (*SnapshotRecord) XXX_DiscardUnknown

func (m *SnapshotRecord) XXX_DiscardUnknown()

func (*SnapshotRecord) XXX_Marshal

func (m *SnapshotRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SnapshotRecord) XXX_Merge

func (m *SnapshotRecord) XXX_Merge(src proto.Message)

func (*SnapshotRecord) XXX_Size

func (m *SnapshotRecord) XXX_Size() int

func (*SnapshotRecord) XXX_Unmarshal

func (m *SnapshotRecord) XXX_Unmarshal(b []byte) error

type SnapshotWriter

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

SnapshotWriter generates two files, a data file and a metadata file. The datafile contains a series of tuples <key, dbValue> and the metadata file contains a series of tuples <namesapce, number-of-tuples-in-the-data-file-that-belong-to-this-namespace>

func NewSnapshotWriter

func NewSnapshotWriter(
	dir, dataFileName, metadataFileName string,
	newHash func() (hash.Hash, error),
) (*SnapshotWriter, error)

NewSnapshotWriter creates a new SnapshotWriter

func (*SnapshotWriter) AddData

func (w *SnapshotWriter) AddData(namespace string, snapshotRecord *SnapshotRecord) error

func (*SnapshotWriter) Close

func (w *SnapshotWriter) Close()

func (*SnapshotWriter) Done

func (w *SnapshotWriter) Done() ([]byte, []byte, error)

type StateDBConfig

type StateDBConfig struct {
	// ledger.StateDBConfig is used to configure the stateDB for the ledger.
	*ledger.StateDBConfig
	// LevelDBPath is the filesystem path when statedb type is "goleveldb".
	// It is internally computed by the ledger component,
	// so it is not in ledger.StateDBConfig and not exposed to other components.
	LevelDBPath string
}

StateDBConfig encapsulates the configuration for stateDB on the ledger.

type TestEnv

type TestEnv interface {
	StartExternalResource()
	Init(t testing.TB)
	GetDBHandle(id string) *DB
	GetProvider() *DBProvider
	GetName() string
	Cleanup()
	StopExternalResource()
}

TestEnv - an interface that a test environment implements

type UpdateBatch

type UpdateBatch struct {
	PubUpdates  *PubUpdateBatch
	HashUpdates *HashedUpdateBatch
	PvtUpdates  *PvtUpdateBatch
}

UpdateBatch encapsulates the updates to Public, Private, and Hashed data. This is expected to contain a consistent set of updates

func NewUpdateBatch

func NewUpdateBatch() *UpdateBatch

NewUpdateBatch creates and empty UpdateBatch

type UpdateMap

type UpdateMap map[string]NsBatch

UpdateMap maintains entries of tuple <Namespace, UpdatesForNamespace>

func (UpdateMap) Contains

func (b UpdateMap) Contains(ns, coll, key string) bool

Contains returns true if the given <ns,coll,key> tuple is present in the batch

func (UpdateMap) Delete

func (b UpdateMap) Delete(ns, coll, key string, version *version.Height)

Delete adds a delete marker in the batch for a given combination of namespace and collection name

func (UpdateMap) Get

func (b UpdateMap) Get(ns, coll, key string) *statedb.VersionedValue

Get retrieves the value from the batch for a given combination of namespace and collection name

func (UpdateMap) GetUpdatedNamespaces

func (b UpdateMap) GetUpdatedNamespaces() []string

GetUpdatedNamespaces returns the namespaces present in the UpdateMap

func (UpdateMap) IsEmpty

func (b UpdateMap) IsEmpty() bool

IsEmpty returns true if there exists any updates

func (UpdateMap) Put

func (b UpdateMap) Put(ns, coll, key string, value []byte, version *version.Height)

Put sets the value in the batch for a given combination of namespace and collection name

func (UpdateMap) PutValAndMetadata

func (b UpdateMap) PutValAndMetadata(ns, coll, key string, value []byte, metadata []byte, version *version.Height)

PutValAndMetadata adds a key with value and metadata

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