database

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package database exposes the postgres database

Index

Constants

This section is empty.

Variables

View Source
var (
	TableValidatorRegistration  = tableBase + "_validator_registration"
	TableExecutionPayload       = tableBase + "_execution_payload"
	TableBuilderBlockSubmission = tableBase + "_builder_block_submission"
	TableDeliveredPayload       = tableBase + "_payload_delivered"
	TableBlockBuilder           = tableBase + "_blockbuilder"
)

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

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"`
	NumSubmissionsTopBid   uint64 `db:"num_submissions_topbid"   json:"num_submissions_topbid"`

	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"`

	// 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"`
	WasMostProfitable bool   `db:"was_most_profitable"`
}

type DatabaseService

type DatabaseService struct {
	DB *sqlx.DB
}

func NewDatabaseService

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

func (*DatabaseService) Close

func (s *DatabaseService) Close() 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) 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) 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(slot uint64, blockhash 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 *types.BuilderSubmitBlockRequest, simError error, isMostProfitable bool) (entry *BuilderBlockSubmissionEntry, err error)

func (*DatabaseService) SaveDeliveredPayload

func (s *DatabaseService) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *types.SignedBlindedBeaconBlock) 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, isTopbid bool) error

type DeliveredPayloadEntry

type DeliveredPayloadEntry struct {
	ID         int64     `db:"id"`
	InsertedAt time.Time `db:"inserted_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 *types.BuilderSubmitBlockRequest) (*ExecutionPayloadEntry, error)

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 *types.BuilderSubmitBlockRequest, simError error, isMostProfitable bool) (entry *BuilderBlockSubmissionEntry, err error)
	GetBlockSubmissionEntry(slot uint64, proposerPubkey, blockHash string) (entry *BuilderBlockSubmissionEntry, err error)
	GetBuilderSubmissions(filters GetBuilderSubmissionsFilters) ([]*BuilderBlockSubmissionEntry, error)
	GetExecutionPayloadEntryByID(executionPayloadID int64) (entry *ExecutionPayloadEntry, err error)
	GetExecutionPayloadEntryBySlotPkHash(slot uint64, proposerPubkey, blockHash string) (entry *ExecutionPayloadEntry, err error)

	SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *types.SignedBlindedBeaconBlock) 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, isTopbid bool) error
	IncBlockBuilderStatsAfterGetPayload(slot uint64, blockhash string) error
}

type MockDB

type MockDB struct{}

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) 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) 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(slot uint64, blockhash 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 *types.BuilderSubmitBlockRequest, simError error, isMostProfitable bool) (entry *BuilderBlockSubmissionEntry, err error)

func (MockDB) SaveDeliveredPayload

func (db MockDB) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *types.SignedBlindedBeaconBlock) 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, isTopbid 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)

Jump to

Keyboard shortcuts

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