Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion timeboost/auctioneer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package timeboost
import (
"context"
"fmt"
"math"
"math/big"
"strconv"
"strings"
Expand Down Expand Up @@ -44,6 +45,9 @@ const (

// Auctioneer coordination key for failover
AUCTIONEER_CHOSEN_KEY = "auctioneer.chosen"

// Default buffer size for bids receiver channel
DefaultBidsReceiverBufferSize = 100_000
)

var (
Expand Down Expand Up @@ -75,6 +79,7 @@ type AuctioneerServerConfig struct {
AuctionContractAddress string `koanf:"auction-contract-address"`
DbDirectory string `koanf:"db-directory"`
AuctionResolutionWaitTime time.Duration `koanf:"auction-resolution-wait-time"`
BidsReceiverBufferSize uint64 `koanf:"bids-receiver-buffer-size"`
S3Storage S3StorageServiceConfig `koanf:"s3-storage"`
}

Expand All @@ -92,6 +97,7 @@ var DefaultAuctioneerServerConfig = AuctioneerServerConfig{
ConsumerConfig: DefaultAuctioneerConsumerConfig,
StreamTimeout: 10 * time.Minute,
AuctionResolutionWaitTime: 2 * time.Second,
BidsReceiverBufferSize: DefaultBidsReceiverBufferSize,
S3Storage: DefaultS3StorageServiceConfig,
}

Expand All @@ -101,6 +107,7 @@ var TestAuctioneerServerConfig = AuctioneerServerConfig{
ConsumerConfig: DefaultAuctioneerConsumerConfig,
StreamTimeout: time.Minute,
AuctionResolutionWaitTime: 2 * time.Second,
BidsReceiverBufferSize: 1_000,
}

func AuctioneerServerConfigAddOptions(prefix string, f *pflag.FlagSet) {
Expand All @@ -116,6 +123,7 @@ func AuctioneerServerConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".auction-contract-address", DefaultAuctioneerServerConfig.AuctionContractAddress, "express lane auction contract address")
f.String(prefix+".db-directory", DefaultAuctioneerServerConfig.DbDirectory, "path to database directory for persisting validated bids in a sqlite file")
f.Duration(prefix+".auction-resolution-wait-time", DefaultAuctioneerServerConfig.AuctionResolutionWaitTime, "wait time after auction closing before resolving the auction")
f.Uint64(prefix+".bids-receiver-buffer-size", DefaultAuctioneerServerConfig.BidsReceiverBufferSize, fmt.Sprintf("buffer size for the bids receiver channel (0 = use default of %d)", DefaultBidsReceiverBufferSize))
S3StorageServiceConfigAddOptions(prefix+".s3-storage", f)
}

Expand Down Expand Up @@ -229,6 +237,14 @@ func NewAuctioneerServer(ctx context.Context, configFetcher AuctioneerServerConf
return nil, err
}

bufferSize := cfg.BidsReceiverBufferSize
if bufferSize == 0 {
bufferSize = DefaultBidsReceiverBufferSize
}
if bufferSize > uint64(math.MaxInt) {
return nil, fmt.Errorf("bids receiver buffer size %d exceeds maximum int value", bufferSize)
}

// Generate unique ID for this auctioneer instance
myId := fmt.Sprintf("auctioneer-%s-%d",
uuid.New().String()[:8], // Short UUID
Expand All @@ -246,7 +262,7 @@ func NewAuctioneerServer(ctx context.Context, configFetcher AuctioneerServerConf
auctionContract: auctionContract,
auctionContractAddr: auctionContractAddr,
auctionContractDomainSeparator: domainSeparator,
bidsReceiver: make(chan *JsonValidatedBid, 100_000), // TODO(Terence): Is 100k enough? Make this configurable?
bidsReceiver: make(chan *JsonValidatedBid, int(bufferSize)),
bidCache: newBidCache(domainSeparator),
roundTimingInfo: *roundTimingInfo,
auctionResolutionWaitTime: cfg.AuctionResolutionWaitTime,
Expand Down
Loading