Skip to content

Commit

Permalink
feat: read-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Sep 16, 2024
1 parent f028a92 commit ae7a0da
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .env.example.holesky
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion .env.example.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ EIGENDA_PROXY_SERVICE_MANAGER_ADDR=0x870679E138bCdf293b7Ff14dD44b70FC97e12fc0
# EIGENDA_PROXY_S3_BUCKET=

# endpoint for S3 storage
# EIGENDA_PROXY_S3_ENDPOINT
# EIGENDA_PROXY_S3_ENDPOINT

# set to true to disable writing to EigenDA
# EIGENDA_PROXY_READ_ONLY=false
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) .
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()...)
Expand Down
2 changes: 1 addition & 1 deletion server/load_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 10 additions & 4 deletions store/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ae7a0da

Please sign in to comment.