datastore

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderPrefix        = "header-"
	HeaderContentPrefix = "hc/"
)
View Source
const (
	RegistrationPrefix = "registration-"
)

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var (
	HeaderPrefixBytes = []byte("header-")
)

Functions

func DeliveredHashKey

func DeliveredHashKey(bh types.Hash) ds.Key

func DeliveredKey

func DeliveredKey(slot structs.Slot) ds.Key

func DeliveredNumKey

func DeliveredNumKey(bn uint64) ds.Key

func DeliveredPubkeyKey

func DeliveredPubkeyKey(pk types.PublicKey) ds.Key

func HeaderHashKey

func HeaderHashKey(bh types.Hash) ds.Key

func HeaderKey

func HeaderKey(slot uint64) ds.Key

func HeaderKeyContent

func HeaderKeyContent(slot uint64, blockHash string) ds.Key

func HeaderMaxNewKey

func HeaderMaxNewKey(slot uint64) ds.Key

func HeaderMaxProfitKey

func HeaderMaxProfitKey(slot uint64) ds.Key

OLD Entries

func HeaderNumKey

func HeaderNumKey(bn uint64) ds.Key

func InitDatastoreMetrics

func InitDatastoreMetrics(m *metrics.Metrics) error

func PayloadKeyKey

func PayloadKeyKey(key structs.PayloadKey) ds.Key

func RegistrationKey

func RegistrationKey(pk structs.PubKey) ds.Key

func ValidatorKey

func ValidatorKey(pk structs.PubKey) ds.Key

Types

type Badger

type Badger interface {
	View(func(txn *badger.Txn) error) error
	Update(func(txn *badger.Txn) error) error
	NewTransaction(bool) *badger.Txn
}

type Datastore

type Datastore struct {
	TTLStorage
	Badger
	PayloadCache *lru.Cache[structs.PayloadKey, *structs.BlockBidAndTrace]
	// contains filtered or unexported fields
}

func NewDatastore

func NewDatastore(t TTLStorage, v Badger, hc *HeaderController, payloadCacheSize int) (*Datastore, error)

func (*Datastore) CacheBlock added in v0.3.4

func (s *Datastore) CacheBlock(ctx context.Context, block *structs.CompleteBlockstruct) error

func (*Datastore) CheckSlotDelivered

func (s *Datastore) CheckSlotDelivered(ctx context.Context, slot uint64) (bool, error)

func (*Datastore) FixOrphanHeaders

func (s *Datastore) FixOrphanHeaders(ctx context.Context, ttl time.Duration) error

FixOrphanHeaders is reading all the orphan headers from

func (*Datastore) GetAllRegistration

func (s *Datastore) GetAllRegistration() (map[string]types.SignedValidatorRegistration, error)

func (*Datastore) GetDelivered

func (*Datastore) GetDeliveredBatch

func (s *Datastore) GetDeliveredBatch(ctx context.Context, queries []structs.PayloadQuery) ([]structs.BidTraceWithTimestamp, error)

func (*Datastore) GetHeadersByBlockHash

func (s *Datastore) GetHeadersByBlockHash(ctx context.Context, hash types.Hash) ([]structs.HeaderAndTrace, error)

func (*Datastore) GetHeadersByBlockNum

func (s *Datastore) GetHeadersByBlockNum(ctx context.Context, blockNumber uint64) ([]structs.HeaderAndTrace, error)

func (*Datastore) GetHeadersBySlot

func (s *Datastore) GetHeadersBySlot(ctx context.Context, slot uint64) ([]structs.HeaderAndTrace, error)

func (*Datastore) GetLatestHeaders

func (s *Datastore) GetLatestHeaders(ctx context.Context, limit uint64, stopLag uint64) ([]structs.HeaderAndTrace, error)

func (*Datastore) GetMaxProfitHeader

func (s *Datastore) GetMaxProfitHeader(ctx context.Context, slot uint64) (structs.HeaderAndTrace, error)

func (*Datastore) GetPayload

func (*Datastore) GetRegistration

func (*Datastore) MemoryCleanup

func (s *Datastore) MemoryCleanup(ctx context.Context, slotPurgeDuration time.Duration, ttl time.Duration) error

func (*Datastore) PutDelivered

func (s *Datastore) PutDelivered(ctx context.Context, slot structs.Slot, trace structs.DeliveredTrace, ttl time.Duration) error

func (*Datastore) PutHeader

func (s *Datastore) PutHeader(ctx context.Context, hd structs.HeaderData, ttl time.Duration) (err error)

func (*Datastore) PutPayload

func (s *Datastore) PutPayload(ctx context.Context, key structs.PayloadKey, payload *structs.BlockBidAndTrace, ttl time.Duration) error

func (*Datastore) PutRegistration

func (s *Datastore) PutRegistration(ctx context.Context, pk structs.PubKey, registration types.SignedValidatorRegistration, ttl time.Duration) error

func (*Datastore) PutRegistrationRaw

func (s *Datastore) PutRegistrationRaw(ctx context.Context, pk structs.PubKey, registration []byte, ttl time.Duration) error

func (*Datastore) SaveHeaders

func (s *Datastore) SaveHeaders(ctx context.Context, slots []uint64, ttl time.Duration) error

SaveHeaders is meant to persist the all the keys under one key As optimization in future this function can operate only on database, so instead from memory it may just reorganize keys

type HeaderController

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

func NewHeaderController

func NewHeaderController(slotLag uint64, slotTimeLag time.Duration) *HeaderController

func (*HeaderController) Add

func (hc *HeaderController) Add(slot uint64, hnt structs.HeaderAndTrace) (newCreated bool, err error)

func (*HeaderController) AttachMetrics added in v0.3.1

func (r *HeaderController) AttachMetrics(m *metrics.Metrics)

func (*HeaderController) CheckForRemoval

func (hc *HeaderController) CheckForRemoval() (toBeRemoved []uint64, ok bool)

func (*HeaderController) GetHeaders

func (hc *HeaderController) GetHeaders(startingSlot, stopSlot uint64, limit int) (elements []structs.HeaderAndTrace, lastSlot uint64)

func (*HeaderController) GetLatestSlot

func (hc *HeaderController) GetLatestSlot() (slot uint64)

func (*HeaderController) GetMaxProfit

func (hc *HeaderController) GetMaxProfit(slot uint64) (hnt structs.HeaderAndTrace, ok bool)

func (*HeaderController) GetSingleSlot

func (hc *HeaderController) GetSingleSlot(slot uint64) (elements []structs.HeaderAndTrace, maxProfitHash [32]byte, revision uint64, err error)

func (*HeaderController) PrependMultiple added in v0.3.3

func (hc *HeaderController) PrependMultiple(slot uint64, hnt []structs.HeaderAndTrace) (err error)

func (*HeaderController) RemoveSlot

func (hc *HeaderController) RemoveSlot(slot, expectedRevision uint64) (success bool)

type HeaderControllerMetrics added in v0.3.1

type HeaderControllerMetrics struct {
	LatestSlot    prometheus.Gauge
	HeadersSize   prometheus.Gauge
	RemovalChecks prometheus.Gauge

	HeadersAdded prometheus.Counter
}

type IndexMeta

type IndexMeta struct {
	Hash          [32]byte
	Value         *big.Int
	BuilderPubkey [48]byte
}

type IndexedHeaders

type IndexedHeaders struct {
	S StoredIndex
	// contains filtered or unexported fields
}

func NewIndexedHeaders

func NewIndexedHeaders() (h *IndexedHeaders)

func (*IndexedHeaders) AddContent

func (h *IndexedHeaders) AddContent(hnt structs.HeaderAndTrace) error

func (*IndexedHeaders) GetContent

func (h *IndexedHeaders) GetContent() (content []structs.HeaderAndTrace, maxProfitHash [32]byte, revision uint64)

func (*IndexedHeaders) GetMaxProfit

func (h *IndexedHeaders) GetMaxProfit() (hnt structs.HeaderAndTrace, ok bool)

func (*IndexedHeaders) GetRevision

func (h *IndexedHeaders) GetRevision() (revision uint64)

func (*IndexedHeaders) PrependContent added in v0.3.3

func (h *IndexedHeaders) PrependContent(hnts []structs.HeaderAndTrace) error

type LoadItem

type LoadItem struct {
	Time    uint64
	Content []byte
}

type SlotInfo

type SlotInfo struct {
	Slot  uint64
	Added time.Time
}

type StoredIndex

type StoredIndex struct {
	Index                []IndexMeta
	MaxProfit            IndexMeta
	SubmissionsByPubKeys map[[48]byte]IndexMeta
}

func NewStoreIndex

func NewStoreIndex() StoredIndex

type TTLDatastoreBatcher

type TTLDatastoreBatcher struct {
	ds.TTLDatastore
}

func (*TTLDatastoreBatcher) GetBatch

func (bb *TTLDatastoreBatcher) GetBatch(ctx context.Context, keys []ds.Key) (batch [][]byte, err error)

type TTLStorage

type TTLStorage interface {
	PutWithTTL(context.Context, ds.Key, []byte, time.Duration) error
	Get(context.Context, ds.Key) ([]byte, error)
	GetBatch(ctx context.Context, keys []ds.Key) (batch [][]byte, err error)
	Close() error
}

Jump to

Keyboard shortcuts

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