ethereummock

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: AGPL-3.0 Imports: 30 Imported by: 0

README

This is a super simplified version of an ethereum node, written to support a simulation. Eventually it will have the same interfaces as a standard ethereum node and will be able to be swapped for one.

Documentation

Index

Constants

View Source
const SecondsPerSlot = uint64(12)

Variables

View Source
var EmptyHash = gethcommon.Hash{}

EmptyHash is useful for comparisons to check if hash has been set

View Source
var (

	// MgmtContractAddresses make all these addresses available for the host to know what receipts will be forwarded to the enclave
	MgmtContractAddresses = []gethcommon.Address{
		depositTxAddr,
		rollupTxAddr,
		storeSecretTxAddr,
		requestSecretTxAddr,
		initializeSecretTxAddr,
	}
)
View Source
var MockGenesisBlock = NewBlock(nil, common.HexToAddress("0x0"), []*types.Transaction{}, 0)

Functions

func LCA added in v0.27.0

func LCA(ctx context.Context, newCanonical *types.Block, oldCanonical *types.Block, resolver *blockResolverInMem) (*common.ChainFork, error)

LCA - returns the latest common ancestor of the 2 blocks or an error if no common ancestor is found it also returns the blocks that became canonical, and the once that are now the fork

func NewBlock

func NewBlock(parent *types.Block, nodeID common.Address, txs []*types.Transaction, blockTime uint64) *types.Block

func NewERC20ContractLibMock

func NewERC20ContractLibMock() erc20contractlib.ERC20ContractLib

NewERC20ContractLibMock is an implementation of the erc20contractlib.ERC20ContractLib

func NewMgmtContractLibMock

func NewMgmtContractLibMock() mgmtcontractlib.MgmtContractLib

func NewMockBlobResolver added in v0.28.0

func NewMockBlobResolver() l1.BlobResolver

func NewResolver

func NewResolver() *blockResolverInMem

Types

type BlobResolverInMem added in v0.28.0

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

func (*BlobResolverInMem) FetchBlobs added in v0.28.0

func (b *BlobResolverInMem) FetchBlobs(_ context.Context, _ *types.Header, hashes []gethcommon.Hash) ([]*kzg4844.Blob, error)

func (*BlobResolverInMem) StoreBlobs added in v0.28.0

func (b *BlobResolverInMem) StoreBlobs(_ uint64, blobs []*kzg4844.Blob) error

type BlockWithBlobs added in v0.28.0

type BlockWithBlobs struct {
	Block *types.Block
	Blobs []*kzg4844.Blob
}

type L1Network

type L1Network interface {
	// BroadcastBlock - send the block and the parent to make sure there are no gaps
	BroadcastBlock(b common.EncodedL1Block, p common.EncodedL1Block)
	BroadcastTx(tx *types.Transaction)
}

type MiningConfig

type MiningConfig struct {
	PowTime      common.Latency
	LogFile      string
	L1BeaconPort int
}

type MockEthNetwork

type MockEthNetwork struct {
	CurrentNode *Node

	AllNodes []*Node

	Stats *stats.Stats
	// contains filtered or unexported fields
}

MockEthNetwork - models a full network including artificial random latencies This is the gateway through which the mock L1 nodes communicate with each other

func NewMockEthNetwork

func NewMockEthNetwork(avgBlockDuration time.Duration, avgLatency time.Duration, stats *stats.Stats) *MockEthNetwork

NewMockEthNetwork returns an instance of a configured L1 Network (no nodes)

func (*MockEthNetwork) BroadcastBlock

func (n *MockEthNetwork) BroadcastBlock(b common.EncodedL1Block, p common.EncodedL1Block)

BroadcastBlock broadcast a block to the l1 nodes

func (*MockEthNetwork) BroadcastTx

func (n *MockEthNetwork) BroadcastTx(tx *types.Transaction)

BroadcastTx Broadcasts the L1 tx containing the rollup to the L1 network

type Node

type Node struct {
	Network L1Network

	BlockResolver *blockResolverInMem
	BlobResolver  l1.BlobResolver
	// contains filtered or unexported fields
}

func NewMiner

func NewMiner(
	id gethcommon.Address,
	cfg MiningConfig,
	network L1Network,
	statsCollector StatsCollector,
	blobResolver l1.BlobResolver,
	logger gethlog.Logger,
) *Node

func (*Node) Alive

func (m *Node) Alive() bool

func (*Node) BalanceAt

func (m *Node) BalanceAt(gethcommon.Address, *big.Int) (*big.Int, error)

func (*Node) BlockByHash

func (m *Node) BlockByHash(id gethcommon.Hash) (*types.Block, error)

func (*Node) BlockByNumber

func (m *Node) BlockByNumber(n *big.Int) (*types.Block, error)

func (*Node) BlockListener

func (m *Node) BlockListener() (chan *types.Header, ethereum.Subscription)

BlockListener provides stream of latest mock head headers as they are created

func (*Node) BlockNumber

func (m *Node) BlockNumber() (uint64, error)

func (*Node) BlocksBetween

func (m *Node) BlocksBetween(blockA *types.Header, blockB *types.Block) []*types.Block

func (*Node) BroadcastTx

func (m *Node) BroadcastTx(tx types.TxData)

func (*Node) CallContract

func (m *Node) CallContract(ethereum.CallMsg) ([]byte, error)

func (*Node) EthClient

func (m *Node) EthClient() *ethclient_ethereum.Client

func (*Node) FetchHeadBlock

func (m *Node) FetchHeadBlock() (*types.Block, error)

func (*Node) FetchLastBatchSeqNo

func (m *Node) FetchLastBatchSeqNo(gethcommon.Address) (*big.Int, error)

func (*Node) GetLogs

func (m *Node) GetLogs(fq ethereum.FilterQuery) ([]types.Log, error)

GetLogs is a mock method - we don't really have logs on the mock transactions, so it returns a basic log for every tx so the host recognises them as relevant

func (*Node) Info

func (m *Node) Info() ethadapter.Info

func (*Node) IsBlockAncestor

func (m *Node) IsBlockAncestor(block *types.Block, proof common.L1BlockHash) bool

func (*Node) Nonce

func (m *Node) Nonce(gethcommon.Address) (uint64, error)

func (*Node) P2PGossipTx

func (m *Node) P2PGossipTx(tx *types.Transaction)

P2PGossipTx receive rollups to publish from the linked aggregators

func (*Node) P2PReceiveBlock

func (m *Node) P2PReceiveBlock(b common.EncodedL1Block, p common.EncodedL1Block)

P2PReceiveBlock is called by counterparties when there is a block to broadcast All it does is drop the blocks in a channel for processing.

func (*Node) PrepareTransactionToRetry

func (m *Node) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, _ uint64, _ int) (types.TxData, error)

func (*Node) PrepareTransactionToSend

func (m *Node) PrepareTransactionToSend(_ context.Context, txData types.TxData, _ gethcommon.Address) (types.TxData, error)

func (*Node) ProcessBlobs added in v0.28.0

func (m *Node) ProcessBlobs(b *types.Block) error

func (*Node) ReconnectIfClosed

func (m *Node) ReconnectIfClosed() error

func (*Node) RemoveSubscription

func (m *Node) RemoveSubscription(id uuid.UUID)

func (*Node) SendTransaction

func (m *Node) SendTransaction(tx *types.Transaction) error

func (*Node) Start

func (m *Node) Start()

func (*Node) Stop

func (m *Node) Stop()

func (*Node) TransactionReceipt

func (m *Node) TransactionReceipt(_ gethcommon.Hash) (*types.Receipt, error)

type StatsCollector

type StatsCollector interface {
	// L1Reorg registers when a miner has to process a reorg (a winning block from a fork)
	L1Reorg(id gethcommon.Address)
}

type TxDB

type TxDB interface {
	Txs(block *types.Block) (map[common.TxHash]*types.Transaction, bool)
	AddTxs(*types.Block, map[common.TxHash]*types.Transaction)
}

func NewTxDB

func NewTxDB() TxDB

Jump to

Keyboard shortcuts

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