l1_check_block

package
v0.7.0-fork11 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDeSync is an error that indicates that from the starting of verification to end something have been changed on state
	ErrDeSync = errors.New("DeSync: a block hash is different from the state block hash")
)

Functions

func CheckBlockHash

func CheckBlockHash(ctx context.Context, stateBlock *state.Block, L1Client L1Requester, checkerName string) error

CheckBlockHash is a method that checks the L1 block hash

Types

type AsyncCheck

type AsyncCheck struct {

	// Wg is a wait group to wait for the result
	Wg sync.WaitGroup
	// contains filtered or unexported fields
}

AsyncCheck is a wrapper for L1BlockChecker to become asynchronous

func NewAsyncCheck

func NewAsyncCheck(checker L1BlockChecker) *AsyncCheck

NewAsyncCheck creates a new AsyncCheck

func (*AsyncCheck) GetResult

func (a *AsyncCheck) GetResult() *syncinterfaces.IterationResult

GetResult returns the last result of the check: - Nil -> still running - Not nil -> finished, and this is the result. You must call again Run to start a new check

func (*AsyncCheck) GetResultBlockingUntilAvailable

func (a *AsyncCheck) GetResultBlockingUntilAvailable(timeout time.Duration) *syncinterfaces.IterationResult

GetResultBlockingUntilAvailable wait the time specific in timeout, if reach timeout returns current result, if not, wait until the result is available. if timeout is 0, it waits indefinitely

func (*AsyncCheck) Run

func (a *AsyncCheck) Run(ctx context.Context, onFinish func())

Run is a method that starts the async check

func (*AsyncCheck) RunSynchronous

func (a *AsyncCheck) RunSynchronous(ctx context.Context) syncinterfaces.IterationResult

RunSynchronous is a method that forces the check to be synchronous before starting the async check

func (*AsyncCheck) SetPeriodTime

func (a *AsyncCheck) SetPeriodTime(periodTime time.Duration)

SetPeriodTime sets the period time between relaunch checker.Step

func (*AsyncCheck) Stop

func (a *AsyncCheck) Stop()

Stop is a method that stops the async check

type CheckL1BlockHash

type CheckL1BlockHash struct {
	L1Client               L1Requester
	State                  StateInterfacer
	SafeBlockNumberFetcher SafeL1BlockNumberFetcher
}

CheckL1BlockHash is a struct that implements a checker of L1Block hash

func NewCheckL1BlockHash

func NewCheckL1BlockHash(l1Client L1Requester, state StateInterfacer, safeBlockNumberFetcher SafeL1BlockNumberFetcher) *CheckL1BlockHash

NewCheckL1BlockHash creates a new CheckL1BlockHash

func (*CheckL1BlockHash) Name

func (p *CheckL1BlockHash) Name() string

Name is a method that returns the name of the checker

func (*CheckL1BlockHash) Step

func (p *CheckL1BlockHash) Step(ctx context.Context) error

Step is a method that checks the L1 block hash, run until all blocks are checked and returns

type L1BlockChecker

type L1BlockChecker interface {
	Step(ctx context.Context) error
}

L1BlockChecker is an interface that defines the method to check L1 blocks

type L1BlockCheckerIntegration

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

L1BlockCheckerIntegration is a struct that integrates the L1BlockChecker with the synchronizer

func NewL1BlockCheckerIntegration

func NewL1BlockCheckerIntegration(checker syncinterfaces.AsyncL1BlockChecker, preChecker syncinterfaces.AsyncL1BlockChecker, state StateForL1BlockCheckerIntegration, sync SyncCheckReorger, forceCheckOnStart bool, timeBetweenRetries time.Duration) *L1BlockCheckerIntegration

NewL1BlockCheckerIntegration creates a new L1BlockCheckerIntegration

func (*L1BlockCheckerIntegration) CheckReorgWrapper

func (v *L1BlockCheckerIntegration) CheckReorgWrapper(ctx context.Context, reorgFirstBlockOk *state.Block, errReportedByReorgFunc error) (*state.Block, error)

CheckReorgWrapper is a wrapper over reorg function of synchronizer. it checks the result of the function and the result of background process and decides which return

func (*L1BlockCheckerIntegration) OnResetState

func (v *L1BlockCheckerIntegration) OnResetState(ctx context.Context)

OnResetState is a method that is called after a resetState

func (*L1BlockCheckerIntegration) OnStart

OnStart is a method that is called before starting the synchronizer

func (*L1BlockCheckerIntegration) OnStartL1Sync

func (v *L1BlockCheckerIntegration) OnStartL1Sync(ctx context.Context) bool

OnStartL1Sync is a method that is called before starting the L1 sync

func (*L1BlockCheckerIntegration) OnStartL2Sync

func (v *L1BlockCheckerIntegration) OnStartL2Sync(ctx context.Context) bool

OnStartL2Sync is a method that is called before starting the L2 sync

type L1BlockPoint

type L1BlockPoint int

L1BlockPoint is an enum that represents the point of the L1 block

const (
	// FinalizedBlockNumber is the finalized block number
	FinalizedBlockNumber L1BlockPoint = 3
	// SafeBlockNumber is the safe block number
	SafeBlockNumber L1BlockPoint = 2
	// PendingBlockNumber is the pending block number
	PendingBlockNumber L1BlockPoint = 1
	// LastBlockNumber is the last block number
	LastBlockNumber L1BlockPoint = 0
)

func StringToL1BlockPoint

func StringToL1BlockPoint(s string) L1BlockPoint

StringToL1BlockPoint converts a string to a L1BlockPoint

func (L1BlockPoint) ToGethRequest

func (v L1BlockPoint) ToGethRequest() *big.Int

ToGethRequest converts a L1BlockPoint to a big.Int used for request to GETH

func (L1BlockPoint) ToString

func (v L1BlockPoint) ToString() string

ToString converts a L1BlockPoint to a string

type L1Requester

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

L1Requester is an interface for GETH client

type PreCheckL1BlockHash

type PreCheckL1BlockHash struct {
	L1Client                  L1Requester
	State                     StatePreCheckInterfacer
	InitialSegmentBlockNumber SafeL1BlockNumberFetcher
	EndSegmentBlockNumber     SafeL1BlockNumberFetcher
}

PreCheckL1BlockHash is a struct that implements a checker of L1Block hash

func NewPreCheckL1BlockHash

func NewPreCheckL1BlockHash(l1Client L1Requester, state StatePreCheckInterfacer,
	initial, end SafeL1BlockNumberFetcher) *PreCheckL1BlockHash

NewPreCheckL1BlockHash creates a new CheckL1BlockHash

func (*PreCheckL1BlockHash) Name

func (p *PreCheckL1BlockHash) Name() string

Name is a method that returns the name of the checker

func (*PreCheckL1BlockHash) Step

Step is a method that checks the L1 block hash, run until all blocks are checked and returns

type SafeL1BlockNumberFetch

type SafeL1BlockNumberFetch struct {
	// SafeBlockPoint is the block number that is reference to l1 Block
	SafeBlockPoint L1BlockPoint
	// Offset is a vaule add to the L1 block
	Offset int
}

SafeL1BlockNumberFetch is a struct that implements a safe L1 block number fetch

func NewSafeL1BlockNumberFetch

func NewSafeL1BlockNumberFetch(safeBlockPoint L1BlockPoint, offset int) *SafeL1BlockNumberFetch

NewSafeL1BlockNumberFetch creates a new SafeL1BlockNumberFetch

func (*SafeL1BlockNumberFetch) Description

func (p *SafeL1BlockNumberFetch) Description() string

Description returns a string representation of SafeL1BlockNumberFetch

func (*SafeL1BlockNumberFetch) GetSafeBlockNumber

func (p *SafeL1BlockNumberFetch) GetSafeBlockNumber(ctx context.Context, requester L1Requester) (uint64, error)

GetSafeBlockNumber gets the safe block number from L1

func (*SafeL1BlockNumberFetch) String

func (p *SafeL1BlockNumberFetch) String() string

String returns a string representation of SafeL1BlockNumberFetch

type SafeL1BlockNumberFetcher

type SafeL1BlockNumberFetcher interface {
	GetSafeBlockNumber(ctx context.Context, l1Client L1Requester) (uint64, error)
	Description() string
}

SafeL1BlockNumberFetcher is an interface for fetching the L1 block number reference point (safe, finalized,...)

type StateForL1BlockCheckerIntegration

type StateForL1BlockCheckerIntegration interface {
	GetPreviousBlockToBlockNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*state.Block, error)
}

StateForL1BlockCheckerIntegration is an interface for the state

type StateInterfacer

type StateInterfacer interface {
	GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx) (*state.Block, error)
	UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.Tx) error
}

StateInterfacer is an interface for the state

type StatePreCheckInterfacer

type StatePreCheckInterfacer interface {
	GetUncheckedBlocks(ctx context.Context, fromBlockNumber uint64, toBlockNumber uint64, dbTx pgx.Tx) ([]*state.Block, error)
}

StatePreCheckInterfacer is an interface for the state

type SyncCheckReorger

type SyncCheckReorger interface {
	ExecuteReorgFromMismatchBlock(blockNumber uint64, reason string) error
	OnDetectedMismatchL1BlockReorg()
}

SyncCheckReorger is an interface that defines the methods required from Synchronizer object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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