Skip to content

Commit

Permalink
fix(store): make storePrefix actually optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Jul 6, 2023
1 parent 56a9e20 commit b389bbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 1 addition & 4 deletions store/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Parameters struct {
WriteBatchSize int

// storePrefix defines the prefix used to wrap the store
// OPTIONAL
storePrefix datastore.Key
}

Expand All @@ -32,7 +33,6 @@ func DefaultParameters() Parameters {
StoreCacheSize: 4096,
IndexCacheSize: 16384,
WriteBatchSize: 2048,
storePrefix: datastore.NewKey("headers"),
}
}

Expand All @@ -48,9 +48,6 @@ func (p *Parameters) Validate() error {
if p.WriteBatchSize <= 0 {
return fmt.Errorf("invalid batch size:%s", errSuffix)
}
if len(p.storePrefix.Bytes()) == 0 {
return fmt.Errorf("invalid store prefix: prefix cannot be empty")
}
return nil
}

Expand Down
9 changes: 8 additions & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
var log = logging.Logger("header/store")

var (
// defaultStorePrefix defines default datastore prefix
defaultStorePrefix = datastore.NewKey("headers")
// errStoppedStore is returned for attempted operations on a stopped store
errStoppedStore = errors.New("stopped store")
)
Expand Down Expand Up @@ -89,7 +91,12 @@ func newStore[H header.Header](ds datastore.Batching, opts ...Option) (*Store[H]
return nil, fmt.Errorf("failed to create index cache: %w", err)
}

wrappedStore := namespace.Wrap(ds, params.storePrefix)
prefix := params.storePrefix
if len(prefix.String()) == 0 {
prefix = defaultStorePrefix
}

wrappedStore := namespace.Wrap(ds, prefix)
index, err := newHeightIndexer[H](wrappedStore, params.IndexCacheSize)
if err != nil {
return nil, fmt.Errorf("failed to create height indexer: %w", err)
Expand Down

0 comments on commit b389bbe

Please sign in to comment.