Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
InoMurko authored and epociask committed Aug 12, 2024
1 parent c833c70 commit 2ffeb0a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ In order to disperse to the EigenDA network in production, or at high throughput
| `--s3.bucket` | | `$EIGENDA_PROXY_S3_BUCKET` | Bucket name for S3 storage. |
| `--s3.path` | | `$EIGENDA_PROXY_S3_PATH` | Bucket path for S3 storage. |
| `--s3.endpoint` | | `$EIGENDA_PROXY_S3_ENDPOINT` | Endpoint for S3 storage. |
| `--s3.backup` | | `$EIGENDA_PROXY_S3_BACKUP` | Enable parallel blob backup to s3 from EigenDA. |
| `--s3.backup` | | `$EIGENDA_PROXY_S3_BACKUP` | Enable parallel blob backup to S3 from EigenDA. |
| `--s3.timeout` | | `$EIGENDA_PROXY_S3_TIMEOUT` | Timeout duration for S3 operations. |
| `--help, -h` | `false` | | Show help. |
| `--version, -v` | `false` | | Print the version. |

Expand Down
16 changes: 15 additions & 1 deletion server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
S3AccessKeyIDFlagName = "s3.access-key-id" // #nosec G101
S3AccessKeySecretFlagName = "s3.access-key-secret" // #nosec G101
S3BackupFlagName = "s3.backup"
S3TimeoutFlagName = "s3.timeout"
)

const BytesPerSymbol = 31
Expand Down Expand Up @@ -141,6 +142,7 @@ func ReadConfig(ctx *cli.Context) Config {
AccessKeyID: ctx.String(S3AccessKeyIDFlagName),
AccessKeySecret: ctx.String(S3AccessKeySecretFlagName),
Backup: ctx.Bool(S3BackupFlagName),
Timeout: ctx.Duration(S3TimeoutFlagName),
},
ClientConfig: clients.EigenDAClientConfig{
RPC: ctx.String(EigenDADisperserRPCFlagName),
Expand Down Expand Up @@ -201,7 +203,7 @@ func (cfg *Config) Check() error {
if cfg.EthConfirmationDepth >= 0 && (cfg.SvcManagerAddr == "" || cfg.EthRPC == "") {
return fmt.Errorf("eth confirmation depth is set for certificate verification, but Eth RPC or SvcManagerAddr is not set")
}

if cfg.S3Config.S3CredentialType == store.S3CredentialUnknown {
return fmt.Errorf("s3 credential type must be set")
}
Expand Down Expand Up @@ -358,5 +360,17 @@ func CLIFlags(envPrefix string) []cli.Flag {
Value: "",
EnvVars: prefixEnvVars("S3_ACCESS_KEY_SECRET"),
},
&cli.BoolFlag{
Name: S3BackupFlagName,
Usage: "Backup to S3 in parallel with Eigenda.",
Value: false,
EnvVars: prefixEnvVars("S3_BACKUP"),
},
&cli.StringFlag{
Name: S3TimeoutFlagName,
Usage: "S3 timeout",
Value: "60s",
EnvVars: prefixEnvVars("S3_TIMEOUT"),
},
}
}
6 changes: 5 additions & 1 deletion server/load_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package server

import (
"context"

"fmt"

"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/Layr-Labs/eigenda/api/clients"
Expand All @@ -19,6 +20,9 @@ func LoadStoreRouter(cfg CLIConfig, ctx context.Context, log log.Logger) (*store
return nil, err
}
}
if s3 == nil && cfg.S3Config.Backup {
return nil, fmt.Errorf("S3 backup enabled but no valid S3 config present")
}

daCfg := cfg.EigenDAConfig
vCfg := daCfg.VerificationCfg()
Expand Down
14 changes: 8 additions & 6 deletions store/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/Layr-Labs/eigenda-proxy/commitments"
"github.com/Layr-Labs/eigenda-proxy/utils"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -56,7 +56,7 @@ func (r *Router) Get(ctx context.Context, key []byte, cm commitments.CommitmentM
}
if r.s3 != nil && r.s3.cfg.Backup {
r.log.Info("Retrieving data from S3", "key", crypto.Keccak256(key))
ctx2, cancel := context.WithTimeout(ctx, time.Minute)
ctx2, cancel := context.WithTimeout(ctx, r.s3.cfg.Timeout)
defer cancel()
value, err := r.s3.Get(ctx2, crypto.Keccak256(key))
if err != nil {
Expand Down Expand Up @@ -104,10 +104,12 @@ func (r *Router) PutWithoutKey(ctx context.Context, value []byte) (key []byte, e
result, err := r.eigenda.Put(ctx, value)
if err == nil {
if r.s3 != nil && r.s3.cfg.Backup {
r.log.Info("Storing data to S3 backend with key", "key", crypto.Keccak256(result))
ctx2, cancel := context.WithTimeout(ctx, time.Minute)
err = r.s3.Put(ctx2, crypto.Keccak256(result), value)
cancel()
//we make a keccak of the commitment so that we get 32bytes (valid s3 key)
key := crypto.Keccak256(result)
r.log.Info("Storing data to S3 backend with key", "key", key)
ctx2, cancel := context.WithTimeout(ctx, r.s3.cfg.Timeout)
defer cancel()
err = r.s3.Put(ctx2, key, value)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion store/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"io"
"path"

"time"
"github.com/minio/minio-go/v7"

"github.com/minio/minio-go/v7/pkg/credentials"
Expand All @@ -29,6 +29,7 @@ type S3Config struct {
AccessKeySecret string
Profiling bool
Backup bool
Timeout time.Duration
}

type S3Store struct {
Expand Down

0 comments on commit 2ffeb0a

Please sign in to comment.