rwsetutil

package
v0.0.0-...-b544036 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsKVWriteDelete

func IsKVWriteDelete(kvWrite *kvrwset.KVWrite) bool

IsKVWriteDelete returns true if the kvWrite indicates a delete operation. See FAB-18386 for details.

func IsKVWriteHashDelete

func IsKVWriteHashDelete(kvWriteHash *kvrwset.KVWriteHash) bool

IsKVWriteHashDelete returns true if the kvWriteHash indicates a delete operation. See FAB-18386 for details.

func NewKVRead

func NewKVRead(key string, version *version.Height) *kvrwset.KVRead

NewKVRead helps constructing proto message kvrwset.KVRead

func NewVersion

func NewVersion(protoVersion *kvrwset.Version) *version.Height

NewVersion helps converting proto message kvrwset.Version to version.Height

func SetMerkelSummary

func SetMerkelSummary(rqi *kvrwset.RangeQueryInfo, merkleSummary *kvrwset.QueryReadsMerkleSummary)

SetMerkelSummary sets the 'readsInfo' field to merkle summary of the raw KVReads of query results

func SetRawReads

func SetRawReads(rqi *kvrwset.RangeQueryInfo, kvReads []*kvrwset.KVRead)

SetRawReads sets the 'readsInfo' field to raw KVReads performed by the query

Types

type CollHashedRwSet

type CollHashedRwSet struct {
	CollectionName string
	HashedRwSet    *kvrwset.HashedRWSet
	PvtRwSetHash   []byte
}

CollHashedRwSet encapsulates 'kvrwset.HashedRWSet' proto message for a specific collection

type CollPvtRwSet

type CollPvtRwSet struct {
	CollectionName string
	KvRwSet        *kvrwset.KVRWSet
}

CollPvtRwSet encapsulates 'kvrwset.KVRWSet' proto message for a private rwset for a specific collection KvRwSet in a private RwSet should not contain range query info

type Hash

type Hash []byte

Hash represents bytes of a hash

type HashFunc

type HashFunc func(data []byte) (hashsum []byte, err error)

HashFunc - the function signature for the hash function that is used in building and validating the merkle tree in the rwset, for the range query results

type MerkleTreeLevel

type MerkleTreeLevel uint32

MerkleTreeLevel used for representing a level of the merkle tree

type NsPvtRwSet

type NsPvtRwSet struct {
	NameSpace     string
	CollPvtRwSets []*CollPvtRwSet
}

NsPvtRwSet represents 'rwset.NsPvtReadWriteSet' proto message

type NsRwSet

type NsRwSet struct {
	NameSpace        string
	KvRwSet          *kvrwset.KVRWSet
	CollHashedRwSets []*CollHashedRwSet
}

NsRwSet encapsulates 'kvrwset.KVRWSet' proto message for a specific name space (chaincode)

type RWSetBuilder

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

RWSetBuilder helps building the read-write set

func NewRWSetBuilder

func NewRWSetBuilder() *RWSetBuilder

NewRWSetBuilder constructs a new instance of RWSetBuilder

func (*RWSetBuilder) AddToHashedMetadataWriteSet

func (b *RWSetBuilder) AddToHashedMetadataWriteSet(ns, coll, key string, metadata map[string][]byte)

AddToHashedMetadataWriteSet adds a metadata to a key in the hashed write-set

func (*RWSetBuilder) AddToHashedReadSet

func (b *RWSetBuilder) AddToHashedReadSet(ns string, coll string, key string, version *version.Height)

AddToHashedReadSet adds a key and corresponding version to the hashed read-set

func (*RWSetBuilder) AddToMetadataWriteSet

func (b *RWSetBuilder) AddToMetadataWriteSet(ns, key string, metadata map[string][]byte)

AddToMetadataWriteSet adds a metadata to a key in the write-set A nil/empty-map for 'metadata' parameter indicates the delete of the metadata

func (*RWSetBuilder) AddToPvtAndHashedWriteSet

func (b *RWSetBuilder) AddToPvtAndHashedWriteSet(ns string, coll string, key string, value []byte)

AddToPvtAndHashedWriteSet adds a key and value to the private and hashed write-set

func (*RWSetBuilder) AddToRangeQuerySet

func (b *RWSetBuilder) AddToRangeQuerySet(ns string, rqi *kvrwset.RangeQueryInfo)

AddToRangeQuerySet adds a range query info for performing phantom read validation

func (*RWSetBuilder) AddToReadSet

func (b *RWSetBuilder) AddToReadSet(ns string, key string, version *version.Height)

AddToReadSet adds a key and corresponding version to the read-set

func (*RWSetBuilder) AddToWriteSet

func (b *RWSetBuilder) AddToWriteSet(ns string, key string, value []byte)

AddToWriteSet adds a key and value to the write-set

func (*RWSetBuilder) GetTxReadWriteSet

func (b *RWSetBuilder) GetTxReadWriteSet() *TxRwSet

GetTxReadWriteSet returns the read-write set TODO make this function private once txmgr starts using new function `GetTxSimulationResults` introduced here

func (*RWSetBuilder) GetTxSimulationResults

func (b *RWSetBuilder) GetTxSimulationResults() (*ledger.TxSimulationResults, error)

GetTxSimulationResults returns the proto bytes of public rwset (public data + hashes of private data) and the private rwset for the transaction

type RangeQueryResultsHelper

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

RangeQueryResultsHelper helps preparing range query results for phantom items detection during validation. The results are expected to be fed as they are being iterated over. If the `hashingEnabled` is set to true, a merkle tree is built of the hashes over the results. The merkle tree helps reducing the size of the RWSet which otherwise would need to store all the raw KVReads

The mental model of the tree can be described as below: All the results are treated as leaf nodes (level 0) of the tree. Next up level of the tree is built by collecting 'maxDegree + 1' items from the previous level and hashing the entire collection. Further upper levels of the tree are built in similar manner however the only difference is that unlike level-0 (where collection consists of raw KVReads), collection at level 1 and above, consists of the hashes (of the collection of previous level). This is repeated until we reach at a level where we are left with the number of items less than or equals to `maxDegree`. In the last collection, the number of items can be less than 'maxDegree' (except if this is the only collection at the given level).

As a result, if the number of total input results are less than or equals to 'maxDegree', no hashing is performed at all. And the final output of the computation is either the collection of raw results (if less that or equals to 'maxDegree') or a collection of hashes (that or equals to 'maxDegree') at some level in the tree.

`AddResult` function should be invoke to supply the next result and at the end `Done` function should be invoked. The `Done` function does the final processing and returns the final output

func NewRangeQueryResultsHelper

func NewRangeQueryResultsHelper(enableHashing bool, maxDegree uint32, hashFunc HashFunc) (*RangeQueryResultsHelper, error)

NewRangeQueryResultsHelper constructs a RangeQueryResultsHelper

func (*RangeQueryResultsHelper) AddResult

func (helper *RangeQueryResultsHelper) AddResult(kvRead *kvrwset.KVRead) error

AddResult adds a new query result for processing. Put the result into the list of pending results. If the number of pending results exceeds `maxDegree`, consume the results for incrementally update the merkle tree

func (*RangeQueryResultsHelper) Done

Done processes any pending results if needed This returns the final pending results (i.e., []*KVRead) and hashes of the results (i.e., *MerkleSummary) Only one of these two will be non-nil (except when no results are ever added). `MerkleSummary` will be nil if and only if either `enableHashing` is set to false or the number of total results are less than `maxDegree`

func (*RangeQueryResultsHelper) GetMerkleSummary

func (helper *RangeQueryResultsHelper) GetMerkleSummary() *kvrwset.QueryReadsMerkleSummary

GetMerkleSummary return the current state of the MerkleSummary This intermediate state of the merkle tree helps during validation to detect a mismatch early on. That helps by not requiring to build the complete merkle tree during validation if there is a mismatch in early portion of the result-set.

type TxPvtRwSet

type TxPvtRwSet struct {
	NsPvtRwSet []*NsPvtRwSet
}

TxPvtRwSet represents 'rwset.TxPvtReadWriteSet' proto message

func TxPvtRwSetFromProtoMsg

func TxPvtRwSetFromProtoMsg(protoMsg *rwset.TxPvtReadWriteSet) (*TxPvtRwSet, error)

TxPvtRwSetFromProtoMsg transforms the proto message into a struct for ease of use

func (*TxPvtRwSet) FromProtoBytes

func (txPvtRwSet *TxPvtRwSet) FromProtoBytes(protoBytes []byte) error

FromProtoBytes deserializes protobytes into 'TxPvtReadWriteSet' proto message and populates 'TxPvtRwSet'

func (*TxPvtRwSet) ToProtoBytes

func (txPvtRwSet *TxPvtRwSet) ToProtoBytes() ([]byte, error)

ToProtoBytes constructs 'TxPvtReadWriteSet' proto message and serializes using protobuf Marshal

func (*TxPvtRwSet) ToProtoMsg

func (txPvtRwSet *TxPvtRwSet) ToProtoMsg() (*rwset.TxPvtReadWriteSet, error)

ToToProtoMsg transforms the struct into equivalent proto message

type TxRwSet

type TxRwSet struct {
	NsRwSets []*NsRwSet
}

TxRwSet acts as a proxy of 'rwset.TxReadWriteSet' proto message and helps constructing Read-write set specifically for KV data model

func TxRwSetFromProtoMsg

func TxRwSetFromProtoMsg(protoMsg *rwset.TxReadWriteSet) (*TxRwSet, error)

TxRwSetFromProtoMsg transforms the proto message into a struct for ease of use

func (*TxRwSet) FromProtoBytes

func (txRwSet *TxRwSet) FromProtoBytes(protoBytes []byte) error

FromProtoBytes deserializes protobytes into TxReadWriteSet proto message and populates 'TxRwSet'

func (*TxRwSet) GetPvtDataHash

func (txRwSet *TxRwSet) GetPvtDataHash(ns, coll string) []byte

GetPvtDataHash returns the PvtRwSetHash for a given namespace and collection

func (*TxRwSet) NumCollections

func (txRwSet *TxRwSet) NumCollections() int

NumCollections returns the number of collections present in the TxRwSet

func (*TxRwSet) ToProtoBytes

func (txRwSet *TxRwSet) ToProtoBytes() ([]byte, error)

ToProtoBytes constructs TxReadWriteSet proto message and serializes using protobuf Marshal

Jump to

Keyboard shortcuts

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