Skip to content

Commit

Permalink
Fix Blob Storage Path (#13222)
Browse files Browse the repository at this point in the history
* fix the path

* gaz
  • Loading branch information
nisdas authored Nov 25, 2023
1 parent 098d6a3 commit 0498e0a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
13 changes: 12 additions & 1 deletion cmd/beacon-chain/storage/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@prysm//tools/go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
Expand All @@ -12,3 +12,14 @@ go_library(
"@com_github_urfave_cli_v2//:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["options_test.go"],
embed = [":go_default_library"],
deps = [
"//cmd:go_default_library",
"//testing/assert:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)
16 changes: 10 additions & 6 deletions cmd/beacon-chain/storage/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ var (
// create a cancellable context. If we switch to using App.RunContext, we can set up this cancellation in the cmd
// package instead, and allow the functional options to tap into context cancellation.
func BeaconNodeOptions(c *cli.Context) (node.Option, error) {
blobsPath := c.Path(BlobStoragePath.Name)
if blobsPath == "" {
// append a "blobs" subdir to the end of the data dir path
blobsPath = path.Join(path.Clean(c.String(c.Path(cmd.DataDirFlag.Name))), "blobs")
}

blobsPath := blobStoragePath(c)
bs, err := filesystem.NewBlobStorage(blobsPath)
if err != nil {
return nil, err
}
return node.WithBlobStorage(bs), nil
}

func blobStoragePath(c *cli.Context) string {
blobsPath := c.Path(BlobStoragePath.Name)
if blobsPath == "" {
// append a "blobs" subdir to the end of the data dir path
blobsPath = path.Join(c.String(cmd.DataDirFlag.Name), "blobs")
}
return blobsPath
}
30 changes: 30 additions & 0 deletions cmd/beacon-chain/storage/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package storage

import (
"flag"
"testing"

"github.com/prysmaticlabs/prysm/v4/cmd"
"github.com/prysmaticlabs/prysm/v4/testing/assert"
"github.com/urfave/cli/v2"
)

func TestBlobStoragePath_NoFlagSpecified(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(cmd.DataDirFlag.Name, cmd.DataDirFlag.Value, cmd.DataDirFlag.Usage)
cliCtx := cli.NewContext(&app, set, nil)
storagePath := blobStoragePath(cliCtx)

assert.Equal(t, cmd.DefaultDataDir()+"/blobs", storagePath)
}

func TestBlobStoragePath_FlagSpecified(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(BlobStoragePath.Name, "/blah/blah", BlobStoragePath.Usage)
cliCtx := cli.NewContext(&app, set, nil)
storagePath := blobStoragePath(cliCtx)

assert.Equal(t, "/blah/blah", storagePath)
}

0 comments on commit 0498e0a

Please sign in to comment.