storage

package
v0.18.15 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

This file is for grabbing a leveldb instance without cleveldb support

Index

Constants

View Source
const (
	MEMORY StorageType = iota
	PERSISTENT

	CACHE         = "cache"
	CACHE_SAFE    = "cache_safe"
	KEYVALUE      = "keyvalue"
	SESSION_CACHE = "session_cache"

	CHAINKEY_MAXLEN       = 20
	CHAINSTATE_CACHE_SIZE = 10000

	DB_PREFIX   = "_"
	DB_RANGEFIX = "~"

	TOMBSTONE = "⛼"
)

Different types

View Source
const (
	OLDATA   = "OLDATA"
	NODEDATA = "nodedata"
)

Variables

View Source
var (
	ErrNotFound       = errors.New("key not found")
	ErrSetFailed      = errors.New("failed to set data")
	ErrExceedGasLimit = errors.New("gas exceeds limit")
)
View Source
var ErrNilData = errors.New("data is nil")

Functions

func GetDatabase added in v0.12.0

func GetDatabase(name, dbDir, configDB string) (db.DB, error)

func NewCache

func NewCache(name string) *cache

func NewCacheSafe

func NewCacheSafe(name string) *cacheSafe

func NewSessionCache added in v0.14.0

func NewSessionCache(name string) *sessionCache

func Prefix added in v0.12.0

func Prefix(prefix string) []byte

func Rangefix added in v0.12.0

func Rangefix(prefix string) []byte

Types

type ChainState

type ChainState struct {
	Name string

	Delivered *iavl.MutableTree // Build us a new set of transactions

	// Last committed values
	LastVersion int64
	Version     int64
	LastHash    []byte
	Hash        []byte
	TreeHeight  int8

	ChainStateRotation ChainStateRotationSetting

	sync.RWMutex
}

Chainstate is a storage for balances on the chain, a snapshot of all accounts

func NewChainState

func NewChainState(name string, db tmdb.DB) *ChainState

NewChainState generates a new ChainState object

func (*ChainState) ClearFrom added in v0.13.0

func (state *ChainState) ClearFrom(version int64) error

func (*ChainState) Commit

func (state *ChainState) Commit() ([]byte, int64)

TODO: Not sure about this, it seems to be Cosmos-sdk's way of getting arround the immutable copy problem...

func (*ChainState) Delete added in v0.12.0

func (state *ChainState) Delete(key StoreKey) (bool, error)

func (*ChainState) Exists

func (state *ChainState) Exists(key StoreKey) bool

TODO: Should be against the commit tree, not the delivered one!!!

func (*ChainState) FindAll

func (state *ChainState) FindAll() map[string][]byte

Expensive O(n) search through everything...

func (*ChainState) Get

func (state *ChainState) Get(key StoreKey) ([]byte, error)

TODO: Should be against the commit tree, not the delivered one!!!

func (*ChainState) GetIterable added in v0.14.0

func (state *ChainState) GetIterable() Iterable

func (*ChainState) GetLatestVersioned added in v0.12.0

func (state *ChainState) GetLatestVersioned(key StoreKey) (int64, []byte)

func (*ChainState) GetVersioned added in v0.12.0

func (state *ChainState) GetVersioned(version int64, key StoreKey) (int64, []byte)

func (*ChainState) Iterate added in v0.10.4

func (state *ChainState) Iterate(fn func(key []byte, value []byte) bool) (stopped bool)

func (*ChainState) IterateRange added in v0.12.0

func (state *ChainState) IterateRange(start, end []byte, ascending bool, fn func(key, value []byte) bool) (stop bool)

func (*ChainState) LoadVersion added in v0.14.0

func (state *ChainState) LoadVersion(version int64) (int64, error)

func (*ChainState) Set

func (state *ChainState) Set(key StoreKey, val []byte) error

Do this only for the Delivery side

func (*ChainState) SetupRotation added in v0.12.0

func (state *ChainState) SetupRotation(chainStateRotationCfg config.ChainStateRotationCfg) error

Setup the rotation configuration for ChainState, "recent" : latest number of version to persist "every" : every X number of version to persist "cycles" : number of latest every version to persist

type ChainStateRotationSetting added in v0.14.0

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

type Gas added in v0.12.0

type Gas int
const (
	STOREBYTES Gas = 20
	READFLAT   Gas = 20
	READBYTES  Gas = 2
	WRITEFLAT  Gas = 200
	WRITEBYTES Gas = 20
	VERIFYSIG  Gas = 5000
	HASHBYTES  Gas = 5
	CHECKEXIST Gas = 20
	DELETE     Gas = 50
	FLAT       Gas = 1
	CONTRACT   Gas = 1
)

type GasCalculator added in v0.12.0

type GasCalculator interface {
	// Consume amount of Gas for the Category
	Consume(amount, category Gas, allowOverflow bool) bool

	// Get the max amount of Gas the GasCalculator accept
	GetLimit() Gas

	// Get the current consumed Gas
	GetConsumed() Gas

	// Check if the block has fullfill the Gas Limit
	IsEnough() bool

	// GetLeft return total gas left, used right now in olvm (frankenstein update)
	GetLeft() uint64
}

Calculate the gas used for each action, will be embedded with GasStore.

func NewGasCalculator added in v0.12.0

func NewGasCalculator(limit Gas) GasCalculator

type GasStore added in v0.12.0

type GasStore struct {
	SessionedDirectStorage
	GasCalculator
}

func NewGasStore added in v0.12.0

func NewGasStore(store SessionedDirectStorage, gc GasCalculator) *GasStore

func (*GasStore) Delete added in v0.12.0

func (g *GasStore) Delete(key StoreKey) (bool, error)

func (*GasStore) Exists added in v0.12.0

func (g *GasStore) Exists(key StoreKey) bool

func (*GasStore) Get added in v0.12.0

func (g *GasStore) Get(key StoreKey) ([]byte, error)

func (*GasStore) Set added in v0.12.0

func (g *GasStore) Set(key StoreKey, value []byte) error

type IGasStore added in v0.18.15

type IGasStore interface {
	Set(key StoreKey, value []byte) error
	Get(key StoreKey) ([]byte, error)
	Exists(key StoreKey) bool
	Delete(key StoreKey) (bool, error)

	BeginSession() Session
	Close()
	DumpState()
	GetIterable() Iterable
}

type Iterable added in v0.14.0

type Iterable interface {
	Iterate(fn func(key, value []byte) bool) (stop bool)
	IterateRange(start, end []byte, ascending bool, fn func(key, value []byte) bool) (stop bool)
}

The Iterable interface include the function for iteration Iterable function only be implemented for persistent data, doesn't guaranteed in the cache storage

type KeyValue

type KeyValue struct {
	Type StorageType

	Name string
	File string

	sync.RWMutex
	// contains filtered or unexported fields
}
KeyValue begins here

KeyValue Wrap the underlying usage

func (KeyValue) BeginSession

func (store KeyValue) BeginSession() Session

BeginSession a new writable session

func (KeyValue) Close

func (store KeyValue) Close() error

Close the database

func (KeyValue) Delete added in v0.12.0

func (store KeyValue) Delete(StoreKey) (bool, error)

func (KeyValue) Dump

func (store KeyValue) Dump()

Dump out debugging information from the KeyValue datastore

func (KeyValue) Errors

func (store KeyValue) Errors() string

Print out the error details

func (KeyValue) Exists

func (store KeyValue) Exists(key StoreKey) (bool, error)

Test to see if a key exists

func (KeyValue) FindAll

func (store KeyValue) FindAll() []StoreKey

FindAll of the keys in the database

func (KeyValue) Get

func (store KeyValue) Get(key StoreKey) ([]byte, error)

Get a key from the database

func (KeyValue) GetIterable added in v0.14.0

func (store KeyValue) GetIterable() Iterable

func (KeyValue) Iterate

func (store KeyValue) Iterate(fn func(key []byte, value []byte) bool) (stopped bool)

func (KeyValue) Set added in v0.12.0

func (store KeyValue) Set(StoreKey, []byte) error

type KeyValueIterator added in v0.13.0

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

func (*KeyValueIterator) Iterate added in v0.13.0

func (kvi *KeyValueIterator) Iterate(fn func(key, value []byte) bool) (stop bool)

func (*KeyValueIterator) IterateRange added in v0.13.0

func (kvi *KeyValueIterator) IterateRange(start, end []byte, ascending bool, fn func(key, value []byte) bool) (stop bool)

type KeyValueSession

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

KeyValueSession begins here

func (KeyValueSession) Commit

func (session KeyValueSession) Commit() bool

Commit the changes to persistence

func (KeyValueSession) Delete

func (session KeyValueSession) Delete(key StoreKey) (bool, error)

Delete a key from the datastore

func (KeyValueSession) Dump

func (session KeyValueSession) Dump()

Dump out the contents of the database

func (KeyValueSession) Errors

func (session KeyValueSession) Errors() string

List out the errors

func (KeyValueSession) Exists

func (session KeyValueSession) Exists(key StoreKey) bool

Test to see if a key exists

func (KeyValueSession) FindAll

func (session KeyValueSession) FindAll() []StoreKey

Find all of the keys in the datastore

func (KeyValueSession) Get

func (session KeyValueSession) Get(key StoreKey) ([]byte, error)

Load return the stored value

func (KeyValueSession) GetIterable added in v0.14.0

func (session KeyValueSession) GetIterable() Iterable

func (KeyValueSession) Iterate added in v0.12.0

func (session KeyValueSession) Iterate(fn func(key []byte, value []byte) bool) (stopped bool)

GetIterable dummy iterator

func (KeyValueSession) IterateRange added in v0.12.0

func (session KeyValueSession) IterateRange(start, end []byte, ascending bool, fn func(key, value []byte) bool) (stop bool)

func (KeyValueSession) Rollback

func (session KeyValueSession) Rollback() bool

Rollback any changes since the last commit

func (KeyValueSession) Set

func (session KeyValueSession) Set(key StoreKey, dat []byte) error

Store inserts or updates a value under a key

type NoGasStore added in v0.18.15

type NoGasStore struct {
	SessionedDirectStorage
	GasCalculator
}

NoGasStore skip gas consume because EVM will calculate it and apply at fee processor

func NewNoGasStore added in v0.18.15

func NewNoGasStore(store SessionedDirectStorage) *NoGasStore

func (*NoGasStore) Delete added in v0.18.15

func (g *NoGasStore) Delete(key StoreKey) (bool, error)

func (*NoGasStore) Exists added in v0.18.15

func (g *NoGasStore) Exists(key StoreKey) bool

func (*NoGasStore) Get added in v0.18.15

func (g *NoGasStore) Get(key StoreKey) ([]byte, error)

func (*NoGasStore) Set added in v0.18.15

func (g *NoGasStore) Set(key StoreKey, value []byte) error

type Session

type Session interface {
	Store
	Commit() bool
}

Session defines a session-ed storage object of your choice

func NewKeyValueSession

func NewKeyValueSession(store *KeyValue) Session

Create a new session

type SessionedDirectStorage added in v0.14.0

type SessionedDirectStorage interface {
	Store

	BeginSession() Session
	Close()
	DumpState()
}

SessionedDirectStorage

func NewSessionedDirectStorage added in v0.14.0

func NewSessionedDirectStorage(flavor, name string) SessionedDirectStorage

NewSessionedDirectStorage initializes a non sessioned storage

type SessionedStorage

type SessionedStorage interface {
	Get(StoreKey) ([]byte, error)
	Exists(StoreKey) (bool, error)

	BeginSession() Session
	Close() error
}

SessionedStorage wraps objects with option to start a session(db transaction)

func NewStorageDB

func NewStorageDB(flavor, name string, DBDir, DBType string) SessionedStorage

NewStorageSession creates a new SessionStorage

type State added in v0.12.0

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

func NewState added in v0.12.0

func NewState(state *ChainState) *State

func (*State) BeginTxSession added in v0.14.0

func (s *State) BeginTxSession()

func (*State) Commit added in v0.12.0

func (s *State) Commit() (hash []byte, version int64)

func (*State) CommitTxSession added in v0.14.0

func (s *State) CommitTxSession()

func (*State) ConsumeContractGas added in v0.17.0

func (s *State) ConsumeContractGas(gas Gas) bool

func (*State) ConsumeStorageGas added in v0.12.0

func (s *State) ConsumeStorageGas(gas Gas) bool

func (*State) ConsumeUpfront added in v0.13.0

func (s *State) ConsumeUpfront(gas Gas) bool

func (*State) ConsumeVerifySigGas added in v0.12.0

func (s *State) ConsumeVerifySigGas(gas Gas) bool

func (*State) ConsumedGas added in v0.12.0

func (s *State) ConsumedGas() Gas

func (*State) Delete added in v0.12.0

func (s *State) Delete(key StoreKey) (bool, error)

func (*State) DiscardTxSession added in v0.14.0

func (s *State) DiscardTxSession()

func (*State) DumpState added in v0.18.15

func (s *State) DumpState()

func (*State) Exists added in v0.12.0

func (s *State) Exists(key StoreKey) bool

func (*State) Get added in v0.12.0

func (s *State) Get(key StoreKey) ([]byte, error)

func (*State) GetAtHeight added in v0.18.15

func (s *State) GetAtHeight(version int64, key StoreKey) ([]byte, error)

func (*State) GetCalculator added in v0.18.15

func (s *State) GetCalculator() GasCalculator

func (*State) GetGasStore added in v0.18.15

func (s *State) GetGasStore() IGasStore

func (*State) GetIterable added in v0.14.0

func (s *State) GetIterable() Iterable

This only Iterate for the ChainState

func (*State) GetPrevious added in v0.12.0

func (s *State) GetPrevious(num int64, key StoreKey) []byte

func (*State) GetVersioned added in v0.12.0

func (s *State) GetVersioned(version int64, key StoreKey) []byte

func (*State) Iterate added in v0.12.0

func (s *State) Iterate(fn func(key []byte, value []byte) bool) (stopped bool)

func (*State) IterateRange added in v0.12.0

func (s *State) IterateRange(start, end []byte, ascending bool, fn func(key, value []byte) bool) (stop bool)

func (*State) LoadVersion added in v0.14.0

func (s *State) LoadVersion(version int64) (int64, error)

func (State) RootHash added in v0.12.0

func (s State) RootHash() []byte

func (*State) Set added in v0.12.0

func (s *State) Set(key StoreKey, value []byte) error

func (State) Version added in v0.12.0

func (s State) Version() int64

func (*State) WithGas added in v0.12.0

func (s *State) WithGas(gc GasCalculator) *State

func (*State) WithGasStore added in v0.18.15

func (s *State) WithGasStore(gs IGasStore)

func (*State) WithoutGas added in v0.12.0

func (s *State) WithoutGas() *State

func (State) Write added in v0.12.0

func (s State) Write() bool

type StorageType

type StorageType int

ENUM for datastore type

type Store

type Store interface {
	Get(StoreKey) ([]byte, error)
	Set(StoreKey, []byte) error
	Exists(StoreKey) bool
	Delete(StoreKey) (bool, error)
	GetIterable() Iterable
}

store wraps object with option to use a cache type db

func NewStorage

func NewStorage(flavor, name string) Store

NewStorage initializes a non sessioned storage

type StoreKey

type StoreKey []byte

func (StoreKey) Bytes

func (sk StoreKey) Bytes() []byte

func (StoreKey) String

func (sk StoreKey) String() string

Jump to

Keyboard shortcuts

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