Documentation
¶
Index ¶
- Constants
- Variables
- func BigIntToLittleEndianBytes(n *big.Int) []byte
- func BytesToUint32(bytes []byte) uint32
- func BytesToUint64(bytes []byte) uint64
- func ChunkedRangeQuery[T any](ctx context.Context, fromBlock, toBlock, maxRange uint64, ...) (T, error)
- func EstimateSliceCapacity(total int, span, fullSpan uint64) int
- func Execute[T any](retryHandler commontypes.RetryHandler, ctx context.Context, ...) (T, error)
- func IsHex(s string) bool
- func MapSlice[T any, R any](in []T, f func(T) R) []R
- func NewKeyFromKeystore(cfg types.KeystoreFileConfig) (*ecdsa.PrivateKey, error)
- func NewRetryBackoffConfig(cfg *RetryPolicyGenericConfig) (commontypes.RetryPolicyConfigurer, error)
- func NewRetryDelaysConfig(cfg *RetryPolicyGenericConfig) (commontypes.RetryPolicyConfigurer, error)
- func ParseMaxRangeFromError(errMsg string) (uint64, bool)
- func ParseUint64Hex(hexStr string) (uint64, error)
- func ParseUint64HexOrDecimal(str string) (uint64, error)
- func Uint32ToBigEndianBytes(num uint32) []byte
- func Uint32ToBytes(num uint32) []byte
- func Uint64ToBigEndianBytes(num uint64) []byte
- func Uint64ToLittleEndianBytes(num uint64) []byte
- func ValidateComponents(components []string) error
- type BlockRange
- func (b BlockRange) Cap(maxBlockNumber uint64) BlockRange
- func (b BlockRange) Contains(other BlockRange) bool
- func (b BlockRange) CountBlocks() uint64
- func (b BlockRange) Equal(other BlockRange) bool
- func (b BlockRange) Extend(other BlockRange) BlockRange
- func (b BlockRange) Gap(other BlockRange) BlockRange
- func (b BlockRange) Greater(other BlockRange) bool
- func (b BlockRange) Intersect(other BlockRange) BlockRange
- func (b BlockRange) IsEmpty() bool
- func (b BlockRange) IsNextContigousBlock(next BlockRange) bool
- func (b BlockRange) Merge(other BlockRange) []BlockRange
- func (b BlockRange) Overlaps(other BlockRange) bool
- func (b BlockRange) String() string
- func (b BlockRange) Subtract(other BlockRange) []BlockRange
- type GenericSubscriber
- type Logger
- type PubSub
- type RESTConfig
- type RateLimit
- type RateLimitConfig
- type RetryBackoffConfig
- type RetryConfigMode
- type RetryDelaysConfig
- type RetryHandlerDelays
- func (r *RetryHandlerDelays) Delay(attempt int) time.Duration
- func (r *RetryHandlerDelays) IsInfiniteRetriesConfigured() bool
- func (r *RetryHandlerDelays) IsNoRetriesConfigured() bool
- func (r *RetryHandlerDelays) MustExecuteAttempt(attempt int) bool
- func (r *RetryHandlerDelays) String() string
- func (r *RetryHandlerDelays) StringAttempt(attempt int) string
- func (r *RetryHandlerDelays) Validate() error
- type RetryPolicyGenericConfig
- func (r *RetryPolicyGenericConfig) Brief() string
- func (r *RetryPolicyGenericConfig) CleanCache()
- func (r *RetryPolicyGenericConfig) Factory() (commontypes.RetryPolicyConfigurer, error)
- func (r *RetryPolicyGenericConfig) NewRetryHandler() (commontypes.RetryHandler, error)
- func (r *RetryPolicyGenericConfig) SetCache(instance commontypes.RetryPolicyConfigurer)
- func (r *RetryPolicyGenericConfig) String() string
- func (r *RetryPolicyGenericConfig) Validate() error
- type TimeTracker
Constants ¶
const ( Uint32ByteSize = 4 Uint64ByteSize = 8 SignatureSize = 65 HashSize = 32 )
const ( // AGGORACLE name to identify the aggoracle component AGGORACLE = "aggoracle" // BRIDGE name to identify the bridge component (have RPC) BRIDGE = "bridge" // PROVER name to identify the prover component PROVER = "prover" // AGGSENDER name to identify the aggsender component AGGSENDER = "aggsender" // L1INFOTREESYNC name to identify the l1infotreesync component L1INFOTREESYNC = "l1infotreesync" // L2BRIDGESYNC name to identify the l2 bridge sync component L2BRIDGESYNC = "l2bridgesync" // L1BRIDGESYNC name to identify the l1 bridge sync component L1BRIDGESYNC = "l1bridgesync" // L2GERSYNC name to identify the l2 ger sync component L2GERSYNC = "l2gersync" // AGGCHAINPROOFGEN name to identify the aggchain-proof-gen component AGGCHAINPROOFGEN = "aggchain-proof-gen" // AGGSENDERVALIDATOR runs aggsender certificate validator AGGSENDERVALIDATOR = "aggsender-validator" )
const KB = 1 << 10 // 1024
const (
MaxAttemptsInfinite = -1 // MaxAttemptsInfinite means infinite retries are allowed
)
Variables ¶
var ( ZeroHash = common.HexToHash("0x0") EmptyBytesHash = crypto.Keccak256(nil) ZeroAddress = common.HexToAddress("0x0") EmptySignature = make([]byte, SignatureSize) )
var ( // If this error is in the returned error, it means that the function should be aborted // and no more retries should be attempted. ErrAbort = fmt.Errorf("abort") ErrInvalidConfig = fmt.Errorf("invalid config") ErrExecutionFails = fmt.Errorf("execution fails after retries exceeded") )
var (
BlockRangeZero = BlockRange{}
)
var (
ErrInvalidRetryConfigMode = fmt.Errorf("invalid retry config mode")
)
var (
TimeProvider = time.Now
)
Functions ¶
func BigIntToLittleEndianBytes ¶
BigIntToLittleEndianBytes converts a big.Int to a 32-byte little-endian representation. big.Int is capped to 32 bytes
func BytesToUint32 ¶
BytesToUint32 converts a byte slice to a uint32. If byte slice is shorter than 4 bytes, it is padded with 0s. In case it is longer than 4 bytes, it panics.
func BytesToUint64 ¶
BytesToUint64 converts a byte slice to a uint64
func ChunkedRangeQuery ¶
func ChunkedRangeQuery[T any]( ctx context.Context, fromBlock, toBlock, maxRange uint64, fetchChunk func(ctx context.Context, from, to uint64) (T, error), combine func(all T, chunk T) T, empty T, ) (T, error)
ChunkedRangeQuery is a generic chunker for block range queries. T is the result type (e.g., []Unclaim, map[common.Hash]GlobalExitRootInfo, []*RemovedGER, etc.)
func EstimateSliceCapacity ¶ added in v0.3.0
EstimateSliceCapacity estimates the capacity of a slice based on the total number of elements, the span of interest, and the full span of the range.
Parameters:
- total: The total number of elements.
- span: The span of interest within the range.
- fullSpan: The full span of the range.
Returns:
- An integer representing the estimated slice capacity. If fullSpan is 0, the function returns 0 to avoid division by zero. If the calculation would result in integer overflow, it returns math.MaxInt to prevent overflow.
func Execute ¶ added in v0.7.0
func Execute[T any](retryHandler commontypes.RetryHandler, ctx context.Context, logFunc func(format string, args ...interface{}), name string, payloadFunc func() (T, error)) (T, error)
Execute executes the provided function with retry logic. retryDelaysConfig: it's the RetryDelays struct that holds the retry delays and the maximum number of retries. ctx: the context to use for cancellation. logFunc: a function to log messages, if nil a silent logger will be used. name: the name of the operation, used for logging. fn: the function to execute, it should return a result of type T and an error. If the function returns an error that is wrapped with ErrAbort, the execution will be aborted and no more retries will be attempted.
func MapSlice ¶ added in v0.5.0
MapSlice transforms a slice of type T into a slice of type R using the provided mapping function f. It's a generic utility that reduces boilerplate when converting between types.
func NewKeyFromKeystore ¶
func NewKeyFromKeystore(cfg types.KeystoreFileConfig) (*ecdsa.PrivateKey, error)
NewKeyFromKeystore creates a private key from a keystore file
func NewRetryBackoffConfig ¶ added in v0.7.0
func NewRetryBackoffConfig(cfg *RetryPolicyGenericConfig) (commontypes.RetryPolicyConfigurer, error)
func NewRetryDelaysConfig ¶ added in v0.7.0
func NewRetryDelaysConfig(cfg *RetryPolicyGenericConfig) (commontypes.RetryPolicyConfigurer, error)
New creates a new instance of RetryDelaysConfig based on the generic retry policy configuration.
func ParseMaxRangeFromError ¶
ParseMaxRangeFromError extracts the max range value from error message Expected formats:
- "block range too large, max range: 1000"
- "exceeded maximum block range: 5000"
func ParseUint64Hex ¶
func ParseUint64HexOrDecimal ¶
func Uint32ToBigEndianBytes ¶ added in v0.7.0
Uint32ToBigEndianBytes converts a uint32 to a byte slice in big-endian order it's an alias of Uint32ToBytes
func Uint32ToBytes ¶
Uint32ToBytes converts a uint32 to a byte slice in big-endian order
func Uint64ToBigEndianBytes ¶ added in v0.4.0
Uint64ToBigEndianBytes converts a uint64 to a byte slice in big-endian order
func Uint64ToLittleEndianBytes ¶ added in v0.4.0
Uint64ToLittleEndianBytes converts a uint64 to a byte slice in little-endian order
func ValidateComponents ¶ added in v0.7.0
ValidateComponents validates that all provided components are known/supported.
Types ¶
type BlockRange ¶
BlockRange represents a range of blocks with inclusive starting (FromBlock) and ending (ToBlock) block numbers.
func NewBlockRange ¶
func NewBlockRange(fromBlock, toBlock uint64) BlockRange
NewBlockRange creates and returns a new BlockRange with the specified fromBlock and toBlock values.
func (BlockRange) Cap ¶
func (b BlockRange) Cap(maxBlockNumber uint64) BlockRange
func (BlockRange) Contains ¶
func (b BlockRange) Contains(other BlockRange) bool
func (BlockRange) CountBlocks ¶
func (b BlockRange) CountBlocks() uint64
CountBlocks returns the total number of blocks in the BlockRange, inclusive of both FromBlock and ToBlock. If both FromBlock and ToBlock are zero, or if FromBlock is greater than ToBlock, it returns 0.
func (BlockRange) Equal ¶
func (b BlockRange) Equal(other BlockRange) bool
func (BlockRange) Extend ¶
func (b BlockRange) Extend(other BlockRange) BlockRange
Extend merges two BlockRanges into one encompassing BlockRange.
func (BlockRange) Gap ¶
func (b BlockRange) Gap(other BlockRange) BlockRange
Gap returns the BlockRange representing the gap between the receiver BlockRange (b) and another BlockRange (other). If the two ranges overlap or are adjacent (touching), it returns an empty BlockRange. If there is a gap, it returns the range of blocks strictly between b and other. The direction of the gap depends on the relative positions of the two ranges.
func (BlockRange) Greater ¶
func (b BlockRange) Greater(other BlockRange) bool
Greater returns true if the receiver BlockRange (b) is strictly greater than the other BlockRange (other). [ 10 - 50 ] > [ 1 - 9 ] = true [ 10 - 50 ] > [ 5 - 15 ] = false (overlap) [ 10 - 50 ] > [ 51 - 100 ] = false (not greater)
func (BlockRange) Intersect ¶
func (b BlockRange) Intersect(other BlockRange) BlockRange
func (BlockRange) IsEmpty ¶
func (b BlockRange) IsEmpty() bool
IsEmpty returns true if the BlockRange contains no blocks.
func (BlockRange) IsNextContigousBlock ¶
func (b BlockRange) IsNextContigousBlock(next BlockRange) bool
IsNextContigousBlock checks if 'next' BlockRange is exactly the next contiguous block so the way to use this is: previousBlockRange.IsNextContigousBlock(nextBlockRange)
func (BlockRange) Merge ¶
func (b BlockRange) Merge(other BlockRange) []BlockRange
Merge merges two BlockRanges and returns a slice of BlockRanges. If the two BlockRanges overlap, it returns a single BlockRange that encompasses both. If they do not overlap, it returns both BlockRanges in sorted order.
func (BlockRange) Overlaps ¶
func (b BlockRange) Overlaps(other BlockRange) bool
func (BlockRange) String ¶
func (b BlockRange) String() string
String returns a string representation of the BlockRange in the format "From: <from>, To: <to>".
func (BlockRange) Subtract ¶
func (b BlockRange) Subtract(other BlockRange) []BlockRange
Subtract two BlockRanges A----(C---D)----B -> [A-C-1] , [D+1 - B] A----B (C---D) -> [A-B] (C---D) A----B -> [A-B] A----B C----D -> [A-B] (C---A---B---D) -> []
type GenericSubscriber ¶
type GenericSubscriber[T any] struct { // contains filtered or unexported fields }
func NewGenericSubscriber ¶
func NewGenericSubscriber[T any]() *GenericSubscriber[T]
func (*GenericSubscriber[T]) Publish ¶
func (g *GenericSubscriber[T]) Publish(data T)
func (*GenericSubscriber[T]) Subscribe ¶
func (g *GenericSubscriber[T]) Subscribe(subscriberName string) <-chan T
type Logger ¶ added in v0.2.0
type Logger interface {
Panicf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Info(args ...interface{})
Infof(format string, args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
Warn(args ...interface{})
Warnf(format string, args ...interface{})
Debug(args ...interface{})
Debugf(format string, args ...interface{})
}
Logger is an interface that defines the methods to log messages
type RESTConfig ¶ added in v0.5.0
type RESTConfig struct {
// Host specifies the hostname or IP address on which the REST service will listen.
Host string `mapstructure:"Host"`
// Port defines the port number on which the REST service will be accessible.
Port int `mapstructure:"Port"`
// ReadTimeout is the HTTP server read timeout
// check net/http.server.ReadTimeout and net/http.server.ReadHeaderTimeout
ReadTimeout types.Duration `mapstructure:"ReadTimeout"`
// WriteTimeout is the HTTP server write timeout
// check net/http.server.WriteTimeout
WriteTimeout types.Duration `mapstructure:"WriteTimeout"`
// MaxRequestsPerIPAndSecond defines how many requests a single IP can
// send within a single second
MaxRequestsPerIPAndSecond float64 `mapstructure:"MaxRequestsPerIPAndSecond"`
}
RESTConfig contains the configuration settings for the REST service in the Aggkit application.
func (*RESTConfig) Address ¶ added in v0.5.0
func (c *RESTConfig) Address() string
Address constructs and returns the address as a string in the format "host:port".
type RateLimit ¶ added in v0.0.2
type RateLimit struct {
// contains filtered or unexported fields
}
RateLimit is a rate limiter
func NewRateLimit ¶ added in v0.0.2
func NewRateLimit(cfg RateLimitConfig) *RateLimit
NewRateLimit creates a new RateLimit
type RateLimitConfig ¶ added in v0.0.2
type RateLimitConfig struct {
NumRequests int `mapstructure:"NumRequests"`
Interval types.Duration `mapstructure:"Interval"`
}
RateLimitConfig is the configuration for the rate limit, if NumRequests==0 or Interval==0, the rate limit is disabled
func NewRateLimitConfig ¶ added in v0.0.2
func NewRateLimitConfig(numRequests int, period time.Duration) RateLimitConfig
NewRateLimitConfig creates a new RateLimitConfig
func (RateLimitConfig) Enabled ¶ added in v0.0.2
func (r RateLimitConfig) Enabled() bool
Enabled returns true if the rate limit is enabled
func (RateLimitConfig) String ¶ added in v0.0.2
func (r RateLimitConfig) String() string
String returns a string representation of the RateLimitConfig
type RetryBackoffConfig ¶ added in v0.7.0
type RetryBackoffConfig struct {
InitialBackoff types.Duration
MaxBackoff types.Duration
BackoffMultiplier float64
MaxRetries int
}
func (*RetryBackoffConfig) Brief ¶ added in v0.7.0
func (r *RetryBackoffConfig) Brief() string
func (*RetryBackoffConfig) NewRetryHandler ¶ added in v0.7.0
func (r *RetryBackoffConfig) NewRetryHandler() (commontypes.RetryHandler, error)
func (*RetryBackoffConfig) String ¶ added in v0.7.0
func (r *RetryBackoffConfig) String() string
func (*RetryBackoffConfig) Validate ¶ added in v0.7.0
func (r *RetryBackoffConfig) Validate() error
type RetryConfigMode ¶ added in v0.7.0
type RetryConfigMode string
const ( RetryConfigModeNoRetries RetryConfigMode = "" RetryConfigModeDelays RetryConfigMode = "delays" RetryConfigModeBackoff RetryConfigMode = "backoff" )
type RetryDelaysConfig ¶ added in v0.7.0
type RetryDelaysConfig struct {
// MaxRetries is the maximum number of retries to attempt.
// if MaxRetries is -1, it means infinite retries.
// if MaxRetries is 0, it means no retries will be attempted.
MaxRetries int
// Delays is a list of durations to wait before each retry.
// If there are more retry attempts than items in the list, the last item
// in the list is reused for all subsequent attempts.
Delays []types.Duration
}
RetryDelaysConfig defines the configuration for retry delays.
func (*RetryDelaysConfig) Brief ¶ added in v0.7.0
func (r *RetryDelaysConfig) Brief() string
func (*RetryDelaysConfig) NewRetryHandler ¶ added in v0.7.0
func (r *RetryDelaysConfig) NewRetryHandler() (commontypes.RetryHandler, error)
RetryHandler returns a object that implements the logic
func (*RetryDelaysConfig) String ¶ added in v0.7.0
func (r *RetryDelaysConfig) String() string
func (*RetryDelaysConfig) Validate ¶ added in v0.7.0
func (r *RetryDelaysConfig) Validate() error
type RetryHandlerDelays ¶ added in v0.7.0
type RetryHandlerDelays struct {
RetryDelaysConfig
}
RetryHandlerDelays is a struct that holds the retry delays and the maximum number of retries. It implements the RetryDelayer interface, which allows executing a function with retry logic. You can check object RetryDelaysConfig for more details
func NewRetryHandler ¶ added in v0.7.0
func NewRetryHandler(delays []types.Duration, maxRetries int) *RetryHandlerDelays
NewRetryHandler creates a new RetryHandler with the specified delays and maximum retries.
func (*RetryHandlerDelays) Delay ¶ added in v0.7.0
func (r *RetryHandlerDelays) Delay(attempt int) time.Duration
Delay returns the delay for the given attempt.
func (*RetryHandlerDelays) IsInfiniteRetriesConfigured ¶ added in v0.7.0
func (r *RetryHandlerDelays) IsInfiniteRetriesConfigured() bool
IsInfiniteRetriesConfigured return true if the configuration allows infinite retries.
func (*RetryHandlerDelays) IsNoRetriesConfigured ¶ added in v0.7.0
func (r *RetryHandlerDelays) IsNoRetriesConfigured() bool
func (*RetryHandlerDelays) MustExecuteAttempt ¶ added in v0.7.0
func (r *RetryHandlerDelays) MustExecuteAttempt(attempt int) bool
MustExecuteAttempt returns true if must execute `attempt`
func (*RetryHandlerDelays) String ¶ added in v0.7.0
func (r *RetryHandlerDelays) String() string
String returns a string representation of the RetryDelays struct.
func (*RetryHandlerDelays) StringAttempt ¶ added in v0.7.0
func (r *RetryHandlerDelays) StringAttempt(attempt int) string
StringAttempt returns the string representation of the number of attempts.
func (*RetryHandlerDelays) Validate ¶ added in v0.7.0
func (r *RetryHandlerDelays) Validate() error
Validate checks if the RetryDelays configuration is valid.
type RetryPolicyGenericConfig ¶ added in v0.7.0
type RetryPolicyGenericConfig struct {
// Mode denotes the retry configuration mode, is it defined using the
// predefined delays, backoff formula or no retries
Mode RetryConfigMode `mapstructure:"RetryMode"`
// MaxRetries is the maximum number of retries
MaxRetries int `mapstructure:"MaxRetries"`
// Delays is the predefined set of delays for each retry
Delays []types.Duration `mapstructure:"Delays"`
// InitialBackoff is the initial backoff duration for retries
InitialBackoff types.Duration `mapstructure:"InitialBackoff"`
// MaxBackoff is the maximum backoff duration for retries
MaxBackoff types.Duration `mapstructure:"MaxBackoff"`
// BackoffMultiplier is the multiplier for exponential backoff
BackoffMultiplier float64 `mapstructure:"BackoffMultiplier"`
// contains filtered or unexported fields
}
RetryPolicyGenericConfig defines the configuration for retry policies in the system. it's a merge of struct RetryBackoffConfig and RetryDelaysConfig in order of simplify reading from config file (check types)
func (*RetryPolicyGenericConfig) Brief ¶ added in v0.7.0
func (r *RetryPolicyGenericConfig) Brief() string
func (*RetryPolicyGenericConfig) CleanCache ¶ added in v0.7.0
func (r *RetryPolicyGenericConfig) CleanCache()
CleanCache clears the internal cache of the RetryPolicyGenericConfig. useful if you modify any params and want to rebuild the underlying object
func (*RetryPolicyGenericConfig) Factory ¶ added in v0.7.0
func (r *RetryPolicyGenericConfig) Factory() (commontypes.RetryPolicyConfigurer, error)
func (*RetryPolicyGenericConfig) NewRetryHandler ¶ added in v0.7.0
func (r *RetryPolicyGenericConfig) NewRetryHandler() (commontypes.RetryHandler, error)
func (*RetryPolicyGenericConfig) SetCache ¶ added in v0.7.0
func (r *RetryPolicyGenericConfig) SetCache(instance commontypes.RetryPolicyConfigurer)
func (*RetryPolicyGenericConfig) String ¶ added in v0.7.0
func (r *RetryPolicyGenericConfig) String() string
func (*RetryPolicyGenericConfig) Validate ¶ added in v0.7.0
func (r *RetryPolicyGenericConfig) Validate() error
type TimeTracker ¶
type TimeTracker struct {
// contains filtered or unexported fields
}
func NewTimeTracker ¶
func NewTimeTracker() *TimeTracker
func NewTimeTrackerValues ¶
func NewTimeTrackerValues(start, end time.Time, times uint32) *TimeTracker
func (*TimeTracker) Duration ¶
func (t *TimeTracker) Duration() time.Duration
Duration returns the duration between Start and Stop (must be stopeed)
func (*TimeTracker) Elapsed ¶
func (t *TimeTracker) Elapsed() time.Duration
Elapsed returns the elapsed time since Start was called
func (*TimeTracker) Start ¶
func (t *TimeTracker) Start()
func (*TimeTracker) Stop ¶
func (t *TimeTracker) Stop()
func (*TimeTracker) String ¶
func (t *TimeTracker) String() string
func (*TimeTracker) TotalDuration ¶
func (t *TimeTracker) TotalDuration() time.Duration