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

Hackathon.0 - Rough overview of blob #41

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
keystore_path: /keystore
log-level: debug
l1-rpc-url: <L1_URL>
settlement-rpc-url: http://sl-bootnode:8545
settlement-rpc-url: http://54.191.222.69:8545
pg-host: oracle-db
pg-port: 5432
pg-user: oracle_user
Expand Down
24 changes: 1 addition & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
dockerfile: ./Dockerfile
restart: always
environment:
- L1_URL=${L1_URL}
- L1_URL=http://54.191.222.69:8545
- ORACLE_USER=${ORACLE_USER}
- ORACLE_PASS=${ORACLE_PASS}
labels:
Expand All @@ -26,8 +26,6 @@ services:
]
depends_on:
- oracle-db
networks:
- primev_net

oracle-db:
image: postgres:latest
Expand All @@ -41,26 +39,6 @@ services:
volumes:
- postgres_data:/var/lib/postgresql/data

datadog-agent:
image: gcr.io/datadoghq/agent:latest
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /proc/:/host/proc/:ro
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
environment:
- DD_API_KEY=${DD_KEY}
- DD_TAGS=env:production
- DD_SITE=datadoghq.com
- DD_LOGS_ENABLED=true
- DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true
- DD_CONTAINER_EXCLUDE="name:datadog-agent"
networks:
- primev_net

networks:
primev_net:
external: true


volumes:
Expand Down
28 changes: 3 additions & 25 deletions integration-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ services:
dockerfile: ./integrationtest/Dockerfile
restart: always
environment:
- L1_URL=${L1_URL}
networks:
- primev_net
- L1_URL=http://54.191.222.69:8545
labels:
com.datadoghq.ad.check_names: '["openmetrics"]'
com.datadoghq.ad.init_configs: '[{}]'
Expand All @@ -26,6 +24,8 @@ services:
]
depends_on:
- oracle-db
ports:
- "8080:8080"

oracle-db:
image: postgres:latest
Expand All @@ -38,29 +38,7 @@ services:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- primev_net

datadog-agent:
image: gcr.io/datadoghq/agent:latest
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /proc/:/host/proc/:ro
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
environment:
- DD_API_KEY=${DD_KEY}
- DD_TAGS=env:test
- DD_SITE=datadoghq.com
- DD_LOGS_ENABLED=true
- DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true
- DD_CONTAINER_EXCLUDE="name:datadog-agent"
networks:
- primev_net

networks:
primev_net:
external: true

volumes:
postgres_data:
2 changes: 1 addition & 1 deletion integrationtest/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ keystore-path: /keystore
keystore-password: primev
log-level: debug
l1-rpc-url: <L1_URL>
settlement-rpc-url: http://sl-bootnode:8545
settlement-rpc-url: http://54.191.222.69:8545
pg-host: oracle-db
pg-port: 5432
pg-user: oracle_user
Expand Down
69 changes: 69 additions & 0 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"context"
"encoding/json"
"expvar"
"fmt"
"net"
"net/http"
"net/http/pprof"
"strconv"
"strings"
"time"

"github.com/primevprotocol/mev-oracle/pkg/store"
Expand Down Expand Up @@ -41,9 +43,76 @@ func New(st *store.Store) *Service {

srv.registerDebugEndpoints()
srv.registerStatsEndpoints()
srv.registerAuctionEndpoints()
fmt.Println("I OUTPUT STUFF")
return srv
}

func GetLeader(w http.ResponseWriter, r *http.Request) {
// Assuming the pattern is "/auction/leader/:blocknumber"
// Split the URL path
pathParts := strings.Split(r.URL.Path, "/")

// Ensure the slice has enough parts to avoid out of range errors
// "/auction/leader/blocknumber" would split into 4 parts
if len(pathParts) < 4 {
http.Error(w, "Bad request", http.StatusBadRequest)
return
}

// The blocknumber is expected to be the 4th part
blocknumberStr := pathParts[3]

// Convert the blocknumber from string to int (or desired type)
blocknumber, err := strconv.Atoi(blocknumberStr)
if err != nil {
// Handle the error if the conversion fails
http.Error(w, "Invalid block number", http.StatusBadRequest)
return
}

w.Write([]byte(fmt.Sprintf("Auction Leader for block number %d", blocknumber)))
}

// Allows a user to send a json paylaod over HTTP to the server
// The payload includes:
// - The block number
// - The address of the sender
// - The amount of the bid

func SendBid(w http.ResponseWriter, r *http.Request) {
// Process the json payload and serlialze into a struct
// Assuming the payload is in the form of:
// {
// "blocknumber": 123,
// "address": "0x1234",
// "amount": 100
// }
type Bid struct {
Blocknumber int `json:"blocknumber"`
Address string `json:"address"`
Amount int `json:"amount"`
}

// Deseralize json payload body into a Bid struct
var bid Bid
err := json.NewDecoder(r.Body).Decode(&bid)
if err != nil {
http.Error(w, "Invalid payload", http.StatusBadRequest)
return
}

// Write the bid to w
w.Write([]byte(fmt.Sprintf("Bid for block number %d from address %s for %d", bid.Blocknumber, bid.Address, bid.Amount)))

}

func (a *Service) registerAuctionEndpoints() {
// Router handle for /auction/leader/blocknumber
a.router.Handle("/auction/leader/", http.HandlerFunc(GetLeader))
a.router.Handle("/auction/sendbid/", http.HandlerFunc(SendBid))
}

func (a *Service) registerDebugEndpoints() {
// register metrics handler
a.router.Handle("/metrics", promhttp.HandlerFor(a.metricsRegistry, promhttp.HandlerOpts{}))
Expand Down
6 changes: 6 additions & 0 deletions pkg/l1Listener/l1Listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var checkInterval = 2 * time.Second

type WinnerRegister interface {
RegisterWinner(ctx context.Context, blockNum int64, winner string) error
RegisterAuctionWinner(ctx context.Context, blockNum int64, winner string) error
}

type EthClient interface {
Expand Down Expand Up @@ -76,6 +77,11 @@ func (l *L1Listener) Start(ctx context.Context) <-chan struct{} {
continue
}

// We want to regiseter the winner of the auction for a given slot
relayWinner := auction.WinnerByNumber(ctx, big.NewInt(int64(blockNum)))
if relayWinner != "" {
err = l.winnerRegister.RegisterAuctionWinner(ctx, int64(blockNum), relayWinner)
}
winner := string(bytes.ToValidUTF8(header.Extra, []byte("�")))
if len(winner) == 0 {
log.Warn().
Expand Down
5 changes: 5 additions & 0 deletions pkg/l1Listener/l1Listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func (t *testRegister) RegisterWinner(_ context.Context, blockNum int64, winner
return nil
}

func (t *testRegister) RegisterAuctionWinner(_ context.Context, blockNum int64, winner string) error {
t.winners <- winnerObj{blockNum: blockNum, winner: winner}
return nil
}

type testEthClient struct {
mu sync.Mutex
headers map[uint64]*types.Header
Expand Down
11 changes: 11 additions & 0 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ func (s *Store) RegisterWinner(ctx context.Context, blockNum int64, winner strin
return nil
}

func (s *Store) RegisterAuctionWinner(ctx context.Context, blockNum int64, winner string) error {
insertStr := "INSERT INTO winners (block_number, builder_address, processed) VALUES ($1, $2, $3)"

_, err := s.db.ExecContext(ctx, insertStr, blockNum, winner, false)
if err != nil {
return err
}
s.triggerWinner()
return nil
}

func (s *Store) SubscribeWinners(ctx context.Context) <-chan updater.BlockWinner {
resChan := make(chan updater.BlockWinner)
go func() {
Expand Down