Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store all relays bids #53

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions cmd/service/bidcollect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (

runWebserverOnly bool // provides a SSE stream of new bids
WebserverListenAddr string

withDuplicates bool
)

func init() {
Expand Down Expand Up @@ -70,6 +72,7 @@ func init() {
bidCollectCmd.Flags().BoolVar(&buildWebsite, "build-website", false, "build file listing website")
bidCollectCmd.Flags().BoolVar(&buildWebsiteUpload, "build-website-upload", false, "upload after building")
bidCollectCmd.Flags().StringVar(&buildWebsiteOutDir, "build-website-out", "build", "output directory for website")
bidCollectCmd.Flags().BoolVar(&withDuplicates, "with-duplicates", false, "store all bids, including duplicates from different relays")
}

var bidCollectCmd = &cobra.Command{
Expand Down Expand Up @@ -129,6 +132,7 @@ var bidCollectCmd = &cobra.Command{
OutputTSV: outputTSV,
RedisAddr: redisAddr,
UseRedis: useRedis,
WithDuplicates: withDuplicates,
}

bidCollector, err := bidcollect.NewBidCollector(&opts)
Expand Down
3 changes: 3 additions & 0 deletions docs/2024-06_bidcollect.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Different data sources have different limitations:
- Bids are deduplicated based on this key:
- `fmt.Sprintf("%d-%s-%s-%s-%s", bid.Slot, bid.BlockHash, bid.ParentHash, bid.BuilderPubkey, bid.Value)`
- this means only the first bid for a given key is stored, even if - for instance - other relays also deliver the same bid
- To store the same bid delivered by different relays use the `--with-duplicates` flag. This will change the deduplication key to:
- `fmt.Sprintf("%d-%s-%s-%s-%s-%s", bid.Slot, bid.BlockHash, bid.ParentHash, bid.Relay, bid.BuilderPubkey, bid.Value)`
- this is helpful to measure builder to relay latency.
- Bids can be published to Redis (to be consumed by whatever, i.e. a webserver). The channel is called `bidcollect/bids`.
- Enable publishing to Redis with the `--redis` flag
- You can start a webserver that publishes the data via a SSE stream with `--webserver`
Expand Down
27 changes: 18 additions & 9 deletions services/bidcollect/bid-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
// - One CSV for top bids only

type BidProcessorOpts struct {
Log *logrus.Entry
UID string
OutDir string
OutputTSV bool
RedisAddr string
UseRedis bool
Log *logrus.Entry
UID string
OutDir string
OutputTSV bool
RedisAddr string
UseRedis bool
WithDuplicates bool
}

type OutFiles struct {
Expand Down Expand Up @@ -114,10 +115,18 @@ func (c *BidProcessor) processBids(bids []*types.CommonBid) {
}
}

// process regular bids only once per unique key (slot+blockhash+parenthash+builderpubkey+value)
if _, ok := c.bidCache[bid.Slot][bid.UniqueKey()]; !ok {
var uniqueKey string
if c.opts.WithDuplicates {
// process regular bids only once per unique key (slot+blockhash+parenthash+relay+builderpubkey+value)
uniqueKey = bid.UniqueKeyWithRelay()
} else {
// process regular bids only once per unique key (slot+blockhash+parenthash+builderpubkey+value)
uniqueKey = bid.UniqueKey()
}

if _, ok := c.bidCache[bid.Slot][uniqueKey]; !ok {
// yet unknown bid, save it
c.bidCache[bid.Slot][bid.UniqueKey()] = bid
c.bidCache[bid.Slot][uniqueKey] = bid
isNewBid = true
}

Expand Down
15 changes: 9 additions & 6 deletions services/bidcollect/bidcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type BidCollectorOpts struct {

RedisAddr string
UseRedis bool

WithDuplicates bool
}

type BidCollector struct {
Expand Down Expand Up @@ -53,12 +55,13 @@ func NewBidCollector(opts *BidCollectorOpts) (c *BidCollector, err error) {

// output
c.processor, err = NewBidProcessor(&BidProcessorOpts{
Log: opts.Log,
UID: opts.UID,
OutDir: opts.OutDir,
OutputTSV: opts.OutputTSV,
RedisAddr: opts.RedisAddr,
UseRedis: opts.UseRedis,
Log: opts.Log,
UID: opts.UID,
OutDir: opts.OutDir,
OutputTSV: opts.OutputTSV,
RedisAddr: opts.RedisAddr,
UseRedis: opts.UseRedis,
WithDuplicates: opts.WithDuplicates,
})
return c, err
}
Expand Down
4 changes: 4 additions & 0 deletions services/bidcollect/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (bid *CommonBid) UniqueKey() string {
return fmt.Sprintf("%d-%s-%s-%s-%s", bid.Slot, bid.BlockHash, bid.ParentHash, bid.BuilderPubkey, bid.Value)
}

func (bid *CommonBid) UniqueKeyWithRelay() string {
return fmt.Sprintf("%d-%s-%s-%s-%s-%s", bid.Slot, bid.BlockHash, bid.ParentHash, bid.Relay, bid.BuilderPubkey, bid.Value)
}

func (bid *CommonBid) ValueAsBigInt() *big.Int {
value := new(big.Int)
value.SetString(bid.Value, 10)
Expand Down
Loading