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: mem store #15

Merged
merged 8 commits into from
May 23, 2024
Merged
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
30 changes: 15 additions & 15 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
go-version: 1.21

- name: Build App
run: make da-server
run: make eigenda-proxy

go-test:
outputs:
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
CMD ["./eigenda-proxy"]
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)"
Expand All @@ -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.*"
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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)


60 changes: 38 additions & 22 deletions cmd/daserver/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions cmd/daserver/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -48,23 +49,24 @@ 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...)
}

// Flags contains the list of configuration options available to the binary.
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),
}
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/daserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions eigenda/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
}
}
6 changes: 3 additions & 3 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
Namespace = "plasma_eigenda"
Namespace = "eigenda_proxy"
)

// Config ... Metrics server configuration
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
Loading
Loading