state

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmptyBackend

type EmptyBackend struct{}

EmptyBackend defines a backend containing no data. Intended to be used for local-only state databases.

func (EmptyBackend) GetStateObject

func (d EmptyBackend) GetStateObject(address common.Address) (*uint256.Int, uint64, []byte, error)

func (EmptyBackend) GetStorageAt

func (d EmptyBackend) GetStorageAt(address common.Address, hash common.Hash) (common.Hash, error)

type ForkedStateFactory

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

ForkedStateFactory is used to build StateDBs that are backed by a remote RPC

func NewForkedStateFactory

func NewForkedStateFactory(globalCache stateBackend) *ForkedStateFactory

func (*ForkedStateFactory) New

type MedusaStateFactory

type MedusaStateFactory interface {
	// New initializes a new state
	New(root common.Hash, db state.Database) (types.MedusaStateDB, error)
}

MedusaStateFactory defines a thread-safe interface for creating new state databases. This abstraction allows globally shared data like RPC caches to be shared across all TestChain instances.

type RPCBackend

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

RPCBackend defines a stateBackend for fetching state from a remote RPC server. It is locked to a single block height, and caches data in-memory with no expiry.

func NewRPCBackend

func NewRPCBackend(
	ctx context.Context,
	url string,
	height uint64,
	poolSize uint) (*RPCBackend, error)

func (*RPCBackend) GetStateObject

func (q *RPCBackend) GetStateObject(addr common.Address) (*uint256.Int, uint64, []byte, error)

GetStateObject returns the data stored in the remote RPC for the specified state object Note that the Ethereum RPC will return zero for accounts that do not exist. Errors may be network errors or a context cancelled error when the fuzzer is shutting down.

func (*RPCBackend) GetStorageAt

func (q *RPCBackend) GetStorageAt(addr common.Address, slot common.Hash) (common.Hash, error)

GetStorageAt returns data stored in the remote RPC for the given address/slot. Note that Ethereum RPC will return zero for slots that have never been written to or are associated with undeployed contracts. Errors may be network errors or a context cancelled error when the fuzzer is shutting down.

type RemoteStateProvider

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

RemoteStateProvider implements an import mechanism for state that was not written by a locally executed transaction. This allows us to use the state of a remote RPC server for fork mode, or the state of some other serialized database. It is consumed by medusa-geth's ForkStateDb. This provider is snapshot-aware and will refuse to fetch certain data if it has reason to believe the local statedb has newer data.

func (*RemoteStateProvider) ImportStateObject

func (s *RemoteStateProvider) ImportStateObject(
	addr common.Address,
	snapId int,
) (bal *uint256.Int, nonce uint64, code []byte, e *gethState.RemoteStateError)

ImportStateObject attempts to import a state object from the backend. If the state object has already been imported and its snapshot has not been reverted, this function will return an error with CannotQueryDirtyAccount set to true.

func (*RemoteStateProvider) ImportStorageAt

func (s *RemoteStateProvider) ImportStorageAt(
	addr common.Address,
	slot common.Hash,
	snapId int,
) (common.Hash, *gethState.RemoteStorageError)

ImportStorageAt attempts to import a storage slot from the backend. If the slot has already been imported and its snapshot has not been reverted, this function will return an error with CannotQueryDirtySlot set to true. If the storage slot is associated with a contract that was deployed locally, this function will return an error with CannotQueryDirtySlot set to true, since the remote database will never contain canonical slot data for a locally deployed contract.

func (*RemoteStateProvider) MarkContractDeployed

func (s *RemoteStateProvider) MarkContractDeployed(addr common.Address, snapId int)

MarkContractDeployed is used to notify the provider that a contract was locally deployed to the specified address. As long as the snapshot indicated by snapId is not reverted, the provider will not return "dirty" if ImportStorageAt is called for any slots associated with the contract.

func (*RemoteStateProvider) MarkSlotWritten

func (s *RemoteStateProvider) MarkSlotWritten(addr common.Address, slot common.Hash, snapId int)

MarkSlotWritten is used to notify the provider that a local transaction has written a value to the specified slot. As long as the snapshot indicated by snapId is not reverted, the provider will now return "dirty" if ImportStorageAt is called for the slot in the future.

func (*RemoteStateProvider) NotifyRevertedToSnapshot

func (s *RemoteStateProvider) NotifyRevertedToSnapshot(snapId int)

NotifyRevertedToSnapshot is used to notify the provider that the state has been reverted back to snapId. The provider uses this information to clear its import history up to and not including the provided snapId.

type UnbackedStateFactory

type UnbackedStateFactory struct{}

UnbackedStateFactory is used to build StateDBs that are not backed by any remote state, but still use the custom forked stateDB logic around state object existence checks.

func NewUnbackedStateFactory

func NewUnbackedStateFactory() *UnbackedStateFactory

func (*UnbackedStateFactory) New

type VanillaStateDbFactory added in v1.1.0

type VanillaStateDbFactory struct {
}

func NewVanillaStateFactory added in v1.1.0

func NewVanillaStateFactory() *VanillaStateDbFactory

func (VanillaStateDbFactory) New added in v1.1.0

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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