Help us shape the future of Go! Take the 2026 Go Developer Survey

reorgdetector

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DBPath is the path to the database
	DBPath string `mapstructure:"DBPath"`

	// CheckReorgsInterval is the interval to check for reorgs in tracked blocks
	CheckReorgsInterval types.Duration `mapstructure:"CheckReorgsInterval"`
	// FinalizedBlockType indicates the status of the blocks that will be queried in order to sync
	// if finalizedBlock == "LatestBlock" then it's disabled and we assume the network has no chances of reorgs
	FinalizedBlock aggkittypes.BlockNumberFinality `` //nolint:lll
	/* 135-byte string literal not displayed */
}

Config is the configuration for the reorg detector

func (*Config) GetCheckReorgsInterval

func (c *Config) GetCheckReorgsInterval() time.Duration

GetCheckReorgsInterval returns the interval to check for reorgs in tracked blocks

type Header struct {
	Num  uint64      `meddler:"num"`
	Hash common.Hash `meddler:"hash,hash"`
}

type HeaderWithSubscriberID added in v0.7.1

type HeaderWithSubscriberID struct {
	SubscriberID string      `meddler:"subscriber_id"`
	Num          uint64      `meddler:"num"`
	Hash         common.Hash `meddler:"hash,hash"`
}

type Network added in v0.0.2

type Network string
const (
	L1 Network = "l1"
	L2 Network = "l2"
)

func (Network) String added in v0.0.2

func (n Network) String() string

type NoOpReorgDetector added in v0.7.0

type NoOpReorgDetector struct {
}

NoOpReorgDetector is a no-operation implementation of sync.ReorgDetector that does nothing when called, used when reorg detection is not needed

func NewNoOpReorgDetector added in v0.7.0

func NewNoOpReorgDetector() *NoOpReorgDetector

NewNoOpReorgDetector creates a new no-op reorg detector

func (*NoOpReorgDetector) AddBlockToTrack added in v0.7.0

func (n *NoOpReorgDetector) AddBlockToTrack(
	ctx context.Context,
	id string,
	blockNum uint64,
	blockHash common.Hash,
) error

AddBlockToTrack implements sync.ReorgDetector interface

func (*NoOpReorgDetector) GetFinalizedBlockType added in v0.7.0

func (n *NoOpReorgDetector) GetFinalizedBlockType() aggkittypes.BlockNumberFinality

GetFinalizedBlockType implements sync.ReorgDetector interface

func (*NoOpReorgDetector) GetLastReorgEvent added in v0.7.0

func (n *NoOpReorgDetector) GetLastReorgEvent(ctx context.Context) (ReorgEvent, error)

GetLastReorgEvent returns an empty reorg event since no-op detector never detects reorgs

func (*NoOpReorgDetector) GetTrackedBlockByBlockNumber added in v0.7.1

func (n *NoOpReorgDetector) GetTrackedBlockByBlockNumber(id string, blockNumber uint64) (*Header, error)

GetTrackedBlockByBlockNumber implements sync.ReorgDetector interface

func (*NoOpReorgDetector) String added in v0.7.0

func (n *NoOpReorgDetector) String() string

String implements sync.ReorgDetector interface

func (*NoOpReorgDetector) Subscribe added in v0.7.0

func (n *NoOpReorgDetector) Subscribe(id string) (*Subscription, error)

Subscribe implements sync.ReorgDetector interface

type ReorgDetector

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

func New

func New(client aggkittypes.BaseEthereumClienter, cfg Config, network Network) (*ReorgDetector, error)

func (*ReorgDetector) AddBlockToTrack

func (rd *ReorgDetector) AddBlockToTrack(ctx context.Context, id string, num uint64, hash common.Hash) error

AddBlockToTrack adds a block to the tracked list for a subscriber

func (*ReorgDetector) GetDB added in v0.7.1

func (rd *ReorgDetector) GetDB() *sql.DB

GetDB returns the database connection for testing purposes

func (*ReorgDetector) GetFinalizedBlockType added in v0.0.2

func (rd *ReorgDetector) GetFinalizedBlockType() aggkittypes.BlockNumberFinality

GetFinalizedBlockType returns the finalized block name

func (*ReorgDetector) GetLastReorgEvent added in v0.5.0

func (rd *ReorgDetector) GetLastReorgEvent(ctx context.Context) (ReorgEvent, error)

GetLastReorgEvent returns the the last ReorgEvent stored in reorg_event table

func (*ReorgDetector) GetTrackedBlockByBlockNumber added in v0.7.1

func (rd *ReorgDetector) GetTrackedBlockByBlockNumber(id string, blockNumber uint64) (*Header, error)

func to get the tracked blocks for a subscriber by block number and hash, it should be 1 or none, from headercache

func (*ReorgDetector) Start

func (rd *ReorgDetector) Start(ctx context.Context) (err error)

Start starts the reorg detector

func (*ReorgDetector) String added in v0.0.2

func (rd *ReorgDetector) String() string

func (*ReorgDetector) Subscribe

func (rd *ReorgDetector) Subscribe(id string) (*Subscription, error)

Subscribe subscribes to reorg events

type ReorgEvent added in v0.1.0

type ReorgEvent struct {
	DetectedAt   int64       `meddler:"detected_at"`
	FromBlock    uint64      `meddler:"from_block"`
	ToBlock      uint64      `meddler:"to_block"`
	SubscriberID string      `meddler:"subscriber_id"`
	TrackedHash  common.Hash `meddler:"tracked_hash,hash"`
	CurrentHash  common.Hash `meddler:"current_hash,hash"`
	Version      string      `meddler:"version"`
}

type Subscription

type Subscription struct {
	ReorgedBlock   chan uint64
	ReorgProcessed chan bool
}

Subscription is a subscription to reorg events

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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