forking

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountDiff

type AccountDiff struct {
	// Nonce change.
	// No diff if nil.
	Nonce *uint64 `json:"nonce"`

	// Balance change.
	// No diff if nil.
	Balance *uint256.Int `json:"balance"`

	// Storage changes.
	// No diff if not present in map. Deletions are zero-value entries.
	Storage map[common.Hash]common.Hash `json:"storage"`

	// CodeHash, for lookup of contract bytecode in the code diff map.
	// No code-diff if nil.
	CodeHash *common.Hash `json:"codeHash"`
}

AccountDiff represents changes to an account. Unchanged values of the account are not included.

func (*AccountDiff) Copy

func (d *AccountDiff) Copy() *AccountDiff

type CachedSource

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

CachedSource wraps a ForkSource, and caches the retrieved data for faster repeat-queries. The ForkSource should be immutable (as per the StateRoot value). All cache data accumulates in-memory in LRU collections per data type.

func Cache

func Cache(src ForkSource) *CachedSource

func (*CachedSource) Balance

func (c *CachedSource) Balance(addr common.Address) (*uint256.Int, error)

func (*CachedSource) Code

func (c *CachedSource) Code(addr common.Address) ([]byte, error)

func (*CachedSource) Nonce

func (c *CachedSource) Nonce(addr common.Address) (uint64, error)

func (*CachedSource) StateRoot

func (c *CachedSource) StateRoot() common.Hash

func (*CachedSource) StorageAt

func (c *CachedSource) StorageAt(addr common.Address, key common.Hash) (common.Hash, error)

func (*CachedSource) URLOrAlias

func (c *CachedSource) URLOrAlias() string

type ExportDiff

type ExportDiff struct {
	// Accounts diff. Deleted accounts are set to nil.
	// Warning: this only contains finalized state changes.
	// The state itself holds on to non-flushed changes.
	Account map[common.Address]*AccountDiff `json:"account"`

	// Stores new contract codes by code-hash
	Code map[common.Hash][]byte `json:"code"`
}

func NewExportDiff

func NewExportDiff() *ExportDiff

func (*ExportDiff) Any

func (ed *ExportDiff) Any() bool

func (*ExportDiff) Clear

func (ed *ExportDiff) Clear()

func (*ExportDiff) Copy

func (ed *ExportDiff) Copy() *ExportDiff

type ForkDB

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

ForkDB is a virtual state database: it wraps a forked accounts trie, and can maintain a state diff, so we can mutate the forked state, and even finalize state changes (so we can accurately measure things like cold storage gas cost).

func NewForkDB

func NewForkDB(source ForkSource) *ForkDB

func (*ForkDB) ContractCode

func (f *ForkDB) ContractCode(addr common.Address, codeHash common.Hash) ([]byte, error)

func (*ForkDB) ContractCodeSize

func (f *ForkDB) ContractCodeSize(addr common.Address, codeHash common.Hash) (int, error)

func (*ForkDB) CopyTrie

func (f *ForkDB) CopyTrie(trie state.Trie) state.Trie

func (*ForkDB) DiskDB

func (f *ForkDB) DiskDB() ethdb.KeyValueStore

func (*ForkDB) OpenStorageTrie

func (f *ForkDB) OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, trie state.Trie) (state.Trie, error)

func (*ForkDB) OpenTrie

func (f *ForkDB) OpenTrie(root common.Hash) (state.Trie, error)

func (*ForkDB) PointCache

func (f *ForkDB) PointCache() *utils.PointCache

func (*ForkDB) Reader

func (f *ForkDB) Reader(root common.Hash) (state.Reader, error)

Reader for read-only access to a known state. All cold reads go through this. So the state-DB creates one initially, and then holds on to it. The diff will be overlayed on the reader still. To get rid of the diff, it has to be explicitly cleared. Warning: diffs applied to the original state that the reader wraps will be visible. Geth StateDB is meant to be reinitialized after committing state.

func (*ForkDB) Snapshot

func (f *ForkDB) Snapshot() *snapshot.Tree

func (*ForkDB) TrieDB

func (f *ForkDB) TrieDB() *triedb.Database

type ForkID

type ForkID uint256.Int

ForkID is an identifier of a fork

func ForkIDFromBig

func ForkIDFromBig(b *big.Int) ForkID

func (ForkID) String

func (id ForkID) String() string

func (*ForkID) U256

func (id *ForkID) U256() *uint256.Int

U256 returns a uint256 copy of the fork ID, for usage inside the EVM.

type ForkSource

type ForkSource interface {
	// URLOrAlias returns the URL or alias that the fork uses. This is not unique to a single fork.
	URLOrAlias() string
	// StateRoot returns the accounts-trie root of the committed-to state.
	// This root must never change.
	StateRoot() common.Hash
	// Nonce returns 0, without error, if the account does not exist.
	Nonce(addr common.Address) (uint64, error)
	// Balance returns 0, without error, if the account does not exist.
	Balance(addr common.Address) (*uint256.Int, error)
	// StorageAt returns a zeroed hash, without error, if the storage does not exist.
	StorageAt(addr common.Address, key common.Hash) (common.Hash, error)
	// Code returns an empty byte slice, without error, if no code exists.
	Code(addr common.Address) ([]byte, error)
}

ForkSource is a read-only source for ethereum state, that can be used to fork a ForkableState.

type ForkableState

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

ForkableState implements the vm.StateDB interface, and a few other methods as defined in the VMStateDB interface. This state can be forked in-place, swapping over operations to route to in-memory states that wrap fork sources.

func NewForkableState

func NewForkableState(base VMStateDB) *ForkableState

func (*ForkableState) ActiveFork

func (fst *ForkableState) ActiveFork() (id ForkID, active bool)

ActiveFork returns the ID current active fork, or active == false if no fork is active.

func (*ForkableState) AddAddressToAccessList

func (fst *ForkableState) AddAddressToAccessList(addr common.Address)

func (*ForkableState) AddBalance

func (fst *ForkableState) AddBalance(address common.Address, u *uint256.Int, reason tracing.BalanceChangeReason)

func (*ForkableState) AddLog

func (fst *ForkableState) AddLog(log *types.Log)

func (*ForkableState) AddPreimage

func (fst *ForkableState) AddPreimage(hash common.Hash, img []byte)

func (*ForkableState) AddRefund

func (fst *ForkableState) AddRefund(u uint64)

func (*ForkableState) AddSlotToAccessList

func (fst *ForkableState) AddSlotToAccessList(addr common.Address, slot common.Hash)

func (*ForkableState) AddressInAccessList

func (fst *ForkableState) AddressInAccessList(addr common.Address) bool

func (*ForkableState) CreateAccount

func (fst *ForkableState) CreateAccount(address common.Address)

func (*ForkableState) CreateContract

func (fst *ForkableState) CreateContract(address common.Address)

func (*ForkableState) CreateFork

func (fst *ForkableState) CreateFork(source ForkSource) (ForkID, error)

CreateFork is like vm.createFork, it creates a fork, but does not select it yet.

func (*ForkableState) CreateSelectFork

func (fst *ForkableState) CreateSelectFork(source ForkSource) (ForkID, error)

CreateSelectFork is like vm.createSelectFork, it creates a fork, and selects it immediately.

func (*ForkableState) Empty

func (fst *ForkableState) Empty(address common.Address) bool

func (*ForkableState) Exist

func (fst *ForkableState) Exist(address common.Address) bool

func (*ForkableState) ExportDiff

func (fst *ForkableState) ExportDiff(id ForkID) (*ExportDiff, error)

ExportDiff exports a state diff. Warning: diffs are like flushed states. So we flush the state, making all the contents cold, losing transient storage, etc.

func (*ForkableState) Finalise

func (fst *ForkableState) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the destructed objects and clears the journal as well as the refunds. Finalise, however, will not push any updates into the tries just yet.

The changes will be flushed to the underlying DB. A *ForkDB if the state is currently forked.

func (*ForkableState) ForkURLOrAlias

func (fst *ForkableState) ForkURLOrAlias(id ForkID) (string, error)

ForkURLOrAlias returns the URL or alias that the fork was configured with as source. Returns an error if no fork is active

func (*ForkableState) GetBalance

func (fst *ForkableState) GetBalance(address common.Address) *uint256.Int

func (*ForkableState) GetCode

func (fst *ForkableState) GetCode(address common.Address) []byte

func (*ForkableState) GetCodeHash

func (fst *ForkableState) GetCodeHash(address common.Address) common.Hash

func (*ForkableState) GetCodeSize

func (fst *ForkableState) GetCodeSize(address common.Address) int

func (*ForkableState) GetCommittedState

func (fst *ForkableState) GetCommittedState(address common.Address, hash common.Hash) common.Hash

func (*ForkableState) GetNonce

func (fst *ForkableState) GetNonce(address common.Address) uint64

func (*ForkableState) GetRefund

func (fst *ForkableState) GetRefund() uint64

func (*ForkableState) GetState

func (fst *ForkableState) GetState(address common.Address, k common.Hash) common.Hash

func (*ForkableState) GetStorageRoot

func (fst *ForkableState) GetStorageRoot(addr common.Address) common.Hash

func (*ForkableState) GetTransientState

func (fst *ForkableState) GetTransientState(addr common.Address, key common.Hash) common.Hash

func (*ForkableState) HasSelfDestructed

func (fst *ForkableState) HasSelfDestructed(address common.Address) bool

func (*ForkableState) IsPersistent

func (fst *ForkableState) IsPersistent(addr common.Address) bool

IsPersistent is like vm.isPersistent, it checks if an account persists across forks.

func (*ForkableState) MakeExcluded

func (fst *ForkableState) MakeExcluded(addr common.Address)

MakeExcluded excludes an account from forking. This is useful for things like scripts, which should always use the fallback state.

func (*ForkableState) MakePersistent

func (fst *ForkableState) MakePersistent(addr common.Address)

MakePersistent is like vm.makePersistent, it maintains this account context across all forks. It does not make the account of a fork persistent, it makes an account override what might be in a fork.

func (*ForkableState) PointCache

func (fst *ForkableState) PointCache() *utils.PointCache

func (*ForkableState) Prepare

func (fst *ForkableState) Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)

func (*ForkableState) ResetFork

func (fst *ForkableState) ResetFork(id ForkID, src ForkSource) error

ResetFork resets the fork to be coupled to the given fork-source. Any ephemeral state changes (transient storage, warm s-loads, etc.) as well as any uncommitted state, as well as any previously flushed diffs, will be lost.

func (*ForkableState) RevertToSnapshot

func (fst *ForkableState) RevertToSnapshot(i int)

func (*ForkableState) RevokeExcluded

func (fst *ForkableState) RevokeExcluded(addr common.Address)

RevokeExcluded undoes MakeExcluded. It will panic if the account was marked as persistent in a different fork.

func (*ForkableState) RevokePersistent

func (fst *ForkableState) RevokePersistent(addr common.Address)

RevokePersistent is like vm.revokePersistent, it undoes a previous vm.makePersistent.

func (*ForkableState) SelectFork

func (fst *ForkableState) SelectFork(id ForkID) error

SelectFork is like vm.selectFork, it activates the usage of a previously created fork.

func (*ForkableState) SelfDestruct

func (fst *ForkableState) SelfDestruct(address common.Address)

func (*ForkableState) Selfdestruct6780

func (fst *ForkableState) Selfdestruct6780(address common.Address)

func (*ForkableState) SetBalance

func (fst *ForkableState) SetBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason)

func (*ForkableState) SetCode

func (fst *ForkableState) SetCode(address common.Address, bytes []byte)

func (*ForkableState) SetNonce

func (fst *ForkableState) SetNonce(address common.Address, u uint64)

func (*ForkableState) SetState

func (fst *ForkableState) SetState(address common.Address, k common.Hash, v common.Hash)

func (*ForkableState) SetTransientState

func (fst *ForkableState) SetTransientState(addr common.Address, key, value common.Hash)

func (*ForkableState) SlotInAccessList

func (fst *ForkableState) SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)

func (*ForkableState) Snapshot

func (fst *ForkableState) Snapshot() int

func (*ForkableState) SubBalance

func (fst *ForkableState) SubBalance(address common.Address, u *uint256.Int, reason tracing.BalanceChangeReason)

func (*ForkableState) SubRefund

func (fst *ForkableState) SubRefund(u uint64)

func (*ForkableState) SubstituteBaseState

func (fst *ForkableState) SubstituteBaseState(base VMStateDB)

SubstituteBaseState substitutes in a fallback state.

func (*ForkableState) Witness

func (fst *ForkableState) Witness() *stateless.Witness

type ForkedAccountsTrie

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

func (*ForkedAccountsTrie) ClearDiff

func (f *ForkedAccountsTrie) ClearDiff()

ClearDiff clears the flushed changes. This does not clear the warm state changes. To fully clear, first Finalise the forked state that uses this trie, and then clear the diff.

func (*ForkedAccountsTrie) Commit

func (f *ForkedAccountsTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet)

func (*ForkedAccountsTrie) ContractCode

func (f *ForkedAccountsTrie) ContractCode(addr common.Address, codeHash common.Hash) ([]byte, error)

ContractCode is not directly part of the vm.State interface, but is used by the ForkDB to retrieve the contract code.

func (*ForkedAccountsTrie) ContractCodeSize

func (f *ForkedAccountsTrie) ContractCodeSize(addr common.Address, codeHash common.Hash) (int, error)

ContractCodeSize is not directly part of the vm.State interface, but is used by the ForkDB to retrieve the contract code-size.

func (*ForkedAccountsTrie) Copy

func (*ForkedAccountsTrie) DeleteAccount

func (f *ForkedAccountsTrie) DeleteAccount(address common.Address) error

func (*ForkedAccountsTrie) DeleteStorage

func (f *ForkedAccountsTrie) DeleteStorage(addr common.Address, key []byte) error

func (*ForkedAccountsTrie) ExportDiff

func (f *ForkedAccountsTrie) ExportDiff() *ExportDiff

func (*ForkedAccountsTrie) GetAccount

func (f *ForkedAccountsTrie) GetAccount(address common.Address) (*types.StateAccount, error)

func (*ForkedAccountsTrie) GetKey

func (f *ForkedAccountsTrie) GetKey(bytes []byte) []byte

func (*ForkedAccountsTrie) GetStorage

func (f *ForkedAccountsTrie) GetStorage(addr common.Address, key []byte) ([]byte, error)

func (*ForkedAccountsTrie) HasDiff

func (f *ForkedAccountsTrie) HasDiff() bool

func (*ForkedAccountsTrie) Hash

func (f *ForkedAccountsTrie) Hash() common.Hash

func (*ForkedAccountsTrie) IsVerkle

func (f *ForkedAccountsTrie) IsVerkle() bool

func (*ForkedAccountsTrie) NodeIterator

func (f *ForkedAccountsTrie) NodeIterator(startKey []byte) (trie.NodeIterator, error)

func (*ForkedAccountsTrie) Prove

func (f *ForkedAccountsTrie) Prove(key []byte, proofDb ethdb.KeyValueWriter) error

func (*ForkedAccountsTrie) UpdateAccount

func (f *ForkedAccountsTrie) UpdateAccount(address common.Address, account *types.StateAccount, codeLen int) error

func (*ForkedAccountsTrie) UpdateContractCode

func (f *ForkedAccountsTrie) UpdateContractCode(addr common.Address, codeHash common.Hash, code []byte) error

func (*ForkedAccountsTrie) UpdateStorage

func (f *ForkedAccountsTrie) UpdateStorage(addr common.Address, key, value []byte) error

func (*ForkedAccountsTrie) Witness

func (f *ForkedAccountsTrie) Witness() map[string]struct{}
type Header struct {
	StateRoot common.Hash `json:"stateRoot"`
	BlockHash common.Hash `json:"hash"`
}

type RPCClient

type RPCClient interface {
	CallContext(ctx context.Context, result any, method string, args ...any) error
}

type RPCSource

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

func RPCSourceByHash

func RPCSourceByHash(urlOrAlias string, cl RPCClient, h common.Hash) (*RPCSource, error)

func RPCSourceByNumber

func RPCSourceByNumber(urlOrAlias string, cl RPCClient, num uint64) (*RPCSource, error)

func (*RPCSource) Balance

func (r *RPCSource) Balance(addr common.Address) (*uint256.Int, error)

func (*RPCSource) BlockHash

func (r *RPCSource) BlockHash() common.Hash

func (*RPCSource) Close

func (r *RPCSource) Close()

Close stops any ongoing RPC requests by cancelling the RPC context

func (*RPCSource) Code

func (r *RPCSource) Code(addr common.Address) ([]byte, error)

func (*RPCSource) Nonce

func (r *RPCSource) Nonce(addr common.Address) (uint64, error)

func (*RPCSource) StateRoot

func (r *RPCSource) StateRoot() common.Hash

func (*RPCSource) StorageAt

func (r *RPCSource) StorageAt(addr common.Address, key common.Hash) (common.Hash, error)

func (*RPCSource) URLOrAlias

func (c *RPCSource) URLOrAlias() string

type VMStateDB

type VMStateDB interface {
	vm.StateDB
	Finalise(deleteEmptyObjects bool)
	// SetBalance sets the balance of an account. Not part of the geth VM StateDB interface (add/sub balance are).
	SetBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason)
}

Jump to

Keyboard shortcuts

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