state

package
v0.1.8-beta-hotfix Latest Latest
Warning

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

Go to latest
Published: May 26, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrNotASubTransaction

func ErrNotASubTransaction() errors.TMError

func IsNotASubTransactionErr

func IsNotASubTransactionErr(err error) bool

Types

type Bonsai

type Bonsai struct {
	Tree *iavl.VersionedTree
	// contains filtered or unexported fields
}

Bonsai is a deformed tree forced to fit in a small pot

func NewBonsai

func NewBonsai(tree *iavl.VersionedTree) *Bonsai

NewBonsai wraps a merkle tree and tags it to track children

func (*Bonsai) Checkpoint

func (b *Bonsai) Checkpoint() SimpleDB

func (*Bonsai) Commit

func (b *Bonsai) Commit(sub SimpleDB) error

func (*Bonsai) Discard

func (b *Bonsai) Discard()

Discard will remove reference to this

func (*Bonsai) First

func (b *Bonsai) First(start, end []byte) Model

func (*Bonsai) Get

func (b *Bonsai) Get(key []byte) []byte

Get matches the signature of KVStore

func (*Bonsai) GetVersioned

func (b *Bonsai) GetVersioned(key []byte, version int64) (int, []byte)

func (*Bonsai) GetVersionedWithProof

func (b *Bonsai) GetVersionedWithProof(key []byte, version int64) ([]byte, *iavl.RangeProof, error)

func (*Bonsai) GetWithProof

func (b *Bonsai) GetWithProof(key []byte) ([]byte, *iavl.RangeProof, error)

func (*Bonsai) Has

func (b *Bonsai) Has(key []byte) bool

Get matches the signature of KVStore

func (*Bonsai) Last

func (b *Bonsai) Last(start, end []byte) Model

func (*Bonsai) List

func (b *Bonsai) List(start, end []byte, limit int) []Model

func (*Bonsai) Remove

func (b *Bonsai) Remove(key []byte) (value []byte)

func (*Bonsai) Set

func (b *Bonsai) Set(key, value []byte)

Set matches the signature of KVStore

func (*Bonsai) String

func (b *Bonsai) String() string

type ChainState

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

chainState maintains general information for the chain

func NewChainState

func NewChainState() *ChainState

NewChainState creates a blank state

func (*ChainState) GetChainID

func (s *ChainState) GetChainID(store KVStore) string

GetChainID gets the chain id from the cache or the store

func (*ChainState) SetChainID

func (s *ChainState) SetChainID(store KVStore, chainID string)

SetChainID stores the chain id in the store

type KVStore

type KVStore interface {
	Set(key, value []byte)
	Get(key []byte) (value []byte)
}

KVStore is a simple interface to get/set data

type MemKVCache

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

MemKVCache is designed to wrap MemKVStore as a cache

func NewMemKVCache

func NewMemKVCache(store SimpleDB) *MemKVCache

NewMemKVCache wraps a cache around MemKVStore

You probably don't want to use directly, but rather via MemKVCache.Checkpoint()

func (*MemKVCache) Checkpoint

func (c *MemKVCache) Checkpoint() SimpleDB

Checkpoint returns the same state, but where writes are buffered and don't affect the parent

func (*MemKVCache) Commit

func (c *MemKVCache) Commit(sub SimpleDB) error

Commit will take all changes from the checkpoint and write them to the parent. Returns an error if this is not a child of this one

func (*MemKVCache) Discard

func (c *MemKVCache) Discard()

Discard will remove reference to this

func (*MemKVCache) First

func (c *MemKVCache) First(start, end []byte) Model

First is done with List, but could be much more efficient

func (*MemKVCache) Get

func (c *MemKVCache) Get(key []byte) (value []byte)

Get gets a key, fulfills KVStore interface

func (*MemKVCache) Has

func (c *MemKVCache) Has(key []byte) bool

Has checks existence of a key, fulfills KVStore interface

func (*MemKVCache) Last

func (c *MemKVCache) Last(start, end []byte) Model

Last is done with List, but could be much more efficient

func (*MemKVCache) List

func (c *MemKVCache) List(start, end []byte, limit int) []Model

List is also inefficiently implemented...

func (*MemKVCache) Remove

func (c *MemKVCache) Remove(key []byte) (value []byte)

Remove uses nil value as a flag to delete... not ideal but good enough for testing

func (*MemKVCache) Set

func (c *MemKVCache) Set(key []byte, value []byte)

Set sets a key, fulfills KVStore interface

type MemKVStore

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

MemKVStore is a simple implementation of SimpleDB. It is only intended for quick testing, not to be used in production or with large data stores.

func NewMemKVStore

func NewMemKVStore() *MemKVStore

NewMemKVStore initializes a MemKVStore

func (*MemKVStore) Checkpoint

func (m *MemKVStore) Checkpoint() SimpleDB

func (*MemKVStore) Commit

func (m *MemKVStore) Commit(sub SimpleDB) error

func (*MemKVStore) Discard

func (m *MemKVStore) Discard()

func (*MemKVStore) First

func (m *MemKVStore) First(start, end []byte) Model

First iterates through all keys to find the one that matches

func (*MemKVStore) Get

func (m *MemKVStore) Get(key []byte) (value []byte)

func (*MemKVStore) Has

func (m *MemKVStore) Has(key []byte) (has bool)

func (*MemKVStore) Last

func (m *MemKVStore) Last(start, end []byte) Model

func (*MemKVStore) List

func (m *MemKVStore) List(start, end []byte, limit int) []Model

func (*MemKVStore) Remove

func (m *MemKVStore) Remove(key []byte) (value []byte)

func (*MemKVStore) Set

func (m *MemKVStore) Set(key []byte, value []byte)

type Model

type Model struct {
	Key   []byte
	Value []byte
}

Model grabs together key and value to allow easier return values

type SimpleDB

type SimpleDB interface {
	KVStore

	Has(key []byte) (has bool)
	Remove(key []byte) (value []byte) // returns old value if there was one

	// Start is inclusive, End is exclusive...
	// Thus List ([]byte{12, 13}, []byte{12, 14}) will return anything with
	// the prefix []byte{12, 13}
	List(start, end []byte, limit int) []Model
	First(start, end []byte) Model
	Last(start, end []byte) Model

	// Checkpoint returns the same state, but where writes
	// are buffered and don't affect the parent
	Checkpoint() SimpleDB

	// Commit will take all changes from the checkpoint and write
	// them to the parent.
	// Returns an error if this is not a child of this one
	Commit(SimpleDB) error

	// Discard will remove reference to this
	Discard()
}

SimpleDB allows us to do some basic range queries on a db

type State

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

State represents the app states, separating the commited state (for queries) from the working state (for CheckTx and AppendTx)

func NewState

func NewState(tree *iavl.VersionedTree, historySize int64) *State

NewState wraps a versioned tree and maintains all needed states for the abci app

func (State) Append

func (s State) Append() SimpleDB

Append gives us read-write access to the current working state (to be committed at EndBlock)

func (State) Check

func (s State) Check() SimpleDB

Append gives us read-write access to the current scratch state (to be reset at EndBlock)

func (*State) Commit

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

Commit saves persistent nodes to the database and re-copies the trees

func (State) Committed

func (s State) Committed() *Bonsai

Committed gives us read-only access to the committed state(s), including historical queries

func (State) IsEmpty

func (s State) IsEmpty() bool

IsEmpty is true is no data was ever in the tree (and signals it is unsafe to save)

func (State) LatestHash

func (s State) LatestHash() []byte

LatestHash is the root hash of the last state we have committed

func (State) LatestHeight

func (s State) LatestHeight() int64

LatestHeight is the last block height we have committed

func (State) Size

func (s State) Size() int

Size is the number of nodes in the last commit

Jump to

Keyboard shortcuts

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