operationdb

package
v0.0.0-...-de85661 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Unlicense Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStateSync

func NewStateSync(root entity.Hash, database typedb.KeyValueReader, onLeaf func(paths [][]byte, leaf []byte) error) *trie.Sync

NewStateSync create a new state trie download scheduler.

Types

type Code

type Code []byte

type DatabaseI

type DatabaseI interface {
	// 打开主帐户trie。
	OpenTrie(root entity.Hash) (TrieI, error)

	// 打开帐户的存储trie。
	OpenStorageTrie(addrHash, root entity.Hash) (TrieI, error)

	// CopyTrie返回给定trie的独立副本。
	CopyTrie(TrieI) TrieI

	// ContractCode检索特定合同的代码。
	ContractCode(addrHash, codeHash entity.Hash) ([]byte, error)

	// ContractCodeSize检索特定合同代码的大小。
	ContractCodeSize(addrHash, codeHash entity.Hash) (int, error)

	// TrieDB检索用于数据存储的低级trie数据库。
	TrieDB() *trie.TrieDatabase
}

func NewDatabase

func NewDatabase(db typedb.Database) DatabaseI

NewDatabase为状态创建备份存储。返回的数据库可以安全地并发使用,但不会在内存中保留任何最近的trie节点。 要在内存中保留一些历史状态,请使用NewDatabaseWithConfig构造函数。

func NewDatabaseWithConfig

func NewDatabaseWithConfig(db typedb.Database, config *trie.Config) DatabaseI

NewDatabaseWithConfig为状态创建备份存储。 返回的数据库可以安全地并发使用,并在大型内存缓存中保留大量折叠的RLP trie节点。

type Journal

type Journal struct {
	Dirties map[entity.Address]int // 脏账户和更改数量
	// contains filtered or unexported fields
}

日志包含自上次状态提交以来应用的状态修改列表。这些被跟踪,以便在执行异常或请求撤销时能够恢复。

func NewJournal

func NewJournal() *Journal

newJournal创建一个新的初始化日志。

type OperationDB

type OperationDB struct {
	OperationObjects        map[entity.Address]*OperationObject // 数据库活动对象缓存map集合
	OperationObjectsPending map[entity.Address]struct{}         //状态对象已完成但尚未写入trie
	OperationObjectsDirty   map[entity.Address]struct{}         // 当前执行中修改的状态对象

	//AccountReads         time.Duration
	//AccountHashes        time.Duration
	//AccountUpdates       time.Duration
	//AccountCommits       time.Duration
	//StorageReads         time.Duration
	//StorageHashes        time.Duration
	//StorageUpdates       time.Duration
	//StorageCommits       time.Duration
	//SnapshotAccountReads time.Duration
	//SnapshotStorageReads time.Duration
	//SnapshotCommits      time.Duration
	//
	AccountUpdated int
	StorageUpdated int
	AccountDeleted int
	StorageDeleted int
	// contains filtered or unexported fields
}

数据库操作结构体

func NewOperationDb

func NewOperationDb(root entity.Hash, db DatabaseI) (*OperationDB, error)

创建根状态数据库

func (*OperationDB) AddAddressToAccessList

func (o *OperationDB) AddAddressToAccessList(addr entity.Address)

func (*OperationDB) AddBalance

func (o *OperationDB) AddBalance(address entity.Address, amount *big.Int)

headerTDMark将金额添加到与addr关联的帐户。

func (*OperationDB) AddLog

func (o *OperationDB) AddLog(log *block.Log)

func (*OperationDB) AddPreimage

func (o *OperationDB) AddPreimage(hash entity.Hash, bytes []byte)

func (*OperationDB) AddRefund

func (o *OperationDB) AddRefund(gas uint64)

添加退款向退款柜台添加气体

func (*OperationDB) AddSlotToAccessList

func (o *OperationDB) AddSlotToAccessList(addr entity.Address, slot entity.Hash)

func (*OperationDB) AddressInAccessList

func (o *OperationDB) AddressInAccessList(addr entity.Address) bool

func (*OperationDB) Ancient

func (o *OperationDB) Ancient(kind string, number uint64) ([]byte, error)

func (*OperationDB) AncientRange

func (o *OperationDB) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error)

func (*OperationDB) AncientSize

func (o *OperationDB) AncientSize(kind string) (uint64, error)

func (*OperationDB) Ancients

func (o *OperationDB) Ancients() (uint64, error)

func (*OperationDB) Commit

func (o *OperationDB) Commit(deleteEmptyObjects bool) (entity.Hash, error)

Commit将状态写入底层内存中的trie数据库。

func (*OperationDB) Copy

func (s *OperationDB) Copy() *OperationDB

复制创建状态的深度、独立副本。复制状态的快照无法应用于副本。

func (*OperationDB) CreateAccount

func (o *OperationDB) CreateAccount(address entity.Address)

func (*OperationDB) Database

func (o *OperationDB) Database() DatabaseI

数据库检索支持较低级别trie操作的低级别数据库。

func (*OperationDB) Empty

func (o *OperationDB) Empty(address entity.Address) bool

func (*OperationDB) Error

func (s *OperationDB) Error() error

func (*OperationDB) Exist

func (o *OperationDB) Exist(address entity.Address) bool

func (*OperationDB) Finalise

func (o *OperationDB) Finalise(deleteEmptyObjects bool)

Finalize通过删除o销毁的对象来最终确定状态,并清除日记账和退款。 不过,Finalize目前还不会将任何更新推送到试用中。只有IntermediateRoot或Commit会这样做。

func (*OperationDB) ForEachStorage

func (o *OperationDB) ForEachStorage(address entity.Address, f func(entity.Hash, entity.Hash) bool) error

func (*OperationDB) GetBalance

func (o *OperationDB) GetBalance(address entity.Address) *big.Int

func (*OperationDB) GetCode

func (o *OperationDB) GetCode(address entity.Address) []byte

func (*OperationDB) GetCodeHash

func (o *OperationDB) GetCodeHash(address entity.Address) entity.Hash

func (*OperationDB) GetCodeSize

func (o *OperationDB) GetCodeSize(address entity.Address) int

func (*OperationDB) GetCommittedState

func (o *OperationDB) GetCommittedState(address entity.Address, hash entity.Hash) entity.Hash

GetCommittedState从给定帐户的提交存储trie中检索值。

func (*OperationDB) GetNonce

func (o *OperationDB) GetNonce(address entity.Address) uint64

func (*OperationDB) GetOrNewOperationObject

func (o *OperationDB) GetOrNewOperationObject(address entity.Address) *OperationObject

GetOrNewOperationObject检索操作对象,如果为nil,则创建新的操作对象。

func (*OperationDB) GetProof

func (o *OperationDB) GetProof(addr entity.Address) ([][]byte, error)

GetProof返回给定帐户的Merkle证明。

func (*OperationDB) GetProofByHash

func (o *OperationDB) GetProofByHash(addrHash entity.Hash) ([][]byte, error)

GetProofByHash返回给定帐户的Merkle证明。

func (*OperationDB) GetRefund

func (o *OperationDB) GetRefund() uint64

GetReturn返回退款计数器的当前值。

func (*OperationDB) GetState

func (o *OperationDB) GetState(address entity.Address, hash entity.Hash) entity.Hash

func (*OperationDB) GetStorageProof

func (o *OperationDB) GetStorageProof(a entity.Address, key entity.Hash) ([][]byte, error)

GetStorageProof returns the Merkle proof for given storage slot.

func (*OperationDB) HasAncient

func (o *OperationDB) HasAncient(kind string, number uint64) (bool, error)

func (*OperationDB) HasSuicided

func (o *OperationDB) HasSuicided(address entity.Address) bool

func (*OperationDB) IntermediateRoot

func (o *OperationDB) IntermediateRoot(deleteEmptyObjects bool) entity.Hash

IntermediateRoot计算状态trie的当前根哈希。在事务之间调用它以获取进入事务收据的根哈希。

func (*OperationDB) Prepare

func (s *OperationDB) Prepare(thash entity.Hash, ti int)

Prepare设置EVM发出新状态日志时使用的当前事务哈希和索引。

func (*OperationDB) ReadAncients

func (db *OperationDB) ReadAncients(fn func(op typedb.AncientReaderOp) error) (err error)

Ancient的实现

func (*OperationDB) RevertToSnapshot

func (o *OperationDB) RevertToSnapshot(i int)

func (*OperationDB) SetBalance

func (o *OperationDB) SetBalance(addr entity.Address, amount *big.Int)

func (*OperationDB) SetCode

func (o *OperationDB) SetCode(address entity.Address, code []byte)

func (*OperationDB) SetNonce

func (o *OperationDB) SetNonce(address entity.Address, nonce uint64)

func (*OperationDB) SetState

func (o *OperationDB) SetState(address entity.Address, key entity.Hash, hash entity.Hash)

func (*OperationDB) SetStorage

func (o *OperationDB) SetStorage(addr entity.Address, storage map[entity.Hash]entity.Hash)

设置存储将指定帐户的整个存储替换为给定存储。此函数只能用于调试。

func (*OperationDB) SlotInAccessList

func (o *OperationDB) SlotInAccessList(addr entity.Address, slot entity.Hash) (addressOk bool, slotOk bool)

func (*OperationDB) Snapshot

func (o *OperationDB) Snapshot() int

func (*OperationDB) StopPrefetcher

func (s *OperationDB) StopPrefetcher()

StopRefetcher终止正在运行的预取程序,并报告收集的度量中的任何剩余统计信息。

func (*OperationDB) StorageTrie

func (o *OperationDB) StorageTrie(addr entity.Address) TrieI

StorageTrie返回帐户的存储trie。返回值为副本,对于不存在的帐户,返回值为零。

func (*OperationDB) SubBalance

func (o *OperationDB) SubBalance(address entity.Address, amount *big.Int)

子平衡从与addr关联的帐户中减去金额。

func (*OperationDB) SubRefund

func (o *OperationDB) SubRefund(gas uint64)

SubRefund将汽油从退款柜台中取出。如果退款计数器低于零,此方法将死机

func (*OperationDB) Suicide

func (o *OperationDB) Suicide(address entity.Address) bool

func (*OperationDB) Tail

func (o *OperationDB) Tail() (uint64, error)

type OperationObject

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

数据库存储对象

func (*OperationObject) AddBalance

func (s *OperationObject) AddBalance(amount *big.Int)

AddBalance将金额添加到s的余额中。它用于将资金添加到转账的目标帐户。

func (*OperationObject) Address

func (s *OperationObject) Address() entity.Address

返回合同/帐户的地址

func (*OperationObject) Balance

func (s *OperationObject) Balance() *big.Int

func (*OperationObject) Code

func (s *OperationObject) Code(db DatabaseI) []byte

代码返回与此对象关联的合同代码(如果有)。

func (*OperationObject) CodeHash

func (s *OperationObject) CodeHash() []byte

func (*OperationObject) CodeSize

func (s *OperationObject) CodeSize(db DatabaseI) int

CodeSize返回与此对象关联的合同代码的大小,如果没有,则返回零。 这种方法几乎是代码的镜像,但在数据库中使用缓存来避免加载最近看到的代码。

func (*OperationObject) CommitTrie

func (o *OperationObject) CommitTrie(db DatabaseI) (int, error)

将对象的存储trie提交给db。这将更新trie根目录。

func (*OperationObject) GetCommittedState

func (s *OperationObject) GetCommittedState(db DatabaseI, key entity.Hash) entity.Hash

GetCommittedState从提交的帐户存储trie中检索值。

func (*OperationObject) GetState

func (s *OperationObject) GetState(db DatabaseI, key entity.Hash) entity.Hash

GetState从帐户存储trie中检索值。

func (*OperationObject) Nonce

func (s *OperationObject) Nonce() uint64

func (*OperationObject) SetBalance

func (s *OperationObject) SetBalance(amount *big.Int)

func (*OperationObject) SetCode

func (s *OperationObject) SetCode(codeHash entity.Hash, code []byte)

func (*OperationObject) SetNonce

func (s *OperationObject) SetNonce(nonce uint64)

func (*OperationObject) SetState

func (s *OperationObject) SetState(db DatabaseI, key, value entity.Hash)

设置状态更新帐户存储中的值。

func (*OperationObject) SetStorage

func (s *OperationObject) SetStorage(storage map[entity.Hash]entity.Hash)

设置存储用给定的状态存储替换整个状态存储。 调用此函数后,将忽略所有原始状态,并且状态查找仅在伪状态存储中发生。 注意:此功能仅用于调试目的。

func (*OperationObject) SubBalance

func (s *OperationObject) SubBalance(amount *big.Int)

子平衡从s的余额中删除金额。它用于从转账的原始帐户中删除资金。

type Storage

type Storage map[entity.Hash]entity.Hash

func (Storage) Copy

func (s Storage) Copy() Storage

func (Storage) String

func (s Storage) String() (str string)

type TrieI

type TrieI interface {
	// GetKey返回以前用于存储值的哈希键的sha3前映像。
	GetKey([]byte) ([]byte, error)

	//TryGet返回存储在trie中的键的值。调用者不得修改值字节。如果在数据库中找不到节点,则会创建一个trie。将返回MissingNodeError。
	TryGet(key []byte) ([]byte, error)

	// TryUpdateAccount摘要在trie中写入的帐户。
	TryUpdateAccount(key []byte, account *entity.StateAccount) error

	// TryUpdate将键与trie中的值相关联。如果值的长度为零,则会从trie中删除任何现有值。
	//值字节存储在trie中时,调用者不得修改它们。如果在数据库中找不到节点,则会创建一个trie。将返回MissingNodeError。
	TryUpdate(key, value []byte) error

	// TryDelete从trie中删除key的所有现有值。如果在数据库中找不到节点,则会创建一个trie。将返回MissingNodeError。
	TryDelete(key []byte) error

	// 哈希返回trie的根哈希。它不会写入数据库,即使trie没有数据库,也可以使用它。
	Hash() entity.Hash

	// Commit将所有节点写入trie的内存数据库,跟踪内部和外部(用于帐户尝试)引用。
	Commit(onleaf trie.LeafCallback) (entity.Hash, int, error)

	// Prove为key构造了一个Merkle证明。结果包含指向键处值的路径上的所有编码节点。值本身也包含在最后一个节点中,可以通过验证证明来检索。
	//如果trie不包含key的值,则返回的证明将包含该key现有前缀最长的所有节点(至少是根节点),以证明没有该key的节点结束。
	Prove(key []byte, fromLevel uint, proofDb typedb.KeyValueWriter) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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