utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownErrorCode                 = -1
	NoMetaDBRegisteredErrorCode      = 41001
	WriterStoppedErrorCode           = 41002
	ReadInvalidHeaderErrorCode       = 41003
	AwsS3ErrorCode                   = 41004
	WriterRecoveryErrorCode          = 41005
	RemoteErrorCode                  = 41006
	MetaDBAlreadyRegisteredErrorCode = 41007
	BroadcasterErrorCode             = 41008
	StreamNotInitErrorCode           = 41009
)
View Source
const (
	UnInited  int = 0
	InProcess int = 1
	Sucess    int = 2
	Failed    int = 3
)
View Source
const ConnNum = 32
View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
)

Lengths of hashes and addresses in bytes.

Variables

View Source
var (
	ErrNoMetaDBRegistered = New(NoMetaDBRegisteredErrorCode, "no meta db registered")

	ErrMetaDBAlreadyRegistered = New(MetaDBAlreadyRegisteredErrorCode, "meta db already registered")

	ErrWriterStopped = New(WriterStoppedErrorCode, "writer stopped")

	ErrReadInvalidHeader = New(ReadInvalidHeaderErrorCode, "invalid header")

	ErrAwsS3 = New(AwsS3ErrorCode, "aws s3 error")

	ErrWriterRecovey = New(WriterRecoveryErrorCode, "writer recovery error")

	ErrStreamNotInit = New(StreamNotInitErrorCode, "stream not init")
)

Functions

func BlockPrefix

func BlockPrefix(info *pb.BlockInfo) string

func BytesToHashString

func BytesToHashString(b []byte) string

BytesToHashString returns the hash as the hexadecimal string of the byte-reversed hash.

func CheckConnState

func CheckConnState(conn *grpc.ClientConn) error

func CommonPrefix

func CommonPrefix(env, chainId, role string, blockTy pb.BlockInfo_BlockType) string

func DevelopmentMode

func DevelopmentMode()

func DevelopmentModeWithoutStackTrace

func DevelopmentModeWithoutStackTrace()

func HeaderPrefix

func HeaderPrefix(info *pb.BlockInfo) string

func HexEncode

func HexEncode(b []byte) string

HexEncode encodes b to hex format.

func InfoToPrefix

func InfoToPrefix(info *pb.BlockInfo) string

func IntegrationTestMod

func IntegrationTestMod()

func Less

func Less(item *entry, than *entry) bool

func Logger

func Logger() *zap.Logger

Logger returns the global logger.

func New

func New(code int, text string) error

func OpenAndReadDbInfo

func OpenAndReadDbInfo(path string) (*pb.DBInfoList, error)

func PrefixToBlockInfo

func PrefixToBlockInfo(key string) (info *pb.BlockInfo, err error)

func PrefixToHeaderInfo

func PrefixToHeaderInfo(key string) (info *pb.BlockInfo, err error)

func ProductionMode

func ProductionMode()

func ProductionModeWithoutStackTrace

func ProductionModeWithoutStackTrace()

func Topic

func Topic(env, chainId, role string) string

func TopicPrefix

func TopicPrefix(env, chainId, role string) string

Types

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCache

func NewCache(cacheSize uint) *Cache

func (*Cache) GetOrCreatePrefixCache

func (c *Cache) GetOrCreatePrefixCache(prefix string) (lru *LRU)

type ClientPool

type ClientPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewClientPool

func NewClientPool(target string) (*ClientPool, error)

func (*ClientPool) GetConn

func (cc *ClientPool) GetConn() (*grpc.ClientConn, int64, error)

func (*ClientPool) ResetConn

func (cc *ClientPool) ResetConn(idx int64) (*grpc.ClientConn, error)

type Config

type Config struct {
	S3ProxyAddr      string
	KafkaAddr        string
	RemoteAddr       string
	RemoteListenAddr string
	Env              string
	ChainId          string
	Role             string
	DBInfoPath       string
	ReorgDeep        int
	DBCacheSize      int
	NdrcAddr         string
	MetricEndpoint   string
}

Config represents the configuration of the replicator.

func NewDevelopmentConfig

func NewDevelopmentConfig() *Config

NewDevelopmentConfig returns a Dev env Config with default values.

type ErrorCode

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

func ErrorToErrorCode

func ErrorToErrorCode(err error) *ErrorCode

func (*ErrorCode) Code

func (e *ErrorCode) Code() int

func (*ErrorCode) Error

func (e *ErrorCode) Error() string

type FetchFn

type FetchFn func() (value interface{}, err error)

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b.

type LRU

type LRU struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LRU implements a non-thread safe fixed size/weight LRU cache

func NewLru

func NewLru(maxSize uint) *LRU

NewLru creates a weighted LRU of the given size.

func (*LRU) Get

func (c *LRU) Get(key string, height int64, fetchFn FetchFn) (value interface{}, err error)

Get looks up a key's value from the cache.

func (*LRU) Insert

func (c *LRU) Insert(key string, value interface{}, height int64) *entry

Jump to

Keyboard shortcuts

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