evmreader

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateEpochIndex

func CalculateEpochIndex(epochLength uint64, blockNumber uint64) uint64

CalculateEpochIndex calculates the epoch index given the input block number and epoch length

Types

type ApplicationContract

type ApplicationContract interface {
	GetConsensus(opts *bind.CallOpts) (Address, error)
	RetrieveOutputExecutionEvents(
		opts *bind.FilterOpts,
	) ([]*appcontract.IApplicationOutputExecuted, error)
}

type ApplicationContractAdapter

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

IConsensus Wrapper

func NewApplicationContractAdapter

func NewApplicationContractAdapter(
	appAddress common.Address,
	client *ethclient.Client,
) (*ApplicationContractAdapter, error)

func (*ApplicationContractAdapter) GetConsensus

func (a *ApplicationContractAdapter) GetConsensus(opts *bind.CallOpts) (common.Address, error)

func (*ApplicationContractAdapter) RetrieveOutputExecutionEvents

func (a *ApplicationContractAdapter) RetrieveOutputExecutionEvents(
	opts *bind.FilterOpts,
) ([]*appcontract.IApplicationOutputExecuted, error)

type ConsensusContract

type ConsensusContract interface {
	GetEpochLength(opts *bind.CallOpts) (*big.Int, error)
	RetrieveClaimAcceptanceEvents(
		opts *bind.FilterOpts,
		appAddresses []Address,
	) ([]*iconsensus.IConsensusClaimAcceptance, error)
}

type ConsensusContractAdapter

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

IConsensus Wrapper

func NewConsensusContractAdapter

func NewConsensusContractAdapter(
	iconsensusAddress common.Address,
	client *ethclient.Client,
) (*ConsensusContractAdapter, error)

func (*ConsensusContractAdapter) GetEpochLength

func (c *ConsensusContractAdapter) GetEpochLength(opts *bind.CallOpts) (*big.Int, error)

func (*ConsensusContractAdapter) RetrieveClaimAcceptanceEvents

func (c *ConsensusContractAdapter) RetrieveClaimAcceptanceEvents(
	opts *bind.FilterOpts,
	appAddresses []common.Address,
) ([]*iconsensus.IConsensusClaimAcceptance, error)

type ContractFactory

type ContractFactory interface {
	NewApplication(address Address) (ApplicationContract, error)
	NewIConsensus(address Address) (ConsensusContract, error)
}

type EthClient

type EthClient interface {
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

EthClient mimics part of ethclient.Client functions to narrow down the interface needed by the EvmReader. It must be bound to an HTTP endpoint

type EthWsClient

type EthWsClient interface {
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
}

EthWsClient mimics part of ethclient.Client functions to narrow down the interface needed by the EvmReader. It must be bound to a WS endpoint

type EvmReader

type EvmReader struct {
	IOAbi abi.ABI
	// contains filtered or unexported fields
}

EvmReader reads Input Added, Claim Submitted and Output Executed events from the blockchain

func NewEvmReader

func NewEvmReader(
	client EthClient,
	wsClient EthWsClient,
	inputSource InputSource,
	repository EvmReaderRepository,
	inputBoxDeploymentBlock uint64,
	defaultBlock DefaultBlock,
	contractFactory ContractFactory,
	shouldModifyIndex bool,
) EvmReader

Creates a new EvmReader

func (*EvmReader) AddAppEpochLengthIntoCache

func (r *EvmReader) AddAppEpochLengthIntoCache(app application) error

AddAppEpochLengthIntoCache checks the epoch length cache and read epoch length from IConsensus contract and add it to the cache if needed

func (*EvmReader) CheckForClaimStatus

func (r *EvmReader) CheckForClaimStatus(
	ctx context.Context,
	apps []application,
	mostRecentBlockNumber uint64,
)

func (*EvmReader) CheckForOutputExecution

func (r *EvmReader) CheckForOutputExecution(
	ctx context.Context,
	apps []application,
	mostRecentBlockNumber uint64,
)

func (*EvmReader) GetAppContracts

func (r *EvmReader) GetAppContracts(app Application,
) (ApplicationContract, ConsensusContract, error)

GetAppContracts retrieves the ApplicationContract and ConsensusContract for a given Application. Also validates if IConsensus configuration matches the blockchain registered one

func (*EvmReader) GetEpochLengthCache

func (r *EvmReader) GetEpochLengthCache(a Address) uint64

func (*EvmReader) GetEthClient

func (r *EvmReader) GetEthClient() *EthClient

func (*EvmReader) ReadAndStoreInputs

func (r *EvmReader) ReadAndStoreInputs(
	ctx context.Context,
	startBlock uint64,
	endBlock uint64,
	apps []TypeExportApplication,
) error

ReadAndStoreInputs reads, inputs from the InputSource given specific filter options, indexes them into epochs and store the indexed inputs and epochs

func (*EvmReader) Run

func (r *EvmReader) Run(ctx context.Context, ready chan<- struct{}) error

func (*EvmReader) String

func (r *EvmReader) String() string

type EvmReaderRepository

type EvmReaderRepository interface {
	StoreEpochAndInputsTransaction(
		ctx context.Context, epochInputMap map[*Epoch][]Input, blockNumber uint64,
		appAddress Address,
	) (epochIndexIdMap map[uint64]uint64, epochIndexInputIdsMap map[uint64][]uint64, err error)

	GetAllRunningApplications(ctx context.Context) ([]Application, error)
	GetNodeConfig(ctx context.Context) (*NodePersistentConfig, error)
	GetEpoch(ctx context.Context, indexKey uint64, appAddressKey Address) (*Epoch, error)
	GetPreviousEpochsWithOpenClaims(
		ctx context.Context,
		app Address,
		lastBlock uint64,
	) ([]*Epoch, error)
	UpdateEpochs(ctx context.Context,
		app Address,
		claims []*Epoch,
		mostRecentBlockNumber uint64,
	) error
	GetOutput(
		ctx context.Context, appAddressKey Address, indexKey uint64,
	) (*Output, error)
	UpdateOutputExecutionTransaction(
		ctx context.Context, app Address, executedOutputs []*Output, blockNumber uint64,
	) error
	GetInputIndex(
		ctx context.Context,
		applicationAddress Address,
	) (uint64, error)
	UpdateInputIndex(
		ctx context.Context,
		applicationAddress Address,
	) error
}

Interface for the node repository

type InputSource

type InputSource interface {
	// Wrapper for FilterInputAdded(), which is automatically generated
	// by go-ethereum and cannot be used for testing
	RetrieveInputs(opts *bind.FilterOpts, appAddresses []Address, index []*big.Int,
	) ([]iinputbox.IInputBoxInputAdded, error)
}

Interface for Input reading

type InputSourceAdapter

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

InputBox Wrapper

func NewInputSourceAdapter

func NewInputSourceAdapter(
	inputBoxAddress common.Address,
	client *ethclient.Client,
) (*InputSourceAdapter, error)

func (*InputSourceAdapter) RetrieveInputs

func (i *InputSourceAdapter) RetrieveInputs(
	opts *bind.FilterOpts,
	appContract []common.Address,
	index []*big.Int,
) ([]iinputbox.IInputBoxInputAdded, error)

type SubscriptionError

type SubscriptionError struct {
	Cause error
}

func (*SubscriptionError) Error

func (e *SubscriptionError) Error() string

type TypeExportApplication

type TypeExportApplication = application

Directories

Path Synopsis
(c) Cartesi and individual authors (see AUTHORS) SPDX-License-Identifier: Apache-2.0 (see LICENSE)
(c) Cartesi and individual authors (see AUTHORS) SPDX-License-Identifier: Apache-2.0 (see LICENSE)

Jump to

Keyboard shortcuts

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