From ae7a0da530ec89a8432f3d3d6d65af95da46ee02 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 13 Sep 2024 23:34:51 -0500 Subject: [PATCH] feat: read-only mode --- .env.example.holesky | 3 +++ .env.example.mainnet | 5 ++++- Makefile | 6 ++++++ cmd/server/entrypoint.go | 2 +- server/config.go | 9 +++++++++ server/load_store.go | 2 +- store/router.go | 14 ++++++++++---- 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.env.example.holesky b/.env.example.holesky index eaadd434..b1c19936 100644 --- a/.env.example.holesky +++ b/.env.example.holesky @@ -87,3 +87,6 @@ EIGENDA_PROXY_SERVICE_MANAGER_ADDR=0xD4A7E1Bd8015057293f0D0A557088c286942e84b # endpoint for S3 storage # EIGENDA_PROXY_S3_ENDPOINT + +# set to true to disable writing to EigenDA +# EIGENDA_PROXY_READ_ONLY=false diff --git a/.env.example.mainnet b/.env.example.mainnet index 5ccc746e..221fe209 100644 --- a/.env.example.mainnet +++ b/.env.example.mainnet @@ -85,4 +85,7 @@ EIGENDA_PROXY_SERVICE_MANAGER_ADDR=0x870679E138bCdf293b7Ff14dD44b70FC97e12fc0 # EIGENDA_PROXY_S3_BUCKET= # endpoint for S3 storage -# EIGENDA_PROXY_S3_ENDPOINT \ No newline at end of file +# EIGENDA_PROXY_S3_ENDPOINT + +# set to true to disable writing to EigenDA +# EIGENDA_PROXY_READ_ONLY=false diff --git a/Makefile b/Makefile index 8dbd5b07..cafb47c1 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,12 @@ HOLESKYTEST = TESTNET=true go test -timeout 50m -v ./e2e -parallel 4 -deploy-co eigenda-proxy: env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/eigenda-proxy ./cmd/server +.PHONY: eigenda-proxy-codesign +proxy-build-sign-run: + env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/eigenda-proxy ./cmd/server + codesign --sign - --force --preserve-metadata=entitlements,requirements,flags,runtime ./bin/eigenda-proxy + ENV_PATH=.env ./bin/eigenda-proxy --addr 127.0.0.1 --port 3100 + .PHONY: docker-build docker-build: @docker build -t $(IMAGE_NAME) . diff --git a/cmd/server/entrypoint.go b/cmd/server/entrypoint.go index 77cad471..254740d1 100644 --- a/cmd/server/entrypoint.go +++ b/cmd/server/entrypoint.go @@ -34,7 +34,7 @@ func StartProxySvr(cliCtx *cli.Context) error { server := server.NewServer(cliCtx.String(server.ListenAddrFlagName), cliCtx.Int(server.PortFlagName), daRouter, log, m) if err := server.Start(); err != nil { - return fmt.Errorf("failed to start the DA server") + return fmt.Errorf("failed to start the DA server: %w", err) } log.Info("Started EigenDA proxy server") diff --git a/server/config.go b/server/config.go index 43fa48b3..cc72e398 100644 --- a/server/config.go +++ b/server/config.go @@ -30,6 +30,7 @@ const ( SignerPrivateKeyHexFlagName = "eigenda-signer-private-key-hex" PutBlobEncodingVersionFlagName = "eigenda-put-blob-encoding-version" DisablePointVerificationModeFlagName = "eigenda-disable-point-verification-mode" + ReadOnlyFlagName = "read-only" // kzg flags G1PathFlagName = "eigenda-g1-path" @@ -77,6 +78,7 @@ var ( type Config struct { // eigenda ClientConfig clients.EigenDAClientConfig + ReadOnly bool // the blob encoding version to use when writing blobs from the high level interface. PutBlobEncodingVersion codecs.BlobEncodingVersion @@ -213,6 +215,7 @@ func ReadConfig(ctx *cli.Context) Config { MemstorePutLatency: ctx.Duration(MemstorePutLatencyFlagName), FallbackTargets: ctx.StringSlice(FallbackTargets), CacheTargets: ctx.StringSlice(CacheTargets), + ReadOnly: ctx.Bool(ReadOnlyFlagName), } cfg.ClientConfig.WaitForFinalization = (cfg.EthConfirmationDepth < 0) @@ -507,6 +510,12 @@ func CLIFlags() []cli.Flag { Value: cli.NewStringSlice(), EnvVars: prefixEnvVars("CACHE_TARGETS"), }, + &cli.BoolFlag{ + Name: ReadOnlyFlagName, + Usage: "Whether the proxy should operate in read-only mode.", + Value: false, + EnvVars: prefixEnvVars("READ_ONLY"), + }, } flags = append(flags, s3Flags()...) diff --git a/server/load_store.go b/server/load_store.go index e73f09db..fd6eb5b5 100644 --- a/server/load_store.go +++ b/server/load_store.go @@ -121,5 +121,5 @@ func LoadStoreRouter(ctx context.Context, cfg CLIConfig, log log.Logger) (store. caches := populateTargets(cfg.EigenDAConfig.CacheTargets, s3, redis) log.Info("Creating storage router", "eigenda backend type", eigenda != nil, "s3 backend type", s3 != nil) - return store.NewRouter(eigenda, s3, log, caches, fallbacks) + return store.NewRouter(eigenda, s3, log, caches, fallbacks, cfg.EigenDAConfig.ReadOnly) } diff --git a/store/router.go b/store/router.go index ad2805cc..428ee706 100644 --- a/store/router.go +++ b/store/router.go @@ -25,9 +25,10 @@ type IRouter interface { // Router ... storage backend routing layer type Router struct { - log log.Logger - eigenda KeyGeneratedStore - s3 PrecomputedKeyStore + log log.Logger + eigenda KeyGeneratedStore + s3 PrecomputedKeyStore + readonly bool caches []PrecomputedKeyStore cacheLock sync.RWMutex @@ -37,11 +38,12 @@ type Router struct { } func NewRouter(eigenda KeyGeneratedStore, s3 PrecomputedKeyStore, l log.Logger, - caches []PrecomputedKeyStore, fallbacks []PrecomputedKeyStore) (IRouter, error) { + caches []PrecomputedKeyStore, fallbacks []PrecomputedKeyStore, readonly bool) (IRouter, error) { return &Router{ log: l, eigenda: eigenda, s3: s3, + readonly: readonly, caches: caches, cacheLock: sync.RWMutex{}, fallbacks: fallbacks, @@ -117,6 +119,10 @@ func (r *Router) Get(ctx context.Context, key []byte, cm commitments.CommitmentM // Put ... inserts a value into a storage backend based on the commitment mode func (r *Router) Put(ctx context.Context, cm commitments.CommitmentMode, key, value []byte) ([]byte, error) { + if r.readonly { + return nil, errors.New("read-only router does not support Put") + } + var commit []byte var err error