auctioneer

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: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotifyTimeout is the max duration the auctioneer will wait for a response from bidders.
	NotifyTimeout = time.Second * 30
)

Variables

View Source
var (

	// ErrAuctionNotFound indicates the requested auction was not found.
	ErrAuctionNotFound = errors.New("auction not found")

	// ErrInsufficientBids indicates the auction failed due to insufficient bids.
	ErrInsufficientBids = errors.New("insufficient bids")
)

Functions

This section is empty.

Types

type AuctionConfig

type AuctionConfig struct {
	// Duration auctions will be held for.
	Duration time.Duration
}

AuctionConfig defines auction params.

type Auctioneer

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

Auctioneer handles deal auctions for a broker.

func New

func New(
	conf rpcpeer.Config,
	postgresURI string,
	mb mbroker.MsgBroker,
	fc filclient.FilClient,
	auctionConf AuctionConfig,
	recordBidbotEvents bool,
) (*Auctioneer, error)

New returns a new Auctioneer.

func (*Auctioneer) Close

func (a *Auctioneer) Close() error

Close the auctioneer.

func (*Auctioneer) CreateAuction

func (a *Auctioneer) CreateAuction(ctx context.Context, auction auctioneer.Auction) error

CreateAuction creates a new auction. New auctions are queued if the auctioneer is busy.

func (*Auctioneer) DeliverBoostProposal

func (a *Auctioneer) DeliverBoostProposal(
	ctx context.Context,
	auctionID core.ID,
	bidID core.BidID,
	dealUID string) error

DeliverBoostProposal delivers the dealUID for an accepted deal to the winning bidder. This may be called multiple times by the broker in the event delivery fails.

func (*Auctioneer) DeliverProposal

func (a *Auctioneer) DeliverProposal(ctx context.Context, auctionID core.ID, bidID core.BidID, pcid cid.Cid) error

DeliverProposal delivers the proposal Cid for an accepted deal to the winning bidder. This may be called multiple times by the broker in the event delivery fails.

func (*Auctioneer) GetAuction

func (a *Auctioneer) GetAuction(ctx context.Context, id core.ID) (*auctioneer.Auction, error)

GetAuction returns an auction by id. If an auction is not found for id, ErrAuctionNotFound is returned.

func (*Auctioneer) MarkFinalizedDeal

func (a *Auctioneer) MarkFinalizedDeal(ctx context.Context, fad broker.FinalizedDeal) error

MarkFinalizedDeal marks the deal as confirmed if it has no error.

func (*Auctioneer) PeerInfo

func (a *Auctioneer) PeerInfo() (*rpcpeer.Info, error)

PeerInfo returns the peer info of the auctioneer.

func (*Auctioneer) Start

func (a *Auctioneer) Start(bootstrap bool) error

Start the deal auction feed. If bootstrap is true, the peer will dial the configured bootstrap addresses before creating the deal auction feed.

type BidbotEventsHandler

type BidbotEventsHandler func(peer.ID, *pb.BidbotEvent)

BidbotEventsHandler handles bidbot events.

type BidsHandler

type BidsHandler func(peer.ID, *pb.Bid) ([]byte, error)

BidsHandler handles bids from bidbots.

type BidsIter

type BidsIter func() (auctioneer.Bid, bool)

BidsIter provides a general way to iterate bids sorted by sorter.

func (BidsIter) MustNext

func (i BidsIter) MustNext() auctioneer.Bid

MustNext is similar to Next, but panics when the next bid doesn't exist.

func (BidsIter) Next

func (i BidsIter) Next() (auctioneer.Bid, bool)

Next gets the next bid from the iterator, if exists.

type Cmp

type Cmp interface {
	// Cmp returns arbitrary number with the following semantics:
	// negative: i is considered to be less than j
	// zero: i is considered to be equal to j
	// positive: i is considered to be greater than j
	Cmp(a *auctioneer.Auction, i auctioneer.Bid, j auctioneer.Bid) int
}

Cmp is the interface for a comparator.

func CmpFn

func CmpFn(f func(a *auctioneer.Auction, i auctioneer.Bid, j auctioneer.Bid) int) Cmp

CmpFn is a helper which turns a function to a Cmp interface.

func EarlierStartEpoch

func EarlierStartEpoch(resolution time.Duration) Cmp

EarlierStartEpoch returns a comparator which prefers bid with earlier start epoch. The difference between the start epochs in the scale of the resolution is returned.

func LowerPrice

func LowerPrice() Cmp

LowerPrice returns a comparator which prefers lower ask price or verified ask price depending on if the auction is verified. The price difference is returned.

func LowerProviderRate

func LowerProviderRate(rates map[string]int) Cmp

LowerProviderRate returns a comparator which considers some rate of the storage provider. Provider with lower rate gets a higher chance to win. Provider not in the provided rates table are considered to have zero rate.

func Ordered

func Ordered(cmps ...Cmp) Cmp

Ordered executes each comparator in order, i.e., if the first comparator judges the two bids to be equal, continues to the next comparator, and so on. It considers two bids to be equal if all comparators are exhausted.

func Random

func Random() Cmp

Random returns a comparator which randomly returns -1, 0, or 1 using the global random source. Note that it violates the invariants of heap operations and the result distribution is very uneven.

type CommChannel

type CommChannel interface {
	PublishAuction(ctx context.Context, id auction.ID, auctionPb *pb.Auction, bidsHandler BidsHandler) error
	PublishWin(ctx context.Context, id auction.ID, bid auction.BidID, bidder peer.ID, sources auction.Sources) error
	PublishProposal(ctx context.Context, id auction.ID, bid auction.BidID, bidder peer.ID, identifier string) error
	Start(bootstrap bool) error
	Info() (*rpcpeer.Info, error)
	ListPeers() []peer.ID
	Close() error
}

CommChannel represents the communication channel with bidbots.

type Libp2pPubsub

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

Libp2pPubsub communicates with bidbots via libp2p pubsub.

func NewLibp2pPubsub

func NewLibp2pPubsub(ctx context.Context, conf rpcpeer.Config,
	eventsHandler BidbotEventsHandler) (*Libp2pPubsub, error)

NewLibp2pPubsub creates a communication channel backed by libp2p pubsub.

func (*Libp2pPubsub) Close

func (ps *Libp2pPubsub) Close() error

Close closes the communication channel.

func (*Libp2pPubsub) Info

func (ps *Libp2pPubsub) Info() (*rpcpeer.Info, error)

Info returns the peer info of the channel.

func (*Libp2pPubsub) ListPeers

func (ps *Libp2pPubsub) ListPeers() []peer.ID

ListPeers returns the list of connected peers.

func (*Libp2pPubsub) PublishAuction

func (ps *Libp2pPubsub) PublishAuction(ctx context.Context, id auction.ID, auctionPb *pb.Auction,
	bidsHandler BidsHandler) error

PublishAuction publishs the auction to the deal auction feed until the context expires, and calls the bid handler for each bid for the auction.

func (*Libp2pPubsub) PublishProposal

func (ps *Libp2pPubsub) PublishProposal(ctx context.Context, id core.ID, bid core.BidID,
	bidder peer.ID, identifier string) error

PublishProposal publishs the proposal to the specific bidder.

func (*Libp2pPubsub) PublishWin

func (ps *Libp2pPubsub) PublishWin(ctx context.Context, id core.ID, bid core.BidID,
	bidder peer.ID, sources core.Sources) error

PublishWin publishs the winning bid message to the specific bidder.

func (*Libp2pPubsub) Start

func (ps *Libp2pPubsub) Start(bootstrap bool) error

Start creates the deal auction feed.

type Sorter

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

Sorter has a single sort method which takes an aunction and some bids, then sort the bids based on the comparator given.

func BidsSorter

func BidsSorter(auction *auctioneer.Auction, bids []auctioneer.Bid) *Sorter

BidsSorter constructs a sorter from the given comparator and bids.

func (*Sorter) Iterate

func (s *Sorter) Iterate(cmp Cmp) BidsIter

Iterate returns an iterator which gives the sorted result one by one.

func (Sorter) Len

func (s Sorter) Len() int

Len returns the number of bids remain in the sorter right now.

func (*Sorter) Random

func (s *Sorter) Random() BidsIter

Random returns an iterator which randomly choose one bid to return.

func (*Sorter) RandomTopN

func (s *Sorter) RandomTopN(n int, cmp Cmp) BidsIter

RandomTopN returns an iterator which randomly choose one of the top N from the sorted list to return.

func (Sorter) Select

func (s Sorter) Select(filter func(*auctioneer.Bid) bool) Sorter

Select returns a new sorter with the bids don't pass the filter being removed.

type Weighed

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

Weighed combines comparators togethers with different weights. The result depends on both the weights given to each comparator and the scale of the comparison result of each comparator. Be aware to not cause integer overflow.

func (Weighed) Add

func (wc Weighed) Add(cmp Cmp, weight int) Weighed

Add returns a new weighed comparator with the comparator being added with the given weight.

func (Weighed) Cmp

Cmp adds up the result of calling Cmp of each comparators with their respective weights.

Directories

Path Synopsis
migrations
Package migrations generated by go-bindata.// sources: migrations/001_init.down.sql migrations/001_init.up.sql migrations/002_bids_support_calculating_rates.down.sql migrations/002_bids_support_calculating_rates.up.sql migrations/003_auctions_add_client_address.down.sql migrations/003_auctions_add_client_address.up.sql migrations/004_bids_add_won_reason.down.sql migrations/004_bids_add_won_reason.up.sql migrations/005_auctions_add_providers.down.sql migrations/005_auctions_add_providers.up.sql migrations/006_consume_bidbot_events.down.sql migrations/006_consume_bidbot_events.up.sql migrations/007_bids_add_deal_failed_at.down.sql migrations/007_bids_add_deal_failed_at.up.sql migrations/008_leader_board.down.sql migrations/008_leader_board.up.sql migrations/009_leader_board_update.down.sql migrations/009_leader_board_update.up.sql migrations/010_leader_board_update2.down.sql migrations/010_leader_board_update2.up.sql migrations/011_leader_board_update3.down.sql migrations/011_leader_board_update3.up.sql migrations/012_leader_board_update4.down.sql migrations/012_leader_board_update4.up.sql migrations/013_leader_board_update5.down.sql migrations/013_leader_board_update5.up.sql migrations/014_leader_board_update6.down.sql migrations/014_leader_board_update6.up.sql
Package migrations generated by go-bindata.// sources: migrations/001_init.down.sql migrations/001_init.up.sql migrations/002_bids_support_calculating_rates.down.sql migrations/002_bids_support_calculating_rates.up.sql migrations/003_auctions_add_client_address.down.sql migrations/003_auctions_add_client_address.up.sql migrations/004_bids_add_won_reason.down.sql migrations/004_bids_add_won_reason.up.sql migrations/005_auctions_add_providers.down.sql migrations/005_auctions_add_providers.up.sql migrations/006_consume_bidbot_events.down.sql migrations/006_consume_bidbot_events.up.sql migrations/007_bids_add_deal_failed_at.down.sql migrations/007_bids_add_deal_failed_at.up.sql migrations/008_leader_board.down.sql migrations/008_leader_board.up.sql migrations/009_leader_board_update.down.sql migrations/009_leader_board_update.up.sql migrations/010_leader_board_update2.down.sql migrations/010_leader_board_update2.up.sql migrations/011_leader_board_update3.down.sql migrations/011_leader_board_update3.up.sql migrations/012_leader_board_update4.down.sql migrations/012_leader_board_update4.up.sql migrations/013_leader_board_update5.down.sql migrations/013_leader_board_update5.up.sql migrations/014_leader_board_update6.down.sql migrations/014_leader_board_update6.up.sql

Jump to

Keyboard shortcuts

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