database

package
v1.0.0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package database exposes the postgres database

Index

Constants

This section is empty.

Variables

View Source
var ExecutionPayloadEntryCSVHeader = []string{"id", "inserted_at", "slot", "proposer_pubkey", "block_hash", "version", "payload"}

Functions

func BuilderSubmissionEntryToBidTraceV2WithTimestampJSON added in v0.10.0

func BuilderSubmissionEntryToBidTraceV2WithTimestampJSON(payload *BuilderBlockSubmissionEntry) common.BidTraceV2WithTimestampJSON

func DeliveredPayloadEntryToBidTraceV2JSON added in v0.10.0

func DeliveredPayloadEntryToBidTraceV2JSON(payload *DeliveredPayloadEntry) common.BidTraceV2JSON

func NewNullInt64

func NewNullInt64(i int64) sql.NullInt64

func NewNullString

func NewNullString(s string) sql.NullString

func NewNullTime added in v0.14.0

func NewNullTime(t time.Time) sql.NullTime

Types

type BlockBuilderEntry added in v0.7.0

type BlockBuilderEntry struct {
	ID         int64     `db:"id"          json:"id"`
	InsertedAt time.Time `db:"inserted_at" json:"inserted_at"`

	BuilderPubkey string `db:"builder_pubkey" json:"builder_pubkey"`
	Description   string `db:"description"    json:"description"`

	IsHighPrio    bool `db:"is_high_prio"   json:"is_high_prio"`
	IsBlacklisted bool `db:"is_blacklisted" json:"is_blacklisted"`

	LastSubmissionID   sql.NullInt64 `db:"last_submission_id"   json:"last_submission_id"`
	LastSubmissionSlot uint64        `db:"last_submission_slot" json:"last_submission_slot"`

	NumSubmissionsTotal    uint64 `db:"num_submissions_total"    json:"num_submissions_total"`
	NumSubmissionsSimError uint64 `db:"num_submissions_simerror" json:"num_submissions_simerror"`

	NumSentGetPayload uint64 `db:"num_sent_getpayload" json:"num_sent_getpayload"`
}

type BuilderBlockSubmissionEntry

type BuilderBlockSubmissionEntry struct {
	ID         int64        `db:"id"`
	InsertedAt time.Time    `db:"inserted_at"`
	ReceivedAt sql.NullTime `db:"received_at"`
	EligibleAt sql.NullTime `db:"eligible_at"`

	// Delivered ExecutionPayload
	ExecutionPayloadID sql.NullInt64 `db:"execution_payload_id"`

	// Sim Result
	SimSuccess bool   `db:"sim_success"`
	SimError   string `db:"sim_error"`

	// BidTrace data
	Signature string `db:"signature"`

	Slot       uint64 `db:"slot"`
	ParentHash string `db:"parent_hash"`
	BlockHash  string `db:"block_hash"`

	BuilderPubkey        string `db:"builder_pubkey"`
	ProposerPubkey       string `db:"proposer_pubkey"`
	ProposerFeeRecipient string `db:"proposer_fee_recipient"`

	GasUsed  uint64 `db:"gas_used"`
	GasLimit uint64 `db:"gas_limit"`

	NumTx uint64 `db:"num_tx"`
	Value string `db:"value"`

	// Helpers
	Epoch       uint64 `db:"epoch"`
	BlockNumber uint64 `db:"block_number"`
}

type DatabaseService

type DatabaseService struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

func NewDatabaseService

func NewDatabaseService(dsn string) (*DatabaseService, error)

func (*DatabaseService) Close

func (s *DatabaseService) Close() error

func (*DatabaseService) DeleteExecutionPayloads added in v0.11.0

func (s *DatabaseService) DeleteExecutionPayloads(idFirst, idLast uint64) error

func (*DatabaseService) GetBlockBuilderByPubkey added in v0.7.0

func (s *DatabaseService) GetBlockBuilderByPubkey(pubkey string) (*BlockBuilderEntry, error)

func (*DatabaseService) GetBlockBuilders added in v0.7.0

func (s *DatabaseService) GetBlockBuilders() ([]*BlockBuilderEntry, error)

func (*DatabaseService) GetBlockSubmissionEntry

func (s *DatabaseService) GetBlockSubmissionEntry(slot uint64, proposerPubkey, blockHash string) (entry *BuilderBlockSubmissionEntry, err error)

func (*DatabaseService) GetBuilderSubmissions added in v0.5.1

func (s *DatabaseService) GetBuilderSubmissions(filters GetBuilderSubmissionsFilters) ([]*BuilderBlockSubmissionEntry, error)

func (*DatabaseService) GetBuilderSubmissionsBySlots added in v0.14.0

func (s *DatabaseService) GetBuilderSubmissionsBySlots(slotFrom, slotTo uint64) (entries []*BuilderBlockSubmissionEntry, err error)

func (*DatabaseService) GetDeliveredPayloads added in v0.9.1

func (s *DatabaseService) GetDeliveredPayloads(idFirst, idLast uint64) (entries []*DeliveredPayloadEntry, err error)

func (*DatabaseService) GetExecutionPayloadEntryByID

func (s *DatabaseService) GetExecutionPayloadEntryByID(executionPayloadID int64) (entry *ExecutionPayloadEntry, err error)

func (*DatabaseService) GetExecutionPayloadEntryBySlotPkHash

func (s *DatabaseService) GetExecutionPayloadEntryBySlotPkHash(slot uint64, proposerPubkey, blockHash string) (entry *ExecutionPayloadEntry, err error)

func (*DatabaseService) GetExecutionPayloads added in v0.11.0

func (s *DatabaseService) GetExecutionPayloads(idFirst, idLast uint64) (entries []*ExecutionPayloadEntry, err error)

func (*DatabaseService) GetLatestValidatorRegistrations added in v0.9.1

func (s *DatabaseService) GetLatestValidatorRegistrations(timestampOnly bool) ([]*ValidatorRegistrationEntry, error)

func (*DatabaseService) GetNumDeliveredPayloads

func (s *DatabaseService) GetNumDeliveredPayloads() (uint64, error)

func (*DatabaseService) GetRecentDeliveredPayloads

func (s *DatabaseService) GetRecentDeliveredPayloads(queryArgs GetPayloadsFilters) ([]*DeliveredPayloadEntry, error)

func (*DatabaseService) GetValidatorRegistration added in v0.9.1

func (s *DatabaseService) GetValidatorRegistration(pubkey string) (*ValidatorRegistrationEntry, error)

func (*DatabaseService) GetValidatorRegistrationsForPubkeys added in v0.9.1

func (s *DatabaseService) GetValidatorRegistrationsForPubkeys(pubkeys []string) (entries []*ValidatorRegistrationEntry, err error)

func (*DatabaseService) IncBlockBuilderStatsAfterGetPayload added in v0.7.0

func (s *DatabaseService) IncBlockBuilderStatsAfterGetPayload(builderPubkey string) error

func (*DatabaseService) NumRegisteredValidators added in v0.9.1

func (s *DatabaseService) NumRegisteredValidators() (count uint64, err error)

NumRegisteredValidators returns the number of unique pubkeys that have registered

func (*DatabaseService) NumValidatorRegistrationRows added in v0.9.1

func (s *DatabaseService) NumValidatorRegistrationRows() (count uint64, err error)

func (*DatabaseService) SaveBuilderBlockSubmission

func (s *DatabaseService) SaveBuilderBlockSubmission(payload *common.BuilderSubmitBlockRequest, simError error, receivedAt, eligibleAt time.Time, saveExecPayload bool) (entry *BuilderBlockSubmissionEntry, err error)

func (*DatabaseService) SaveDeliveredPayload

func (s *DatabaseService) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.SignedBlindedBeaconBlock, signedAt time.Time) error

func (*DatabaseService) SaveValidatorRegistration

func (s *DatabaseService) SaveValidatorRegistration(entry ValidatorRegistrationEntry) error

func (*DatabaseService) SetBlockBuilderStatus added in v0.7.0

func (s *DatabaseService) SetBlockBuilderStatus(pubkey string, isHighPrio, isBlacklisted bool) error

func (*DatabaseService) UpsertBlockBuilderEntryAfterSubmission added in v0.7.0

func (s *DatabaseService) UpsertBlockBuilderEntryAfterSubmission(lastSubmission *BuilderBlockSubmissionEntry, isError bool) error

type DeliveredPayloadEntry

type DeliveredPayloadEntry struct {
	ID         int64        `db:"id"`
	InsertedAt time.Time    `db:"inserted_at"`
	SignedAt   sql.NullTime `db:"signed_at"`

	SignedBlindedBeaconBlock sql.NullString `db:"signed_blinded_beacon_block"`

	Slot  uint64 `db:"slot"`
	Epoch uint64 `db:"epoch"`

	BuilderPubkey        string `db:"builder_pubkey"`
	ProposerPubkey       string `db:"proposer_pubkey"`
	ProposerFeeRecipient string `db:"proposer_fee_recipient"`

	ParentHash  string `db:"parent_hash"`
	BlockHash   string `db:"block_hash"`
	BlockNumber uint64 `db:"block_number"`

	GasUsed  uint64 `db:"gas_used"`
	GasLimit uint64 `db:"gas_limit"`

	NumTx uint64 `db:"num_tx"`
	Value string `db:"value"`
}

type ExecutionPayloadEntry

type ExecutionPayloadEntry struct {
	ID         int64     `db:"id"`
	InsertedAt time.Time `db:"inserted_at"`

	Slot           uint64 `db:"slot"`
	ProposerPubkey string `db:"proposer_pubkey"`
	BlockHash      string `db:"block_hash"`

	Version string `db:"version"`
	Payload string `db:"payload"`
}

func PayloadToExecPayloadEntry

func PayloadToExecPayloadEntry(payload *common.BuilderSubmitBlockRequest) (*ExecutionPayloadEntry, error)

func (*ExecutionPayloadEntry) ToCSVRecord added in v0.11.0

func (e *ExecutionPayloadEntry) ToCSVRecord() []string

type GetBuilderSubmissionsFilters added in v0.5.1

type GetBuilderSubmissionsFilters struct {
	Slot        uint64
	Limit       uint64
	BlockHash   string
	BlockNumber uint64
	// Cursor      uint64
	BuilderPubkey string
}

type GetPayloadsFilters

type GetPayloadsFilters struct {
	Slot           uint64
	Cursor         uint64
	Limit          uint64
	BlockHash      string
	BlockNumber    uint64
	ProposerPubkey string
	BuilderPubkey  string
	OrderByValue   int8
}

type IDatabaseService

type IDatabaseService interface {
	NumRegisteredValidators() (count uint64, err error)
	SaveValidatorRegistration(entry ValidatorRegistrationEntry) error
	GetLatestValidatorRegistrations(timestampOnly bool) ([]*ValidatorRegistrationEntry, error)
	GetValidatorRegistration(pubkey string) (*ValidatorRegistrationEntry, error)
	GetValidatorRegistrationsForPubkeys(pubkeys []string) ([]*ValidatorRegistrationEntry, error)

	SaveBuilderBlockSubmission(payload *common.BuilderSubmitBlockRequest, simError error, receivedAt, eligibleAt time.Time, saveExecPayload bool) (entry *BuilderBlockSubmissionEntry, err error)
	GetBlockSubmissionEntry(slot uint64, proposerPubkey, blockHash string) (entry *BuilderBlockSubmissionEntry, err error)
	GetBuilderSubmissions(filters GetBuilderSubmissionsFilters) ([]*BuilderBlockSubmissionEntry, error)
	GetBuilderSubmissionsBySlots(slotFrom, slotTo uint64) (entries []*BuilderBlockSubmissionEntry, err error)
	GetExecutionPayloadEntryByID(executionPayloadID int64) (entry *ExecutionPayloadEntry, err error)
	GetExecutionPayloadEntryBySlotPkHash(slot uint64, proposerPubkey, blockHash string) (entry *ExecutionPayloadEntry, err error)
	GetExecutionPayloads(idFirst, idLast uint64) (entries []*ExecutionPayloadEntry, err error)
	DeleteExecutionPayloads(idFirst, idLast uint64) error

	SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.SignedBlindedBeaconBlock, signedAt time.Time) error
	GetNumDeliveredPayloads() (uint64, error)
	GetRecentDeliveredPayloads(filters GetPayloadsFilters) ([]*DeliveredPayloadEntry, error)
	GetDeliveredPayloads(idFirst, idLast uint64) (entries []*DeliveredPayloadEntry, err error)

	GetBlockBuilders() ([]*BlockBuilderEntry, error)
	GetBlockBuilderByPubkey(pubkey string) (*BlockBuilderEntry, error)
	SetBlockBuilderStatus(pubkey string, isHighPrio, isBlacklisted bool) error
	UpsertBlockBuilderEntryAfterSubmission(lastSubmission *BuilderBlockSubmissionEntry, isError bool) error
	IncBlockBuilderStatsAfterGetPayload(builderPubkey string) error
}

type MockDB

type MockDB struct{}

func (MockDB) DeleteExecutionPayloads added in v0.11.0

func (db MockDB) DeleteExecutionPayloads(idFirst, idLast uint64) error

func (MockDB) GetBlockBuilderByPubkey added in v0.7.0

func (db MockDB) GetBlockBuilderByPubkey(pubkey string) (*BlockBuilderEntry, error)

func (MockDB) GetBlockBuilders added in v0.7.0

func (db MockDB) GetBlockBuilders() ([]*BlockBuilderEntry, error)

func (MockDB) GetBlockSubmissionEntry

func (db MockDB) GetBlockSubmissionEntry(slot uint64, proposerPubkey, blockHash string) (entry *BuilderBlockSubmissionEntry, err error)

func (MockDB) GetBuilderSubmissions added in v0.5.1

func (db MockDB) GetBuilderSubmissions(filters GetBuilderSubmissionsFilters) ([]*BuilderBlockSubmissionEntry, error)

func (MockDB) GetBuilderSubmissionsBySlots added in v0.14.0

func (db MockDB) GetBuilderSubmissionsBySlots(slotFrom, slotTo uint64) (entries []*BuilderBlockSubmissionEntry, err error)

func (MockDB) GetDeliveredPayloads added in v0.9.1

func (db MockDB) GetDeliveredPayloads(idFirst, idLast uint64) (entries []*DeliveredPayloadEntry, err error)

func (MockDB) GetExecutionPayloadEntryByID

func (db MockDB) GetExecutionPayloadEntryByID(executionPayloadID int64) (entry *ExecutionPayloadEntry, err error)

func (MockDB) GetExecutionPayloadEntryBySlotPkHash

func (db MockDB) GetExecutionPayloadEntryBySlotPkHash(slot uint64, proposerPubkey, blockHash string) (entry *ExecutionPayloadEntry, err error)

func (MockDB) GetExecutionPayloads added in v0.11.0

func (db MockDB) GetExecutionPayloads(idFirst, idLast uint64) (entries []*ExecutionPayloadEntry, err error)

func (MockDB) GetLatestValidatorRegistrations added in v0.9.1

func (db MockDB) GetLatestValidatorRegistrations(timestampOnly bool) ([]*ValidatorRegistrationEntry, error)

func (MockDB) GetNumDeliveredPayloads

func (db MockDB) GetNumDeliveredPayloads() (uint64, error)

func (MockDB) GetRecentDeliveredPayloads

func (db MockDB) GetRecentDeliveredPayloads(filters GetPayloadsFilters) ([]*DeliveredPayloadEntry, error)

func (MockDB) GetValidatorRegistration added in v0.9.1

func (db MockDB) GetValidatorRegistration(pubkey string) (*ValidatorRegistrationEntry, error)

func (MockDB) GetValidatorRegistrationsForPubkeys added in v0.9.1

func (db MockDB) GetValidatorRegistrationsForPubkeys(pubkeys []string) (entries []*ValidatorRegistrationEntry, err error)

func (MockDB) IncBlockBuilderStatsAfterGetHeader added in v0.7.0

func (db MockDB) IncBlockBuilderStatsAfterGetHeader(slot uint64, blockhash string) error

func (MockDB) IncBlockBuilderStatsAfterGetPayload added in v0.7.0

func (db MockDB) IncBlockBuilderStatsAfterGetPayload(builderPubkey string) error

func (MockDB) NumRegisteredValidators added in v0.9.1

func (db MockDB) NumRegisteredValidators() (count uint64, err error)

func (MockDB) SaveBuilderBlockSubmission

func (db MockDB) SaveBuilderBlockSubmission(payload *common.BuilderSubmitBlockRequest, simError error, receivedAt, eligibleAt time.Time, saveExecPayload bool) (entry *BuilderBlockSubmissionEntry, err error)

func (MockDB) SaveDeliveredPayload

func (db MockDB) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.SignedBlindedBeaconBlock, signedAt time.Time) error

func (MockDB) SaveValidatorRegistration

func (db MockDB) SaveValidatorRegistration(entry ValidatorRegistrationEntry) error

func (MockDB) SetBlockBuilderStatus added in v0.7.0

func (db MockDB) SetBlockBuilderStatus(pubkey string, isHighPrio, isBlacklisted bool) error

func (MockDB) UpsertBlockBuilderEntryAfterSubmission added in v0.7.0

func (db MockDB) UpsertBlockBuilderEntryAfterSubmission(lastSubmission *BuilderBlockSubmissionEntry, isError bool) error

type ValidatorRegistrationEntry

type ValidatorRegistrationEntry struct {
	ID         int64     `db:"id"`
	InsertedAt time.Time `db:"inserted_at"`

	Pubkey       string `db:"pubkey"`
	FeeRecipient string `db:"fee_recipient"`
	Timestamp    uint64 `db:"timestamp"`
	GasLimit     uint64 `db:"gas_limit"`
	Signature    string `db:"signature"`
}

func SignedValidatorRegistrationToEntry added in v0.9.1

func SignedValidatorRegistrationToEntry(valReg types.SignedValidatorRegistration) ValidatorRegistrationEntry

func (ValidatorRegistrationEntry) ToSignedValidatorRegistration added in v0.9.1

func (reg ValidatorRegistrationEntry) ToSignedValidatorRegistration() (*types.SignedValidatorRegistration, error)

Directories

Path Synopsis
Package migrations contains all the migration files
Package migrations contains all the migration files
Package vars contains the database variables such as dynamic table names
Package vars contains the database variables such as dynamic table names

Jump to

Keyboard shortcuts

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