statecache

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBlockTxnCaches

func NewBlockTxnCaches(sc *StateCache, b Block) (*BlockCache, *TransactionCache)

NewBlockTxnCaches creates a new block cache and a transaction cache for the given block

Types

type Block

type Block struct {
	Round    int64  // round number when this block cache is created
	Hash     string // block hash
	PrevHash string // previous hash of the block
}

type BlockCache

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

BlockCache is a pre commit cache for all changes in a block. This is mainly for caching values in current block when executing blocks.

Call `Commit()` method to merge the changes to the StateCache when the block is executed.

func NewBlockCache

func NewBlockCache(main *StateCache, b Block) *BlockCache

func (*BlockCache) Commit

func (pcc *BlockCache) Commit()

Commit moves the values from the pre-commit cache to the main cache

func (*BlockCache) Get

func (pcc *BlockCache) Get(key string) (Value, bool)

Get returns the value with the given key

func (*BlockCache) Round

func (pcc *BlockCache) Round() int64

func (*BlockCache) Set

func (pcc *BlockCache) Set(key string, e Value)

Set sets the value with the given key in the pre-commit cache

func (*BlockCache) SetBlockHash

func (pcc *BlockCache) SetBlockHash(hash string)

SetBlockHash sets the block hash, which is used after miners generating the block. miners generator does not know the block hash until the block is generated.

func (*BlockCache) Stats

func (pcc *BlockCache) Stats() (hit, miss int64)

type BlockCacher

type BlockCacher interface {
	Get(key string) (Value, bool)
	Round() int64
	Commit()
	// contains filtered or unexported methods
}

type Copyer

type Copyer interface {
	// CopyFrom copies the value from the given value, returns false if not able to copy
	CopyFrom(v interface{}) bool
}

func Copyable

func Copyable(v interface{}) (Copyer, bool)

Copyable checks if the given value is able to be copied

type EmptyValue

type EmptyValue struct{}

func (*EmptyValue) Clone

func (e *EmptyValue) Clone() Value

func (*EmptyValue) CopyFrom

func (e *EmptyValue) CopyFrom(interface{}) bool

type QueryBlockCache

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

QueryBlockCache is a read-only cache for querying values from the current block.

func NewQueryBlockCache

func NewQueryBlockCache(sc *StateCache, blockHash string) *QueryBlockCache

NewQueryBlockCache creates a new QueryBlockCache instance.

func (*QueryBlockCache) Commit

func (qbc *QueryBlockCache) Commit()

func (*QueryBlockCache) Get

func (qbc *QueryBlockCache) Get(key string) (Value, bool)

Get returns the value with the given key from the current block cache.

func (*QueryBlockCache) Round

func (qbc *QueryBlockCache) Round() int64

type StateCache

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

func NewStateCache

func NewStateCache() *StateCache

func (*StateCache) Get

func (sc *StateCache) Get(key, blockHash string) (Value, bool)

Get returns the value with the given key and block hash

func (*StateCache) Remove

func (sc *StateCache) Remove(key string)

Remove removes the values map with the given key

func (*StateCache) Stats

func (sc *StateCache) Stats() (hits int64, miss int64)

type String

type String string

func (String) Clone

func (se String) Clone() Value

func (String) CopyFrom

func (set String) CopyFrom(v interface{}) bool

type TransactionCache

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

func NewEmpty

func NewEmpty() *TransactionCache

NewEmpty creates a new empty transaction cache

func NewTransactionCache

func NewTransactionCache(main BlockCacher) *TransactionCache

func (*TransactionCache) AddHit

func (tc *TransactionCache) AddHit()

func (*TransactionCache) AddMiss

func (tc *TransactionCache) AddMiss()

func (*TransactionCache) Commit

func (tc *TransactionCache) Commit()

func (*TransactionCache) Get

func (tc *TransactionCache) Get(key string) (Value, bool)

func (*TransactionCache) Remove

func (tc *TransactionCache) Remove(key string)

func (*TransactionCache) Set

func (tc *TransactionCache) Set(key string, e Value)

func (*TransactionCache) Stats

func (tc *TransactionCache) Stats() (hit, miss int64)

type Value

type Value interface {
	Clone() Value
	CopyFrom(v interface{}) bool
}

Value is an interface that all values in the state cache must implement

func Cacheable

func Cacheable(v interface{}) (Value, bool)

Cacheable checks if the given value is able to be cached

Jump to

Keyboard shortcuts

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