state

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var MaxTrieCacheGen = uint16(120)

MaxTrieCacheGen is trie cache generation limit after which to evict trie nodes from memory.

Functions

This section is empty.

Types

type Account

type Account struct {
	Address  types.Address
	Balance  *math.BigInt
	Nonce    uint64
	Root     types.Hash
	CodeHash []byte
}

func (*Account) DecodeMsg

func (z *Account) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Account) EncodeMsg

func (z *Account) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Account) MarshalMsg

func (z *Account) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Account) Msgsize

func (z *Account) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Account) UnmarshalMsg

func (z *Account) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Database

type Database interface {
	// OpenTrie opens the main account trie.
	OpenTrie(root types.Hash) (Trie, error)

	// OpenStorageTrie opens the storage trie of an account.
	OpenStorageTrie(addrHash, root types.Hash) (Trie, error)

	// CopyTrie returns an independent copy of the given trie.
	CopyTrie(Trie) Trie

	// ContractCode retrieves a particular contract's code.
	ContractCode(addrHash, codeHash types.Hash) ([]byte, error)

	// ContractCodeSize retrieves a particular contracts code's size.
	ContractCodeSize(addrHash, codeHash types.Hash) (int, error)

	// TrieDB retrieves the low level trie database used for data storage.
	TrieDB() *trie.Database
}

Database wraps access to tries and contract code.

func NewDatabase

func NewDatabase(db ogdb.Database) Database

NewDatabase creates a backing store for state. The returned database is safe for concurrent use and retains cached trie nodes in memory. The pool is an optional intermediate trie-node memory pool between the low level storage layer and the high level trie abstraction.

type StateDB

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

StateDB stores account's data. Account's data include address, balance, nonce, code and its contract db if it is an contract address. An account is stored as a StateObject, for more detail please check StateObject struct.

func NewStateDB

func NewStateDB(conf StateDBConfig, db Database, root types.Hash) (*StateDB, error)

func (*StateDB) AddBalance

func (sd *StateDB) AddBalance(addr types.Address, increment *math.BigInt)

AddBalance

func (*StateDB) AddLog

func (sd *StateDB) AddLog(l *vmtypes.Log)

func (*StateDB) AddPreimage

func (sd *StateDB) AddPreimage(h types.Hash, b []byte)

func (*StateDB) AddRefund

func (sd *StateDB) AddRefund(increment uint64)

func (*StateDB) Commit

func (sd *StateDB) Commit() (types.Hash, error)

Commit tries to save dirty data to memory trie db.

func (*StateDB) CreateAccount

func (sd *StateDB) CreateAccount(addr types.Address)

CreateAccount will create a new state for input address and return the state. If input address already exists in StateDB returns it.

func (*StateDB) Database

func (sd *StateDB) Database() Database

func (*StateDB) DeleteStateObject

func (sd *StateDB) DeleteStateObject(addr types.Address) error

DeleteStateObject remove a state from StateDB. Return error if it fails.

func (*StateDB) Empty

func (sd *StateDB) Empty(addr types.Address) bool

func (*StateDB) Exist

func (sd *StateDB) Exist(addr types.Address) bool

func (*StateDB) ForEachStorage

func (sd *StateDB) ForEachStorage(addr types.Address, f func(key, value types.Hash) bool)

func (*StateDB) GetBalance

func (sd *StateDB) GetBalance(addr types.Address) *math.BigInt

func (*StateDB) GetCode

func (sd *StateDB) GetCode(addr types.Address) []byte

func (*StateDB) GetCodeHash

func (sd *StateDB) GetCodeHash(addr types.Address) types.Hash

func (*StateDB) GetCodeSize

func (sd *StateDB) GetCodeSize(addr types.Address) int

func (*StateDB) GetCommittedState

func (sd *StateDB) GetCommittedState(addr types.Address, key types.Hash) types.Hash

func (*StateDB) GetNonce

func (sd *StateDB) GetNonce(addr types.Address) uint64

func (*StateDB) GetOrCreateStateObject

func (sd *StateDB) GetOrCreateStateObject(addr types.Address) *StateObject

GetOrCreateStateObject will find a state from memory by account address. If state not exists, it will load a state from db.

func (*StateDB) GetRefund

func (sd *StateDB) GetRefund() uint64

func (*StateDB) GetState

func (sd *StateDB) GetState(addr types.Address, key types.Hash) types.Hash

func (*StateDB) GetStateObject

func (sd *StateDB) GetStateObject(addr types.Address) *StateObject

GetStateObject get a state from StateDB. If state not exist, load it from db.

func (*StateDB) HasSuicided

func (sd *StateDB) HasSuicided(addr types.Address) bool

func (*StateDB) RevertToSnapshot

func (sd *StateDB) RevertToSnapshot(snapshotid int)

func (*StateDB) Root

func (sd *StateDB) Root() types.Hash

func (*StateDB) SetBalance

func (sd *StateDB) SetBalance(addr types.Address, balance *math.BigInt)

SetBalance

func (*StateDB) SetCode

func (sd *StateDB) SetCode(addr types.Address, code []byte)

func (*StateDB) SetNonce

func (sd *StateDB) SetNonce(addr types.Address, nonce uint64)

func (*StateDB) SetState

func (sd *StateDB) SetState(addr types.Address, key, value types.Hash)

func (*StateDB) SetStateObject

func (sd *StateDB) SetStateObject(addr types.Address, stobj *StateObject)

func (*StateDB) Snapshot

func (sd *StateDB) Snapshot() int

func (*StateDB) Stop

func (sd *StateDB) Stop()

func (*StateDB) String

func (sd *StateDB) String() string

func (*StateDB) SubBalance

func (sd *StateDB) SubBalance(addr types.Address, decrement *math.BigInt)

SubBalance

func (*StateDB) SubRefund

func (sd *StateDB) SubRefund(decrement uint64)

func (*StateDB) Suicide

func (sd *StateDB) Suicide(addr types.Address) bool

type StateDBConfig

type StateDBConfig struct {
	PurgeTimer     time.Duration
	BeatExpireTime time.Duration
}

func DefaultStateDBConfig

func DefaultStateDBConfig() StateDBConfig

type StateObject

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

func NewStateObject

func NewStateObject(addr types.Address, db *StateDB) *StateObject

func (*StateObject) AddBalance

func (s *StateObject) AddBalance(increment *math.BigInt)

func (*StateObject) CommitStorage

func (s *StateObject) CommitStorage(db Database) error

func (*StateObject) Decode

func (s *StateObject) Decode(b []byte, db *StateDB) error

func (*StateObject) DecodeMsg

func (z *StateObject) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*StateObject) Encode

func (s *StateObject) Encode() ([]byte, error)

func (StateObject) EncodeMsg

func (z StateObject) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*StateObject) GetBalance

func (s *StateObject) GetBalance() *math.BigInt

func (*StateObject) GetCode

func (s *StateObject) GetCode(db Database) []byte

func (*StateObject) GetCodeHash

func (s *StateObject) GetCodeHash() types.Hash

func (*StateObject) GetCodeSize

func (s *StateObject) GetCodeSize(db Database) (int, error)

func (*StateObject) GetCommittedState

func (s *StateObject) GetCommittedState(db Database, key types.Hash) types.Hash

func (*StateObject) GetNonce

func (s *StateObject) GetNonce() uint64

func (*StateObject) GetState

func (s *StateObject) GetState(db Database, key types.Hash) types.Hash

func (StateObject) MarshalMsg

func (z StateObject) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (StateObject) Msgsize

func (z StateObject) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*StateObject) SetBalance

func (s *StateObject) SetBalance(balance *math.BigInt)

func (*StateObject) SetCode

func (s *StateObject) SetCode(codehash types.Hash, code []byte)

func (*StateObject) SetNonce

func (s *StateObject) SetNonce(nonce uint64)

func (*StateObject) SetState

func (s *StateObject) SetState(db Database, key, value types.Hash)

func (*StateObject) SubBalance

func (s *StateObject) SubBalance(decrement *math.BigInt)

func (*StateObject) Uncache

func (s *StateObject) Uncache()

Uncache clears dirtyStorage and committedStorage. This is aimed to check if state is committed into db.

Note that this function is for test debug only, should not be called by other functions.

func (*StateObject) UnmarshalMsg

func (z *StateObject) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Trie

type Trie interface {
	TryGet(key []byte) ([]byte, error)
	TryUpdate(key, value []byte) error
	TryDelete(key []byte) error
	Commit(onleaf trie.LeafCallback) (types.Hash, error)
	Hash() types.Hash
	NodeIterator(startKey []byte) trie.NodeIterator
	GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed
	Prove(key []byte, fromLevel uint, proofDb ogdb.Putter) error
}

Trie is a Ethereum Merkle Trie.

Jump to

Keyboard shortcuts

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