common

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetReorgError added in v0.6.6

func GetReorgError(err error) error

GetReorgError returns the error that caused the reorg

func GetReorgErrorBlockNumber added in v0.6.6

func GetReorgErrorBlockNumber(err error) uint64

GetReorgErrorBlockNumber returns the block number that caused the reorg

func IsReorgError added in v0.6.6

func IsReorgError(err error) bool

IsReorgError checks if an error is a ReorgError

func LogComparedBytes

func LogComparedBytes(name1 string, name2 string, data1 []byte, data2 []byte, numBytesBefore int, numBytesAfter int) string

LogComparedBytes returns a string the bytes of two []bytes, starting from the first byte that is different

func RpcBatchToStateBatch

func RpcBatchToStateBatch(rpcBatch *types.Batch) *state.Batch

RpcBatchToStateBatch converts a rpc batch to a state batch

Types

type Cache

type Cache[K comparable, T any] struct {
	// contains filtered or unexported fields
}

Cache is a generic cache implementation with TOL (time of live) for each item

func NewCache

func NewCache[K comparable, T any](timerProvider TimeProvider, timeOfLiveItems time.Duration) *Cache[K, T]

NewCache creates a new cache

func (*Cache[K, T]) Clear

func (c *Cache[K, T]) Clear()

Clear clears the cache

func (*Cache[K, T]) Delete

func (c *Cache[K, T]) Delete(key K)

Delete deletes the key from the cache

func (*Cache[K, T]) DeleteOutdated

func (c *Cache[K, T]) DeleteOutdated()

DeleteOutdated deletes the outdated items from the cache

func (*Cache[K, T]) Get

func (c *Cache[K, T]) Get(key K) (T, bool)

Get returns the value of the key and true if the key exists and is not outdated

func (*Cache[K, T]) GetOrDefault

func (c *Cache[K, T]) GetOrDefault(key K, defaultValue T) T

GetOrDefault returns the value of the key and defaultValue if the key does not exist or is outdated

func (*Cache[K, T]) Keys

func (c *Cache[K, T]) Keys() []K

Keys returns the keys of the cache

func (*Cache[K, T]) Len

func (c *Cache[K, T]) Len() int

Len returns the number of items in the cache

func (*Cache[K, T]) RenewEntry

func (c *Cache[K, T]) RenewEntry(key K, validTime time.Time)

RenewEntry renews the entry of the key

func (*Cache[K, T]) Set

func (c *Cache[K, T]) Set(key K, value T)

Set sets the value of the key

func (*Cache[K, T]) Values

func (c *Cache[K, T]) Values() []T

Values returns the values of the cache

type CriticalErrorHalt

type CriticalErrorHalt struct {
	EventLog  syncinterfaces.EventLogInterface
	SleepTime time.Duration
}

CriticalErrorHalt is a Synchronizer halter, implements syncinterfaces.Halter basically it logs an error and keep in a infinite loop to halt the synchronizer

func NewCriticalErrorHalt

func NewCriticalErrorHalt(eventLog syncinterfaces.EventLogInterface, sleepTime time.Duration) *CriticalErrorHalt

NewCriticalErrorHalt creates a new HaltSynchronizer

func (*CriticalErrorHalt) CriticalError

func (g *CriticalErrorHalt) CriticalError(ctx context.Context, err error)

CriticalError halts the Synchronizer and write a eventLog on Database

type DefaultTimeProvider

type DefaultTimeProvider struct{}

DefaultTimeProvider is the default implementation of TimeProvider

func (DefaultTimeProvider) Now

func (d DefaultTimeProvider) Now() time.Time

Now returns current time

type MockTimerProvider

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

MockTimerProvider is a mock implementation of the TimerProvider interface that return the internal variable

func (*MockTimerProvider) Now

func (m *MockTimerProvider) Now() time.Time

Now in the implementation of TimeProvider.Now()

type ReorgError added in v0.6.6

type ReorgError struct {
	// BlockNumber is the block number that caused the reorg
	BlockNumber uint64
	Err         error
}

ReorgError is an error that is raised when a reorg is detected

func NewReorgError added in v0.6.6

func NewReorgError(blockNumber uint64, err error) *ReorgError

NewReorgError creates a new ReorgError

func (*ReorgError) Error added in v0.6.6

func (e *ReorgError) Error() string

type TimeProvider

type TimeProvider interface {
	// Now returns current time
	Now() time.Time
}

TimeProvider is a interface for classes that needs time and we want to be able to unittest it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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