db

package
v0.0.0-...-269d6e4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auction

type Auction struct {
	ID                       auction.ID           `json:"id"`
	BatchID                  broker.BatchID       `json:"batchID"`
	DealSize                 int64                `json:"dealSize"`
	DealDuration             uint64               `json:"dealDuration"`
	DealReplication          int32                `json:"dealReplication"`
	DealVerified             bool                 `json:"dealVerified"`
	FilEpochDeadline         uint64               `json:"filEpochDeadline"`
	ExcludedStorageProviders []string             `json:"excludedStorageProviders"`
	PayloadCid               string               `json:"payloadCid"`
	CarUrl                   string               `json:"carUrl"`
	CarIpfsCid               string               `json:"carIpfsCid"`
	CarIpfsAddrs             []string             `json:"carIpfsAddrs"`
	Status                   broker.AuctionStatus `json:"status"`
	ErrorCause               string               `json:"errorCause"`
	Duration                 int64                `json:"duration"`
	StartedAt                time.Time            `json:"startedAt"`
	UpdatedAt                time.Time            `json:"updatedAt"`
	ClientAddress            string               `json:"clientAddress"`
	Providers                []string             `json:"providers"`
}

type Bid

type Bid struct {
	ID                       auction.BidID  `json:"id"`
	AuctionID                auction.ID     `json:"auctionID"`
	WalletAddrSig            []byte         `json:"walletAddrSig"`
	StorageProviderID        string         `json:"storageProviderID"`
	BidderID                 string         `json:"bidderID"`
	AskPrice                 int64          `json:"askPrice"`
	VerifiedAskPrice         int64          `json:"verifiedAskPrice"`
	StartEpoch               int64          `json:"startEpoch"`
	FastRetrieval            bool           `json:"fastRetrieval"`
	ReceivedAt               time.Time      `json:"receivedAt"`
	WonAt                    sql.NullTime   `json:"wonAt"`
	ProposalCid              sql.NullString `json:"proposalCid"`
	ProposalCidDeliveredAt   sql.NullTime   `json:"proposalCidDeliveredAt"`
	ProposalCidDeliveryError sql.NullString `json:"proposalCidDeliveryError"`
	DealConfirmedAt          sql.NullTime   `json:"dealConfirmedAt"`
	WonReason                sql.NullString `json:"wonReason"`
	DealFailedAt             sql.NullTime   `json:"dealFailedAt"`
}

type BidEvent

type BidEvent struct {
	BidID      string         `json:"bidID"`
	EventType  BidEventType   `json:"eventType"`
	Attempts   sql.NullInt32  `json:"attempts"`
	Error      sql.NullString `json:"error"`
	HappenedAt time.Time      `json:"happenedAt"`
	ReceivedAt time.Time      `json:"receivedAt"`
}

type BidEventType

type BidEventType string
const (
	BidEventTypeStartFetching  BidEventType = "start_fetching"
	BidEventTypeErrorFetching  BidEventType = "error_fetching"
	BidEventTypeStartImporting BidEventType = "start_importing"
	BidEventTypeEndImporting   BidEventType = "end_importing"
	BidEventTypeFinalized      BidEventType = "finalized"
	BidEventTypeErrored        BidEventType = "errored"
)

func (*BidEventType) Scan

func (e *BidEventType) Scan(src interface{}) error

type CompetitionResult

type CompetitionResult struct {
	StorageProviderID string `json:"storageProviderID"`
	SuccessfulDeals   int64  `json:"successfulDeals"`
	AuctionsWon       int64  `json:"auctionsWon"`
	SuccessRate       int32  `json:"successRate"`
	Bonus             int32  `json:"bonus"`
	Total             int32  `json:"total"`
	Gibs              int64  `json:"gibs"`
	Qualified         bool   `json:"qualified"`
}

type CreateAuctionParams

type CreateAuctionParams struct {
	ID                       auction.ID           `json:"id"`
	BatchID                  broker.BatchID       `json:"batchID"`
	DealSize                 int64                `json:"dealSize"`
	DealDuration             uint64               `json:"dealDuration"`
	DealReplication          int32                `json:"dealReplication"`
	DealVerified             bool                 `json:"dealVerified"`
	FilEpochDeadline         uint64               `json:"filEpochDeadline"`
	ExcludedStorageProviders []string             `json:"excludedStorageProviders"`
	Providers                []string             `json:"providers"`
	PayloadCid               string               `json:"payloadCid"`
	CarUrl                   string               `json:"carUrl"`
	CarIpfsCid               string               `json:"carIpfsCid"`
	CarIpfsAddrs             []string             `json:"carIpfsAddrs"`
	Status                   broker.AuctionStatus `json:"status"`
	Duration                 int64                `json:"duration"`
	ClientAddress            string               `json:"clientAddress"`
}

type CreateBidEventParams

type CreateBidEventParams struct {
	BidID      string         `json:"bidID"`
	EventType  BidEventType   `json:"eventType"`
	Attempts   sql.NullInt32  `json:"attempts"`
	Error      sql.NullString `json:"error"`
	HappenedAt time.Time      `json:"happenedAt"`
	ReceivedAt time.Time      `json:"receivedAt"`
}

type CreateBidParams

type CreateBidParams struct {
	ID                auction.BidID `json:"id"`
	AuctionID         auction.ID    `json:"auctionID"`
	WalletAddrSig     []byte        `json:"walletAddrSig"`
	StorageProviderID string        `json:"storageProviderID"`
	BidderID          string        `json:"bidderID"`
	AskPrice          int64         `json:"askPrice"`
	VerifiedAskPrice  int64         `json:"verifiedAskPrice"`
	StartEpoch        int64         `json:"startEpoch"`
	FastRetrieval     bool          `json:"fastRetrieval"`
	ReceivedAt        time.Time     `json:"receivedAt"`
}

type CreateOrUpdateStorageProviderParams

type CreateOrUpdateStorageProviderParams struct {
	ID                   string `json:"id"`
	BidbotVersion        string `json:"bidbotVersion"`
	DealStartWindow      int64  `json:"dealStartWindow"`
	CidGravityConfigured bool   `json:"cidGravityConfigured"`
	CidGravityStrict     bool   `json:"cidGravityStrict"`
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type GetRecentWeekFailureRateRow

type GetRecentWeekFailureRateRow struct {
	StorageProviderID string `json:"storageProviderID"`
	FailureRatePpm    int64  `json:"failureRatePpm"`
}

type GetRecentWeekMaxOnChainSecondsRow

type GetRecentWeekMaxOnChainSecondsRow struct {
	StorageProviderID string `json:"storageProviderID"`
	MaxOnChainSeconds int64  `json:"maxOnChainSeconds"`
}

type GetRecentWeekWinningRateRow

type GetRecentWeekWinningRateRow struct {
	StorageProviderID string `json:"storageProviderID"`
	WinningRatePpm    int64  `json:"winningRatePpm"`
}

type Queries

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

func New

func New(db DBTX) *Queries

func Prepare

func Prepare(ctx context.Context, db DBTX) (*Queries, error)

func (*Queries) Close

func (q *Queries) Close() error

func (*Queries) CreateAuction

func (q *Queries) CreateAuction(ctx context.Context, arg CreateAuctionParams) error

func (*Queries) CreateBid

func (q *Queries) CreateBid(ctx context.Context, arg CreateBidParams) error

func (*Queries) CreateBidEvent

func (q *Queries) CreateBidEvent(ctx context.Context, arg CreateBidEventParams) error

func (*Queries) CreateOrUpdateStorageProvider

func (q *Queries) CreateOrUpdateStorageProvider(ctx context.Context, arg CreateOrUpdateStorageProviderParams) error

func (*Queries) GetAuction

func (q *Queries) GetAuction(ctx context.Context, id auction.ID) (Auction, error)

func (*Queries) GetAuctionBids

func (q *Queries) GetAuctionBids(ctx context.Context, auctionID auction.ID) ([]Bid, error)

func (*Queries) GetAuctionWinningBids

func (q *Queries) GetAuctionWinningBids(ctx context.Context, auctionID auction.ID) ([]Bid, error)

func (*Queries) GetNextReadyToExecute

func (q *Queries) GetNextReadyToExecute(ctx context.Context, stuckSeconds int64) (Auction, error)

func (*Queries) GetRecentWeekFailureRate

func (q *Queries) GetRecentWeekFailureRate(ctx context.Context) ([]GetRecentWeekFailureRateRow, error)

here's the logic: 1. take all winning bids happened in the recent week until 1 day ago (to exclude the deals waiting to be on-chain), or if their deals failed. 2. calculate the freshness of each bid, ranging from 1 (1 week ago) to 7 (1 day ago). 3. sum up the failed bids (not be able to make a deal), weighed by their freshness, then divide by the number of wins.

func (*Queries) GetRecentWeekMaxOnChainSeconds

func (q *Queries) GetRecentWeekMaxOnChainSeconds(ctx context.Context) ([]GetRecentWeekMaxOnChainSecondsRow, error)

get the maximum time in the last week a storage provider making a deal on chain.

func (*Queries) GetRecentWeekWinningRate

func (q *Queries) GetRecentWeekWinningRate(ctx context.Context) ([]GetRecentWeekWinningRateRow, error)

here's the logic: 1. take all received bids happened in the recent week until 10 minutes ago (to exclude the ongoing ones). 2. calculate the freshness of each bid, ranging from 1 (1 week ago) to 1008 (10 minutes ago). 3. sum up the winning bids, weighed by their freshness, then divide by the number of received bids.

func (*Queries) SetStorageProviderUnhealthy

func (q *Queries) SetStorageProviderUnhealthy(ctx context.Context, arg SetStorageProviderUnhealthyParams) error

func (*Queries) UpdateAuctionStatusAndError

func (q *Queries) UpdateAuctionStatusAndError(ctx context.Context, arg UpdateAuctionStatusAndErrorParams) error

func (*Queries) UpdateDealConfirmedAt

func (q *Queries) UpdateDealConfirmedAt(ctx context.Context, arg UpdateDealConfirmedAtParams) error

func (*Queries) UpdateDealFailedAt

func (q *Queries) UpdateDealFailedAt(ctx context.Context, arg UpdateDealFailedAtParams) error

func (*Queries) UpdateProposalCid

func (q *Queries) UpdateProposalCid(ctx context.Context, arg UpdateProposalCidParams) error

func (*Queries) UpdateProposalCidDeliveryError

func (q *Queries) UpdateProposalCidDeliveryError(ctx context.Context, arg UpdateProposalCidDeliveryErrorParams) error

func (*Queries) UpdateWinningBid

func (q *Queries) UpdateWinningBid(ctx context.Context, arg UpdateWinningBidParams) (int64, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type SetStorageProviderUnhealthyParams

type SetStorageProviderUnhealthyParams struct {
	ID                 string         `json:"id"`
	LastUnhealthyError sql.NullString `json:"lastUnhealthyError"`
}

type StorageProvider

type StorageProvider struct {
	ID                   string         `json:"id"`
	BidbotVersion        string         `json:"bidbotVersion"`
	DealStartWindow      int64          `json:"dealStartWindow"`
	CidGravityConfigured bool           `json:"cidGravityConfigured"`
	CidGravityStrict     bool           `json:"cidGravityStrict"`
	FirstSeenAt          time.Time      `json:"firstSeenAt"`
	LastSeenAt           time.Time      `json:"lastSeenAt"`
	LastUnhealthyAt      sql.NullTime   `json:"lastUnhealthyAt"`
	LastUnhealthyError   sql.NullString `json:"lastUnhealthyError"`
}

type UpdateAuctionStatusAndErrorParams

type UpdateAuctionStatusAndErrorParams struct {
	ID         auction.ID           `json:"id"`
	Status     broker.AuctionStatus `json:"status"`
	ErrorCause string               `json:"errorCause"`
}

type UpdateDealConfirmedAtParams

type UpdateDealConfirmedAtParams struct {
	ID        auction.BidID `json:"id"`
	AuctionID auction.ID    `json:"auctionID"`
}

type UpdateDealFailedAtParams

type UpdateDealFailedAtParams struct {
	ID        auction.BidID `json:"id"`
	AuctionID auction.ID    `json:"auctionID"`
}

type UpdateProposalCidDeliveryErrorParams

type UpdateProposalCidDeliveryErrorParams struct {
	ID                       auction.BidID  `json:"id"`
	AuctionID                auction.ID     `json:"auctionID"`
	ProposalCidDeliveryError sql.NullString `json:"proposalCidDeliveryError"`
}

type UpdateProposalCidParams

type UpdateProposalCidParams struct {
	ID          auction.BidID  `json:"id"`
	AuctionID   auction.ID     `json:"auctionID"`
	ProposalCid sql.NullString `json:"proposalCid"`
}

type UpdateWinningBidParams

type UpdateWinningBidParams struct {
	ID        auction.BidID  `json:"id"`
	AuctionID auction.ID     `json:"auctionID"`
	WonReason sql.NullString `json:"wonReason"`
}

Jump to

Keyboard shortcuts

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