shards

package
v0.0.0-...-215623d Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModifiedFlag    uint16 = 1 // Set when the item is different seek what is last committed to the database
	AbsentFlag      uint16 = 2 // Set when the item is absent in the state
	DeletedFlag     uint16 = 4 // Set when the item is marked for deletion, even though it might have the value in it
	UnprocessedFlag uint16 = 8 // Set when there is a modification in the item that invalidates merkle root calculated previously
)

Variables

View Source
var (
	AccRead       = metrics.NewRegisteredCounter("cache/acc_read/total", nil)
	AccReadHit    = metrics.NewRegisteredCounter("cache/acc_read/hits", nil)
	StRead        = metrics.NewRegisteredCounter("cache/st_read/total", nil)
	StReadHit     = metrics.NewRegisteredCounter("cache/st_read/hits", nil)
	WritesRead    = metrics.NewRegisteredCounter("cache/writes/total", nil)
	WritesReadHit = metrics.NewRegisteredCounter("cache/writes/hits", nil)
)

Metrics

Functions

func WalkAccountHashesWrites

func WalkAccountHashesWrites(writes [5]*btree.BTree, update func(prefix []byte, hasState, hasTree, hasHash uint16, h []common.Hash), del func(prefix []byte, hasState, hasTree, hasHash uint16, h []common.Hash))

func WalkStorageHashesWrites

func WalkStorageHashesWrites(writes [5]*btree.BTree, update func(addrHash common.Hash, incarnation uint64, locHashPrefix []byte, hasState, hasTree, hasHash uint16, h []common.Hash), del func(addrHash common.Hash, incarnation uint64, locHashPrefix []byte, hasStat, hasTree, hasHash uint16, h []common.Hash))

func WalkWrites

func WalkWrites(
	writes [5]*btree.BTree,
	accountWrite func(address []byte, account *accounts.Account) error,
	accountDelete func(address []byte, original *accounts.Account) error,
	storageWrite func(address []byte, incarnation uint64, location []byte, value []byte) error,
	storageDelete func(address []byte, incarnation uint64, location []byte) error,
	codeWrite func(address []byte, incarnation uint64, code []byte) error,
	codeDelete func(address []byte, incarnation uint64) error,
) error

Types

type AccountHashItem

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

func (*AccountHashItem) ClearFlags

func (ahi *AccountHashItem) ClearFlags(flags uint16)

func (*AccountHashItem) CopyValueFrom

func (ahi *AccountHashItem) CopyValueFrom(item CacheItem)

func (*AccountHashItem) GetQueuePos

func (ahi *AccountHashItem) GetQueuePos() int

func (*AccountHashItem) GetSequence

func (ahi *AccountHashItem) GetSequence() int

func (*AccountHashItem) GetSize

func (ahi *AccountHashItem) GetSize() int

func (*AccountHashItem) HasFlag

func (ahi *AccountHashItem) HasFlag(flag uint16) bool

func (*AccountHashItem) HasPrefix

func (ahi *AccountHashItem) HasPrefix(prefix CacheItem) bool

func (*AccountHashItem) Less

func (ahi *AccountHashItem) Less(than btree.Item) bool

func (*AccountHashItem) SetFlags

func (ahi *AccountHashItem) SetFlags(flags uint16)

func (*AccountHashItem) SetQueuePos

func (ahi *AccountHashItem) SetQueuePos(pos int)

func (*AccountHashItem) SetSequence

func (ahi *AccountHashItem) SetSequence(sequence int)

func (*AccountHashItem) String

func (ahi *AccountHashItem) String() string

type AccountHashWriteItem

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

func (*AccountHashWriteItem) GetCacheItem

func (awi *AccountHashWriteItem) GetCacheItem() CacheItem

func (*AccountHashWriteItem) GetSize

func (awi *AccountHashWriteItem) GetSize() int

func (*AccountHashWriteItem) Less

func (awi *AccountHashWriteItem) Less(than btree.Item) bool

func (*AccountHashWriteItem) SetCacheItem

func (awi *AccountHashWriteItem) SetCacheItem(item CacheItem)

type AccountItem

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

AccountItem is an element in the `readWrites` B-tree representing an Ethereum account. It can mean either value just read seek the database and cache (read), or value that is different seek what the last committed value in the DB is (write). Reads can be removed or evicted seek the B-tree at any time, because this does not hurt the consistency. Writes cannot be removed or evicted one by one, therefore they can either be deleted all together, or committed all together and turned into reads.

func (*AccountItem) ClearFlags

func (ai *AccountItem) ClearFlags(flags uint16)

func (*AccountItem) CopyValueFrom

func (ai *AccountItem) CopyValueFrom(item CacheItem)

func (*AccountItem) GetQueuePos

func (ai *AccountItem) GetQueuePos() int

func (*AccountItem) GetSequence

func (ai *AccountItem) GetSequence() int

func (*AccountItem) GetSize

func (ai *AccountItem) GetSize() int

func (*AccountItem) HasFlag

func (ai *AccountItem) HasFlag(flag uint16) bool

func (*AccountItem) HasPrefix

func (ai *AccountItem) HasPrefix(prefix CacheItem) bool

func (*AccountItem) Less

func (ai *AccountItem) Less(than btree.Item) bool

func (*AccountItem) SetFlags

func (ai *AccountItem) SetFlags(flags uint16)

func (*AccountItem) SetQueuePos

func (ai *AccountItem) SetQueuePos(pos int)

func (*AccountItem) SetSequence

func (ai *AccountItem) SetSequence(sequence int)

func (*AccountItem) String

func (ai *AccountItem) String() string

type AccountSeek

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

AccountSeek allows to traverse sub-tree

func (*AccountSeek) Less

func (r *AccountSeek) Less(than btree.Item) bool

type AccountWriteItem

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

AccountWriteItem is an item in the `writes` B-tree. As can be seen, it always references a corresponding `AccountItem`. There can be `AccountItem` without corresponding `AccountWriteItem` (in that case `AccountItem` represents a cached read), but there cannot be `AccountWriteItem` without a corresponding `AccountItem`. Such pair represents an account that has been modified in the cache, but the modification has not been committed to the database yet. The correspondence of an `ai AccountItem` and an `awi AccountWriteItem` implies that `keccak(awi.address) == ai.addrHash`.

func (*AccountWriteItem) GetCacheItem

func (awi *AccountWriteItem) GetCacheItem() CacheItem

func (*AccountWriteItem) GetSize

func (awi *AccountWriteItem) GetSize() int

func (*AccountWriteItem) Less

func (awi *AccountWriteItem) Less(than btree.Item) bool

func (*AccountWriteItem) SetCacheItem

func (awi *AccountWriteItem) SetCacheItem(item CacheItem)

type CacheItem

type CacheItem interface {
	btree.Item
	GetSequence() int
	SetSequence(sequence int)
	GetSize() int
	GetQueuePos() int
	SetQueuePos(pos int)
	HasFlag(flag uint16) bool        // Check if specified flag is set
	SetFlags(flags uint16)           // Set specified flags, but leaves other flags alone
	ClearFlags(flags uint16)         // Clear specified flags, but laves other flags alone
	CopyValueFrom(item CacheItem)    // Copy value (not key) seek given item
	HasPrefix(prefix CacheItem) bool // Whether this item has specified item as a prefix
}

type CacheWriteItem

type CacheWriteItem interface {
	btree.Item
	GetCacheItem() CacheItem
	SetCacheItem(item CacheItem)
	GetSize() int
}

type CodeItem

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

func (*CodeItem) ClearFlags

func (ci *CodeItem) ClearFlags(flags uint16)

func (*CodeItem) CopyValueFrom

func (ci *CodeItem) CopyValueFrom(item CacheItem)

func (*CodeItem) GetQueuePos

func (ci *CodeItem) GetQueuePos() int

func (*CodeItem) GetSequence

func (ci *CodeItem) GetSequence() int

func (*CodeItem) GetSize

func (ci *CodeItem) GetSize() int

func (*CodeItem) HasFlag

func (ci *CodeItem) HasFlag(flag uint16) bool

func (*CodeItem) HasPrefix

func (ci *CodeItem) HasPrefix(prefix CacheItem) bool

func (*CodeItem) Less

func (ci *CodeItem) Less(than btree.Item) bool

func (*CodeItem) SetFlags

func (ci *CodeItem) SetFlags(flags uint16)

func (*CodeItem) SetQueuePos

func (ci *CodeItem) SetQueuePos(pos int)

func (*CodeItem) SetSequence

func (ci *CodeItem) SetSequence(sequence int)

func (*CodeItem) String

func (ci *CodeItem) String() string

type CodeWriteItem

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

func (*CodeWriteItem) GetCacheItem

func (cwi *CodeWriteItem) GetCacheItem() CacheItem

func (*CodeWriteItem) GetSize

func (cwi *CodeWriteItem) GetSize() int

func (*CodeWriteItem) Less

func (cwi *CodeWriteItem) Less(than btree.Item) bool

func (*CodeWriteItem) SetCacheItem

func (cwi *CodeWriteItem) SetCacheItem(item CacheItem)

type ReadHeap

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

Heap for reads

func (ReadHeap) Len

func (rh ReadHeap) Len() int

func (ReadHeap) Less

func (rh ReadHeap) Less(i, j int) bool

func (*ReadHeap) Pop

func (rh *ReadHeap) Pop() interface{}

func (*ReadHeap) Push

func (rh *ReadHeap) Push(x interface{})

func (ReadHeap) Swap

func (rh ReadHeap) Swap(i, j int)

type StateCache

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

StateCache is the structure containing B-trees and priority queues for the state cache

func NewStateCache

func NewStateCache(degree int, limit datasize.ByteSize) *StateCache

NewStateCache create a new state cache based on the B-trees of specific degree. The second and the third parameters are the limit on the number of reads and writes to cache, respectively

func (*StateCache) AccountHashCount

func (sc *StateCache) AccountHashCount() int

func (*StateCache) AccountHashesSeek

func (sc *StateCache) AccountHashesSeek(prefix []byte) ([]byte, uint16, uint16, uint16, []common.Hash)

func (*StateCache) AccountTree

func (sc *StateCache) AccountTree(prefix []byte, walker func(k []byte, h common.Hash, hasTree, hasHash bool) (toChild bool, err error), onMiss func(k []byte)) error

func (*StateCache) Clone

func (sc *StateCache) Clone() *StateCache

Clone creates a clone cache which can be modified independently, but it shares the parts of the cache that are common

func (*StateCache) DebugPrintAccounts

func (sc *StateCache) DebugPrintAccounts() error

func (*StateCache) DeprecatedSetAccountDelete

func (sc *StateCache) DeprecatedSetAccountDelete(addrHash common.Hash)

hack to set hashed addr - we don't have another one in trie stage

func (*StateCache) DeprecatedSetAccountRead

func (sc *StateCache) DeprecatedSetAccountRead(addrHash common.Hash, account *accounts.Account)

hack to set hashed addr - we don't have another one in trie stage

func (*StateCache) DeprecatedSetAccountWrite

func (sc *StateCache) DeprecatedSetAccountWrite(addrHash common.Hash, account *accounts.Account)

hack to set hashed addr - we don't have another one in trie stage

func (*StateCache) DeprecatedSetStorageDelete

func (sc *StateCache) DeprecatedSetStorageDelete(addrHash common.Hash, incarnation uint64, locHash common.Hash)

hack to set hashed addr - we don't have another one in trie stage

func (*StateCache) DeprecatedSetStorageRead

func (sc *StateCache) DeprecatedSetStorageRead(addrHash common.Hash, incarnation uint64, locHash common.Hash, val []byte)

hack to set hashed addr - we don't have another one in trie stage

func (*StateCache) DeprecatedSetStorageWrite

func (sc *StateCache) DeprecatedSetStorageWrite(addrHash common.Hash, incarnation uint64, locHash common.Hash, v []byte)

hack to set hashed addr - we don't have another one in trie stage

func (*StateCache) GetAccount

func (sc *StateCache) GetAccount(address []byte) (*accounts.Account, bool)

GetAccount searches and account with given address, without modifying any structures Second return value is true if such account is found

func (*StateCache) GetAccountByHashedAddress

func (sc *StateCache) GetAccountByHashedAddress(addrHash common.Hash) (*accounts.Account, bool)

func (*StateCache) GetAccountHash

func (sc *StateCache) GetAccountHash(prefix []byte) ([]byte, uint16, uint16, uint16, []common.Hash, bool)

func (*StateCache) GetCode

func (sc *StateCache) GetCode(address []byte, incarnation uint64) ([]byte, bool)

GetCode searches contract code with given address, without modifying any structures Second return value is true if such item is found

func (*StateCache) GetDeletedAccount

func (sc *StateCache) GetDeletedAccount(address []byte) *accounts.Account

GetDeletedAccount attempts to retrieve the last version of account before it was deleted

func (*StateCache) GetStorage

func (sc *StateCache) GetStorage(address []byte, incarnation uint64, location []byte) ([]byte, bool)

GetStorage searches storage item with given address, incarnation, and location, without modifying any structures Second return value is true if such item is found

func (*StateCache) GetStorageByHashedAddress

func (sc *StateCache) GetStorageByHashedAddress(addrHash common.Hash, incarnation uint64, locHash common.Hash) ([]byte, bool)

func (*StateCache) GetStorageHash

func (sc *StateCache) GetStorageHash(addrHash common.Hash, incarnation uint64, prefix []byte) ([]byte, uint16, uint16, uint16, []common.Hash, bool)

func (*StateCache) HasAccountHashWithPrefix

func (sc *StateCache) HasAccountHashWithPrefix(addrHashPrefix []byte) bool

func (*StateCache) HasAccountWithInPrefix

func (sc *StateCache) HasAccountWithInPrefix(addrHashPrefix []byte) bool

func (*StateCache) PrepareWrites

func (sc *StateCache) PrepareWrites() [5]*btree.BTree

func (*StateCache) ReadSize

func (sc *StateCache) ReadSize() int

func (*StateCache) SetAccountAbsent

func (sc *StateCache) SetAccountAbsent(address []byte)

SetAccountRead adds given account address to the cache, marking it as a absent

func (*StateCache) SetAccountDelete

func (sc *StateCache) SetAccountDelete(address []byte)

SetAccountDelete is very similar to SetAccountWrite with the difference that there no set value

func (*StateCache) SetAccountHashDelete

func (sc *StateCache) SetAccountHashDelete(prefix []byte)

func (*StateCache) SetAccountHashWrite

func (sc *StateCache) SetAccountHashWrite(prefix []byte, hasState, hasTree, hasHash uint16, hashes []common.Hash)

func (*StateCache) SetAccountHashesRead

func (sc *StateCache) SetAccountHashesRead(prefix []byte, hasState, hasTree, hasHash uint16, hashes []common.Hash)

func (*StateCache) SetAccountRead

func (sc *StateCache) SetAccountRead(address []byte, account *accounts.Account)

SetAccountRead adds given account to the cache, marking it as a read (not written)

func (*StateCache) SetAccountWrite

func (sc *StateCache) SetAccountWrite(address []byte, account *accounts.Account)

SetAccountWrite adds given account to the cache, marking it as written (cannot be evicted)

func (*StateCache) SetCodeAbsent

func (sc *StateCache) SetCodeAbsent(address []byte, incarnation uint64)

func (*StateCache) SetCodeDelete

func (sc *StateCache) SetCodeDelete(address []byte, incarnation uint64)

func (*StateCache) SetCodeRead

func (sc *StateCache) SetCodeRead(address []byte, incarnation uint64, code []byte)

func (*StateCache) SetCodeWrite

func (sc *StateCache) SetCodeWrite(address []byte, incarnation uint64, code []byte)

func (*StateCache) SetStorageAbsent

func (sc *StateCache) SetStorageAbsent(address []byte, incarnation uint64, location []byte)

func (*StateCache) SetStorageDelete

func (sc *StateCache) SetStorageDelete(address []byte, incarnation uint64, location []byte)

func (*StateCache) SetStorageHashDelete

func (sc *StateCache) SetStorageHashDelete(addrHash common.Hash, incarnation uint64, locHashPrefix []byte, hasState, hasTree, hasHash uint16, hashes []common.Hash)

func (*StateCache) SetStorageHashRead

func (sc *StateCache) SetStorageHashRead(addrHash common.Hash, incarnation uint64, locHashPrefix []byte, hasState, hasTree, hasHash uint16, hashes []common.Hash)

func (*StateCache) SetStorageHashWrite

func (sc *StateCache) SetStorageHashWrite(addrHash common.Hash, incarnation uint64, locHashPrefix []byte, hasState, hasTree, hasHash uint16, hashes []common.Hash)

func (*StateCache) SetStorageRead

func (sc *StateCache) SetStorageRead(address []byte, incarnation uint64, location []byte, value []byte)

func (*StateCache) SetStorageWrite

func (sc *StateCache) SetStorageWrite(address []byte, incarnation uint64, location []byte, value []byte)

func (*StateCache) StorageHashesSeek

func (sc *StateCache) StorageHashesSeek(addrHash common.Hash, incarnation uint64, prefix []byte) ([]byte, uint16, uint16, uint16, []common.Hash)

func (*StateCache) StorageTree

func (sc *StateCache) StorageTree(prefix []byte, accHash common.Hash, incarnation uint64, walker func(k []byte, h common.Hash, hasTree, hasHash bool) (toChild bool, err error), onMiss func(k []byte)) error

func (*StateCache) TotalCount

func (sc *StateCache) TotalCount() (res int)

func (*StateCache) TurnWritesToReads

func (sc *StateCache) TurnWritesToReads(writes [5]*btree.BTree)

func (*StateCache) WalkAccounts

func (sc *StateCache) WalkAccounts(prefix []byte, walker func(addrHash common.Hash, acc *accounts.Account) (bool, error)) error

func (*StateCache) WalkStorage

func (sc *StateCache) WalkStorage(addrHash common.Hash, incarnation uint64, prefix []byte, walker func(locHash common.Hash, val []byte) error) error

func (*StateCache) WalkStorageHashes

func (sc *StateCache) WalkStorageHashes(walker func(addrHash common.Hash, incarnation uint64, prefix []byte, hasStat, hasTree, hasHash uint16, h []common.Hash) error) error

func (*StateCache) WriteCount

func (sc *StateCache) WriteCount() (res int)

func (*StateCache) WriteSize

func (sc *StateCache) WriteSize() int

type StorageHashItem

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

func (*StorageHashItem) ClearFlags

func (shi *StorageHashItem) ClearFlags(flags uint16)

func (*StorageHashItem) CopyValueFrom

func (shi *StorageHashItem) CopyValueFrom(item CacheItem)

func (*StorageHashItem) GetQueuePos

func (shi *StorageHashItem) GetQueuePos() int

func (*StorageHashItem) GetSequence

func (shi *StorageHashItem) GetSequence() int

func (*StorageHashItem) GetSize

func (shi *StorageHashItem) GetSize() int

func (*StorageHashItem) HasFlag

func (shi *StorageHashItem) HasFlag(flag uint16) bool

func (*StorageHashItem) HasPrefix

func (shi *StorageHashItem) HasPrefix(prefix CacheItem) bool

func (*StorageHashItem) Less

func (shi *StorageHashItem) Less(than btree.Item) bool

func (*StorageHashItem) SetFlags

func (shi *StorageHashItem) SetFlags(flags uint16)

func (*StorageHashItem) SetQueuePos

func (shi *StorageHashItem) SetQueuePos(pos int)

func (*StorageHashItem) SetSequence

func (shi *StorageHashItem) SetSequence(sequence int)

func (*StorageHashItem) String

func (shi *StorageHashItem) String() string

type StorageHashWriteItem

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

func (*StorageHashWriteItem) GetCacheItem

func (wi *StorageHashWriteItem) GetCacheItem() CacheItem

func (*StorageHashWriteItem) GetSize

func (wi *StorageHashWriteItem) GetSize() int

func (*StorageHashWriteItem) Less

func (wi *StorageHashWriteItem) Less(than btree.Item) bool

func (*StorageHashWriteItem) SetCacheItem

func (wi *StorageHashWriteItem) SetCacheItem(item CacheItem)

type StorageItem

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

func (*StorageItem) ClearFlags

func (si *StorageItem) ClearFlags(flags uint16)

func (*StorageItem) CopyValueFrom

func (si *StorageItem) CopyValueFrom(item CacheItem)

func (*StorageItem) GetQueuePos

func (si *StorageItem) GetQueuePos() int

func (*StorageItem) GetSequence

func (si *StorageItem) GetSequence() int

func (*StorageItem) GetSize

func (si *StorageItem) GetSize() int

func (*StorageItem) HasFlag

func (si *StorageItem) HasFlag(flag uint16) bool

func (*StorageItem) HasPrefix

func (si *StorageItem) HasPrefix(prefix CacheItem) bool

func (*StorageItem) Less

func (si *StorageItem) Less(than btree.Item) bool

func (*StorageItem) SetFlags

func (si *StorageItem) SetFlags(flags uint16)

func (*StorageItem) SetQueuePos

func (si *StorageItem) SetQueuePos(pos int)

func (*StorageItem) SetSequence

func (si *StorageItem) SetSequence(sequence int)

func (*StorageItem) String

func (si *StorageItem) String() string

type StorageSeek

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

StorageSeek allows to traverse sub-tree

func (*StorageSeek) Less

func (r *StorageSeek) Less(than btree.Item) bool

type StorageWriteItem

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

func (*StorageWriteItem) GetCacheItem

func (swi *StorageWriteItem) GetCacheItem() CacheItem

func (*StorageWriteItem) GetSize

func (swi *StorageWriteItem) GetSize() int

func (*StorageWriteItem) Less

func (swi *StorageWriteItem) Less(than btree.Item) bool

func (*StorageWriteItem) SetCacheItem

func (swi *StorageWriteItem) SetCacheItem(item CacheItem)

type UnprocessedHeap

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

UnprocessedHeap is a priority queue of items that were modified after the last recalculation of the merkle tree

func (UnprocessedHeap) Len

func (uh UnprocessedHeap) Len() int

func (UnprocessedHeap) Less

func (uh UnprocessedHeap) Less(i, j int) bool

func (*UnprocessedHeap) Pop

func (uh *UnprocessedHeap) Pop() interface{}

func (*UnprocessedHeap) Push

func (uh *UnprocessedHeap) Push(x interface{})

func (UnprocessedHeap) Swap

func (uh UnprocessedHeap) Swap(i, j int)

Jump to

Keyboard shortcuts

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