sync

package
v0.5.1-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWaitPeriodBlockNotFound = time.Millisecond * 100
)

Variables

View Source
var ErrInconsistentState = errors.New("state is inconsistent, try again later once the state is consolidated")

Functions

func UnhaltIfAffectedRows added in v0.5.1

func UnhaltIfAffectedRows(halted *bool, haltedReason *string, mu *sync.RWMutex, rowsAffected int64)

Types

type Block

type Block struct {
	Num    uint64
	Events []interface{}
	Hash   common.Hash
}

type EVMBlock

type EVMBlock struct {
	EVMBlockHeader
	IsFinalizedBlock bool
	Events           []interface{}
}

type EVMBlockHeader

type EVMBlockHeader struct {
	Num        uint64
	Hash       common.Hash
	ParentHash common.Hash
	Timestamp  uint64
}

type EVMBlocks added in v0.4.2

type EVMBlocks []*EVMBlock

func (EVMBlocks) Len added in v0.4.2

func (e EVMBlocks) Len() int

type EVMDownloader

type EVMDownloader struct {
	EVMDownloaderInterface
	// contains filtered or unexported fields
}

func NewEVMDownloader

func NewEVMDownloader(
	syncerID string,
	ethClient EthClienter,
	syncBlockChunkSize uint64,
	blockFinalityType etherman.BlockNumberFinality,
	waitForNewBlocksPeriod time.Duration,
	appender LogAppenderMap,
	adressessToQuery []common.Address,
	rh *RetryHandler,
	finalizedBlockType etherman.BlockNumberFinality,
) (*EVMDownloader, error)

func (*EVMDownloader) Download

func (d *EVMDownloader) Download(ctx context.Context, fromBlock uint64, downloadedCh chan EVMBlock)

type EVMDownloaderImplementation

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

func NewEVMDownloaderImplementation

func NewEVMDownloaderImplementation(
	syncerID string,
	ethClient EthClienter,
	blockFinality *big.Int,
	waitForNewBlocksPeriod time.Duration,
	appender LogAppenderMap,
	topicsToQuery []common.Hash,
	adressessToQuery []common.Address,
	rh *RetryHandler,
) *EVMDownloaderImplementation

func (*EVMDownloaderImplementation) GetBlockHeader

func (d *EVMDownloaderImplementation) GetBlockHeader(ctx context.Context, blockNum uint64) (EVMBlockHeader, bool)

func (*EVMDownloaderImplementation) GetEventsByBlockRange

func (d *EVMDownloaderImplementation) GetEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) EVMBlocks

func (*EVMDownloaderImplementation) GetLastFinalizedBlock added in v0.4.2

func (d *EVMDownloaderImplementation) GetLastFinalizedBlock(ctx context.Context) (*types.Header, error)

func (*EVMDownloaderImplementation) GetLogs

func (d *EVMDownloaderImplementation) GetLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log

func (*EVMDownloaderImplementation) WaitForNewBlocks

func (d *EVMDownloaderImplementation) WaitForNewBlocks(
	ctx context.Context, lastBlockSeen uint64,
) (newLastBlock uint64)

type EVMDownloaderInterface

type EVMDownloaderInterface interface {
	WaitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64)
	GetEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) EVMBlocks
	GetLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log
	GetBlockHeader(ctx context.Context, blockNum uint64) (EVMBlockHeader, bool)
	GetLastFinalizedBlock(ctx context.Context) (*types.Header, error)
}

type EVMDriver

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

func NewEVMDriver

func NewEVMDriver(
	reorgDetector ReorgDetector,
	processor processorInterface,
	downloader downloader,
	reorgDetectorID string,
	downloadBufferSize int,
	rh *RetryHandler,
) (*EVMDriver, error)

func (*EVMDriver) Sync

func (d *EVMDriver) Sync(ctx context.Context)

type EthClienter

type EthClienter interface {
	ethereum.LogFilterer
	ethereum.BlockNumberReader
	ethereum.ChainReader
	bind.ContractBackend
}

type LogAppenderMap

type LogAppenderMap map[common.Hash]func(b *EVMBlock, l types.Log) error

type ProcessorInterface

type ProcessorInterface interface {
	GetLastProcessedBlock(ctx context.Context) (uint64, error)
	ProcessBlock(block Block) error
	Reorg(firstReorgedBlock uint64) error
}

type ReorgDetector

type ReorgDetector interface {
	Subscribe(id string) (*reorgdetector.Subscription, error)
	AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error
}

type RetryHandler

type RetryHandler struct {
	RetryAfterErrorPeriod      time.Duration
	MaxRetryAttemptsAfterError int
}

func (*RetryHandler) Handle

func (h *RetryHandler) Handle(funcName string, attempts int)

Jump to

Keyboard shortcuts

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