types

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GasIterNextCostFlatDesc = "IterNextFlat"
	GasValuePerByteDesc     = "ValuePerByte"
	GasWritePerByteDesc     = "WritePerByte"
	GasReadPerByteDesc      = "ReadPerByte"
	GasWriteCostFlatDesc    = "WriteFlat"
	GasReadCostFlatDesc     = "ReadFlat"
	GasHasDesc              = "Has"
	GasDeleteDesc           = "Delete"
)

Gas consumption descriptors.

Variables

View Source
var (
	// PruneEverything defines a pruning strategy where all committed states will
	// be deleted, persisting only the current state.
	PruneEverything = PruningOptions{
		KeepEvery:     1,
		SnapshotEvery: 0,
	}

	// PruneNothing defines a pruning strategy where all committed states will be
	// kept on disk, i.e. no states will be pruned.
	PruneNothing = PruningOptions{
		KeepEvery:     1,
		SnapshotEvery: 1,
	}

	// PruneSyncable defines a pruning strategy where only those states not needed
	// for state syncing will be pruned. It flushes every 100th state to disk and
	// keeps every 10000th.
	PruneSyncable = PruningOptions{
		KeepEvery:     100,
		SnapshotEvery: 10000,
	}
)

Functions

func AssertValidKey

func AssertValidKey(key []byte)

Check if the key is valid(key is not nil)

func AssertValidValue

func AssertValidValue(value []byte)

Check if the value is valid(value is not nil)

func Cp

func Cp(bz []byte) (ret []byte)

----------------------------------------

func DiffKVStores

func DiffKVStores(a KVStore, b KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []tmkv.Pair)

DiffKVStores compares two KVstores and returns all the key/value pairs that differ from one another. It also skips value comparison for a set of provided prefixes

func InclusiveEndBytes

func InclusiveEndBytes(inclusiveBytes []byte) []byte

InclusiveEndBytes returns the []byte that would end a range query such that the input would be included

func PrefixEndBytes

func PrefixEndBytes(prefix []byte) []byte

PrefixEndBytes returns the []byte that would end a range query for all []byte with a certain prefix Deals with last byte of prefix being FF without overflowing

Types

type CacheKVStore

type CacheKVStore interface {
	KVStore

	// Writes operations to underlying KVStore
	Write()
}

CacheKVStore cache-wraps a KVStore. After calling .Write() on the CacheKVStore, all previously created CacheKVStores on the object expire.

type CacheMultiStore

type CacheMultiStore interface {
	MultiStore
	Write() // Writes operations to underlying KVStore
}

From MultiStore.CacheMultiStore()....

type CacheWrap

type CacheWrap interface {
	// Write syncs with the underlying store.
	Write()

	// CacheWrap recursively wraps again.
	CacheWrap() CacheWrap

	// CacheWrapWithTrace recursively wraps again with tracing enabled.
	CacheWrapWithTrace(w io.Writer, tc TraceContext) CacheWrap
}

CacheWrap makes the most appropriate cache-wrap. For example, IAVLStore.CacheWrap() returns a CacheKVStore. CacheWrap should not return a Committer, since Commit cache-wraps make no sense. It can return KVStore, HeapStore, SpaceStore, etc.

type CacheWrapper

type CacheWrapper interface {
	// CacheWrap cache wraps.
	CacheWrap() CacheWrap

	// CacheWrapWithTrace cache wraps with tracing enabled.
	CacheWrapWithTrace(w io.Writer, tc TraceContext) CacheWrap
}

type CommitID

type CommitID struct {
	Version int64
	Hash    []byte
}

CommitID contains the tree version number and its merkle root.

func (CommitID) IsZero

func (cid CommitID) IsZero() bool

func (CommitID) String

func (cid CommitID) String() string

type CommitKVStore

type CommitKVStore interface {
	Committer
	KVStore
}

Stores of MultiStore must implement CommitStore.

type CommitMultiStore

type CommitMultiStore interface {
	Committer
	MultiStore

	// Mount a store of type using the given db.
	// If db == nil, the new store will use the CommitMultiStore db.
	MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB)

	// Panics on a nil key.
	GetCommitStore(key StoreKey) CommitStore

	// Panics on a nil key.
	GetCommitKVStore(key StoreKey) CommitKVStore

	// Load the latest persisted version. Called once after all calls to
	// Mount*Store() are complete.
	LoadLatestVersion() error

	// LoadLatestVersionAndUpgrade will load the latest version, but also
	// rename/delete/create sub-store keys, before registering all the keys
	// in order to handle breaking formats in migrations
	LoadLatestVersionAndUpgrade(upgrades *StoreUpgrades) error

	// LoadVersionAndUpgrade will load the named version, but also
	// rename/delete/create sub-store keys, before registering all the keys
	// in order to handle breaking formats in migrations
	LoadVersionAndUpgrade(ver int64, upgrades *StoreUpgrades) error

	// Load a specific persisted version. When you load an old version, or when
	// the last commit attempt didn't complete, the next commit after loading
	// must be idempotent (return the same commit id). Otherwise the behavior is
	// undefined.
	LoadVersion(ver int64) error

	// Set an inter-block (persistent) cache that maintains a mapping from
	// StoreKeys to CommitKVStores.
	SetInterBlockCache(MultiStorePersistentCache)
}

A non-cache MultiStore.

type CommitStore

type CommitStore interface {
	Committer
	Store
}

Stores of MultiStore must implement CommitStore.

type Committer

type Committer interface {
	Commit() CommitID
	LastCommitID() CommitID
	SetPruning(PruningOptions)
}

something that can persist to disk

type ErrorGasOverflow

type ErrorGasOverflow struct {
	Descriptor string
}

ErrorGasOverflow defines an error thrown when an action results gas consumption unsigned integer overflow.

type ErrorOutOfGas

type ErrorOutOfGas struct {
	Descriptor string
}

ErrorOutOfGas defines an error thrown when an action results in out of gas.

type Gas

type Gas = uint64

Gas measured by the SDK

type GasConfig

type GasConfig struct {
	HasCost          Gas
	DeleteCost       Gas
	ReadCostFlat     Gas
	ReadCostPerByte  Gas
	WriteCostFlat    Gas
	WriteCostPerByte Gas
	IterNextCostFlat Gas
}

GasConfig defines gas cost for each operation on KVStores

func KVGasConfig

func KVGasConfig() GasConfig

KVGasConfig returns a default gas config for KVStores.

func TransientGasConfig

func TransientGasConfig() GasConfig

TransientGasConfig returns a default gas config for TransientStores.

type GasMeter

type GasMeter interface {
	GasConsumed() Gas
	GasConsumedToLimit() Gas
	Limit() Gas
	ConsumeGas(amount Gas, descriptor string)
	IsPastLimit() bool
	IsOutOfGas() bool
}

GasMeter interface to track gas consumption

func NewGasMeter

func NewGasMeter(limit Gas) GasMeter

NewGasMeter returns a reference to a new basicGasMeter.

func NewInfiniteGasMeter

func NewInfiniteGasMeter() GasMeter

NewInfiniteGasMeter returns a reference to a new infiniteGasMeter.

type Iterator

type Iterator = dbm.Iterator

Alias iterator to db's Iterator for convenience.

func KVStorePrefixIterator

func KVStorePrefixIterator(kvs KVStore, prefix []byte) Iterator

Iterator over all the keys with a certain prefix in ascending order

func KVStorePrefixIteratorPaginated

func KVStorePrefixIteratorPaginated(kvs KVStore, prefix []byte, page, limit uint) Iterator

KVStorePrefixIteratorPaginated returns iterator over items in the selected page. Items iterated and skipped in ascending order.

func KVStoreReversePrefixIterator

func KVStoreReversePrefixIterator(kvs KVStore, prefix []byte) Iterator

Iterator over all the keys with a certain prefix in descending order.

func KVStoreReversePrefixIteratorPaginated

func KVStoreReversePrefixIteratorPaginated(kvs KVStore, prefix []byte, page, limit uint) Iterator

KVStoreReversePrefixIteratorPaginated returns iterator over items in the selected page. Items iterated and skipped in descending order.

type KVPair

type KVPair tmkv.Pair

key-value result for iterator queries

type KVStore

type KVStore interface {
	Store

	// Get returns nil iff key doesn't exist. Panics on nil key.
	Get(key []byte) []byte

	// Has checks if a key exists. Panics on nil key.
	Has(key []byte) bool

	// Set sets the key. Panics on nil key or value.
	Set(key, value []byte)

	// Delete deletes the key. Panics on nil key.
	Delete(key []byte)

	// Iterator over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// To iterate over entire domain, use store.Iterator(nil, nil)
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	// Exceptionally allowed for cachekv.Store, safe to write in the modules.
	Iterator(start, end []byte) Iterator

	// Iterator over a domain of keys in descending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	// Exceptionally allowed for cachekv.Store, safe to write in the modules.
	ReverseIterator(start, end []byte) Iterator
}

KVStore is a simple interface to get/set data

type KVStoreKey

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

KVStoreKey is used for accessing substores. Only the pointer value should ever be used - it functions as a capabilities key.

func NewKVStoreKey

func NewKVStoreKey(name string) *KVStoreKey

NewKVStoreKey returns a new pointer to a KVStoreKey. Use a pointer so keys don't collide.

func (*KVStoreKey) Name

func (key *KVStoreKey) Name() string

func (*KVStoreKey) String

func (key *KVStoreKey) String() string

type MultiStore

type MultiStore interface {
	Store

	// Cache wrap MultiStore.
	// NOTE: Caller should probably not call .Write() on each, but
	// call CacheMultiStore.Write().
	CacheMultiStore() CacheMultiStore

	// CacheMultiStoreWithVersion cache-wraps the underlying MultiStore where
	// each stored is loaded at a specific version (height).
	CacheMultiStoreWithVersion(version int64) (CacheMultiStore, error)

	// Convenience for fetching substores.
	// If the store does not exist, panics.
	GetStore(StoreKey) Store
	GetKVStore(StoreKey) KVStore

	// TracingEnabled returns if tracing is enabled for the MultiStore.
	TracingEnabled() bool

	// SetTracer sets the tracer for the MultiStore that the underlying
	// stores will utilize to trace operations. The modified MultiStore is
	// returned.
	SetTracer(w io.Writer) MultiStore

	// SetTracingContext sets the tracing context for a MultiStore. It is
	// implied that the caller should update the context when necessary between
	// tracing operations. The modified MultiStore is returned.
	SetTracingContext(TraceContext) MultiStore
}

type MultiStorePersistentCache

type MultiStorePersistentCache interface {
	// Wrap and return the provided CommitKVStore with an inter-block (persistent)
	// cache.
	GetStoreCache(key StoreKey, store CommitKVStore) CommitKVStore

	// Return the underlying CommitKVStore for a StoreKey.
	Unwrap(key StoreKey) CommitKVStore

	// Reset the entire set of internal caches.
	Reset()
}

MultiStorePersistentCache defines an interface which provides inter-block (persistent) caching capabilities for multiple CommitKVStores based on StoreKeys.

type PaginatedIterator

type PaginatedIterator struct {
	Iterator
	// contains filtered or unexported fields
}

PaginatedIterator is a wrapper around Iterator that iterates over values starting for given page and limit.

func (*PaginatedIterator) Next

func (pi *PaginatedIterator) Next()

Next will panic after limit is reached.

func (*PaginatedIterator) Valid

func (pi *PaginatedIterator) Valid() bool

Valid if below limit and underlying iterator is valid.

type PruningOptions

type PruningOptions struct {
	KeepEvery     int64
	SnapshotEvery int64
}

PruningOptions defines the specific pruning strategy every store in a multi-store will use when committing state, where keepEvery determines which committed heights are flushed to disk and snapshotEvery determines which of these heights are kept after pruning.

func (PruningOptions) FlushVersion

func (po PruningOptions) FlushVersion(ver int64) bool

FlushVersion returns a boolean signaling if the provided version/height should be flushed to disk.

func (PruningOptions) IsValid

func (po PruningOptions) IsValid() bool

IsValid verifies if the pruning options are valid. It returns false if invalid and true otherwise. Pruning options are considered valid iff:

- KeepEvery > 0 - SnapshotEvery >= 0 - SnapshotEvery % KeepEvery = 0

func (PruningOptions) SnapshotVersion

func (po PruningOptions) SnapshotVersion(ver int64) bool

SnapshotVersion returns a boolean signaling if the provided version/height should be snapshotted (kept on disk).

type Queryable

type Queryable interface {
	Query(abci.RequestQuery) abci.ResponseQuery
}

Queryable allows a Store to expose internal state to the abci.Query interface. Multistore can route requests to the proper Store.

This is an optional, but useful extension to any CommitStore

type Store

type Store interface {
	GetStoreType() StoreType
	CacheWrapper
}

type StoreKey

type StoreKey interface {
	Name() string
	String() string
}

StoreKey is a key used to index stores in a MultiStore.

type StoreRename

type StoreRename struct {
	OldKey string `json:"old_key"`
	NewKey string `json:"new_key"`
}

StoreRename defines a name change of a sub-store. All data previously under a PrefixStore with OldKey will be copied to a PrefixStore with NewKey, then deleted from OldKey store.

type StoreType

type StoreType int

kind of store

const (
	//nolint
	StoreTypeMulti StoreType = iota
	StoreTypeDB
	StoreTypeIAVL
	StoreTypeTransient
)

type StoreUpgrades

type StoreUpgrades struct {
	Renamed []StoreRename `json:"renamed"`
	Deleted []string      `json:"deleted"`
}

StoreUpgrades defines a series of transformations to apply the multistore db upon load

func (*StoreUpgrades) IsDeleted

func (s *StoreUpgrades) IsDeleted(key string) bool

IsDeleted returns true if the given key should be deleted

func (*StoreUpgrades) RenamedFrom

func (s *StoreUpgrades) RenamedFrom(key string) string

RenamedFrom returns the oldKey if it was renamed Returns "" if it was not renamed

type TraceContext

type TraceContext map[string]interface{}

TraceContext contains TraceKVStore context data. It will be written with every trace operation.

type TransientStoreKey

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

TransientStoreKey is used for indexing transient stores in a MultiStore

func NewTransientStoreKey

func NewTransientStoreKey(name string) *TransientStoreKey

Constructs new TransientStoreKey Must return a pointer according to the ocap principle

func (*TransientStoreKey) Name

func (key *TransientStoreKey) Name() string

Implements StoreKey

func (*TransientStoreKey) String

func (key *TransientStoreKey) String() string

Implements StoreKey

Jump to

Keyboard shortcuts

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