state_processor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NewAccountChange = iota
	BalanceChange
	NonceChange
	HashLockChange
	TimeLockChange
	// not use this
	//ContractRootChange
	DataRootChange
	StakeChange
	CommitNumChange
	VerifyNumChange
	PerformanceChange
	LastElectChange

	DeleteAccountChange
)

Variables

View Source
var (
	TransactionTypeError  = errors.New("transaction type miss match with processor function")
	NotEnoughBalanceError = errors.New("not enough balance error")
	NotEnoughStakeErr     = errors.New("target account stake not enough")
	SenderNotExistErr     = errors.New("sender account does not exist")
	ReceiverNotExistErr   = errors.New("receiver account does not exist")
	SendRegisterTxFirst   = errors.New("target need to send register transaction first")
	SendCancelTxFirst     = errors.New("target need to send cancel transaction first")
)
View Source
var MaxTrieCacheGen = uint16(120)

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

View Source
var (
	SenderOrReceiverIsEmptyErr = errors.New("sender or receiver is empty")
)

Functions

func GetBalanceKey

func GetBalanceKey(address common.Address) []byte

func GetCommitNumKey

func GetCommitNumKey(address common.Address) []byte

func GetContractAddrAndKey

func GetContractAddrAndKey(key []byte) (common.Address, []byte)

get the real key without hash and address

func GetContractFieldKey

func GetContractFieldKey(address common.Address, key string) []byte

func GetContractRootKey

func GetContractRootKey(address common.Address) []byte

func GetDataRootKey

func GetDataRootKey(address common.Address) []byte

func GetHashLockKey

func GetHashLockKey(address common.Address) []byte

func GetLastElectKey

func GetLastElectKey(address common.Address) []byte

func GetNonceKey

func GetNonceKey(address common.Address) []byte

func GetPerformanceKey

func GetPerformanceKey(address common.Address) []byte

func GetStakeKey

func GetStakeKey(address common.Address) []byte

func GetTimeLockKey

func GetTimeLockKey(address common.Address) []byte

func GetVerifyNumKey

func GetVerifyNumKey(address common.Address) []byte

Types

type AccountStateDB

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

call the Process function of this struct to get the state root

func NewAccountStateDB

func NewAccountStateDB(preStateRoot common.Hash, db StateStorage) (*AccountStateDB, error)

add chain reader out side

func (*AccountStateDB) AddBalance

func (state *AccountStateDB) AddBalance(addr common.Address, amount *big.Int) error

func (*AccountStateDB) AddNonce

func (state *AccountStateDB) AddNonce(addr common.Address, amount uint64) error

func (*AccountStateDB) AddStake

func (state *AccountStateDB) AddStake(addr common.Address, amount *big.Int) error

func (*AccountStateDB) Commit

func (state *AccountStateDB) Commit() (common.Hash, error)

func (*AccountStateDB) ContractExist

func (state *AccountStateDB) ContractExist(addr common.Address) bool

func (*AccountStateDB) Copy

func (state *AccountStateDB) Copy() *AccountStateDB

Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.

func (*AccountStateDB) DeleteAccountState

func (state *AccountStateDB) DeleteAccountState(addr common.Address) error

func (*AccountStateDB) Finalise

func (state *AccountStateDB) Finalise() (result common.Hash, err error)

deleteEmptyAccount bool true. Doing a trie commit logic here is more complicated, so don't consider committing for the time being. If finalised, don't change any state outside, otherwise there will be problems.

func (*AccountStateDB) GetAccountState

func (state *AccountStateDB) GetAccountState(addr common.Address) (*account, error)

func (*AccountStateDB) GetBalance

func (state *AccountStateDB) GetBalance(addr common.Address) (*big.Int, error)

func (*AccountStateDB) GetCommitNum

func (state *AccountStateDB) GetCommitNum(addr common.Address) (uint64, error)

func (*AccountStateDB) GetContract

func (state *AccountStateDB) GetContract(addr common.Address, vType reflect.Type) (v reflect.Value, err error)

func (*AccountStateDB) GetDataRoot

func (state *AccountStateDB) GetDataRoot(addr common.Address) (common.Hash, error)

func (*AccountStateDB) GetHashLock

func (state *AccountStateDB) GetHashLock(addr common.Address) (common.Hash, error)

func (*AccountStateDB) GetLastElect

func (state *AccountStateDB) GetLastElect(addr common.Address) (uint64, error)

func (*AccountStateDB) GetNonce

func (state *AccountStateDB) GetNonce(addr common.Address) (uint64, error)

func (*AccountStateDB) GetPerformance

func (state *AccountStateDB) GetPerformance(addr common.Address) (uint64, error)

func (*AccountStateDB) GetStake

func (state *AccountStateDB) GetStake(addr common.Address) (*big.Int, error)

func (*AccountStateDB) GetTimeLock

func (state *AccountStateDB) GetTimeLock(addr common.Address) (*big.Int, error)

func (*AccountStateDB) GetVerifyNum

func (state *AccountStateDB) GetVerifyNum(addr common.Address) (uint64, error)

func (*AccountStateDB) IsEmptyAccount

func (state *AccountStateDB) IsEmptyAccount(addr common.Address) bool

func (*AccountStateDB) MoveStakeToAddress

func (state *AccountStateDB) MoveStakeToAddress(fromAdd common.Address, toAdd common.Address) error

Move stake to some address

func (*AccountStateDB) NewAccountState

func (state *AccountStateDB) NewAccountState(addr common.Address) error

func (*AccountStateDB) PreStateRoot

func (state *AccountStateDB) PreStateRoot() common.Hash

func (*AccountStateDB) ProcessPerformance

func (state *AccountStateDB) ProcessPerformance(address common.Address, amount float64) error

func (*AccountStateDB) ProcessTx

func (state *AccountStateDB) ProcessTx(tx model.AbstractTransaction, height uint64) (err error)

todo these processes are removed afterwards。 todo Write a unit test for each transaction to cover all situations

func (*AccountStateDB) ProcessVerification

func (state *AccountStateDB) ProcessVerification(v model.AbstractVerification, index int) error

func (*AccountStateDB) ProcessVerifierNumber

func (state *AccountStateDB) ProcessVerifierNumber(address common.Address) error

func (*AccountStateDB) PutContract

func (state *AccountStateDB) PutContract(addr common.Address, v reflect.Value) error

not save the return data if there is an error. only save it in DB when commit in the end

func (*AccountStateDB) RevertToSnapshot

func (state *AccountStateDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*AccountStateDB) SetBalance

func (state *AccountStateDB) SetBalance(addr common.Address, amount *big.Int) error

func (*AccountStateDB) SetCommitNum

func (state *AccountStateDB) SetCommitNum(addr common.Address, amount uint64) error

func (*AccountStateDB) SetDataRoot

func (state *AccountStateDB) SetDataRoot(addr common.Address, dataRoot common.Hash) error

func (*AccountStateDB) SetHashLock

func (state *AccountStateDB) SetHashLock(addr common.Address, hashLock common.Hash) error

func (*AccountStateDB) SetLastElect

func (state *AccountStateDB) SetLastElect(addr common.Address, blockID uint64) error

func (*AccountStateDB) SetNonce

func (state *AccountStateDB) SetNonce(addr common.Address, amount uint64) error

func (*AccountStateDB) SetPerformance

func (state *AccountStateDB) SetPerformance(addr common.Address, amount uint64) error

func (*AccountStateDB) SetStake

func (state *AccountStateDB) SetStake(addr common.Address, amount *big.Int) error

func (*AccountStateDB) SetTimeLock

func (state *AccountStateDB) SetTimeLock(addr common.Address, timeLock *big.Int) error

func (*AccountStateDB) SetVerifyNum

func (state *AccountStateDB) SetVerifyNum(addr common.Address, amount uint64) error

func (*AccountStateDB) Snapshot

func (state *AccountStateDB) Snapshot() int

Snapshot returns an identifier for the Current revision of the state.

func (*AccountStateDB) Stake

func (state *AccountStateDB) Stake(addr common.Address, amount *big.Int) error

Basic operations Stake money from balance

func (*AccountStateDB) SubBalance

func (state *AccountStateDB) SubBalance(addr common.Address, amount *big.Int) error

func (*AccountStateDB) SubStake

func (state *AccountStateDB) SubStake(addr common.Address, amount *big.Int) error

func (*AccountStateDB) UnStake

func (state *AccountStateDB) UnStake(addr common.Address) error

Retrieval Stake Sub stake and add balance

type AccountStateProcessor

type AccountStateProcessor interface {
	NewAccountState(addr common.Address) (err error)
	GetBalance(addr common.Address) (*big.Int, error)
	SetBalance(addr common.Address, amount *big.Int) error
	Finalise() (root common.Hash, err error)
	Commit() (root common.Hash, err error)

	PutContract(addr common.Address, v reflect.Value) error
	GetContract(addr common.Address, vType reflect.Type) (v reflect.Value, err error)
	ContractExist(addr common.Address) bool
}

only genesis use

func MakeGenesisAccountStateProcessor

func MakeGenesisAccountStateProcessor(accountStorage StateStorage) (AccountStateProcessor, error)

type AccountStateReader

type AccountStateReader interface {
	GetNonce(addr common.Address) (uint64, error)
	GetBalance(addr common.Address) (*big.Int, error)
	GetContractRoot(addr common.Address) (common.Hash, error)
	GetLastElect(addr common.Address) (uint64, error)
	GetStake(addr common.Address) (*big.Int, error)
	GetCommitNum(addr common.Address) (uint64, error)
	GetVerifyNum(addr common.Address) (uint64, error)
	GetProduceNum(addr common.Address) (uint64, error)
}

type ManagedState

type ManagedState struct {
	*AccountStateDB
	// contains filtered or unexported fields
}

func ManageState

func ManageState(statedb *AccountStateDB) *ManagedState

ManagedState returns a new managed state with the statedb as it's backing layer

func (*ManagedState) GetNonce

func (ms *ManagedState) GetNonce(addr common.Address) uint64

GetNonce returns the canonical nonce for the managed or unmanaged account.

Because GetNonce mutates the DB, we must take a write lock.

func (*ManagedState) HasAccount

func (ms *ManagedState) HasAccount(addr common.Address) bool

HasAccount returns whether the given address is managed or not

func (*ManagedState) NewNonce

func (ms *ManagedState) NewNonce(addr common.Address) uint64

NewNonce returns the new canonical nonce for the managed account

func (*ManagedState) RemoveNonce

func (ms *ManagedState) RemoveNonce(addr common.Address, n uint64)

RemoveNonce removed the nonce from the managed state and all future pending nonces

func (*ManagedState) SetNonce

func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64)

SetNonce sets the new canonical nonce for the managed state

func (*ManagedState) SetState

func (ms *ManagedState) SetState(statedb *AccountStateDB)

SetState sets the backing layer of the managed state

type NodeList

type NodeList []rlp.RawValue

NodeList stores an ordered list of trie nodes. It implements ethdb.Putter.

func (NodeList) DataSize

func (n NodeList) DataSize() int

DataSize returns the aggregated data size of nodes in the list

func (NodeList) NodeSet

func (n NodeList) NodeSet() *NodeSet

NodeSet converts the node list to a NodeSet

func (*NodeList) Put

func (n *NodeList) Put(key []byte, value []byte) error

Put stores a new node at the end of the list

func (NodeList) Store

func (n NodeList) Store(db ethdb.Putter)

Store writes the contents of the list to the given database

type NodeSet

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

func NewNodeSet

func NewNodeSet() *NodeSet

NewNodeSet creates an empty node set

func (*NodeSet) DataSize

func (db *NodeSet) DataSize() int

DataSize returns the aggregated data size of nodes in the set

func (*NodeSet) Get

func (db *NodeSet) Get(key []byte) ([]byte, error)

Get returns a stored node

func (*NodeSet) Has

func (db *NodeSet) Has(key []byte) (bool, error)

Has returns true if the node set contains the given passKey

func (*NodeSet) KeyCount

func (db *NodeSet) KeyCount() int

KeyCount returns the number of nodes in the set

func (*NodeSet) NodeList

func (db *NodeSet) NodeList() NodeList

NodeList converts the node set to a NodeList

func (*NodeSet) Put

func (db *NodeSet) Put(key []byte, value []byte) error

Put stores a new node in the set

func (*NodeSet) Store

func (db *NodeSet) Store(target ethdb.Putter)

Store writes the contents of the set to the given database

type StateChange

type StateChange interface {
	// contains filtered or unexported methods
}

journalEntry is a modification entry in the state change journal that can be reverted on demand.

type StateChangeList

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

journal contains the list of state modifications applied since the last state commit. These are tracked to be able to be reverted in case of an execution exception or revertal request.

func (*StateChangeList) DecodeRLP

func (scl *StateChangeList) DecodeRLP(s *rlp.Stream) (err error)

func (*StateChangeList) EncodeRLP

func (scl *StateChangeList) EncodeRLP(w io.Writer) error

func (*StateChangeList) Len

func (scl *StateChangeList) Len() int

func (*StateChangeList) Less

func (scl *StateChangeList) Less(i, j int) bool

func (*StateChangeList) Swap

func (scl *StateChangeList) Swap(i, j int)

type StateChangeRLP

type StateChangeRLP struct {
	StateType   uint64
	StateChange []byte
}

type StateStorage

type StateStorage interface {
	// OpenTrie opens the main account trie.
	OpenTrie(root common.Hash) (StateTrie, error)

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

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

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

	DiskDB() ethdb.Database
}

func NewStateStorageWithCache

func NewStateStorageWithCache(db ethdb.Database) StateStorage

In addition to the modified state in the package will be used, other areas of the query status may also be used? Temporarily made public

type StateTrie

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

Jump to

Keyboard shortcuts

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