datastore

package
v0.0.0-...-a4e836c Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package datastore helps storing data, utilizing Redis and Postgres as backends

Index

Constants

View Source
const (
	LocalMemory dataSource = "local memory"
	RedisCache  dataSource = "redis"
)
View Source
const (
	BlockSimulationSubmitted = "1"
	BlockSimulationPassed    = "2"
	BlockSimulationFailed    = "3"
)

Variables

View Source
var (
	ErrActiveValidatorNotFound       = errors.New("active validator not found")
	ErrValidatorRegistrationNotFound = errors.New("validator registration not found")
)
View Source
var ErrFailedUpdatingTopBidNoBids = errors.New("failed to update top bid because no bids were found")
View Source
var ErrGetHeaderResponseNotFound = errors.New("getHeader response not found")
View Source
var ErrGetPayloadResponseNotFound = errors.New("getPayloadResponse not found")

Functions

This section is empty.

Types

type AliasSignedValidatorRegistration

type AliasSignedValidatorRegistration types.SignedValidatorRegistration

func (AliasSignedValidatorRegistration) MarshalBinary

func (i AliasSignedValidatorRegistration) MarshalBinary() ([]byte, error)

type BlockSimulationStatus

type BlockSimulationStatus string

type Datastore

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

Datastore provides a local memory cache and Redis

func NewDatastore

func NewDatastore(redisURI, prefix string, connectionPoolLimit int, log *logrus.Entry) (ds *Datastore, err error)

func (*Datastore) CheckDemotedBuilderPubkey

func (ds *Datastore) CheckDemotedBuilderPubkey(ctx context.Context, builderPubkey string) (bool, error)

func (*Datastore) CheckGetPayloadResponse

func (ds *Datastore) CheckGetPayloadResponse(ctx context.Context, slot uint64, blockHash string) (*common.GetPayloadResponse, error)

func (*Datastore) CleanupOldBidsAndBlocks

func (ds *Datastore) CleanupOldBidsAndBlocks(headSlot uint64) (numRemoved, numRemaining int)

func (*Datastore) DeleteBlockSubmissions

func (ds *Datastore) DeleteBlockSubmissions(ctx context.Context, slot uint64, parentHash, proposerPubkey string, blockHashes map[string]struct{}) error

func (*Datastore) GetActiveValidator

func (ds *Datastore) GetActiveValidator(ctx context.Context, pubKey string) (*ValidatorLatency, error)

GetActiveValidator returns the active validator with the given public key.

func (*Datastore) GetActiveValidators

func (ds *Datastore) GetActiveValidators(ctx context.Context) (int, error)

func (*Datastore) GetBidTrace

func (ds *Datastore) GetBidTrace(ctx context.Context, blockHash string) (*v1.BidTrace, error)

func (*Datastore) GetBlockSubmissionStatus

func (ds *Datastore) GetBlockSubmissionStatus(ctx context.Context, blockHash string) (string, error)

func (*Datastore) GetBuilderBlockHash

func (ds *Datastore) GetBuilderBlockHash(ctx context.Context, blockHash string) (string, error)

func (*Datastore) GetBuilderLatestPayloadReceivedAt

func (ds *Datastore) GetBuilderLatestPayloadReceivedAt(ctx context.Context, slot uint64, builderPubkey, parentHash, proposerPubkey string) (int64, error)

func (*Datastore) GetDeliveredPayload

func (ds *Datastore) GetDeliveredPayload(ctx context.Context, slot uint64) (string, error)

func (*Datastore) GetDemotedBuilderPubkeys

func (ds *Datastore) GetDemotedBuilderPubkeys(ctx context.Context) (*syncmap.SyncMap[string, string], error)

func (*Datastore) GetGetHeaderResponse

func (ds *Datastore) GetGetHeaderResponse(ctx context.Context, slot uint64, parentHash, proposerPubkey string) ([]byte, *common.GetHeaderResponse, dataSource, error)

GetGetHeaderResponse returns the bid from memory or Redis

func (*Datastore) GetGetPayloadResponse

func (ds *Datastore) GetGetPayloadResponse(ctx context.Context, slot uint64, blockHash string) (*common.GetPayloadResponse, error)

func (*Datastore) GetSetBlockSubmissionStatus

func (ds *Datastore) GetSetBlockSubmissionStatus(ctx context.Context, blockHash string, status BlockSimulationStatus) (string, error)

func (*Datastore) GetValidatorRegistration

func (ds *Datastore) GetValidatorRegistration(ctx context.Context, proposerPubkey types.PubkeyHex) (*types.SignedValidatorRegistration, error)

GetValidatorRegistration returns the validator registration for the given proposerPubkey.

func (*Datastore) GetValidatorRegistrations

func (ds *Datastore) GetValidatorRegistrations(ctx context.Context, proposerPubKeys []string) ([]types.SignedValidatorRegistration, error)

GetValidatorRegistrations returns the validator registrations for the given proposerPubKeys.

func (*Datastore) IsValidatorTrusted

func (ds *Datastore) IsValidatorTrusted(ctx context.Context, proposerPubkey types.PubkeyHex) bool

IsValidatorTrusted returns the validator is trusted or not for the given proposerPubkey.

func (*Datastore) RedisPublish

func (ds *Datastore) RedisPublish(subscriptionChannelName string, message interface{}, senderUUID string) error

func (*Datastore) RedisSubscribe

func (ds *Datastore) RedisSubscribe(subscriptionChannelName string, msgChannel chan *redis.Message)

func (*Datastore) SaveBidTrace

func (ds *Datastore) SaveBidTrace(ctx context.Context, bidTrace *v1.BidTrace, blockHash string) error

func (*Datastore) SaveBlock

func (ds *Datastore) SaveBlock(
	ctx context.Context,
	getHeaderResponse *common.GetHeaderResponse,
	payload *capella.ExecutionPayload,
	bidTrace *v1.BidTrace,
	receivedAt time.Time,
	slotExpirationChan chan *syncmap.SyncMap[uint64, []string],
	tier sdnmessage.AccountTier,
) (isMostProfitable bool, saveStats *saveBlockStats, err error)

func (*Datastore) SaveBlockSubmissionTx

func (ds *Datastore) SaveBlockSubmissionTx(ctx context.Context, tx redis.Pipeliner, signedBidTrace *v1.BidTrace, headerResp *common.GetHeaderResponse, payloadResp *api.VersionedExecutionPayload, blockHash string, parentHash string, proposerPubkey string) error

SaveBlockSubmissionTx stores getHeader and getPayload for later use, to memory and Redis.

func (*Datastore) SaveBuilderBlockHash

func (ds *Datastore) SaveBuilderBlockHash(ctx context.Context, blockHash string, builderPubkey string) error

func (*Datastore) SaveDeliveredPayloadBuilderRedis

func (ds *Datastore) SaveDeliveredPayloadBuilderRedis(ctx context.Context, slot uint64, blockHash string) error

func (*Datastore) SaveGetPayloadResponseTx

func (ds *Datastore) SaveGetPayloadResponseTx(ctx context.Context, tx redis.Pipeliner, slot uint64, resp *common.GetPayloadResponse) error

SaveGetPayloadResponseTx saves the payload response

func (*Datastore) SaveLatestBuilderBidTx

func (ds *Datastore) SaveLatestBuilderBidTx(ctx context.Context, tx redis.Pipeliner, slot uint64, builderPubkey, parentHash, proposerPubkey string, receivedAt time.Time, headerResp *common.GetHeaderResponse) (keysToExpire []string, err error)

SaveLatestBuilderBidTx saves the latest bid by a specific builder

func (*Datastore) SaveLatestBuilderBidTxSingleMap

func (ds *Datastore) SaveLatestBuilderBidTxSingleMap(ctx context.Context, tx redis.Pipeliner, slot uint64, builderPubkey, parentHash, proposerPubkey string, receivedAt time.Time, headerResp *common.GetHeaderResponse) (keysToExpire []string, bidStr string, err error)

SaveLatestBuilderBidTxSingleMap saves the latest bid by a specific builder using single map

func (*Datastore) SetActiveValidators

func (ds *Datastore) SetActiveValidators(ctx context.Context, validators map[string]interface{}) error

func (*Datastore) SetBlockSubmissionStatus

func (ds *Datastore) SetBlockSubmissionStatus(ctx context.Context, blockHash string, status BlockSimulationStatus) error

func (*Datastore) SetDemotedBuilderPubkey

func (ds *Datastore) SetDemotedBuilderPubkey(ctx context.Context, builderPubkey string) error

func (*Datastore) SetValidatorRegistrationMap

func (ds *Datastore) SetValidatorRegistrationMap(ctx context.Context, data map[string]interface{}) error

func (*Datastore) TxPipeline

func (ds *Datastore) TxPipeline() redis.Pipeliner

TxPipeline returns a new transactional pipeline.

func (*Datastore) UnmarshalRedisCapellaBlockMessage

func (ds *Datastore) UnmarshalRedisCapellaBlockMessage(redisMsg *redis.Message, destination *common.WrappedCapellaBuilderSubmitBlockRequest) (string, error)

func (*Datastore) UnmarshalRedisMessage

func (ds *Datastore) UnmarshalRedisMessage(redisMsg *redis.Message, destination any) (string, error)

func (*Datastore) UpdateActiveValidators

func (ds *Datastore) UpdateActiveValidators() error

func (*Datastore) UpdateTopBidTx

func (ds *Datastore) UpdateTopBidTx(ctx context.Context, tx redis.Pipeliner, slot uint64, parentHash, proposerPubkey, builderPubkey string, newBidValue *big.Int, newBidStr string) (updated bool, err error)

UpdateTopBidTx updates the top bid for a specific slot if needed

type GetHeaderResponseKey

type GetHeaderResponseKey struct {
	Slot           uint64
	ParentHash     string
	ProposerPubkey string
}

type GetPayloadResponseKey

type GetPayloadResponseKey struct {
	Slot           uint64
	ProposerPubkey string
	BlockHash      string
}

type RedisMessage

type RedisMessage struct {
	Message    interface{} `json:"message"`
	SenderUUID string      `json:"sender_uuid"`
}

func (*RedisMessage) MarshalBinary

func (rm *RedisMessage) MarshalBinary() ([]byte, error)

type ValidatorLatency

type ValidatorLatency struct {
	Registration   types.SignedValidatorRegistration `json:"registration"`
	IPAddress      string                            `json:"ip_address"`
	LastRegistered int64                             `json:"last_registered"`
	Latency        float32                           `json:"latency"`
	IsTrusted      bool                              `json:"is_trusted"`
}

func (*ValidatorLatency) MarshalBinary

func (l *ValidatorLatency) MarshalBinary() ([]byte, error)

func (*ValidatorLatency) UnmarshalBinary

func (l *ValidatorLatency) UnmarshalBinary(data []byte) error

Jump to

Keyboard shortcuts

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