Skip to content

Commit

Permalink
bidcollect: fn with uid
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Jun 14, 2024
1 parent 3cc9c9e commit 0964511
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
14 changes: 12 additions & 2 deletions cmd/service/bidcollect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/flashbots/relayscan/services/bidcollect"
"github.com/flashbots/relayscan/services/bidcollect/website"
"github.com/flashbots/relayscan/vars"
"github.com/lithammer/shortuuid"
"github.com/spf13/cobra"
)

Expand All @@ -19,7 +20,8 @@ var (
useAllRelays bool

outDir string
outputTSV bool // by default: CSV, but can be changed to TSV with this setting
outputTSV bool // by default: CSV, but can be changed to TSV with this setting
uid string // used in output filenames, to avoid collissions between multiple collector instances

runDevServerOnly bool // used to play with file listing website
devServerListenAddr string
Expand All @@ -42,6 +44,9 @@ func init() {
bidCollectCmd.Flags().StringVar(&outDir, "out", "csv", "output directory for CSV/TSV")
bidCollectCmd.Flags().BoolVar(&outputTSV, "out-tsv", false, "output as TSV (instead of CSV)")

// utils
bidCollectCmd.Flags().StringVar(&uid, "uid", "", "unique identifier for output files (to avoid collisions)")

// for dev purposes
bidCollectCmd.Flags().BoolVar(&runDevServerOnly, "devserver", false, "only run devserver to play with file listing website")
bidCollectCmd.Flags().StringVar(&devServerListenAddr, "devserver-addr", "localhost:8095", "listen address for devserver")
Expand All @@ -68,7 +73,11 @@ var bidCollectCmd = &cobra.Command{
return
}

log.Infof("Bidcollect %s starting ...", vars.Version)
if uid == "" {
uid = shortuuid.New()[:6]
}

log.WithField("uid", uid).Infof("Bidcollect %s starting ...", vars.Version)

// Prepare relays
relays := []common.RelayEntry{
Expand All @@ -86,6 +95,7 @@ var bidCollectCmd = &cobra.Command{

opts := bidcollect.BidCollectorOpts{
Log: log,
UID: uid,
Relays: relays,
CollectUltrasoundStream: collectUltrasoundStream,
CollectGetHeader: collectGetHeader,
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.9
github.com/lithammer/shortuuid v3.0.0+incompatible
github.com/metachris/flashbotsrpc v0.5.0
github.com/metachris/go-ethutils v0.5.3
github.com/olekukonko/tablewriter v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w=
github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
2 changes: 1 addition & 1 deletion scripts/bidcollect/bids-combine-and-upload-yesterday.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ source .env.prod
./scripts/bidcollect/bids-combine-and-upload.sh "/mnt/data/relayscan-bids/$d/"

# update website
make update-bids-website
./relayscan service bidcollect --build-website --build-website-upload
3 changes: 2 additions & 1 deletion services/bidcollect/bid-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type BidProcessorOpts struct {
Log *logrus.Entry
UID string
OutDir string
OutputTSV bool
}
Expand Down Expand Up @@ -202,7 +203,7 @@ func (c *BidProcessor) getFilename(prefix string, timestamp int64) string {
if prefix != "" {
prefix += "_"
}
return fmt.Sprintf("%s%s.%s", prefix, t.Format("2006-01-02_15-04"), c.csvFileEnding)
return fmt.Sprintf("%s%s_%s.%s", prefix, t.Format("2006-01-02_15-04"), c.opts.UID, c.csvFileEnding)
}

func (c *BidProcessor) housekeeping() {
Expand Down
2 changes: 2 additions & 0 deletions services/bidcollect/bidcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type BidCollectorOpts struct {
Log *logrus.Entry
UID string

CollectUltrasoundStream bool
CollectGetHeader bool
Expand Down Expand Up @@ -49,6 +50,7 @@ func NewBidCollector(opts *BidCollectorOpts) *BidCollector {
// output
c.processor = NewBidProcessor(&BidProcessorOpts{
Log: opts.Log,
UID: opts.UID,
OutDir: opts.OutDir,
OutputTSV: opts.OutputTSV,
})
Expand Down

0 comments on commit 0964511

Please sign in to comment.