storage

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: Apache-2.0 Imports: 10 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"

	CHAINKEY_MAXLEN       = 20
	CHAINSTATE_CACHE_SIZE = 10000

	DB_PREFIX   = "_"
	DB_RANGEFIX = "~"
)

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 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

	sync.RWMutex
	// contains filtered or unexported fields
}

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) 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) GetIterator added in v0.12.0

func (state *ChainState) GetIterator() Iteratable

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) 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(recent, every, cycles int64)

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 Gas added in v0.12.0

type Gas int64
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
)

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
}

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 {
	Store
	GasCalculator
}

func NewGasStore added in v0.12.0

func NewGasStore(store Store, 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 Iteratable added in v0.12.0

type Iteratable 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 iteratable interface include the function for iteration Iteratable 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()

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) GetIterator added in v0.12.0

func (store KeyValue) GetIterator() Iteratable

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 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) GetIterator

func (session KeyValueSession) GetIterator() Iteratable

func (KeyValueSession) Iterate added in v0.12.0

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

GetIterator 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 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 SessionedStorage

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

	BeginSession() Session
	Close()
}

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) Commit added in v0.12.0

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

func (*State) ConsumeStorageGas added in v0.12.0

func (s *State) ConsumeStorageGas(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) 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) GetIterator added in v0.12.0

func (s *State) GetIterator() Iteratable

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) 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) 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)
	GetIterator() Iteratable
}

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