Documentation ¶
Index ¶
- func DefaultConfig() *stateConfig
- func NewStateConfig(vp *viper.Viper) (*stateConfig, error)
- type CompositeRangeScanIterator
- type State
- func (state *State) AddChangesForPersistence(blockNumber uint64, writeBatch *db.DBWriteBatch)
- func (state *State) ApplyStateDelta(delta *statemgmt.StateDelta)
- func (state *State) ApplyTxExec(exec *TxExecStates)
- func (state *State) ClearInMemoryChanges(changesPersisted bool)
- func (state *State) CommitStateDelta() error
- func (state *State) CopyState(sourceChaincodeID string, destChaincodeID string) error
- func (state *State) Delete(chaincodeID string, key string) error
- func (state *State) DeleteState() error
- func (state *State) FetchStateDeltaFromDB(blockNumber uint64) (*statemgmt.StateDelta, error)
- func (state *State) Get(chaincodeID string, key string, sn *db.DBSnapshot, _ int) ([]byte, error)
- func (state *State) GetHash() ([]byte, error)
- func (state *State) GetImpl() statemgmt.HashableState
- func (state *State) GetMaxStateDeltaSize() uint64
- func (state *State) GetRangeScanIterator(chaincodeID string, startKey string, endKey string, committed bool) (statemgmt.RangeScanIterator, error)
- func (state *State) GetSnapshot(blockNumber uint64, dbSnapshot *db.DBSnapshot) (*StateSnapshot, error)
- func (state *State) GetSnapshotManager() statemgmt.SnapshotState
- func (state *State) GetStateDelta() *statemgmt.StateDelta
- func (state *State) GetTransient(chaincodeID string, key string) ([]byte, error)
- func (state *State) GetTxStateDeltaHash() map[string][]byte
- func (state *State) MergeStateDelta(delta *statemgmt.StateDelta)
- func (state *State) Set(chaincodeID string, key string, value []byte) error
- func (state *State) SetMultipleKeys(chaincodeID string, kvs map[string][]byte) error
- func (state *State) TxBegin(txID string)
- func (state *State) TxFinish(txID string, txSuccessful bool)
- type StateConfig
- type StateSnapshot
- type TxExecStates
- func (s *TxExecStates) BindSnapshot(sn *db.DBSnapshot)
- func (s *TxExecStates) DeRef() *statemgmt.StateDelta
- func (s *TxExecStates) Delete(chaincodeID string, key string)
- func (s *TxExecStates) Get(chaincodeID string, key string, underlying statemgmt.HashableState) (ret []byte, err error)
- func (s *TxExecStates) GetRangeScanIterator(chaincodeID string, startKey string, endKey string, ...) (statemgmt.RangeScanIterator, error)
- func (s *TxExecStates) IsEmpty() bool
- func (s *TxExecStates) IsSnapshotRead() bool
- func (s *TxExecStates) RepairWSet(underlying statemgmt.HashableState) error
- func (s *TxExecStates) Set(chaincodeID string, key string, value []byte)
- func (s *TxExecStates) SetMultipleKeys(chaincodeID string, kvs map[string][]byte)
- func (s *TxExecStates) TxExecResultHash() []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfig ¶
func DefaultConfig() *stateConfig
func NewStateConfig ¶
Types ¶
type CompositeRangeScanIterator ¶
type CompositeRangeScanIterator struct {
// contains filtered or unexported fields
}
CompositeRangeScanIterator - an implementation of interface 'statemgmt.RangeScanIterator' This provides a wrapper on top of more than one underlying iterators
func (*CompositeRangeScanIterator) Close ¶
func (citr *CompositeRangeScanIterator) Close()
Close - see interface 'statemgmt.StateDeltaIterator' for details
func (*CompositeRangeScanIterator) GetKeyValue ¶
func (citr *CompositeRangeScanIterator) GetKeyValue() (string, []byte)
GetKeyValue - see interface 'statemgmt.StateDeltaIterator' for details
func (*CompositeRangeScanIterator) Next ¶
func (citr *CompositeRangeScanIterator) Next() bool
type State ¶
type State struct { //this three fields MUST be immutable in the life-time of a ledger //(even the db has been switched) *db.OpenchainDB // contains filtered or unexported fields }
State structure for maintaining world state. This encapsulates a particular implementation for managing the state persistence This is not thread safe
func CreateState ¶
func CreateState(db *db.OpenchainDB, config *stateConfig) *State
CreateState constructs a new State, but not initialize it
func NewState ¶
func NewState(db *db.OpenchainDB, config *stateConfig) *State
NewState constructs a new State. This Initializes encapsulated state implementation
func (*State) AddChangesForPersistence ¶
func (state *State) AddChangesForPersistence(blockNumber uint64, writeBatch *db.DBWriteBatch)
AddChangesForPersistence adds key-value pairs to writeBatch
func (*State) ApplyStateDelta ¶
func (state *State) ApplyStateDelta(delta *statemgmt.StateDelta)
ApplyStateDelta applies already prepared stateDelta to the existing state. This is an in memory change only. state.CommitStateDelta must be used to commit the state to the DB. This method is to be used in state transfer.
func (*State) ApplyTxExec ¶
func (state *State) ApplyTxExec(exec *TxExecStates)
func (*State) ClearInMemoryChanges ¶
ClearInMemoryChanges remove from memory all the changes to state
func (*State) CommitStateDelta ¶
CommitStateDelta commits the changes from state.ApplyStateDelta to the DB.
func (*State) CopyState ¶
CopyState copies all the key-values from sourceChaincodeID to destChaincodeID
func (*State) Delete ¶
Delete tracks the deletion of state for chaincodeID and key. Does not immediately writes to DB
func (*State) DeleteState ¶
DeleteState deletes ALL state keys/values from the DB. This is generally only used during state synchronization when creating a new state from a snapshot.
func (*State) FetchStateDeltaFromDB ¶
func (state *State) FetchStateDeltaFromDB(blockNumber uint64) (*statemgmt.StateDelta, error)
FetchStateDeltaFromDB fetches the StateDelta corrsponding to given blockNumber
func (*State) Get ¶
Get returns state for chaincodeID and key. If committed is false, this first looks in memory and if missing, pulls from db. If committed is true, this pulls from the db only.
func (*State) GetHash ¶
GetHash computes new state hash if the stateDelta is to be applied. Recomputes only if stateDelta has changed after most recent call to this function
func (*State) GetImpl ¶
func (state *State) GetImpl() statemgmt.HashableState
func (*State) GetMaxStateDeltaSize ¶
func (*State) GetRangeScanIterator ¶
func (state *State) GetRangeScanIterator(chaincodeID string, startKey string, endKey string, committed bool) (statemgmt.RangeScanIterator, error)
GetRangeScanIterator returns an iterator to get all the keys (and values) between startKey and endKey (assuming lexical order of the keys) for a chaincodeID.
func (*State) GetSnapshot ¶
func (state *State) GetSnapshot(blockNumber uint64, dbSnapshot *db.DBSnapshot) (*StateSnapshot, error)
GetSnapshot returns a snapshot of the global state for the current block. stateSnapshot.Release() must be called once you are done.
func (*State) GetSnapshotManager ¶
func (state *State) GetSnapshotManager() statemgmt.SnapshotState
func (*State) GetStateDelta ¶
func (state *State) GetStateDelta() *statemgmt.StateDelta
func (*State) GetTransient ¶
func (*State) GetTxStateDeltaHash ¶
the tx-related API which has been deprecated (use TxExecStates instead) GetTxStateDeltaHash return the hash of the StateDelta
func (*State) MergeStateDelta ¶
func (state *State) MergeStateDelta(delta *statemgmt.StateDelta)
similar to ApplyStateDelta but it merge, instead of change the state
func (*State) Set ¶
Set sets state to given value for chaincodeID and key. Does not immediately writes to DB
func (*State) SetMultipleKeys ¶
SetMultipleKeys sets the values for the multiple keys.
type StateConfig ¶
type StateConfig struct {
V *stateConfig
}
func (StateConfig) ImplConfigs ¶
func (cw StateConfig) ImplConfigs() map[string]interface{}
type StateSnapshot ¶
type StateSnapshot struct {
// contains filtered or unexported fields
}
StateSnapshot encapsulates StateSnapshotIterator given by actual state implementation and the db snapshot
func NewStateSnapshot ¶
func NewStateSnapshot(blockNumber uint64, itr statemgmt.StateSnapshotIterator, dbSnapshot *db.DBSnapshot) *StateSnapshot
func (*StateSnapshot) GetBlockNumber ¶
func (ss *StateSnapshot) GetBlockNumber() uint64
GetBlockNumber returns the blocknumber associated with this global state snapshot
func (*StateSnapshot) GetRawKeyValue ¶
func (ss *StateSnapshot) GetRawKeyValue() ([]byte, []byte)
GetRawKeyValue returns the raw bytes for the key and value at the current iterator position
func (*StateSnapshot) Next ¶
func (ss *StateSnapshot) Next() bool
Next moves the iterator to the next key/value pair in the state
func (*StateSnapshot) Release ¶
func (ss *StateSnapshot) Release()
Release the snapshot. This MUST be called when you are done with this resouce.
type TxExecStates ¶
type TxExecStates struct {
// contains filtered or unexported fields
}
supporting for the concurrent executation of tx the r/w in tx exec involve three sets: wset record all set/delete action rset trace all get action, so we can evaluate the whole cost to db for one tx, we also trace each key in the iteration op in tx. baseSets, which is an array, is also used for get operation
func NewExecStates ¶
func NewExecStates(baseSets ...*statemgmt.StateDelta) *TxExecStates
func NewExecStatesFromState ¶
func NewExecStatesFromState(s *State, morebaseSets ...*statemgmt.StateDelta) *TxExecStates
legacy API
func (*TxExecStates) BindSnapshot ¶
func (s *TxExecStates) BindSnapshot(sn *db.DBSnapshot)
caller MUST response for releasing the snapshot
func (*TxExecStates) DeRef ¶
func (s *TxExecStates) DeRef() *statemgmt.StateDelta
func (*TxExecStates) Delete ¶
func (s *TxExecStates) Delete(chaincodeID string, key string)
func (*TxExecStates) Get ¶
func (s *TxExecStates) Get(chaincodeID string, key string, underlying statemgmt.HashableState) (ret []byte, err error)
func (*TxExecStates) GetRangeScanIterator ¶
func (s *TxExecStates) GetRangeScanIterator(chaincodeID string, startKey string, endKey string, underlying statemgmt.HashableState) (statemgmt.RangeScanIterator, error)
GetRangeScanIterator returns an iterator to get all the keys (and values) between startKey and endKey (assuming lexical order of the keys) for a chaincodeID.
func (*TxExecStates) IsSnapshotRead ¶
func (s *TxExecStates) IsSnapshotRead() bool
func (*TxExecStates) RepairWSet ¶
func (s *TxExecStates) RepairWSet(underlying statemgmt.HashableState) error
TODO: cost of repairwset is not count yet
func (*TxExecStates) Set ¶
func (s *TxExecStates) Set(chaincodeID string, key string, value []byte)
we overwrite the set/delete methods with the fashion in state module: previous value is only searched from in-memory variables we availiable (i.e: rset/baseSets) base on the purpose that the most common op is write-after-read we can also repair the wset's previous value later if needed
func (*TxExecStates) SetMultipleKeys ¶
func (s *TxExecStates) SetMultipleKeys(chaincodeID string, kvs map[string][]byte)
SetMultipleKeys sets the values for the multiple keys.
func (*TxExecStates) TxExecResultHash ¶
func (s *TxExecStates) TxExecResultHash() []byte