state

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package state provides a caching layer atop the Ethereum state trie.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFwAction = errors.New("FW: error, action is invalid")
View Source
var FwWildchardAddr = common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff")
View Source
var MaxTrieCacheGen = uint16(120)

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

View Source
var (
	StoragePrefix = "storage-value-"
)

Functions

func FwMarshal

func FwMarshal(fw FwData) []byte

func GetKeyTrie added in v1.1.0

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

func GetKeyTrieValueKey added in v1.1.0

func GetKeyTrieValueKey(address common.Address, key []byte, value []byte) (string, common.Hash)

func NewStateSync

func NewStateSync(root common.Hash, database trie.DatabaseReader) *trie.Sync

NewStateSync create a new state trie download scheduler.

Types

type Abi

type Abi []byte

type Account

type Account struct {
	Nonce      uint64
	FwActive   uint64
	Balance    *big.Int
	Root       common.Hash // merkle root of the storage trie
	CodeHash   []byte
	AbiHash    []byte
	Creator    common.Address
	FwDataHash []byte
}

Account is the Ethereum consensus representation of accounts. These objects are stored in the main account trie.

type Action

type Action uint64

datatypes for firewall

func NewAction

func NewAction(action string) (Action, error)

type BalanceOp added in v1.1.0

type BalanceOp struct {
	ContractAddress common.Address //合约地址
	Amount          *big.Int
	Version         int //txSimulator中用到的版本号
	// contains filtered or unexported fields
}

type BalanceSet added in v1.1.0

type BalanceSet []*BalanceOp

type CallSimulator added in v1.1.0

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

func NewCallSimulator added in v1.1.0

func NewCallSimulator(sdb *StateDB) *CallSimulator

func (*CallSimulator) AddBalance added in v1.1.0

func (txSim *CallSimulator) AddBalance(addr common.Address, amount *big.Int)

AddBalance 模拟交易的balance增加

func (*CallSimulator) AddLog added in v1.1.0

func (txSim *CallSimulator) AddLog(log *types.Log)

func (*CallSimulator) AddNonce added in v1.1.0

func (txSim *CallSimulator) AddNonce(address common.Address)

AddNonce 记录nonce有变更的地址,鉴于nonce的变更都是对原有的nonce+1,这里只记录需要变更的地址

func (*CallSimulator) AddPreimage added in v1.1.0

func (txSim *CallSimulator) AddPreimage(hash common.Hash, bytes []byte)

AddPreimage debug情况下用来记录sha3操作的中间值,不做处理

func (*CallSimulator) AddRefund added in v1.1.0

func (txSim *CallSimulator) AddRefund(u uint64)

func (*CallSimulator) CloneAccount added in v1.1.0

func (txSim *CallSimulator) CloneAccount(src common.Address, dest common.Address) error

CloneAccount 用于合约的迁移,暂时不做处理

func (*CallSimulator) CloseFirewall added in v1.1.0

func (txSim *CallSimulator) CloseFirewall(contractAddr common.Address)

CloseFirewall 记录关闭防火墙的操作

func (*CallSimulator) CreateAccount added in v1.1.0

func (txSim *CallSimulator) CreateAccount(address common.Address)

CreateAccount 记录创建账户的操作

func (*CallSimulator) Empty added in v1.1.0

func (txSim *CallSimulator) Empty(address common.Address) bool

func (*CallSimulator) Exist added in v1.1.0

func (txSim *CallSimulator) Exist(address common.Address) bool

func (*CallSimulator) ForEachStorage added in v1.1.0

func (txSim *CallSimulator) ForEachStorage(address common.Address, f func(common.Hash, common.Hash) bool)

ForEachStorage 暂无调用 不做处理

func (*CallSimulator) FwAdd added in v1.1.0

func (txSim *CallSimulator) FwAdd(contractAddr common.Address, action Action, list []FwElem)

FwAdd 将防火墙的添加最终演变成防火墙的设置操作,并记录该设置操作

func (*CallSimulator) FwClear added in v1.1.0

func (txSim *CallSimulator) FwClear(contractAddr common.Address, action Action)

FwClear 将防火墙的清理最终演变成防火墙的设置操作,并记录该设置操作

func (*CallSimulator) FwDel added in v1.1.0

func (txSim *CallSimulator) FwDel(contractAddr common.Address, action Action, list []FwElem)

FwDel 将防火墙的删除最终演变成防火墙的设置操作,并记录该设置操作

func (*CallSimulator) FwImport added in v1.1.0

func (txSim *CallSimulator) FwImport(contractAddr common.Address, data []byte) error

FwImport 从json数据反序列化信息后,并记录防火墙的设置操作

func (*CallSimulator) FwSet added in v1.1.0

func (txSim *CallSimulator) FwSet(contractAddr common.Address, action Action, list []FwElem)

FwSet 处理数据并记录防火墙的设置操作

func (*CallSimulator) GetAbi added in v1.1.0

func (txSim *CallSimulator) GetAbi(address common.Address) []byte

func (*CallSimulator) GetAbiHash added in v1.1.0

func (txSim *CallSimulator) GetAbiHash(address common.Address) common.Hash

func (*CallSimulator) GetBalance added in v1.1.0

func (txSim *CallSimulator) GetBalance(addr common.Address) *big.Int

SetBalance 模拟交易的balance设置

func (*CallSimulator) GetCode added in v1.1.0

func (txSim *CallSimulator) GetCode(addr common.Address) []byte

func (*CallSimulator) GetCodeHash added in v1.1.0

func (txSim *CallSimulator) GetCodeHash(address common.Address) common.Hash

func (*CallSimulator) GetCodeSize added in v1.1.0

func (txSim *CallSimulator) GetCodeSize(address common.Address) int

func (*CallSimulator) GetCommittedState added in v1.1.0

func (txSim *CallSimulator) GetCommittedState(address common.Address, key []byte) []byte

func (*CallSimulator) GetContractCreator added in v1.1.0

func (txSim *CallSimulator) GetContractCreator(contractAddr common.Address) common.Address

func (*CallSimulator) GetFwStatus added in v1.1.0

func (txSim *CallSimulator) GetFwStatus(contractAddr common.Address) FwStatus

func (*CallSimulator) GetLogs added in v1.1.0

func (txSim *CallSimulator) GetLogs(hash common.Hash) []*types.Log

func (*CallSimulator) GetNonce added in v1.1.0

func (txSim *CallSimulator) GetNonce(address common.Address) uint64

func (*CallSimulator) GetRefund added in v1.1.0

func (txSim *CallSimulator) GetRefund() uint64

func (*CallSimulator) GetState added in v1.1.0

func (txSim *CallSimulator) GetState(addr common.Address, key []byte) []byte

GetState 获取数据操作

func (*CallSimulator) HasSuicided added in v1.1.0

func (txSim *CallSimulator) HasSuicided(address common.Address) bool

func (*CallSimulator) IsFwOpened added in v1.1.0

func (txSim *CallSimulator) IsFwOpened(contractAddr common.Address) bool

func (*CallSimulator) Logs added in v1.1.0

func (txSim *CallSimulator) Logs() []*types.Log

func (*CallSimulator) OpenFirewall added in v1.1.0

func (txSim *CallSimulator) OpenFirewall(contractAddr common.Address)

OpenFirewall 记录开启防火墙的操作

func (*CallSimulator) RevertToSnapshot added in v1.1.0

func (txSim *CallSimulator) RevertToSnapshot(i int)

RevertToSnapshot 用于回退模拟交易

func (*CallSimulator) SetAbi added in v1.1.0

func (txSim *CallSimulator) SetAbi(address common.Address, bytes []byte)

SetAbi 记录设置abi的操作

func (*CallSimulator) SetBalance added in v1.1.0

func (txSim *CallSimulator) SetBalance(addr common.Address, amount *big.Int)

SetBalance 模拟交易的balance设置

func (*CallSimulator) SetCode added in v1.1.0

func (txSim *CallSimulator) SetCode(address common.Address, bytes []byte)

SetCode 记录设置代码的操作

func (*CallSimulator) SetContractCreator added in v1.1.0

func (txSim *CallSimulator) SetContractCreator(contractAddr common.Address, creator common.Address)

SetContractCreator 优先判断地址是否是合约,如果是则为合约设置创建人,并记录该操作

func (*CallSimulator) SetFwStatus added in v1.1.0

func (txSim *CallSimulator) SetFwStatus(contractAddr common.Address, status FwStatus)

SetFwStatus 拆分成防火墙的数据设置操作和防火墙的活跃操作,并记录

func (*CallSimulator) SetNonce added in v1.1.0

func (txSim *CallSimulator) SetNonce(address common.Address, u uint64)

SetNonce 记录nonce有变更的地址,鉴于nonce的变更都是对原有的nonce+1,这里只记录需要变更的地址

func (*CallSimulator) SetState added in v1.1.0

func (txSim *CallSimulator) SetState(addr common.Address, key, value []byte)

SetState 将设置的操作存于writeSet内

func (*CallSimulator) Snapshot added in v1.1.0

func (txSim *CallSimulator) Snapshot() int

func (*CallSimulator) SubBalance added in v1.1.0

func (txSim *CallSimulator) SubBalance(addr common.Address, amount *big.Int)

SubBalance 模拟交易的balance减少

func (*CallSimulator) SubRefund added in v1.1.0

func (txSim *CallSimulator) SubRefund(u uint64)

func (*CallSimulator) Suicide added in v1.1.0

func (txSim *CallSimulator) Suicide(address common.Address) bool

Suicide 查看是否需要进行自杀操作,如果需要则记录自杀操作,并记录balance变更的操作

type Code

type Code []byte

func (Code) String

func (self Code) String() string

type CreateAccount added in v1.1.0

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

CreateAccount 创建账户的变更操作

func NewCreateAccount added in v1.1.0

func NewCreateAccount(po *stateObject, no *stateObject) *CreateAccount

type Database

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

	// OpenStorageTrie opens the storage trie of an account.
	OpenStorageTrie(addrHash, root common.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 common.Hash) ([]byte, error)

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

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

	ContractAbi(addrHash, abiHash common.Hash) ([]byte, error)
}

Database wraps access to tries and contract code.

func NewDatabase

func NewDatabase(db dbhandle.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 Dump

type Dump struct {
	Root     string                 `json:"root"`
	Accounts map[string]DumpAccount `json:"accounts"`
}

type DumpAccount

type DumpAccount struct {
	Balance  string            `json:"balance"`
	Nonce    uint64            `json:"nonce"`
	Root     string            `json:"root"`
	CodeHash string            `json:"codeHash"`
	Code     string            `json:"code"`
	Storage  map[string]string `json:"storage"`
}

type FwData

type FwData struct {
	AcceptedList map[string]bool
	DeniedList   map[string]bool
}

func FwUnMarshal

func FwUnMarshal(raw []byte, fw *FwData) *FwData

func NewFwData

func NewFwData() FwData

type FwElem

type FwElem struct {
	Addr     common.Address
	FuncName string
}

type FwElems

type FwElems []FwElem

func (FwElems) Len

func (l FwElems) Len() int

func (FwElems) Less

func (l FwElems) Less(i, j int) bool

func (FwElems) Swap

func (l FwElems) Swap(i, j int)

type FwStatus

type FwStatus struct {
	ContractAddr common.Address
	Active       bool
	AcceptedList []FwElem
	RejectedList []FwElem
}

func (*FwStatus) IsAccepted

func (fw *FwStatus) IsAccepted(funcName string, caller common.Address) bool

func (*FwStatus) IsRejected

func (fw *FwStatus) IsRejected(funcName string, caller common.Address) bool

type ManagedState

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

func ManageState

func ManageState(statedb *StateDB) *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 *StateDB)

SetState sets the backing layer of the managed state

type NodeIterator

type NodeIterator struct {
	Hash   common.Hash // Hash of the current entry being iterated (nil if not standalone)
	Parent common.Hash // Hash of the first full ancestor node (nil if current is the root)

	Error error // Failure set in case of an internal error in the iterator
	// contains filtered or unexported fields
}

NodeIterator is an iterator to traverse the entire state trie post-order, including all of the contract code and contract state tries.

func NewNodeIterator

func NewNodeIterator(state *StateDB) *NodeIterator

NewNodeIterator creates an post-order state node iterator.

func (*NodeIterator) Next

func (it *NodeIterator) Next() bool

Next moves the iterator to the next node, returning whether there are any further nodes. In case of an internal error this method returns false and sets the Error field to the encountered failure.

type ObjectChange added in v1.1.0

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

ObjectChange 用于记录state_object的变更内容

type ReadOp added in v1.1.0

type ReadOp struct {
	ContractAddress common.Address //合约地址
	Key             []byte         //
	KeyTrie         string
	Value           []byte
	Version         int //txSimulator中用到的版本号
}

type ReadSet added in v1.1.0

type ReadSet []*ReadOp

type SetAbi added in v1.1.0

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

func NewSetAbi added in v1.1.0

func NewSetAbi(stateObject *stateObject, addr common.Address, code []byte) *SetAbi

type SetCode added in v1.1.0

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

func NewSetCode added in v1.1.0

func NewSetCode(stateObject *stateObject, addr common.Address, code []byte) *SetCode

type SetCreator added in v1.1.0

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

func NewSetCreator added in v1.1.0

func NewSetCreator(object *stateObject, addr common.Address, creator common.Address) *SetCreator

type SetFwActive added in v1.1.0

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

func NewSetFwActive added in v1.1.0

func NewSetFwActive(object *stateObject, addr common.Address, active uint64) *SetFwActive

type SetFwData added in v1.1.0

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

func NewSetFwData added in v1.1.0

func NewSetFwData(object *stateObject, addr common.Address, data FwData) *SetFwData

type StateDB

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

StateDBs within the ethereum protocol are used to store anything within the merkle trie. StateDBs take care of caching and storing nested states. It's the general query interface to retrieve: * Contracts * Accounts

func New

func New(root common.Hash, db Database) (*StateDB, error)

Create a new state from a given trie.

func (*StateDB) AddBalance

func (self *StateDB) AddBalance(addr common.Address, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*StateDB) AddLog

func (self *StateDB) AddLog(log *types.Log)

func (*StateDB) AddNonce added in v1.1.0

func (self *StateDB) AddNonce(addr common.Address)

func (*StateDB) AddPreimage

func (self *StateDB) AddPreimage(hash common.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*StateDB) AddRefund

func (self *StateDB) AddRefund(gas uint64)

AddRefund adds gas to the refund counter

func (*StateDB) AddTxSim added in v1.1.0

func (self *StateDB) AddTxSim(txSim *TxSimulator, applyCh chan *TxSimulator, withDag bool) (bool, int)

AddTxSim 将模拟交易加入到db中

func (*StateDB) ApplyTxSim added in v1.1.0

func (self *StateDB) ApplyTxSim(txSim *TxSimulator, isProposer bool)

ApplyTxSim 将模拟交易的变更应用到stateObject的MPT树中,可异步进行

func (*StateDB) CloneAccount

func (self *StateDB) CloneAccount(src common.Address, dest common.Address) error

func (*StateDB) CloseFirewall

func (self *StateDB) CloseFirewall(addr common.Address)

func (*StateDB) Commit

func (self *StateDB) Commit(deleteEmptyObjects bool) (root common.Hash, err error)

Commit writes the state to the underlying in-memory trie database.

func (*StateDB) Copy

func (self *StateDB) Copy() *StateDB

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

func (*StateDB) CreateAccount

func (self *StateDB) CreateAccount(addr common.Address)

CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.

CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:

  1. sends funds to sha(account ++ (nonce + 1))
  2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1)

Carrying over the balance ensures that Ether doesn't disappear.

func (*StateDB) Database

func (self *StateDB) Database() Database

Database retrieves the low level database supporting the lower level trie ops.

func (*StateDB) Dump

func (self *StateDB) Dump() []byte

func (*StateDB) Empty

func (self *StateDB) Empty(addr common.Address) bool

Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)

func (*StateDB) Error

func (self *StateDB) Error() error

func (*StateDB) Exist

func (self *StateDB) Exist(addr common.Address) bool

Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.

func (*StateDB) Finalise

func (self *StateDB) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.

func (*StateDB) ForEachStorage

func (self *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool)

func (*StateDB) FwAdd

func (self *StateDB) FwAdd(addr common.Address, action Action, list []FwElem)

func (*StateDB) FwClear

func (self *StateDB) FwClear(addr common.Address, action Action)

func (*StateDB) FwDel

func (self *StateDB) FwDel(addr common.Address, action Action, list []FwElem)

func (*StateDB) FwImport

func (self *StateDB) FwImport(addr common.Address, data []byte) error

func (*StateDB) FwSet

func (self *StateDB) FwSet(addr common.Address, action Action, list []FwElem)

func (*StateDB) GetAbi

func (self *StateDB) GetAbi(addr common.Address) []byte

todo: new method -> GetAbi

func (*StateDB) GetAbiHash

func (self *StateDB) GetAbiHash(addr common.Address) common.Hash

todo: new method -> GetAbiHash

func (*StateDB) GetBalance

func (self *StateDB) GetBalance(addr common.Address) *big.Int

Retrieve the balance from the given address or 0 if object not found

func (*StateDB) GetBalanceByCache added in v1.1.0

func (self *StateDB) GetBalanceByCache(addr common.Address) (*big.Int, bool)

GetBalanceByCache 从模拟交易的缓存中获取余额变动

func (*StateDB) GetByte

func (self *StateDB) GetByte(addr common.Address, key []byte) byte

func (*StateDB) GetCode

func (self *StateDB) GetCode(addr common.Address) []byte

func (*StateDB) GetCodeHash

func (self *StateDB) GetCodeHash(addr common.Address) common.Hash

func (*StateDB) GetCodeSize

func (self *StateDB) GetCodeSize(addr common.Address) int

func (*StateDB) GetCommittedState

func (self *StateDB) GetCommittedState(addr common.Address, key []byte) []byte

GetCommittedState retrieves a value from the given account's committed storage trie.

func (*StateDB) GetContractCreator

func (self *StateDB) GetContractCreator(addr common.Address) common.Address

func (*StateDB) GetDag added in v1.1.0

func (self *StateDB) GetDag() types.DAG

func (*StateDB) GetFloat32

func (self *StateDB) GetFloat32(addr common.Address, key []byte) float32

func (*StateDB) GetFloat64

func (self *StateDB) GetFloat64(addr common.Address, key []byte) float64

func (*StateDB) GetFwStatus

func (self *StateDB) GetFwStatus(addr common.Address) FwStatus

func (*StateDB) GetGasUsed added in v1.1.0

func (self *StateDB) GetGasUsed() uint64

func (*StateDB) GetInt32

func (self *StateDB) GetInt32(addr common.Address, key []byte) int32

func (*StateDB) GetInt64

func (self *StateDB) GetInt64(addr common.Address, key []byte) int64

func (*StateDB) GetLogs

func (self *StateDB) GetLogs(hash common.Hash) []*types.Log

func (*StateDB) GetNonce

func (self *StateDB) GetNonce(addr common.Address) uint64

func (*StateDB) GetOrNewStateObject

func (self *StateDB) GetOrNewStateObject(addr common.Address) *stateObject

Retrieve a state object or create a new state object if nil.

func (*StateDB) GetOrNewStateObjectSafe added in v1.1.0

func (self *StateDB) GetOrNewStateObjectSafe(addr common.Address) *stateObject

func (*StateDB) GetReceiptHash added in v1.1.0

func (self *StateDB) GetReceiptHash() common.Hash

func (*StateDB) GetReceipts added in v1.1.0

func (self *StateDB) GetReceipts() types.Receipts

func (*StateDB) GetRefund

func (self *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetState

func (self *StateDB) GetState(addr common.Address, key []byte) []byte

GetState retrieves a value from the given account's storage trie.

func (*StateDB) GetStateByCache added in v1.1.0

func (self *StateDB) GetStateByCache(keyTrie string) ([]byte, bool)

GetStateByCache 从模拟交易的缓存中获取状态变动

func (*StateDB) GetStateByKeyTrie added in v1.1.0

func (self *StateDB) GetStateByKeyTrie(addr common.Address, keyTrie string) []byte

GetStateByKeyTrie retrieves a value from the given account's storage trie.

func (*StateDB) GetString

func (self *StateDB) GetString(addr common.Address, key []byte) string

func (*StateDB) GetTxHash added in v1.1.0

func (self *StateDB) GetTxHash() common.Hash

func (*StateDB) GetTxs added in v1.1.0

func (self *StateDB) GetTxs() types.Transactions

func (*StateDB) GetTxsLen added in v1.1.0

func (self *StateDB) GetTxsLen() int

GetTxsLen 获取db加入的模拟交易数

func (*StateDB) HasSuicided

func (self *StateDB) HasSuicided(addr common.Address) bool

func (*StateDB) IntermediateRoot

func (self *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash

IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.

func (*StateDB) IsFwOpened

func (self *StateDB) IsFwOpened(addr common.Address) bool

func (*StateDB) IsProcess added in v1.1.0

func (self *StateDB) IsProcess() bool

IsProcess 判断是否正进行并行计算

func (*StateDB) Logs

func (self *StateDB) Logs() []*types.Log

func (*StateDB) OpenFirewall

func (self *StateDB) OpenFirewall(addr common.Address)

func (*StateDB) Preimages

func (self *StateDB) Preimages() map[common.Hash][]byte

Preimages returns a list of SHA3 preimages that have been submitted.

func (*StateDB) Prepare

func (self *StateDB) Prepare(thash, bhash common.Hash, ti int)

Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.

func (*StateDB) RawDump

func (self *StateDB) RawDump() Dump

func (*StateDB) Reset

func (self *StateDB) Reset(root common.Hash) error

Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.

func (*StateDB) RevertToSnapshot

func (self *StateDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*StateDB) SetAbi

func (self *StateDB) SetAbi(addr common.Address, abi []byte)

todo: new method -> SetAbi

func (*StateDB) SetBalance

func (self *StateDB) SetBalance(addr common.Address, amount *big.Int)

func (*StateDB) SetByte

func (self *StateDB) SetByte(addr common.Address, key []byte, value byte)

func (*StateDB) SetCode

func (self *StateDB) SetCode(addr common.Address, code []byte)

func (*StateDB) SetContractCreator

func (self *StateDB) SetContractCreator(addr, creator common.Address)

func (*StateDB) SetDirty added in v1.1.0

func (self *StateDB) SetDirty(address common.Address)

func (*StateDB) SetFloat32

func (self *StateDB) SetFloat32(addr common.Address, key []byte, value float32)

func (*StateDB) SetFloat64

func (self *StateDB) SetFloat64(addr common.Address, key []byte, value float64)

func (*StateDB) SetFwStatus

func (self *StateDB) SetFwStatus(addr common.Address, status FwStatus)

func (*StateDB) SetHashGenerator added in v1.1.0

func (self *StateDB) SetHashGenerator()

func (*StateDB) SetInt32

func (self *StateDB) SetInt32(addr common.Address, key []byte, value int32)

func (*StateDB) SetInt64

func (self *StateDB) SetInt64(addr common.Address, key []byte, value int64)

func (*StateDB) SetNonce

func (self *StateDB) SetNonce(addr common.Address, nonce uint64)

func (*StateDB) SetState

func (self *StateDB) SetState(address common.Address, key, value []byte)

func (*StateDB) SetStateByCache added in v1.1.0

func (self *StateDB) SetStateByCache(keyTrie string, read *ReadOp)

SetStateByCache 设置读操作的内容

func (*StateDB) SetString

func (self *StateDB) SetString(addr common.Address, key []byte, value string)

func (*StateDB) Snapshot

func (self *StateDB) Snapshot() int

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

func (*StateDB) StartProcess added in v1.1.0

func (self *StateDB) StartProcess()

StartProcess 开始并行计算

func (*StateDB) StopProcess added in v1.1.0

func (self *StateDB) StopProcess()

StopProcess 停止并行计算

func (*StateDB) StorageTrie

func (self *StateDB) StorageTrie(addr common.Address) Trie

StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.

func (*StateDB) SubBalance

func (self *StateDB) SubBalance(addr common.Address, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*StateDB) SubRefund

func (self *StateDB) SubRefund(gas uint64)

SubRefund removes gas from the refund counter. This method will panic if the refund counter goes below zero

func (*StateDB) Suicide

func (self *StateDB) Suicide(addr common.Address) bool

Suicide marks the given account as suicided. This clears the account balance.

The account's state object is still available until the state is committed, getStateObject will return a non-nil account after Suicide.

func (*StateDB) UpdateDirtyObject added in v1.1.0

func (self *StateDB) UpdateDirtyObject()

func (*StateDB) UpdateTrie added in v1.1.0

func (self *StateDB) UpdateTrie(receipts []*types.Receipt, txs []*types.Transaction)

type Storage

type Storage map[string]common.Hash

func (Storage) Copy

func (self Storage) Copy() Storage

Copy a copy of Storage

func (Storage) String

func (self Storage) String() (str string)

type Suicide added in v1.1.0

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

func NewSuicide added in v1.1.0

func NewSuicide(stateObject *stateObject, addr common.Address) *Suicide

type Trie

type Trie interface {
	TryGet(key []byte) ([]byte, error)
	TryUpdate(key, value []byte) error
	TryUpdateValue(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 dbhandle.Putter) error
}

Trie is a Ethereum Merkle Trie.

type TxSimulator added in v1.1.0

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

func NewTxSimulator added in v1.1.0

func NewTxSimulator(sdb *StateDB, transaction *types.Transaction) *TxSimulator

func (*TxSimulator) AddBalance added in v1.1.0

func (txSim *TxSimulator) AddBalance(addr common.Address, amount *big.Int)

AddBalance 模拟交易的balance增加

func (*TxSimulator) AddLog added in v1.1.0

func (txSim *TxSimulator) AddLog(log *types.Log)

func (*TxSimulator) AddNonce added in v1.1.0

func (txSim *TxSimulator) AddNonce(address common.Address)

AddNonce 记录nonce有变更的地址,鉴于nonce的变更都是对原有的nonce+1,这里只记录需要变更的地址

func (*TxSimulator) AddPreimage added in v1.1.0

func (txSim *TxSimulator) AddPreimage(hash common.Hash, bytes []byte)

AddPreimage debug情况下用来记录sha3操作的中间值,不做处理

func (*TxSimulator) AddRefund added in v1.1.0

func (txSim *TxSimulator) AddRefund(u uint64)

func (*TxSimulator) CloneAccount added in v1.1.0

func (txSim *TxSimulator) CloneAccount(src common.Address, dest common.Address) error

CloneAccount 用于合约的迁移,暂时不做处理

func (*TxSimulator) CloseFirewall added in v1.1.0

func (txSim *TxSimulator) CloseFirewall(contractAddr common.Address)

CloseFirewall 记录关闭防火墙的操作

func (*TxSimulator) CreateAccount added in v1.1.0

func (txSim *TxSimulator) CreateAccount(address common.Address)

CreateAccount 记录创建账户的操作

func (*TxSimulator) Empty added in v1.1.0

func (txSim *TxSimulator) Empty(address common.Address) bool

func (*TxSimulator) Exist added in v1.1.0

func (txSim *TxSimulator) Exist(address common.Address) bool

func (*TxSimulator) ForEachStorage added in v1.1.0

func (txSim *TxSimulator) ForEachStorage(address common.Address, f func(common.Hash, common.Hash) bool)

ForEachStorage 暂无调用 不做处理

func (*TxSimulator) FwAdd added in v1.1.0

func (txSim *TxSimulator) FwAdd(contractAddr common.Address, action Action, list []FwElem)

FwAdd 将防火墙的添加最终演变成防火墙的设置操作,并记录该设置操作

func (*TxSimulator) FwClear added in v1.1.0

func (txSim *TxSimulator) FwClear(contractAddr common.Address, action Action)

FwClear 将防火墙的清理最终演变成防火墙的设置操作,并记录该设置操作

func (*TxSimulator) FwDel added in v1.1.0

func (txSim *TxSimulator) FwDel(contractAddr common.Address, action Action, list []FwElem)

FwDel 将防火墙的删除最终演变成防火墙的设置操作,并记录该设置操作

func (*TxSimulator) FwImport added in v1.1.0

func (txSim *TxSimulator) FwImport(contractAddr common.Address, data []byte) error

FwImport 从json数据反序列化信息后,并记录防火墙的设置操作

func (*TxSimulator) FwSet added in v1.1.0

func (txSim *TxSimulator) FwSet(contractAddr common.Address, action Action, list []FwElem)

FwSet 处理数据并记录防火墙的设置操作

func (*TxSimulator) GetAbi added in v1.1.0

func (txSim *TxSimulator) GetAbi(address common.Address) []byte

func (*TxSimulator) GetAbiHash added in v1.1.0

func (txSim *TxSimulator) GetAbiHash(address common.Address) common.Hash

func (*TxSimulator) GetBalance added in v1.1.0

func (txSim *TxSimulator) GetBalance(addr common.Address) *big.Int

SetBalance 模拟交易的balance设置

func (*TxSimulator) GetBalanceMap added in v1.1.0

func (txSim *TxSimulator) GetBalanceMap() map[common.Address]*BalanceOp

func (*TxSimulator) GetCode added in v1.1.0

func (txSim *TxSimulator) GetCode(addr common.Address) []byte

func (*TxSimulator) GetCodeHash added in v1.1.0

func (txSim *TxSimulator) GetCodeHash(address common.Address) common.Hash

func (*TxSimulator) GetCodeSize added in v1.1.0

func (txSim *TxSimulator) GetCodeSize(address common.Address) int

func (*TxSimulator) GetCommittedState added in v1.1.0

func (txSim *TxSimulator) GetCommittedState(address common.Address, key []byte) []byte

func (*TxSimulator) GetContractCreator added in v1.1.0

func (txSim *TxSimulator) GetContractCreator(contractAddr common.Address) common.Address

func (*TxSimulator) GetFwStatus added in v1.1.0

func (txSim *TxSimulator) GetFwStatus(contractAddr common.Address) FwStatus

func (*TxSimulator) GetHash added in v1.1.0

func (txSim *TxSimulator) GetHash() common.Hash

func (*TxSimulator) GetIndex added in v1.1.0

func (txSim *TxSimulator) GetIndex() int

GetIndex 获取交易在区块内的位置

func (*TxSimulator) GetLogs added in v1.1.0

func (txSim *TxSimulator) GetLogs(hash common.Hash) []*types.Log

func (*TxSimulator) GetNonce added in v1.1.0

func (txSim *TxSimulator) GetNonce(address common.Address) uint64

func (*TxSimulator) GetReadMap added in v1.1.0

func (txSim *TxSimulator) GetReadMap() map[string]*ReadOp

func (*TxSimulator) GetReceipt added in v1.1.0

func (txSim *TxSimulator) GetReceipt() *types.Receipt

func (*TxSimulator) GetRefund added in v1.1.0

func (txSim *TxSimulator) GetRefund() uint64

func (*TxSimulator) GetState added in v1.1.0

func (txSim *TxSimulator) GetState(addr common.Address, key []byte) []byte

GetState 获取数据操作

func (*TxSimulator) GetWriteMap added in v1.1.0

func (txSim *TxSimulator) GetWriteMap() map[string]*WriteOp

func (*TxSimulator) HasSuicided added in v1.1.0

func (txSim *TxSimulator) HasSuicided(address common.Address) bool

func (*TxSimulator) IsFwOpened added in v1.1.0

func (txSim *TxSimulator) IsFwOpened(contractAddr common.Address) bool

func (*TxSimulator) Logs added in v1.1.0

func (txSim *TxSimulator) Logs() []*types.Log

func (*TxSimulator) OpenFirewall added in v1.1.0

func (txSim *TxSimulator) OpenFirewall(contractAddr common.Address)

OpenFirewall 记录开启防火墙的操作

func (*TxSimulator) ReTry added in v1.1.0

func (txSim *TxSimulator) ReTry() bool

ReTry 用于判断是否需要重新模拟

func (*TxSimulator) RevertToSnapshot added in v1.1.0

func (txSim *TxSimulator) RevertToSnapshot(i int)

RevertToSnapshot 用于回退模拟交易

func (*TxSimulator) SetAbi added in v1.1.0

func (txSim *TxSimulator) SetAbi(address common.Address, bytes []byte)

SetAbi 记录设置abi的操作

func (*TxSimulator) SetBalance added in v1.1.0

func (txSim *TxSimulator) SetBalance(addr common.Address, amount *big.Int)

SetBalance 模拟交易的balance设置

func (*TxSimulator) SetCode added in v1.1.0

func (txSim *TxSimulator) SetCode(address common.Address, bytes []byte)

SetCode 记录设置代码的操作

func (*TxSimulator) SetContractCreator added in v1.1.0

func (txSim *TxSimulator) SetContractCreator(contractAddr common.Address, creator common.Address)

SetContractCreator 优先判断地址是否是合约,如果是则为合约设置创建人,并记录该操作

func (*TxSimulator) SetFwStatus added in v1.1.0

func (txSim *TxSimulator) SetFwStatus(contractAddr common.Address, status FwStatus)

SetFwStatus 拆分成防火墙的数据设置操作和防火墙的活跃操作,并记录

func (*TxSimulator) SetIndex added in v1.1.0

func (txSim *TxSimulator) SetIndex(index int)

SetIndex 用于标识交易在区块内的位置

func (*TxSimulator) SetNonce added in v1.1.0

func (txSim *TxSimulator) SetNonce(address common.Address, u uint64)

SetNonce 记录nonce有变更的地址,鉴于nonce的变更都是对原有的nonce+1,这里只记录需要变更的地址

func (*TxSimulator) SetReceipt added in v1.1.0

func (txSim *TxSimulator) SetReceipt(rec *types.Receipt)

func (*TxSimulator) SetState added in v1.1.0

func (txSim *TxSimulator) SetState(addr common.Address, key, value []byte)

SetState 将设置的操作存于writeSet内

func (*TxSimulator) Snapshot added in v1.1.0

func (txSim *TxSimulator) Snapshot() int

func (*TxSimulator) SubBalance added in v1.1.0

func (txSim *TxSimulator) SubBalance(addr common.Address, amount *big.Int)

SubBalance 模拟交易的balance减少

func (*TxSimulator) SubRefund added in v1.1.0

func (txSim *TxSimulator) SubRefund(u uint64)

func (*TxSimulator) Suicide added in v1.1.0

func (txSim *TxSimulator) Suicide(address common.Address) bool

Suicide 查看是否需要进行自杀操作,如果需要则记录自杀操作,并记录balance变更的操作

type ValueStorage

type ValueStorage map[common.Hash][]byte

func (ValueStorage) Copy

func (self ValueStorage) Copy() ValueStorage

type WriteOp added in v1.1.0

type WriteOp struct {
	ContractAddress common.Address //合约地址
	Key             []byte         //
	KeyTrie         string
	KeyValue        []byte
	ValueKey        common.Hash
	Value           []byte
	Version         int //txSimulator中用到的版本号
	// contains filtered or unexported fields
}

type WriteSet added in v1.1.0

type WriteSet []*WriteOp

Jump to

Keyboard shortcuts

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