database

package
v1.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package database exposes the postgres database

Index

Constants

This section is empty.

Variables

View Source
var (
	BuilderStatsEntryTypeExtraData     = "extra_data"
	BuilderStatsEntryTypeBuilderPubkey = "builder_pubkey"
)

Functions

func ExtraDataToUtf8Str

func ExtraDataToUtf8Str(extraData types.ExtraData) string

func NewNullBool

func NewNullBool(b bool) sql.NullBool

func NewNullInt64

func NewNullInt64(i int64) sql.NullInt64

func NewNullString

func NewNullString(s string) sql.NullString

Types

type BlockBuilderEntry

type BlockBuilderEntry struct {
	ID            int64     `db:"id"`
	InsertedAt    time.Time `db:"inserted_at"`
	BuilderPubkey string    `db:"builder_pubkey"`
	Description   string    `db:"description"`
}

type BuilderProfitEntry

type BuilderProfitEntry struct {
	ExtraData string   `db:"extra_data" json:"extra_data"`
	Aliases   []string `json:"aliases,omitempty"`

	NumBlocks           uint64 `db:"blocks" json:"num_blocks"`
	NumBlocksProfit     uint64 `db:"blocks_profit" json:"num_blocks_profit"`
	NumBlocksSubsidised uint64 `db:"blocks_sub" json:"num_blocks_sub"`

	ProfitPerBlockAvg    string `db:"avg_profit_per_block" json:"avg_profit_per_block"`
	ProfitPerBlockMedian string `db:"median_profit_per_block" json:"median_profit_per_block"`

	ProfitTotal    string `db:"total_profit" json:"profit_total"`
	SubsidiesTotal string `db:"total_subsidies" json:"subsidies_total"`
}

type BuilderStatsEntry added in v1.3.0

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

	Type  string `db:"type" json:"type"`
	Hours int    `db:"hours" json:"hours"`

	TimeStart   time.Time `db:"time_start" json:"time_start"`
	TimeEnd     time.Time `db:"time_end" json:"time_end"`
	BuilderName string    `db:"builder_name" json:"builder_name"`

	ExtraData      string `db:"extra_data" json:"extra_data"`
	BuilderPubkeys string `db:"builder_pubkeys" json:"builder_pubkeys"`
	BlocksIncluded int    `db:"blocks_included" json:"blocks_included"`
}

type DataAPIBuilderBidEntry

type DataAPIBuilderBidEntry struct {
	ID         int64     `db:"id"`
	InsertedAt time.Time `db:"inserted_at"`
	Relay      string    `db:"relay"`

	Epoch uint64 `db:"epoch"`
	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"`
	GasLimit             uint64        `db:"gas_limit"`
	GasUsed              uint64        `db:"gas_used"`
	Value                string        `db:"value"`
	NumTx                sql.NullInt64 `db:"num_tx"`
	BlockNumber          sql.NullInt64 `db:"block_number"`
	Timestamp            time.Time     `db:"timestamp"`
}

func BidTraceV2WithTimestampJSONToBuilderBidEntry

func BidTraceV2WithTimestampJSONToBuilderBidEntry(relay string, entry relaycommon.BidTraceV2WithTimestampJSON) DataAPIBuilderBidEntry

type DataAPIPayloadDeliveredEntry

type DataAPIPayloadDeliveredEntry struct {
	ID         int64     `db:"id"`
	InsertedAt time.Time `db:"inserted_at"`
	Relay      string    `db:"relay"`

	Epoch uint64 `db:"epoch"`
	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"`
	GasLimit             uint64        `db:"gas_limit"`
	GasUsed              uint64        `db:"gas_used"`
	ValueClaimedWei      string        `db:"value_claimed_wei"`
	ValueClaimedEth      string        `db:"value_claimed_eth"`
	NumTx                sql.NullInt64 `db:"num_tx"`
	BlockNumber          sql.NullInt64 `db:"block_number"`
	ExtraData            string        `db:"extra_data"`

	FoundOnChain  sql.NullBool `db:"found_onchain"`
	SlotWasMissed sql.NullBool `db:"slot_missed"`

	ValueCheckOk     sql.NullBool   `db:"value_check_ok"`
	ValueCheckMethod sql.NullString `db:"value_check_method"`

	ValueDeliveredWei       sql.NullString `db:"value_delivered_wei"`
	ValueDeliveredEth       sql.NullString `db:"value_delivered_eth"`
	ValueDeliveredDiffWei   sql.NullString `db:"value_delivered_diff_wei"`
	ValueDeliveredDiffEth   sql.NullString `db:"value_delivered_diff_eth"`
	BlockCoinbaseAddress    sql.NullString `db:"block_coinbase_addr"`
	BlockCoinbaseIsProposer sql.NullBool   `db:"block_coinbase_is_proposer"`
	CoinbaseDiffWei         sql.NullString `db:"coinbase_diff_wei"`
	CoinbaseDiffEth         sql.NullString `db:"coinbase_diff_eth"`
	Notes                   sql.NullString `db:"notes"`

	// Blob info added 2024-07-25
	NumBlobTxs sql.NullInt64 `db:"num_blob_txs"`
	NumBlobs   sql.NullInt64 `db:"num_blobs"`
}

func BidTraceV2JSONToPayloadDeliveredEntry

func BidTraceV2JSONToPayloadDeliveredEntry(relay string, entry relaycommon.BidTraceV2JSON) DataAPIPayloadDeliveredEntry

type DatabaseService

type DatabaseService struct {
	DB *sqlx.DB
}

func MustConnectPostgres added in v1.8.2

func MustConnectPostgres(log *logrus.Entry, dsn string) *DatabaseService

func NewDatabaseService

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

func (*DatabaseService) Close

func (s *DatabaseService) Close() error

func (*DatabaseService) GetBuilderProfits

func (s *DatabaseService) GetBuilderProfits(since, until time.Time) (res []*BuilderProfitEntry, err error)

func (*DatabaseService) GetDataAPILatestBid

func (s *DatabaseService) GetDataAPILatestBid(relay string) (*DataAPIBuilderBidEntry, error)

func (*DatabaseService) GetDataAPILatestPayloadDelivered

func (s *DatabaseService) GetDataAPILatestPayloadDelivered(relay string) (*DataAPIPayloadDeliveredEntry, error)

func (*DatabaseService) GetDeliveredPayloadsForSlot

func (s *DatabaseService) GetDeliveredPayloadsForSlot(slot uint64) (res []*DataAPIPayloadDeliveredEntry, err error)

func (*DatabaseService) GetDeliveredPayloadsForSlots added in v1.3.0

func (s *DatabaseService) GetDeliveredPayloadsForSlots(slotStart, slotEnd uint64) (res []*DataAPIPayloadDeliveredEntry, err error)

func (*DatabaseService) GetLastDailyBuilderStatsEntry added in v1.3.0

func (s *DatabaseService) GetLastDailyBuilderStatsEntry(filterType string) (*BuilderStatsEntry, error)

func (*DatabaseService) GetLatestDeliveredPayload added in v1.8.2

func (s *DatabaseService) GetLatestDeliveredPayload() (*DataAPIPayloadDeliveredEntry, error)

func (*DatabaseService) GetSignedBuilderBidsForSlot

func (s *DatabaseService) GetSignedBuilderBidsForSlot(slot uint64) (res []*SignedBuilderBidEntry, err error)

func (*DatabaseService) GetStatsForTimerange

func (s *DatabaseService) GetStatsForTimerange(since, until time.Time, relay string) (relays []*TopRelayEntry, builders []*TopBuilderEntry, builderProfits []*BuilderProfitEntry, err error)

func (*DatabaseService) GetTopBuilders

func (s *DatabaseService) GetTopBuilders(since, until time.Time, relay string) (res []*TopBuilderEntry, err error)

func (*DatabaseService) GetTopRelays

func (s *DatabaseService) GetTopRelays(since, until time.Time) (res []*TopRelayEntry, err error)

func (*DatabaseService) SaveBuilder

func (s *DatabaseService) SaveBuilder(entry *BlockBuilderEntry) error

func (*DatabaseService) SaveBuilderStats added in v1.3.0

func (s *DatabaseService) SaveBuilderStats(entries []*BuilderStatsEntry) error

func (*DatabaseService) SaveDataAPIBid

func (s *DatabaseService) SaveDataAPIBid(entry *DataAPIBuilderBidEntry) error

func (*DatabaseService) SaveDataAPIBids

func (s *DatabaseService) SaveDataAPIBids(entries []*DataAPIBuilderBidEntry) error

func (*DatabaseService) SaveDataAPIPayloadDelivered

func (s *DatabaseService) SaveDataAPIPayloadDelivered(entry *DataAPIPayloadDeliveredEntry) error

func (*DatabaseService) SaveDataAPIPayloadDeliveredBatch

func (s *DatabaseService) SaveDataAPIPayloadDeliveredBatch(entries []*DataAPIPayloadDeliveredEntry) (rowsAffected int64, err error)

func (*DatabaseService) SaveSignedBuilderBid

func (s *DatabaseService) SaveSignedBuilderBid(entry SignedBuilderBidEntry) error

type SignedBuilderBidEntry

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

	Relay       string    `db:"relay"`
	RequestedAt time.Time `db:"requested_at"`
	ReceivedAt  time.Time `db:"received_at"`
	LatencyMS   int64     `db:"duration_ms"`

	Slot           uint64 `db:"slot"`
	ParentHash     string `db:"parent_hash"`
	ProposerPubkey string `db:"proposer_pubkey"`

	Pubkey    string `db:"pubkey"`
	Signature string `db:"signature"`

	Value        string `db:"value"`
	FeeRecipient string `db:"fee_recipient"`
	BlockHash    string `db:"block_hash"`
	BlockNumber  uint64 `db:"block_number"`
	GasLimit     uint64 `db:"gas_limit"`
	GasUsed      uint64 `db:"gas_used"`
	ExtraData    string `db:"extra_data"`
	PrevRandao   string `db:"prev_randao"`
	Timestamp    uint64 `db:"timestamp"`
	Epoch        uint64 `db:"epoch"`
}

func SignedBuilderBidToEntry

func SignedBuilderBidToEntry(relay string, slot uint64, parentHash, proposerPubkey string, timeRequestStart, timeRequestEnd time.Time, bid *types.SignedBuilderBid) SignedBuilderBidEntry

type TopBuilderEntry

type TopBuilderEntry struct {
	ExtraData string   `db:"extra_data" json:"extra_data"`
	NumBlocks uint64   `db:"blocks" json:"num_blocks"`
	Percent   string   `json:"percent"`
	Aliases   []string `json:"aliases,omitempty"`
}

type TopRelayEntry

type TopRelayEntry struct {
	Relay       string `db:"relay" json:"relay"`
	NumPayloads uint64 `db:"payloads" json:"num_payloads"`
	Percent     string `json:"percent"`
}

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