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

feat(bidcollect): Make top-bid websocket stream generic (and also subscribe to Aestus) #46

Open
wants to merge 2 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
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ cover-html:
docker-image:
DOCKER_BUILDKIT=1 docker build --platform linux/amd64 --build-arg VERSION=${VERSION} . -t relayscan


generate-ssz:
rm -f common/ultrasoundbid_encoding.go
sszgen --path common --objs UltrasoundStreamBid
rm -f common/top-bid-ws-bid_encoding.go
sszgen --path common --objs TopBidWebsocketStreamBid

update-bids-website:
go run . service bidcollect --build-website --build-website-upload
Expand Down
38 changes: 20 additions & 18 deletions cmd/service/bidcollect.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package service

/**
* https://github.com/ultrasoundmoney/docs/blob/main/top-bid-websocket.md
*/

import (
"github.com/flashbots/relayscan/common"
"github.com/flashbots/relayscan/services/bidcollect"
Expand All @@ -14,10 +10,10 @@ import (
)

var (
collectUltrasoundStream bool
collectGetHeader bool
collectDataAPI bool
useAllRelays bool
collectTopBidWebsocketStream bool
collectGetHeader bool
collectDataAPI bool
useAllRelays bool

outDir string
outputTSV bool // by default: CSV, but can be changed to TSV with this setting
Expand All @@ -32,7 +28,7 @@ var (
)

func init() {
bidCollectCmd.Flags().BoolVar(&collectUltrasoundStream, "ultrasound-stream", false, "use ultrasound top-bid stream")
bidCollectCmd.Flags().BoolVar(&collectTopBidWebsocketStream, "top-bid-ws-stream", false, "use top-bid websocket streams")
bidCollectCmd.Flags().BoolVar(&collectGetHeader, "get-header", false, "use getHeader API")
bidCollectCmd.Flags().BoolVar(&collectDataAPI, "data-api", false, "use data API")
bidCollectCmd.Flags().BoolVar(&useAllRelays, "all-relays", false, "use all relays")
Expand Down Expand Up @@ -93,16 +89,22 @@ var bidCollectCmd = &cobra.Command{
log.Infof("- relay #%d: %s", index+1, relay.Hostname())
}

topBidRelays := []common.RelayEntry{}
for _, url := range vars.TopBidStreamURLs {
topBidRelays = append(topBidRelays, common.MustNewRelayEntry(url, false))
}

opts := bidcollect.BidCollectorOpts{
Log: log,
UID: uid,
Relays: relays,
CollectUltrasoundStream: collectUltrasoundStream,
CollectGetHeader: collectGetHeader,
CollectDataAPI: collectDataAPI,
BeaconNodeURI: beaconNodeURI,
OutDir: outDir,
OutputTSV: outputTSV,
Log: log,
UID: uid,
Relays: relays,
CollectTopBidWebsocketStream: collectTopBidWebsocketStream,
TopBidWebsocketRelays: topBidRelays,
CollectGetHeader: collectGetHeader,
CollectDataAPI: collectDataAPI,
BeaconNodeURI: beaconNodeURI,
OutDir: outDir,
OutputTSV: outputTSV,
}

bidCollector := bidcollect.NewBidCollector(&opts)
Expand Down
2 changes: 1 addition & 1 deletion common/relayentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *RelayEntry) GetURI(path string) string {
// relayURL can be IP@PORT, PUBKEY@IP:PORT, https://IP, etc.
func NewRelayEntry(relayURL string, requireUser bool) (entry RelayEntry, err error) {
// Add protocol scheme prefix if it does not exist.
if !strings.HasPrefix(relayURL, "http") {
if !strings.Contains(relayURL, "://") {
relayURL = "https://" + relayURL
}

Expand Down
2 changes: 1 addition & 1 deletion common/ultrasoundbid.go → common/top-bid-ws-bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (n *U256) String() string {
return new(big.Int).SetBytes(ReverseBytes(n[:])).String()
}

type UltrasoundStreamBid struct {
type TopBidWebsocketStreamBid struct {
Timestamp uint64 `json:"timestamp"`
Slot uint64 `json:"slot"`
BlockNumber uint64 `json:"block_number"`
Expand Down
126 changes: 126 additions & 0 deletions common/top-bid-ws-bid_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestValueDecoding(t *testing.T) {
require.Equal(t, expected, value)
}

func TestUltrasoundBidSSZDecoding(t *testing.T) {
func TestTopBidWSStreamBidSSZDecoding(t *testing.T) {
hex := "0x704b87ce8f010000a94b8c0000000000b6043101000000002c02b28fd8fdb45fd6ac43dd04adad1449a35b64247b1ed23a723a1fcf6cac074d0668c9e0912134628c32a54854b952234ebb6c1fdd6b053566ac2d2a09498da03b00ddb78b2c111450a5417a8c368c40f1f140cdf97d95b7fa9565467e0bbbe27877d08e01c69b4e5b02b144e6a265df99a0839818b3f120ebac9b73f82b617dc6a5556c71794b1a9c5400000000000000000000000000000000000000000000000000"
bytes := hexutil.MustDecode(hex)
bid := new(UltrasoundStreamBid)
bid := new(TopBidWebsocketStreamBid)
err := bid.UnmarshalSSZ(bytes)
require.NoError(t, err)

Expand Down
124 changes: 0 additions & 124 deletions common/ultrasoundbid_encoding.go

This file was deleted.

Loading
Loading