diff --git a/.env.example b/.env.example index 39ba8019..84f82527 100644 --- a/.env.example +++ b/.env.example @@ -1,45 +1,45 @@ # Server listening address -EIGEN_PLASMA_SERVER_ADDR=127.0.0.1 +EIGENDA_PROXY_ADDR=127.0.0.1 # Server listening port (default: 3100) -EIGEN_PLASMA_SERVER_PORT=3100 +EIGENDA_PROXY_PORT=3100 # Directory path to SRS tables -EIGEN_PLASMA_SERVER_EIGENDA_CACHE_PATH= +EIGENDA_PROXY_EIGENDA_CACHE_PATH= # Directory path to g1.point file -EIGEN_PLASMA_SERVER_EIGENDA_KZG_G1_PATH= +EIGENDA_PROXY_EIGENDA_KZG_G1_PATH= # Directory path to g2.point.powerOf2 file -EIGEN_PLASMA_SERVER_EIGENDA_G2_TAU_PATH= +EIGENDA_PROXY_EIGENDA_G2_TAU_PATH= # RPC endpoint of the EigenDA disperser -EIGEN_PLASMA_SERVER_EIGENDA_RPC= +EIGENDA_PROXY_EIGENDA_RPC= # Wait time between retries of EigenDA blob status queries (default: 5s) -EIGEN_PLASMA_SERVER_EIGENDA_STATUS_QUERY_INTERVAL=5s +EIGENDA_PROXY_EIGENDA_STATUS_QUERY_INTERVAL=5s # Timeout for aborting an EigenDA blob dispersal (default: 25m0s) -EIGEN_PLASMA_SERVER_EIGENDA_STATUS_QUERY_TIMEOUT=25m0s +EIGENDA_PROXY_EIGENDA_STATUS_QUERY_TIMEOUT=25m0s # Use TLS when connecting to the EigenDA disperser (default: true) -EIGEN_PLASMA_SERVER_EIGENDA_GRPC_USE_TLS=true +EIGENDA_PROXY_EIGENDA_GRPC_USE_TLS=true # Color the log output if in terminal mode (default: false) -EIGEN_PLASMA_SERVER_LOG_COLOR=false +EIGENDA_PROXY_LOG_COLOR=false # Format the log output (default: text) # Supported formats: 'text', 'terminal', 'logfmt', 'json', 'json-pretty' -EIGEN_PLASMA_SERVER_LOG_FORMAT=text +EIGENDA_PROXY_LOG_FORMAT=text # The lowest log level that will be output (default: INFO) -EIGEN_PLASMA_SERVER_LOG_LEVEL=INFO +EIGENDA_PROXY_LOG_LEVEL=INFO # Metrics listening address (default: 0.0.0.0) -EIGEN_PLASMA_SERVER_METRICS_ADDR=0.0.0.0 +EIGENDA_PROXY_METRICS_ADDR=0.0.0.0 # Enable the metrics server (default: false) -EIGEN_PLASMA_SERVER_METRICS_ENABLED=false +EIGENDA_PROXY_METRICS_ENABLED=false # Metrics listening port (default: 7300) -EIGEN_PLASMA_SERVER_METRICS_PORT=7300 +EIGENDA_PROXY_METRICS_PORT=7300 diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 30433dea..20ab9ee7 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -19,7 +19,7 @@ jobs: go-version: 1.21 - name: Build App - run: make da-server + run: make eigenda-proxy go-test: outputs: diff --git a/Dockerfile b/Dockerfile index 00969916..116d09d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,16 +17,16 @@ RUN go mod download COPY . . # Build the application binary -RUN make da-server +RUN make eigenda-proxy # Use alpine to run app FROM alpine:3.16 WORKDIR /app -COPY --from=builder /app/bin/da-server . +COPY --from=builder /app/bin/eigenda-proxy . # API & metrics servers EXPOSE 4242 7300 # Run app -CMD ["./da-server"] \ No newline at end of file +CMD ["./eigenda-proxy"] \ No newline at end of file diff --git a/Makefile b/Makefile index 200e6e8a..5b0e0171 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -APP_NAME = eigenda-sidecar +APP_NAME = eigenda-proxy LINTER_VERSION = v1.52.1 LINTER_URL = https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh GET_LINT_CMD = "curl -sSfL $(LINTER_URL) | sh -s -- -b $(go env GOPATH)/bin $(LINTER_VERSION)" @@ -12,19 +12,19 @@ LDFLAGSSTRING +=-X main.GitDate=$(GITDATE) LDFLAGSSTRING +=-X main.Version=$(VERSION) LDFLAGS := -ldflags "$(LDFLAGSSTRING)" -.PHONY: da-server -da-server: - env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/da-server ./cmd/daserver +.PHONY: eigenda-proxy +eigenda-proxy: + env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/eigenda-proxy ./cmd/daserver .PHONY: docker-build docker-build: @docker build -t $(APP_NAME) . run-server: - ./bin/da-server + ./bin/eigenda-proxy clean: - rm bin/da-server + rm bin/eigenda-proxy test: go test -v ./... -test.skip ".*E2E.*" diff --git a/README.md b/README.md index 6c5ae25e..b122b20b 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,23 @@ Additional cli args are provided for targeting an EigenDA network backend: - `--eigenda-status-query-timeout`: (default: 25m) Duration for which a client will wait for a blob to finalize after being sent for dispersal. - `--eigenda-status-query-retry-interval`: (default: 5s) How often a client will attempt a retry when awaiting network blob finalization. - `--eigenda-use-tls`: (default: true) Whether or not to use TLS for grpc communication with disperser. -- `eigenda-g1-path`: Directory path to g1.point file -- `eigenda-g2-power-of-tau`: Directory path to g2.point.powerOf2 file -- `eigenda-cache-path`: Directory path to dump cached SRS tables +- `--eigenda-g1-path`: Directory path to g1.point file +- `--eigenda-g2-power-of-tau`: Directory path to g2.point.powerOf2 file +- `--eigenda-cache-path`: Directory path to dump cached SRS tables + +### In-Memory Storage +An ephemeral memory store backend can be used for faster feedback testing when performing rollup integrations. The following cli args can be used to target the feature: +* `--memstore.enabled`: Boolean feature flag +* `--memstore.expiration`: Duration for which a blob will exist ## Running Locally -1. Compile binary: `make da-server` -2. Run binary; e.g: `./bin/da-server --addr 127.0.0.1 --port 5050 --eigenda-rpc 127.0.0.1:443 --eigenda-status-query-timeout 45m --eigenda-g1-path test/resources/g1.point --eigenda-g2-tau-path test/resources/g2.point.powerOf2 --eigenda-use-tls true` +1. Compile binary: `make eigenda-proxy` +2. Run binary; e.g: `./bin/eigenda-proxy --addr 127.0.0.1 --port 5050 --eigenda-rpc 127.0.0.1:443 --eigenda-status-query-timeout 45m --eigenda-g1-path test/resources/g1.point --eigenda-g2-tau-path test/resources/g2.point.powerOf2 --eigenda-use-tls true` **Env File** An env file can be provided to the binary for runtime process ingestion; e.g: 1. Create env: `cp .env.example .env` -2. Pass into binary: `ENV_PATH=.env ./bin/da-server` +2. Pass into binary: `ENV_PATH=.env ./bin/eigenda-proxy` ## Running via Docker Container can be built via running `make build-docker`. @@ -79,5 +84,3 @@ The following specs are recommended for running on a single production server: - [op-stack](https://github.com/ethereum-optimism/optimism) - [plasma spec](https://specs.optimism.io/experimental/plasma.html) - [eigen da](https://github.com/Layr-Labs/eigenda) - - diff --git a/cmd/daserver/entrypoint.go b/cmd/daserver/entrypoint.go index 9c8b951a..bf2dee63 100644 --- a/cmd/daserver/entrypoint.go +++ b/cmd/daserver/entrypoint.go @@ -4,51 +4,65 @@ import ( "context" "fmt" + "github.com/Layr-Labs/op-plasma-eigenda/eigenda" "github.com/Layr-Labs/op-plasma-eigenda/metrics" + "github.com/Layr-Labs/op-plasma-eigenda/store" + "github.com/Layr-Labs/op-plasma-eigenda/verify" + "github.com/ethereum/go-ethereum/log" "github.com/urfave/cli/v2" - plasma "github.com/Layr-Labs/op-plasma-eigenda" - "github.com/Layr-Labs/op-plasma-eigenda/eigenda" - plasma_store "github.com/Layr-Labs/op-plasma-eigenda/store" - "github.com/Layr-Labs/op-plasma-eigenda/verify" + proxy "github.com/Layr-Labs/op-plasma-eigenda" oplog "github.com/ethereum-optimism/optimism/op-service/log" "github.com/ethereum-optimism/optimism/op-service/opio" ) -func StartDAServer(cliCtx *cli.Context) error { - if err := CheckRequired(cliCtx); err != nil { - return err +func LoadStore(cfg CLIConfig, ctx context.Context, log log.Logger) (proxy.Store, error) { + if cfg.MemStoreCfg.Enabled { + log.Info("Using memstore backend") + return store.NewMemStore(ctx, &cfg.MemStoreCfg) } - cfg := ReadCLIConfig(cliCtx) - if err := cfg.Check(); err != nil { - return err - } - m := metrics.NewMetrics("default") - - log := oplog.NewLogger(oplog.AppOut(cliCtx), oplog.ReadCLIConfig(cliCtx)).New("role", "eigenda_plasma_server") - oplog.SetGlobalLogHandler(log.Handler()) - - log.Info("Initializing EigenDA Plasma DA server...") + log.Info("Using eigenda backend") daCfg := cfg.EigenDAConfig v, err := verify.NewVerifier(daCfg.KzgConfig()) if err != nil { - return err + return nil, err } - store, err := plasma_store.NewEigenDAStore( - cliCtx.Context, + return store.NewEigenDAStore( + ctx, eigenda.NewEigenDAClient( log, daCfg, ), v, ) +} + +func StartProxySvr(cliCtx *cli.Context) error { + if err := CheckRequired(cliCtx); err != nil { + return err + } + cfg := ReadCLIConfig(cliCtx) + if err := cfg.Check(); err != nil { + return err + } + ctx, ctxCancel := context.WithCancel(cliCtx.Context) + defer ctxCancel() + + m := metrics.NewMetrics("default") + + log := oplog.NewLogger(oplog.AppOut(cliCtx), oplog.ReadCLIConfig(cliCtx)).New("role", "eigenda_proxy") + oplog.SetGlobalLogHandler(log.Handler()) + + log.Info("Initializing EigenDA Plasma DA server...") + + da, err := LoadStore(cfg, ctx, log) if err != nil { - return fmt.Errorf("failed to create EigenDA store: %w", err) + return fmt.Errorf("failed to create store: %w", err) } - server := plasma.NewDAServer(cliCtx.String(ListenAddrFlagName), cliCtx.Int(PortFlagName), store, log, m) + server := proxy.NewServer(cliCtx.String(ListenAddrFlagName), cliCtx.Int(PortFlagName), da, log, m) if err := server.Start(); err != nil { return fmt.Errorf("failed to start the DA server") @@ -60,6 +74,8 @@ func StartDAServer(cliCtx *cli.Context) error { if err := server.Stop(); err != nil { log.Error("failed to stop DA server", "err", err) } + + log.Info("successfully shutdown API server") }() if cfg.MetricsCfg.Enabled { diff --git a/cmd/daserver/flags.go b/cmd/daserver/flags.go index 0dfdc72f..74e62721 100644 --- a/cmd/daserver/flags.go +++ b/cmd/daserver/flags.go @@ -6,6 +6,7 @@ import ( "github.com/urfave/cli/v2" "github.com/Layr-Labs/op-plasma-eigenda/eigenda" + "github.com/Layr-Labs/op-plasma-eigenda/store" opservice "github.com/ethereum-optimism/optimism/op-service" oplog "github.com/ethereum-optimism/optimism/op-service/log" opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" @@ -16,7 +17,7 @@ const ( PortFlagName = "port" ) -const EnvVarPrefix = "EIGEN_PLASMA_SERVER" +const EnvVarPrefix = "EIGENDA_PROXY" func prefixEnvVars(name string) []string { return opservice.PrefixEnvVar(EnvVarPrefix, name) @@ -48,6 +49,7 @@ func init() { optionalFlags = append(optionalFlags, oplog.CLIFlags(EnvVarPrefix)...) optionalFlags = append(optionalFlags, eigenda.CLIFlags(EnvVarPrefix)...) optionalFlags = append(optionalFlags, opmetrics.CLIFlags(EnvVarPrefix)...) + optionalFlags = append(optionalFlags, store.CLIFlags(EnvVarPrefix)...) Flags = append(requiredFlags, optionalFlags...) } @@ -55,16 +57,16 @@ func init() { var Flags []cli.Flag type CLIConfig struct { - FileStoreDirPath string - S3Bucket string - EigenDAConfig eigenda.Config - MetricsCfg opmetrics.CLIConfig + MemStoreCfg store.MemStoreConfig + EigenDAConfig eigenda.Config + MetricsCfg opmetrics.CLIConfig } func ReadCLIConfig(ctx *cli.Context) CLIConfig { return CLIConfig{ EigenDAConfig: eigenda.ReadConfig(ctx), MetricsCfg: opmetrics.ReadCLIConfig(ctx), + MemStoreCfg: store.ReadConfig(ctx), } } diff --git a/cmd/daserver/main.go b/cmd/daserver/main.go index ffff1581..1340fbcc 100644 --- a/cmd/daserver/main.go +++ b/cmd/daserver/main.go @@ -24,10 +24,10 @@ func main() { app := cli.NewApp() app.Flags = cliapp.ProtectFlags(Flags) app.Version = opservice.FormatVersion(Version, "", "", "") - app.Name = "eigenda-plasma-server" - app.Usage = "EigenDA Plasma DA Storage Service" - app.Description = "Service for storing plasma DA inputs" - app.Action = StartDAServer + app.Name = "eigenda-proxy" + app.Usage = "EigenDA Proxy Sidecar Service" + app.Description = "Service for more trustless and secure interactions with EigenDA" + app.Action = StartProxySvr app.Commands = []*cli.Command{ { Name: "doc", diff --git a/eigenda/config.go b/eigenda/config.go index da57b8a3..39c2aeec 100644 --- a/eigenda/config.go +++ b/eigenda/config.go @@ -90,40 +90,40 @@ func CLIFlags(envPrefix string) []cli.Flag { &cli.StringFlag{ Name: RPCFlagName, Usage: "RPC endpoint of the EigenDA disperser.", - EnvVars: prefixEnvVars("EIGENDA_RPC"), + EnvVars: prefixEnvVars("TARGET_RPC"), }, &cli.DurationFlag{ Name: StatusQueryTimeoutFlagName, Usage: "Timeout for aborting an EigenDA blob dispersal if the disperser does not report that the blob has been confirmed dispersed.", Value: 25 * time.Minute, - EnvVars: prefixEnvVars("EIGENDA_STATUS_QUERY_TIMEOUT"), + EnvVars: prefixEnvVars("TARGET_STATUS_QUERY_TIMEOUT"), }, &cli.DurationFlag{ Name: StatusQueryRetryIntervalFlagName, Usage: "Wait time between retries of EigenDA blob status queries (made while waiting for a blob to be confirmed by).", Value: 5 * time.Second, - EnvVars: prefixEnvVars("EIGENDA_STATUS_QUERY_INTERVAL"), + EnvVars: prefixEnvVars("TARGET_STATUS_QUERY_INTERVAL"), }, &cli.BoolFlag{ Name: UseTlsFlagName, Usage: "Use TLS when connecting to the EigenDA disperser.", Value: true, - EnvVars: prefixEnvVars("EIGENDA_GRPC_USE_TLS"), + EnvVars: prefixEnvVars("TARGET_GRPC_USE_TLS"), }, &cli.StringFlag{ Name: G1PathFlagName, Usage: "Directory path to g1.point file", - EnvVars: prefixEnvVars("EIGENDA_KZG_G1_PATH"), + EnvVars: prefixEnvVars("TARGET_KZG_G1_PATH"), }, &cli.StringFlag{ Name: G2TauFlagName, Usage: "Directory path to g2.point.powerOf2 file", - EnvVars: prefixEnvVars("EIGENDA_G2_TAU_PATH"), + EnvVars: prefixEnvVars("TARGET_G2_TAU_PATH"), }, &cli.StringFlag{ Name: CachePathFlagName, Usage: "Directory path to SRS tables", - EnvVars: prefixEnvVars("EIGENDA_CACHE_PATH"), + EnvVars: prefixEnvVars("TARGET_CACHE_PATH"), }, } } diff --git a/metrics/metrics.go b/metrics/metrics.go index f1392107..269311f9 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -13,7 +13,7 @@ import ( ) const ( - Namespace = "plasma_eigenda" + Namespace = "eigenda_proxy" ) // Config ... Metrics server configuration @@ -62,7 +62,7 @@ func NewMetrics(procName string) *Metrics { Up: factory.NewGauge(prometheus.GaugeOpts{ Namespace: ns, Name: "up", - Help: "1 if the plasma server has finished starting up", + Help: "1 if the proxy server has finished starting up", }), Info: factory.NewGaugeVec(prometheus.GaugeOpts{ Namespace: ns, @@ -79,7 +79,7 @@ func NewMetrics(procName string) *Metrics { } // RecordInfo sets a pseudo-metric that contains versioning and -// config info for the plasma DA node. +// config info for the proxy DA node. func (m *Metrics) RecordInfo(version string) { m.Info.WithLabelValues(version).Set(1) } diff --git a/server.go b/server.go index bfa070a4..8747c38a 100644 --- a/server.go +++ b/server.go @@ -1,4 +1,4 @@ -package plasma +package proxy import ( "context" @@ -22,7 +22,7 @@ var ( ErrNotFound = errors.New("not found") ) -type PlasmaStore interface { +type Store interface { // Get retrieves the given key if it's present in the key-value data store. Get(ctx context.Context, key []byte) ([]byte, error) // Put inserts the given value into the key-value data store. @@ -32,14 +32,14 @@ type PlasmaStore interface { type DAServer struct { log log.Logger endpoint string - store PlasmaStore + store Store m metrics.Metricer tls *rpc.ServerTLSConfig httpServer *http.Server listener net.Listener } -func NewDAServer(host string, port int, store PlasmaStore, log log.Logger, m metrics.Metricer) *DAServer { +func NewServer(host string, port int, store Store, log log.Logger, m metrics.Metricer) *DAServer { endpoint := net.JoinHostPort(host, strconv.Itoa(port)) return &DAServer{ m: m, @@ -72,7 +72,7 @@ func (d *DAServer) Start() error { d.endpoint = listener.Addr().String() - d.log.Info("Starting DA server on", d.endpoint) + d.log.Info("Starting DA server", "endpoint", d.endpoint) errCh := make(chan error, 1) go func() { if d.tls != nil { @@ -108,7 +108,7 @@ func (d *DAServer) Health(w http.ResponseWriter, r *http.Request) { func (d *DAServer) HandleGet(w http.ResponseWriter, r *http.Request) { d.log.Info("GET", "url", r.URL) - recordDur := d.m.RecordRPCServerRequest("put") + recordDur := d.m.RecordRPCServerRequest("get") defer recordDur() route := path.Dir(r.URL.Path) diff --git a/store/memory.go b/store/memory.go new file mode 100644 index 00000000..beb14199 --- /dev/null +++ b/store/memory.go @@ -0,0 +1,145 @@ +package store + +import ( + "context" + "crypto/rand" + "fmt" + "sync" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/urfave/cli/v2" +) + +const ( + MemStoreFlagName = "memstore.enabled" + ExpirationFlagName = "memstore.expiration" + + DefaultPruneInterval = 500 * time.Millisecond +) + +type MemStoreConfig struct { + Enabled bool + BlobExpiration time.Duration +} + +// MemStore is a simple in-memory store for blobs which uses an expiration +// time to evict blobs to best emulate the ephemeral nature of blobs dispersed to +// EigenDA operators. +type MemStore struct { + sync.RWMutex + + cfg *MemStoreConfig + keyStarts map[string]time.Time + store map[string][]byte +} + +// NewMemStore ... constructor +func NewMemStore(ctx context.Context, cfg *MemStoreConfig) (*MemStore, error) { + store := &MemStore{ + cfg: cfg, + keyStarts: make(map[string]time.Time), + store: make(map[string][]byte), + } + + if cfg.BlobExpiration != 0 { + go store.EventLoop(ctx) + } + + return store, nil +} + +func (e *MemStore) EventLoop(ctx context.Context) { + + timer := time.NewTicker(DefaultPruneInterval) + + select { + case <-ctx.Done(): + return + + case <-timer.C: + e.pruneExpired() + } + +} + +func (e *MemStore) pruneExpired() { + e.Lock() + defer e.Unlock() + + for commit, dur := range e.keyStarts { + if time.Since(dur) >= e.cfg.BlobExpiration { + delete(e.keyStarts, commit) + delete(e.store, commit) + } + } + +} + +// Get fetches a value from the store. +func (e *MemStore) Get(ctx context.Context, commit []byte) ([]byte, error) { + e.RLock() + defer e.RUnlock() + + key := common.Bytes2Hex(commit) + if _, exists := e.store[key]; !exists { + return nil, fmt.Errorf("commitment key not found") + } + + return e.store[key], nil +} + +// Put inserts a value into the store. +func (e *MemStore) Put(ctx context.Context, value []byte) ([]byte, error) { + e.Lock() + defer e.Unlock() + + fingerprint := crypto.Keccak256Hash(value) + // add some entropy to commit to emulate randomness seen in EigenDA + // when generating operator BLS signature certificates + entropy := make([]byte, 10) + _, err := rand.Read(entropy) + if err != nil { + return nil, err + } + + rawCommit := append(fingerprint.Bytes(), entropy...) + commit := common.Bytes2Hex(rawCommit) + + if _, exists := e.store[commit]; exists { + return nil, fmt.Errorf("commitment key already exists") + } + + e.store[commit] = value + // add expiration + e.keyStarts[commit] = time.Now() + + return rawCommit, nil +} + +func ReadConfig(ctx *cli.Context) MemStoreConfig { + cfg := MemStoreConfig{ + /* Required Flags */ + Enabled: ctx.Bool(MemStoreFlagName), + BlobExpiration: ctx.Duration(ExpirationFlagName), + } + return cfg +} + +func CLIFlags(envPrefix string) []cli.Flag { + + return []cli.Flag{ + &cli.BoolFlag{ + Name: MemStoreFlagName, + Usage: "Whether to use mem-store for DA logic.", + EnvVars: []string{"MEMSTORE_ENABLED"}, + }, + &cli.DurationFlag{ + Name: ExpirationFlagName, + Usage: "Duration that a blob/commitment pair are allowed to live.", + Value: 25 * time.Minute, + EnvVars: []string{"MEMSTORE_EXPIRATION"}, + }, + } +} diff --git a/store/memory_test.go b/store/memory_test.go new file mode 100644 index 00000000..65b7c6f2 --- /dev/null +++ b/store/memory_test.go @@ -0,0 +1,63 @@ +package store + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +const ( + testPreimage = "Four score and seven years ago" +) + +func TestGetSet(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + ms, err := NewMemStore( + ctx, + &MemStoreConfig{ + Enabled: true, + BlobExpiration: time.Hour * 1000, + }, + ) + + assert.NoError(t, err) + + expected := []byte(testPreimage) + key, err := ms.Put(ctx, expected) + assert.NoError(t, err) + + actual, err := ms.Get(ctx, key) + assert.NoError(t, err) + + assert.Equal(t, actual, expected) +} + +func TestExpiration(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + ms, err := NewMemStore( + ctx, + &MemStoreConfig{ + Enabled: true, + BlobExpiration: time.Millisecond * 10, + }, + ) + + assert.NoError(t, err) + + preimage := []byte(testPreimage) + key, err := ms.Put(ctx, preimage) + assert.NoError(t, err) + + // sleep 1ms and verify that older entries are removed + time.Sleep(time.Second * 1) + + _, err = ms.Get(ctx, key) + assert.Error(t, err) + +} diff --git a/test/e2e_test.go b/test/e2e_test.go index 354b86c5..70460c42 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -10,6 +10,7 @@ import ( "github.com/Layr-Labs/eigenda/encoding/kzg" plasma "github.com/Layr-Labs/op-plasma-eigenda" + proxy "github.com/Layr-Labs/op-plasma-eigenda" "github.com/Layr-Labs/op-plasma-eigenda/eigenda" "github.com/Layr-Labs/op-plasma-eigenda/metrics" "github.com/Layr-Labs/op-plasma-eigenda/store" @@ -24,9 +25,9 @@ import ( // Use of single port makes tests incapable of running in parallel const ( transport = "http" - serviceName = "plasma_test_server" - testSvrHost = "127.0.0.1" - testSvrPort = 6969 + serviceName = "eigenda_proxy" + host = "127.0.0.1" + port = 6969 holeskyDA = "disperser-holesky.eigenda.xyz:443" ) @@ -54,6 +55,7 @@ func createTestSuite(t *testing.T) (TestSuite, func()) { UseTLS: true, } + // these values can be generated locally by running `make srs` kzgCfg := &kzg.KzgConfig{ G1Path: "../operator-setup/resources/g1.point", G2PowerOf2Path: "../operator-setup/resources/g2.point.powerOf2", @@ -75,10 +77,10 @@ func createTestSuite(t *testing.T) (TestSuite, func()) { panic(err) } - server := plasma.NewDAServer(testSvrHost, testSvrPort, daStore, log, metrics.NoopMetrics) + server := proxy.NewServer(host, port, daStore, log, metrics.NoopMetrics) go func() { - t.Log("Starting test plasma server on separate routine...") + t.Log("Starting proxy server on separate routine...") if err := server.Start(); err != nil { panic(err) } @@ -101,21 +103,21 @@ func TestE2EPutGetLogicForEigenDAStore(t *testing.T) { ts, kill := createTestSuite(t) defer kill() - daClient := op_plasma.NewDAClient(fmt.Sprintf("%s://%s:%d", transport, testSvrHost, testSvrPort), false, false) + daClient := op_plasma.NewDAClient(fmt.Sprintf("%s://%s:%d", transport, host, port), false, false) t.Log("Waiting for client to establish connection with plasma server...") // wait for server to come online after starting time.Sleep(5 * time.Second) - // 1 - write arbitrary data to test plasma server + // 1 - write arbitrary data to EigenDA var testPreimage = []byte("inter-subjective and not objective!") - t.Log("Setting input data on plasma server...") + t.Log("Setting input data on proxy server...") commit, err := daClient.SetInput(ts.ctx, testPreimage) assert.NoError(t, err) - // 2 - fetch pre-image data from test plasma server - t.Log("Getting input data from plasma server...") + // 2 - fetch data from EigenDA for generated commitment key + t.Log("Getting input data from proxy server...") preimage, err := daClient.GetInput(ts.ctx, commit) assert.NoError(t, err) assert.Equal(t, testPreimage, preimage)