datastore

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	RedisConfigFieldPubkey         = "pubkey"
	RedisStatsFieldLatestSlot      = "latest-slot"
	RedisStatsFieldValidatorsTotal = "validators-total"

	ErrFailedUpdatingTopBidNoBids            = errors.New("failed to update top bid because no bids were found")
	ErrAnotherPayloadAlreadyDeliveredForSlot = errors.New("another payload block hash for slot was already delivered")
	ErrPastSlotAlreadyDelivered              = errors.New("payload for past slot was already delivered")
)
View Source
var ErrExecutionPayloadNotFound = errors.New("execution payload not found")

Functions

This section is empty.

Types

type BuilderBids added in v0.20.0

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

BuilderBids supports redis.SaveBidAndUpdateTopBid

func NewBuilderBids added in v0.20.0

func NewBuilderBids(bidValueMap map[string]string) *BuilderBids

func NewBuilderBidsFromRedis added in v0.26.0

func NewBuilderBidsFromRedis(ctx context.Context, r *RedisCache, pipeliner redis.Pipeliner, slot uint64, parentHash, proposerPubkey string) (*BuilderBids, error)

type Datastore

type Datastore struct {

	// Used for proposer-API readiness check
	KnownValidatorsWasUpdated uberatomic.Bool
	// contains filtered or unexported fields
}

Datastore provides a local memory cache with a Redis and DB backend

func NewDatastore

func NewDatastore(redisCache *RedisCache, memcached *Memcached, db database.IDatabaseService) (ds *Datastore, err error)

func (*Datastore) GetGetPayloadResponse

func (ds *Datastore) GetGetPayloadResponse(log *logrus.Entry, slot uint64, proposerPubkey, blockHash string) (*builderApi.VersionedSubmitBlindedBlockResponse, error)

GetGetPayloadResponse returns the getPayload response from memory or Redis or Database

func (*Datastore) GetKnownValidatorPubkeyByIndex

func (ds *Datastore) GetKnownValidatorPubkeyByIndex(index uint64) (common.PubkeyHex, bool)

func (*Datastore) IsKnownValidator

func (ds *Datastore) IsKnownValidator(pubkeyHex common.PubkeyHex) bool

func (*Datastore) NumKnownValidators

func (ds *Datastore) NumKnownValidators() int

func (*Datastore) NumRegisteredValidators

func (ds *Datastore) NumRegisteredValidators() (uint64, error)

func (*Datastore) RefreshKnownValidators

func (ds *Datastore) RefreshKnownValidators(log *logrus.Entry, beaconClient beaconclient.IMultiBeaconClient, slot uint64)

RefreshKnownValidators loads known validators from CL client into memory

For the CL client this is an expensive operation and takes a bunch of resources. This is why we schedule the requests for slot 4 and 20 of every epoch, 6 seconds into the slot (on suggestion of @potuz). It's also run once at startup.

func (*Datastore) SaveValidatorRegistration added in v0.9.1

func (ds *Datastore) SaveValidatorRegistration(entry builderApiV1.SignedValidatorRegistration) error

SaveValidatorRegistration saves a validator registration into both Redis and the database

type ExecutionPayloadRepository added in v0.20.0

type ExecutionPayloadRepository interface {
	GetExecutionPayload(slot uint64, proposerPubKey, blockHash string) (*builderApi.VersionedSubmitBlindedBlockResponse, error)
	SaveExecutionPayload(slot uint64, proposerPubKey, blockHash string, payload *builderApi.VersionedSubmitBlindedBlockResponse) error
}

ExecutionPayloadRepository defines methods to fetch and store execution engine payloads

type GetHeaderResponseKey

type GetHeaderResponseKey struct {
	Slot           uint64
	ParentHash     string
	ProposerPubkey string
}

type GetPayloadResponseKey

type GetPayloadResponseKey struct {
	Slot           uint64
	ProposerPubkey string
	BlockHash      string
}

type Memcached added in v0.20.0

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

func NewMemcached added in v0.20.0

func NewMemcached(prefix string, servers ...string) (*Memcached, error)

func (*Memcached) GetExecutionPayload added in v0.20.0

func (m *Memcached) GetExecutionPayload(slot uint64, proposerPubKey, blockHash string) (*builderApi.VersionedSubmitBlindedBlockResponse, error)

GetExecutionPayload attempts to fetch execution engine payload from memcached using composite key of slot, proposer public key, block hash, and cache prefix if specified.

func (*Memcached) SaveExecutionPayload added in v0.20.0

func (m *Memcached) SaveExecutionPayload(slot uint64, proposerPubKey, blockHash string, payload *builderApi.VersionedSubmitBlindedBlockResponse) error

SaveExecutionPayload attempts to insert execution engine payload to memcached using composite key of slot, proposer public key, block hash, and cache prefix if specified. Note that writes to the same key value (i.e. same slot, proposer public key, and block hash) will overwrite the existing entry.

type RedisCache

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

func NewRedisCache

func NewRedisCache(prefix, redisURI, readonlyURI string) (*RedisCache, error)

func (*RedisCache) CheckAndSetLastSlotAndHashDelivered added in v0.24.0

func (r *RedisCache) CheckAndSetLastSlotAndHashDelivered(slot uint64, hash string) (err error)

func (*RedisCache) DelBuilderBid added in v0.26.0

func (r *RedisCache) DelBuilderBid(ctx context.Context, pipeliner redis.Pipeliner, slot uint64, parentHash, proposerPubkey, builderPubkey string) (err error)

DelBuilderBid removes a builders most recent bid

func (*RedisCache) GetBestBid added in v0.11.0

func (r *RedisCache) GetBestBid(slot uint64, parentHash, proposerPubkey string) (*builderSpec.VersionedSignedBuilderBid, error)

func (*RedisCache) GetBidTrace added in v0.10.0

func (r *RedisCache) GetBidTrace(slot uint64, proposerPubkey, blockHash string) (*common.BidTraceV2WithBlobFields, error)

GetBidTrace returns (trace, nil), or (nil, redis.Nil) if the trace does not exist

func (*RedisCache) GetBuilderLatestPayloadReceivedAt added in v0.12.0

func (r *RedisCache) GetBuilderLatestPayloadReceivedAt(ctx context.Context, pipeliner redis.Pipeliner, slot uint64, builderPubkey, parentHash, proposerPubkey string) (int64, error)

func (*RedisCache) GetBuilderLatestValue added in v0.20.0

func (r *RedisCache) GetBuilderLatestValue(slot uint64, parentHash, proposerPubkey, builderPubkey string) (topBidValue *big.Int, err error)

GetBuilderLatestValue gets the latest bid value for a given slot+parent+proposer combination for a specific builder pubkey.

func (*RedisCache) GetExecutionPayloadCapella added in v0.26.0

func (r *RedisCache) GetExecutionPayloadCapella(slot uint64, proposerPubkey, blockHash string) (*builderApi.VersionedSubmitBlindedBlockResponse, error)

func (*RedisCache) GetFloorBidValue added in v0.24.0

func (r *RedisCache) GetFloorBidValue(ctx context.Context, pipeliner redis.Pipeliner, slot uint64, parentHash, proposerPubkey string) (floorValue *big.Int, err error)

GetFloorBidValue returns the value of the highest non-cancellable bid

func (*RedisCache) GetLastHashDelivered added in v0.24.0

func (r *RedisCache) GetLastHashDelivered() (hash string, err error)

func (*RedisCache) GetLastSlotDelivered added in v0.20.0

func (r *RedisCache) GetLastSlotDelivered(ctx context.Context, pipeliner redis.Pipeliner) (slot uint64, err error)

func (*RedisCache) GetObj

func (r *RedisCache) GetObj(key string, obj any) (err error)

func (*RedisCache) GetPayloadContents added in v0.29.0

func (r *RedisCache) GetPayloadContents(slot uint64, proposerPubkey, blockHash string) (*builderApi.VersionedSubmitBlindedBlockResponse, error)

func (*RedisCache) GetPayloadContentsDeneb added in v0.29.0

func (r *RedisCache) GetPayloadContentsDeneb(slot uint64, proposerPubkey, blockHash string) (*builderApi.VersionedSubmitBlindedBlockResponse, error)

func (*RedisCache) GetProposerDuties

func (r *RedisCache) GetProposerDuties() (proposerDuties []common.BuilderGetValidatorsResponseEntry, err error)

func (*RedisCache) GetRelayConfig

func (r *RedisCache) GetRelayConfig(field string) (string, error)

func (*RedisCache) GetStats

func (r *RedisCache) GetStats(field string) (value string, err error)

func (*RedisCache) GetStatsUint64 added in v0.20.0

func (r *RedisCache) GetStatsUint64(field string) (value uint64, err error)

GetStatsUint64 returns (valueUint64, nil), or (0, redis.Nil) if the field does not exist

func (*RedisCache) GetTopBidValue added in v0.20.0

func (r *RedisCache) GetTopBidValue(ctx context.Context, pipeliner redis.Pipeliner, slot uint64, parentHash, proposerPubkey string) (topBidValue *big.Int, err error)

GetTopBidValue gets the top bid value for a given slot+parent+proposer combination

func (*RedisCache) GetValidatorRegistrationTimestamp

func (r *RedisCache) GetValidatorRegistrationTimestamp(proposerPubkey common.PubkeyHex) (uint64, error)

func (*RedisCache) HSetObj added in v0.11.0

func (r *RedisCache) HSetObj(key, field string, value any, expiration time.Duration) (err error)

func (*RedisCache) NewPipeline added in v0.26.0

func (r *RedisCache) NewPipeline() redis.Pipeliner

func (*RedisCache) NewTxPipeline added in v0.26.0

func (r *RedisCache) NewTxPipeline() redis.Pipeliner

func (*RedisCache) SaveBidAndUpdateTopBid added in v0.20.0

func (r *RedisCache) SaveBidAndUpdateTopBid(ctx context.Context, pipeliner redis.Pipeliner, trace *common.BidTraceV2WithBlobFields, payload *common.VersionedSubmitBlockRequest, getPayloadResponse *builderApi.VersionedSubmitBlindedBlockResponse, getHeaderResponse *builderSpec.VersionedSignedBuilderBid, reqReceivedAt time.Time, isCancellationEnabled bool, floorValue *big.Int) (state SaveBidAndUpdateTopBidResponse, err error)

func (*RedisCache) SaveBidTrace added in v0.10.0

func (r *RedisCache) SaveBidTrace(ctx context.Context, pipeliner redis.Pipeliner, trace *common.BidTraceV2WithBlobFields) (err error)

func (*RedisCache) SaveBuilderBid added in v0.20.0

func (r *RedisCache) SaveBuilderBid(ctx context.Context, pipeliner redis.Pipeliner, slot uint64, parentHash, proposerPubkey, builderPubkey string, receivedAt time.Time, headerResp *builderSpec.VersionedSignedBuilderBid) (err error)

SaveBuilderBid saves the latest bid by a specific builder. TODO: use transaction to make these writes atomic

func (*RedisCache) SaveExecutionPayloadCapella added in v0.26.0

func (r *RedisCache) SaveExecutionPayloadCapella(ctx context.Context, pipeliner redis.Pipeliner, slot uint64, proposerPubkey, blockHash string, execPayload *capella.ExecutionPayload) (err error)

func (*RedisCache) SavePayloadContentsDeneb added in v0.29.0

func (r *RedisCache) SavePayloadContentsDeneb(ctx context.Context, tx redis.Pipeliner, slot uint64, proposerPubkey, blockHash string, execPayload *builderApiDeneb.ExecutionPayloadAndBlobsBundle) (err error)

func (*RedisCache) SetFloorBidValue added in v0.27.1

func (r *RedisCache) SetFloorBidValue(slot uint64, parentHash, proposerPubkey, value string) error

SetFloorBidValue is used only for testing.

func (*RedisCache) SetObj

func (r *RedisCache) SetObj(key string, value any, expiration time.Duration) (err error)

func (*RedisCache) SetObjPipelined added in v0.26.0

func (r *RedisCache) SetObjPipelined(ctx context.Context, pipeliner redis.Pipeliner, key string, value any, expiration time.Duration) (err error)

SetObjPipelined saves an object in the given Redis key on a Redis pipeline (JSON encoded)

func (*RedisCache) SetProposerDuties

func (r *RedisCache) SetProposerDuties(proposerDuties []common.BuilderGetValidatorsResponseEntry) (err error)

func (*RedisCache) SetRelayConfig

func (r *RedisCache) SetRelayConfig(field, value string) (err error)

func (*RedisCache) SetStats

func (r *RedisCache) SetStats(field string, value any) (err error)

func (*RedisCache) SetValidatorRegistrationTimestamp added in v0.9.1

func (r *RedisCache) SetValidatorRegistrationTimestamp(proposerPubkey common.PubkeyHex, timestamp uint64) error

func (*RedisCache) SetValidatorRegistrationTimestampIfNewer added in v0.9.1

func (r *RedisCache) SetValidatorRegistrationTimestampIfNewer(proposerPubkey common.PubkeyHex, timestamp uint64) error

type SaveBidAndUpdateTopBidResponse added in v0.20.0

type SaveBidAndUpdateTopBidResponse struct {
	WasBidSaved      bool // Whether this bid was saved
	WasTopBidUpdated bool // Whether the top bid was updated
	IsNewTopBid      bool // Whether the submitted bid became the new top bid

	TopBidValue     *big.Int
	PrevTopBidValue *big.Int

	TimePrep         time.Duration
	TimeSavePayload  time.Duration
	TimeSaveBid      time.Duration
	TimeSaveTrace    time.Duration
	TimeUpdateTopBid time.Duration
	TimeUpdateFloor  time.Duration
}

Jump to

Keyboard shortcuts

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