Skip to content

Commit

Permalink
refactor: move eigenda_client flags to their own (temporary) package
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Sep 22, 2024
1 parent 86aecb6 commit fee342c
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 88 deletions.
4 changes: 2 additions & 2 deletions e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestSuiteConfig(t *testing.T, testCfg *Cfg) server.CLIConfig {
}

eigendaCfg := server.Config{
ClientConfig: clients.EigenDAClientConfig{
EdaClientConfig: clients.EigenDAClientConfig{
RPC: holeskyDA,
StatusQueryTimeout: time.Minute * 45,
StatusQueryRetryInterval: pollInterval,
Expand All @@ -127,7 +127,7 @@ func TestSuiteConfig(t *testing.T, testCfg *Cfg) server.CLIConfig {
}

if testCfg.UseMemory {
eigendaCfg.ClientConfig.SignerPrivateKeyHex = "0000000000000000000100000000000000000000000000000000000000000000"
eigendaCfg.EdaClientConfig.SignerPrivateKeyHex = "0000000000000000000100000000000000000000000000000000000000000000"
}

var cfg server.CLIConfig
Expand Down
112 changes: 112 additions & 0 deletions flags/eigenda_flags/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package eigenda_flags

Check failure on line 1 in flags/eigenda_flags/cli.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use an underscore in package name (revive)

import (
"time"

"github.com/Layr-Labs/eigenda/api/clients"
"github.com/Layr-Labs/eigenda/api/clients/codecs"
"github.com/urfave/cli/v2"
)

// TODO: we should eventually move all of these flags into the eigenda repo

var (
DisperserRPCFlagName = withFlagPrefix("disperser-rpc")
StatusQueryRetryIntervalFlagName = withFlagPrefix("status-query-retry-interval")
StatusQueryTimeoutFlagName = withFlagPrefix("status-query-timeout")
DisableTLSFlagName = withFlagPrefix("disable-tls")
ResponseTimeoutFlagName = withFlagPrefix("response-timeout")
CustomQuorumIDsFlagName = withFlagPrefix("custom-quorum-ids")
SignerPrivateKeyHexFlagName = withFlagPrefix("signer-private-key-hex")
PutBlobEncodingVersionFlagName = withFlagPrefix("put-blob-encoding-version")
DisablePointVerificationModeFlagName = withFlagPrefix("disable-point-verification-mode")
)

func withFlagPrefix(s string) string {
return "eigenda." + s
}

func withEnvPrefix(envPrefix, s string) []string {
return []string{envPrefix + "_EIGENDA_" + s}
}

// CLIFlags ... used for EigenDA client configuration
func CLIFlags(envPrefix, category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: DisperserRPCFlagName,
Usage: "RPC endpoint of the EigenDA disperser.",
EnvVars: withEnvPrefix(envPrefix, "DISPERSER_RPC"),
Category: category,
},
&cli.DurationFlag{
Name: StatusQueryTimeoutFlagName,
Usage: "Duration to wait for a blob to finalize after being sent for dispersal. Default is 30 minutes.",
Value: 30 * time.Minute,
EnvVars: withEnvPrefix(envPrefix, "STATUS_QUERY_TIMEOUT"),
Category: category,
},
&cli.DurationFlag{
Name: StatusQueryRetryIntervalFlagName,
Usage: "Interval between retries when awaiting network blob finalization. Default is 5 seconds.",
Value: 5 * time.Second,
EnvVars: withEnvPrefix(envPrefix, "STATUS_QUERY_INTERVAL"),
Category: category,
},
&cli.BoolFlag{
Name: DisableTLSFlagName,
Usage: "Disable TLS for gRPC communication with the EigenDA disperser. Default is false.",
Value: false,
EnvVars: withEnvPrefix(envPrefix, "GRPC_DISABLE_TLS"),
Category: category,
},
&cli.DurationFlag{
Name: ResponseTimeoutFlagName,
Usage: "Total time to wait for a response from the EigenDA disperser. Default is 60 seconds.",
Value: 60 * time.Second,
EnvVars: withEnvPrefix(envPrefix, "RESPONSE_TIMEOUT"),
Category: category,
},
&cli.UintSliceFlag{
Name: CustomQuorumIDsFlagName,
Usage: "Custom quorum IDs for writing blobs. Should not include default quorums 0 or 1.",
Value: cli.NewUintSlice(),
EnvVars: withEnvPrefix(envPrefix, "CUSTOM_QUORUM_IDS"),
Category: category,
},
&cli.StringFlag{
Name: SignerPrivateKeyHexFlagName,
Usage: "Hex-encoded signer private key. This key should not be associated with an Ethereum address holding any funds.",
EnvVars: withEnvPrefix(envPrefix, "SIGNER_PRIVATE_KEY_HEX"),
Category: category,
},
&cli.UintFlag{
Name: PutBlobEncodingVersionFlagName,
Usage: "Blob encoding version to use when writing blobs from the high-level interface.",
EnvVars: withEnvPrefix(envPrefix, "PUT_BLOB_ENCODING_VERSION"),
Value: 0,
Category: category,
},
&cli.BoolFlag{
Name: DisablePointVerificationModeFlagName,
Usage: "Disable point verification mode. This mode performs IFFT on data before writing and FFT on data after reading. Disabling requires supplying the entire blob for verification against the KZG commitment.",
EnvVars: withEnvPrefix(envPrefix, "DISABLE_POINT_VERIFICATION_MODE"),
Value: false,
Category: category,
},
}
}

func ReadConfig(ctx *cli.Context) clients.EigenDAClientConfig {
return clients.EigenDAClientConfig{
RPC: ctx.String(DisperserRPCFlagName),
StatusQueryRetryInterval: ctx.Duration(StatusQueryRetryIntervalFlagName),
StatusQueryTimeout: ctx.Duration(StatusQueryTimeoutFlagName),
DisableTLS: ctx.Bool(DisableTLSFlagName),
ResponseTimeout: ctx.Duration(ResponseTimeoutFlagName),
CustomQuorumIDs: ctx.UintSlice(CustomQuorumIDsFlagName),
SignerPrivateKeyHex: ctx.String(SignerPrivateKeyHexFlagName),
PutBlobEncodingVersion: codecs.BlobEncodingVersion(ctx.Uint(PutBlobEncodingVersionFlagName)),
DisablePointVerificationMode: ctx.Bool(DisablePointVerificationModeFlagName),
}
}
72 changes: 6 additions & 66 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flags
import (
"time"

"github.com/Layr-Labs/eigenda-proxy/flags/eigenda_flags"
"github.com/Layr-Labs/eigenda-proxy/store/precomputed_key/redis"
"github.com/Layr-Labs/eigenda-proxy/store/precomputed_key/s3"
"github.com/urfave/cli/v2"
Expand All @@ -13,26 +14,16 @@ import (
)

const (
MemstoreFlagsCategory = "Memstore"
RedisCategory = "Redis"
S3Category = "S3"
EigenDAClientCategory = "EigenDA Client"
MemstoreFlagsCategory = "Memstore (replaces EigenDA when enabled)"
RedisCategory = "Redis Cache/Fallback"
S3Category = "S3 Cache/Fallback"
)

const (
ListenAddrFlagName = "addr"
PortFlagName = "port"

// eigenda client flags
EigenDADisperserRPCFlagName = "eigenda-disperser-rpc"
StatusQueryRetryIntervalFlagName = "eigenda-status-query-retry-interval"
StatusQueryTimeoutFlagName = "eigenda-status-query-timeout"
DisableTLSFlagName = "eigenda-disable-tls"
ResponseTimeoutFlagName = "eigenda-response-timeout"
CustomQuorumIDsFlagName = "eigenda-custom-quorum-ids"
SignerPrivateKeyHexFlagName = "eigenda-signer-private-key-hex"
PutBlobEncodingVersionFlagName = "eigenda-put-blob-encoding-version"
DisablePointVerificationModeFlagName = "eigenda-disable-point-verification-mode"

// cert verification flags
// TODO: should we remove the eigenda prefix since these are not eigenda-client flags?
CertVerificationEnabledFlagName = "eigenda-cert-verification-enabled"
Expand Down Expand Up @@ -78,58 +69,6 @@ func CLIFlags() []cli.Flag {
Value: 3100,
EnvVars: prefixEnvVars("PORT"),
},
&cli.StringFlag{
Name: EigenDADisperserRPCFlagName,
Usage: "RPC endpoint of the EigenDA disperser.",
EnvVars: prefixEnvVars("EIGENDA_DISPERSER_RPC"),
},
&cli.DurationFlag{
Name: StatusQueryTimeoutFlagName,
Usage: "Duration to wait for a blob to finalize after being sent for dispersal. Default is 30 minutes.",
Value: 30 * time.Minute,
EnvVars: prefixEnvVars("STATUS_QUERY_TIMEOUT"),
},
&cli.DurationFlag{
Name: StatusQueryRetryIntervalFlagName,
Usage: "Interval between retries when awaiting network blob finalization. Default is 5 seconds.",
Value: 5 * time.Second,
EnvVars: prefixEnvVars("STATUS_QUERY_INTERVAL"),
},
&cli.BoolFlag{
Name: DisableTLSFlagName,
Usage: "Disable TLS for gRPC communication with the EigenDA disperser. Default is false.",
Value: false,
EnvVars: prefixEnvVars("GRPC_DISABLE_TLS"),
},
&cli.DurationFlag{
Name: ResponseTimeoutFlagName,
Usage: "Total time to wait for a response from the EigenDA disperser. Default is 60 seconds.",
Value: 60 * time.Second,
EnvVars: prefixEnvVars("RESPONSE_TIMEOUT"),
},
&cli.UintSliceFlag{
Name: CustomQuorumIDsFlagName,
Usage: "Custom quorum IDs for writing blobs. Should not include default quorums 0 or 1.",
Value: cli.NewUintSlice(),
EnvVars: prefixEnvVars("CUSTOM_QUORUM_IDS"),
},
&cli.StringFlag{
Name: SignerPrivateKeyHexFlagName,
Usage: "Hex-encoded signer private key. This key should not be associated with an Ethereum address holding any funds.",
EnvVars: prefixEnvVars("SIGNER_PRIVATE_KEY_HEX"),
},
&cli.UintFlag{
Name: PutBlobEncodingVersionFlagName,
Usage: "Blob encoding version to use when writing blobs from the high-level interface.",
EnvVars: prefixEnvVars("PUT_BLOB_ENCODING_VERSION"),
Value: 0,
},
&cli.BoolFlag{
Name: DisablePointVerificationModeFlagName,
Usage: "Disable point verification mode. This mode performs IFFT on data before writing and FFT on data after reading. Disabling requires supplying the entire blob for verification against the KZG commitment.",
EnvVars: prefixEnvVars("DISABLE_POINT_VERIFICATION_MODE"),
Value: false,
},
&cli.StringFlag{
Name: MaxBlobLengthFlagName,
Usage: "Maximum blob length to be written or read from EigenDA. Determines the number of SRS points loaded into memory for KZG commitments. Example units: '30MiB', '4Kb', '30MB'. Maximum size slightly exceeds 1GB.",
Expand Down Expand Up @@ -228,6 +167,7 @@ func init() {
Flags = CLIFlags()
Flags = append(Flags, oplog.CLIFlags(EnvVarPrefix)...)
Flags = append(Flags, opmetrics.CLIFlags(EnvVarPrefix)...)
Flags = append(Flags, eigenda_flags.CLIFlags(EnvVarPrefix, EigenDAClientCategory)...)
Flags = append(Flags, redis.CLIFlags(EnvVarPrefix, RedisCategory)...)
Flags = append(Flags, s3.CLIFlags(EnvVarPrefix, S3Category)...)
}
23 changes: 7 additions & 16 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/urfave/cli/v2"

"github.com/Layr-Labs/eigenda-proxy/flags"
"github.com/Layr-Labs/eigenda-proxy/flags/eigenda_flags"
"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/store/precomputed_key/redis"
"github.com/Layr-Labs/eigenda-proxy/store/precomputed_key/s3"
Expand All @@ -32,7 +33,7 @@ var (

type Config struct {
// eigenda
ClientConfig clients.EigenDAClientConfig
EdaClientConfig clients.EigenDAClientConfig

// the blob encoding version to use when writing blobs from the high level interface.
PutBlobEncodingVersion codecs.BlobEncodingVersion
Expand Down Expand Up @@ -116,19 +117,9 @@ func (cfg *Config) VerificationCfg() *verify.Config {
// ReadConfig ... parses the Config from the provided flags or environment variables.
func ReadConfig(ctx *cli.Context) Config {
cfg := Config{
RedisConfig: redis.ReadConfig(ctx),
S3Config: s3.ReadConfig(ctx),
ClientConfig: clients.EigenDAClientConfig{
RPC: ctx.String(flags.EigenDADisperserRPCFlagName),
StatusQueryRetryInterval: ctx.Duration(flags.StatusQueryRetryIntervalFlagName),
StatusQueryTimeout: ctx.Duration(flags.StatusQueryTimeoutFlagName),
DisableTLS: ctx.Bool(flags.DisableTLSFlagName),
ResponseTimeout: ctx.Duration(flags.ResponseTimeoutFlagName),
CustomQuorumIDs: ctx.UintSlice(flags.CustomQuorumIDsFlagName),
SignerPrivateKeyHex: ctx.String(flags.SignerPrivateKeyHexFlagName),
PutBlobEncodingVersion: codecs.BlobEncodingVersion(ctx.Uint(flags.PutBlobEncodingVersionFlagName)),
DisablePointVerificationMode: ctx.Bool(flags.DisablePointVerificationModeFlagName),
},
RedisConfig: redis.ReadConfig(ctx),
S3Config: s3.ReadConfig(ctx),
EdaClientConfig: eigenda_flags.ReadConfig(ctx),
G1Path: ctx.String(flags.G1PathFlagName),
G2PowerOfTauPath: ctx.String(flags.G2TauFlagName),
CacheDir: ctx.String(flags.CachePathFlagName),
Expand All @@ -150,7 +141,7 @@ func ReadConfig(ctx *cli.Context) Config {
// for the da-proxy to 0 (because negative confirmation depth doesn't mean anything and leads to errors)
// TODO: should the eigenda-client implement this feature for us instead?
if cfg.EthConfirmationDepth < 0 {
cfg.ClientConfig.WaitForFinalization = true
cfg.EdaClientConfig.WaitForFinalization = true
cfg.EthConfirmationDepth = 0
}

Expand Down Expand Up @@ -188,7 +179,7 @@ func (cfg *Config) Check() error {
}

if !cfg.MemstoreEnabled {
if cfg.ClientConfig.RPC == "" {
if cfg.EdaClientConfig.RPC == "" {
return fmt.Errorf("using eigenda backend (memstore.enabled=false) but eigenda disperser rpc url is not set")
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func validCfg() *Config {
AccessKeyID: "access-key-id",
AccessKeySecret: "access-key-secret",
},
ClientConfig: clients.EigenDAClientConfig{
EdaClientConfig: clients.EigenDAClientConfig{
RPC: "http://localhost:8545",
StatusQueryRetryInterval: 5 * time.Second,
StatusQueryTimeout: 30 * time.Minute,
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestConfigVerification(t *testing.T) {

t.Run("MissingEigenDADisperserRPC", func(t *testing.T) {
cfg := validCfg()
cfg.ClientConfig.RPC = ""
cfg.EdaClientConfig.RPC = ""
cfg.MemstoreEnabled = false

err := cfg.Check()
Expand Down
4 changes: 2 additions & 2 deletions server/load_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func LoadStoreRouter(ctx context.Context, cfg CLIConfig, log log.Logger) (store.
} else {
var client *clients.EigenDAClient
log.Info("Using EigenDA backend")
client, err = clients.NewEigenDAClient(log.With("subsystem", "eigenda-client"), daCfg.ClientConfig)
client, err = clients.NewEigenDAClient(log.With("subsystem", "eigenda-client"), daCfg.EdaClientConfig)
if err != nil {
return nil, err
}
Expand All @@ -113,7 +113,7 @@ func LoadStoreRouter(ctx context.Context, cfg CLIConfig, log log.Logger) (store.
&eigenda.StoreConfig{
MaxBlobSizeBytes: maxBlobLength,
EthConfirmationDepth: uint64(cfg.EigenDAConfig.EthConfirmationDepth), // #nosec G115
StatusQueryTimeout: cfg.EigenDAConfig.ClientConfig.StatusQueryTimeout,
StatusQueryTimeout: cfg.EigenDAConfig.EdaClientConfig.StatusQueryTimeout,
},
)
}
Expand Down

0 comments on commit fee342c

Please sign in to comment.