Documentation
¶
Index ¶
- Variables
- type AddressToIDFunc
- type Config
- type DataConsistencyError
- type DependencyError
- type DiscoverPoolsFunc
- type ErrorHandlerFunc
- type GetClientFunc
- type GetReservesFunc
- type IDToAddressFunc
- type InBlockedListFunc
- type InitializationError
- type Logger
- type Metrics
- type PoolInitializerFunc
- type PoolView
- type PrunerError
- type RegisterPoolFunc
- type RegisterPoolsFunc
- type RegistrationError
- type SystemError
- type TestBloomFunc
- type UniswapV2Registry
- type UniswapV2System
- type UpdateError
- type UpdatedInBlockFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPoolExists is returned when attempting to add a pool that is already in the registry. ErrPoolExists = errors.New("pool already exists in registry") // ErrPoolNotFound is returned when attempting to access a pool that is not in the registry. ErrPoolNotFound = errors.New("pool not found in registry") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
SystemName string
PrometheusReg prometheus.Registerer
NewBlockEventer chan *types.Block
GetClient GetClientFunc
InBlockedList InBlockedListFunc
PoolInitializer PoolInitializerFunc
DiscoverPools DiscoverPoolsFunc
UpdatedInBlock UpdatedInBlockFunc
GetReserves GetReservesFunc
TokenAddressToID AddressToIDFunc
PoolAddressToID AddressToIDFunc
PoolIDToAddress IDToAddressFunc
RegisterPool RegisterPoolFunc
RegisterPools RegisterPoolsFunc
ErrorHandler ErrorHandlerFunc
TestBloom TestBloomFunc
FilterTopics [][]common.Hash
PruneFrequency time.Duration
InitFrequency time.Duration
ResyncFrequency time.Duration
LogMaxRetries int
LogRetryDelay time.Duration
Logger Logger
}
Config holds all the dependencies and settings for the UniswapV2System. Using a configuration struct makes initialization cleaner and more extensible.
type DataConsistencyError ¶
type DataConsistencyError struct {
SystemError
PoolAddress common.Address
Details string
}
DataConsistencyError indicates a critical internal state mismatch, for example, failing to find a pool ID immediately after it was registered.
func (*DataConsistencyError) Error ¶
func (e *DataConsistencyError) Error() string
Error provides a descriptive message, distinguishing between background and block-specific errors.
type DependencyError ¶
type DependencyError struct {
// Dependency is the name of the function that failed (e.g., "poolAddressToID").
Dependency string
// Input is the value that was passed to the failing dependency.
Input any
// Err is the underlying error returned by the dependency.
Err error
}
DependencyError is returned when a function dependency required by the registry fails.
func (*DependencyError) Error ¶
func (e *DependencyError) Error() string
func (*DependencyError) Unwrap ¶
func (e *DependencyError) Unwrap() error
Unwrap allows the error to be inspected with errors.Is and errors.As.
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(err error)
type GetClientFunc ¶
type GetClientFunc func() (ethclients.ETHClient, error)
type GetReservesFunc ¶
type InBlockedListFunc ¶
type InitializationError ¶
type InitializationError struct {
SystemError
PoolAddress common.Address
}
InitializationError indicates a failure during the initialization of a new pool.
func (*InitializationError) Error ¶
func (e *InitializationError) Error() string
Error provides a descriptive message, distinguishing between background and block-specific errors.
type Logger ¶
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, args ...any)
}
Logger defines a standard interface for structured, leveled logging, compatible with the standard library's slog.
type Metrics ¶
type Metrics struct {
// --- Tier 1: Critical System Health & Liveness ---
LastProcessedBlock *prometheus.GaugeVec
ErrorsTotal *prometheus.CounterVec
// --- Tier 2: Performance & Bottleneck Identification ---
PendingInitQueueSize *prometheus.GaugeVec
BlockProcessingDur *prometheus.HistogramVec
PoolInitDur *prometheus.HistogramVec
ReconciliationDuration *prometheus.HistogramVec
PruningDuration *prometheus.HistogramVec
// --- Tier 3: Data & State Integrity ---
PoolsInRegistry *prometheus.GaugeVec
PoolsInitialized *prometheus.CounterVec
PoolsPruned *prometheus.CounterVec
}
Metrics contains all the Prometheus metrics for the UniswapV2System. Encapsulating them in a struct keeps the main system struct clean and organized.
func NewMetrics ¶
func NewMetrics(reg prometheus.Registerer, systemName string) *Metrics
NewMetrics creates and registers all the Prometheus metrics for the system. It takes a prometheus.Registerer to allow for flexible registration (e.g., default vs. custom).
type PoolInitializerFunc ¶
type PrunerError ¶
PrunerError indicates a failure during the periodic pruning process.
func (*PrunerError) Error ¶
func (e *PrunerError) Error() string
func (*PrunerError) Unwrap ¶
func (e *PrunerError) Unwrap() error
type RegisterPoolFunc ¶
type RegisterPoolsFunc ¶
type RegistrationError ¶
type RegistrationError struct {
InitializationError
Token0Address common.Address
Token1Address common.Address
}
RegistrationError is a critical error when the system fails to register a new, valid pool with the upstream persistence layer.
func (*RegistrationError) Error ¶
func (e *RegistrationError) Error() string
Error provides a descriptive message, distinguishing between background and block-specific errors.
type SystemError ¶
SystemError is a base type for errors originating from the UniswapV2System.
func (*SystemError) Error ¶
func (e *SystemError) Error() string
func (*SystemError) Unwrap ¶
func (e *SystemError) Unwrap() error
type TestBloomFunc ¶
type UniswapV2Registry ¶
type UniswapV2Registry struct {
// contains filtered or unexported fields
}
UniswapV2Registry manages a large number of v2 pools using a data-oriented design.
func NewUniswapV2Registry ¶
func NewUniswapV2Registry() *UniswapV2Registry
func NewUniswapV2RegistryFromViews ¶
func NewUniswapV2RegistryFromViews(views []PoolView) *UniswapV2Registry
NewUniswapV2RegistryFromViews reconstructs a UniswapV2Registry from a slice of PoolView structs. This is the primary mechanism for restoring the registry's state from a snapshot. It is highly optimized, pre-allocating all necessary memory and performing deep copies of mutable data like big.Int reserves to ensure data integrity.
type UniswapV2System ¶
type UniswapV2System struct {
// contains filtered or unexported fields
}
UniswapV2System is the main orchestrator that connects the data registry to the live blockchain. It handles block events, discovers and updates pools, and manages state with thread-safety.
func NewUniswapV2System ¶
func NewUniswapV2System(ctx context.Context, cfg *Config) (*UniswapV2System, error)
NewUniswapV2System constructs a new, live system with an empty initial state.
func NewUniswapV2SystemFromViews ¶
func NewUniswapV2SystemFromViews(ctx context.Context, cfg *Config, views []PoolView) (*UniswapV2System, error)
NewUniswapV2SystemFromViews constructs a new, live system from a snapshot of pool views. This is the primary entry point for rehydrating the system's state on startup.
func (*UniswapV2System) DeletePool ¶
func (s *UniswapV2System) DeletePool(poolID uint64) error
DeletePool removes a pool from the UniswapV2System's internal registry.
@note This is a low-level method that must be called hierarchically, typically from a central registry manager that can orchestrate the deletion across all necessary application subsystems.
⚠️ WARNING: Calling this function in isolation WILL lead to state inconsistency, as it does not affect dependent components. For a safe, application-wide deletion, use the appropriate manager-level method.
func (*UniswapV2System) DeletePools ¶
func (s *UniswapV2System) DeletePools(poolIDs []uint64) []error
DeletePools removes multiple pools from the UniswapV2System's internal registry.
@note This is a low-level method that must be called hierarchically, typically from a central registry manager that can orchestrate the deletion across all necessary application subsystems.
⚠️ WARNING: Calling this function in isolation WILL lead to state inconsistency, as it does not affect dependent components. For a safe, application-wide deletion, use the appropriate manager-level method.
func (*UniswapV2System) LastUpdatedAtBlock ¶
func (s *UniswapV2System) LastUpdatedAtBlock() uint64
LastUpdatedAtBlock returns the block number of the last successfully processed block.
func (*UniswapV2System) View ¶
func (s *UniswapV2System) View() []PoolView
View returns a copy of the latest registry view. This operation is lock-free.
type UpdateError ¶
type UpdateError struct {
SystemError
PoolAddress common.Address
PoolID uint64
Reserve0 *big.Int
Reserve1 *big.Int
}
UpdateError indicates a failure to update the reserves of a known, existing pool.
func (*UpdateError) Error ¶
func (e *UpdateError) Error() string
Error provides a descriptive message, distinguishing between background and block-specific errors.