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

Update EigenDA proxy to match OP v1.7.6 client expectation #31

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Set up Go
uses: actions/setup-go@v3
Expand Down Expand Up @@ -58,6 +60,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Set up Go
uses: actions/setup-go@v3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ clean:
test:
go test -v ./...

e2e-test: submodules srs
e2e-test: submodules
go test -timeout 50m -v ./test/e2e_test.go -testnet-integration

.PHONY: lint
Expand Down
45 changes: 5 additions & 40 deletions cmd/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,18 @@ import (
"fmt"

"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/Layr-Labs/eigenda/api/clients"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"

proxy "github.com/Layr-Labs/eigenda-proxy"
"github.com/Layr-Labs/eigenda-proxy/server"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/opio"
)

func LoadStore(cfg CLIConfig, ctx context.Context, log log.Logger) (store.Store, error) {
log.Info("Using eigenda backend")
daCfg := cfg.EigenDAConfig

verifier, err := verify.NewVerifier(daCfg.KzgConfig())
if err != nil {
return nil, err
}

maxBlobLength, err := daCfg.GetMaxBlobLength()
if err != nil {
return nil, err
}

if cfg.MemStoreCfg.Enabled {
log.Info("Using memstore backend")
return store.NewMemStore(ctx, &cfg.MemStoreCfg, verifier, log, maxBlobLength)
}

client, err := clients.NewEigenDAClient(log, daCfg.ClientConfig)
if err != nil {
return nil, err
}
return store.NewEigenDAStore(
ctx,
client,
verifier,
maxBlobLength,
)
}

func StartProxySvr(cliCtx *cli.Context) error {
if err := CheckRequired(cliCtx); err != nil {
if err := server.CheckRequired(cliCtx); err != nil {
return err
}
cfg := ReadCLIConfig(cliCtx)
cfg := server.ReadCLIConfig(cliCtx)
if err := cfg.Check(); err != nil {
return err
}
Expand All @@ -65,11 +30,11 @@ func StartProxySvr(cliCtx *cli.Context) error {

log.Info("Initializing EigenDA proxy server...")

da, err := LoadStore(cfg, ctx, log)
da, err := server.LoadStore(cfg, ctx, log)
if err != nil {
return fmt.Errorf("failed to create store: %w", err)
}
server := proxy.NewServer(cliCtx.String(ListenAddrFlagName), cliCtx.Int(PortFlagName), da, log, m)
server := server.NewServer(cliCtx.String(server.ListenAddrFlagName), cliCtx.Int(server.PortFlagName), da, log, m)

if err := server.Start(); err != nil {
return fmt.Errorf("failed to start the DA server")
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"

"github.com/Layr-Labs/eigenda-proxy/server"
"github.com/ethereum-optimism/optimism/op-node/metrics"
opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/cliapp"
Expand All @@ -22,7 +23,7 @@ func main() {
oplog.SetupDefaults()

app := cli.NewApp()
app.Flags = cliapp.ProtectFlags(Flags)
app.Flags = cliapp.ProtectFlags(server.Flags)
app.Version = opservice.FormatVersion(Version, "", "", "")
app.Name = "eigenda-proxy"
app.Usage = "EigenDA Proxy Sidecar Service"
Expand Down
2 changes: 1 addition & 1 deletion eigenda/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
type Commitment []byte

func (c Commitment) Encode() []byte {
return append([]byte{byte(op_plasma.GenericCommitmentType), byte(EigenDA), byte(EigenV0)}, c...)
return append([]byte{byte(EigenDA), byte(EigenV0)}, c...)
teddyknox marked this conversation as resolved.
Show resolved Hide resolved
}

func StringToCommit(key string) (Commitment, error) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/Layr-Labs/eigenda v0.7.2-0.20240606180508-e90cb7432ca5
github.com/consensys/gnark-crypto v0.12.1
github.com/ethereum-optimism/optimism v1.7.5-0.20240520224312-38cd9944494a
github.com/ethereum-optimism/optimism v1.7.6
github.com/ethereum/go-ethereum v1.14.0
github.com/joho/godotenv v1.5.1
github.com/prometheus/client_golang v1.19.0
Expand Down Expand Up @@ -49,7 +49,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240516202831-8117b611dc3c // indirect
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240522134500-19555bdbdc95 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/fjl/memsize v0.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/ethereum-optimism/op-geth v1.101315.1-rc.4 h1:8kKEkKIpEiDA1yJfrOO473Tyz4nGgSJHpyK1I0fbPDo=
github.com/ethereum-optimism/op-geth v1.101315.1-rc.4/go.mod h1:TtEUbMSmnt2jrnmxAG0n7tj6ujmcBJ+TKkmU56+NMMw=
github.com/ethereum-optimism/optimism v1.7.5-0.20240520224312-38cd9944494a h1:G/ZEyK8EGxte4pl/2Z5pP+/MbOFxsey4DzC6nHT/pqw=
github.com/ethereum-optimism/optimism v1.7.5-0.20240520224312-38cd9944494a/go.mod h1:0SW2VbS19rHhno7VpBKODQzpUsb7xaNlBgdDkiu/O/I=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240516202831-8117b611dc3c h1:dZYKUyjBsJfkCdlcqQ65pjIV1KD7P46ZvENKTxuxfJQ=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240516202831-8117b611dc3c/go.mod h1:7xh2awFQqsiZxFrHKTgEd+InVfDRrkKVUIuK8SAFHp0=
github.com/ethereum-optimism/optimism v1.7.6 h1:iwbO47lwa6vi5gQA0Lbnf/uOzmqXFHvXgmziLtVMbwM=
github.com/ethereum-optimism/optimism v1.7.6/go.mod h1:0zhgYDWSk2ZgzFkhA4ENcWRvS0EuO9IUQAhXenvtSZM=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240522134500-19555bdbdc95 h1:GjXKQg6u6WkEIcY0dvW2IKhMRY8cVjwdw+rNKhduAo8=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240522134500-19555bdbdc95/go.mod h1:7xh2awFQqsiZxFrHKTgEd+InVfDRrkKVUIuK8SAFHp0=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/flags.go → server/flags.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"fmt"
Expand Down
41 changes: 41 additions & 0 deletions server/load_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package server

import (
"context"

"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/Layr-Labs/eigenda/api/clients"
"github.com/ethereum/go-ethereum/log"
)

func LoadStore(cfg CLIConfig, ctx context.Context, log log.Logger) (store.Store, error) {
log.Info("Using eigenda backend")
daCfg := cfg.EigenDAConfig

verifier, err := verify.NewVerifier(daCfg.KzgConfig())
if err != nil {
return nil, err
}

maxBlobLength, err := daCfg.GetMaxBlobLength()
if err != nil {
return nil, err
}

if cfg.MemStoreCfg.Enabled {
log.Info("Using memstore backend")
return store.NewMemStore(ctx, &cfg.MemStoreCfg, verifier, log, maxBlobLength)
}

client, err := clients.NewEigenDAClient(log, daCfg.ClientConfig)
if err != nil {
return nil, err
}
return store.NewEigenDAStore(
ctx,
client,
verifier,
maxBlobLength,
)
}
64 changes: 26 additions & 38 deletions server.go → server/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proxy
package server

import (
"context"
Expand Down Expand Up @@ -28,8 +28,8 @@ const (
)

const (
GetRoute = "/get"
PutRoute = "/put"
GetRoute = "/get/"
PutRoute = "/put/"

DomainFilterKey = "domain"
)
Expand Down Expand Up @@ -60,43 +60,32 @@ func NewServer(host string, port int, store store.Store, log log.Logger, m metri
}
}

// WithVerify is a middleware that verifies the route path.
func WithVerify(handleFn func(http.ResponseWriter, *http.Request), path string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
route := r.URL.Path

if route != path {
w.WriteHeader(http.StatusBadRequest)
return
}

handleFn(w, r)
}
}

// WithMetrics is a middleware that records metrics for the route path.
func WithMetrics(handleFn func(http.ResponseWriter, *http.Request), m metrics.Metricer) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
func WithMetrics(handleFn func(http.ResponseWriter, *http.Request) error, m metrics.Metricer) func(http.ResponseWriter, *http.Request) error {
return func(w http.ResponseWriter, r *http.Request) error {
recordDur := m.RecordRPCServerRequest(r.URL.Path)
defer recordDur()

handleFn(w, r)
return handleFn(w, r)
}
}

func WithLogging(handleFn func(http.ResponseWriter, *http.Request), log log.Logger) func(http.ResponseWriter, *http.Request) {
func WithLogging(handleFn func(http.ResponseWriter, *http.Request) error, log log.Logger) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
log.Info("request", "method", r.Method, "url", r.URL)
handleFn(w, r)
err := handleFn(w, r)
if err != nil {
log.Error(err.Error())
}
}
}

func (svr *Server) Start() error {
mux := http.NewServeMux()

mux.HandleFunc(GetRoute, WithMetrics(WithVerify(svr.HandleGet, GetRoute), svr.m))
mux.HandleFunc(PutRoute, WithMetrics(WithVerify(svr.HandlePut, PutRoute), svr.m))
mux.HandleFunc("/health", WithVerify(svr.Health, "/health"))
mux.HandleFunc(GetRoute, WithLogging(WithMetrics(svr.HandleGet, svr.m), svr.log))
mux.HandleFunc(PutRoute, WithLogging(WithMetrics(svr.HandlePut, svr.m), svr.log))
mux.HandleFunc("/health", WithLogging(svr.Health, svr.log))

svr.httpServer.Handler = mux

Expand Down Expand Up @@ -147,58 +136,57 @@ func (svr *Server) Stop() error {
}
return nil
}
func (svr *Server) Health(w http.ResponseWriter, r *http.Request) {
svr.log.Info("GET", "url", r.URL)

func (svr *Server) Health(w http.ResponseWriter, r *http.Request) error {
w.WriteHeader(http.StatusOK)
return nil
}

func (svr *Server) HandleGet(w http.ResponseWriter, r *http.Request) {
svr.log.Info("GET", "url", r.URL)

func (svr *Server) HandleGet(w http.ResponseWriter, r *http.Request) error {
domain, err := ReadDomainFilter(r)
if err != nil {
svr.WriteBadRequest(w, invalidDomain)
return
return err
}

key := path.Base(r.URL.Path)
comm, err := eigenda.StringToCommit(key)
if err != nil {
svr.log.Info("failed to decode commitment", "err", err, "key", key)
w.WriteHeader(http.StatusBadRequest)
return
return err
}

input, err := svr.store.Get(r.Context(), comm, domain)
if err != nil && errors.Is(err, ErrNotFound) {
svr.WriteNotFound(w, err.Error())
return
return err
}

if err != nil {
svr.WriteInternalError(w, err)
return
return err
}

svr.WriteResponse(w, input)
return nil
}

func (svr *Server) HandlePut(w http.ResponseWriter, r *http.Request) {
func (svr *Server) HandlePut(w http.ResponseWriter, r *http.Request) error {
input, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
return err
}

var comm []byte
if comm, err = svr.store.Put(r.Context(), input); err != nil {
svr.WriteInternalError(w, err)
return
return err
}

// write out encoded commitment
svr.WriteResponse(w, eigenda.Commitment.Encode(comm))
return nil
}

func (svr *Server) WriteResponse(w http.ResponseWriter, data []byte) {
Expand Down
Loading
Loading