Skip to content

Commit 0c06192

Browse files
sysrexrenaynay
authored andcommitted
fix(store): fixes_#4100_adding_sharding
1 parent 5c1720e commit 0c06192

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

store/store.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ func (s *Store) put(
128128
return err
129129
}
130130

131+
// ensure the blocks hash directory exists
132+
blocksHashDir := filepath.Join(s.basepath, blocksPath, datahash.String()[:2])
133+
if err := mkdir(blocksHashDir); err != nil {
134+
return fmt.Errorf("ensuring blocks hash directory: %w", err)
135+
}
136+
131137
// put to cache before writing to make it accessible while write is happening
132138
accessor := &eds.Rsmt2D{ExtendedDataSquare: square}
133139
acc, err := s.cache.GetOrLoad(ctx, height, accessorLoader(accessor))
@@ -319,6 +325,12 @@ func (s *Store) populateEmptyFile() error {
319325
return fmt.Errorf("cleaning old empty EDS file: %w", err)
320326
}
321327

328+
// ensure the blocks hash directory exists
329+
blocksHashDir := filepath.Join(s.basepath, blocksPath, share.EmptyEDSDataHash().String()[:2])
330+
if err := mkdir(blocksHashDir); err != nil {
331+
return fmt.Errorf("ensuring blocks hash directory: %w", err)
332+
}
333+
322334
err = file.CreateODSQ4(pathOds, pathQ4, share.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare)
323335
if err != nil {
324336
return fmt.Errorf("creating fresh empty EDS file: %w", err)
@@ -514,11 +526,11 @@ func (s *Store) removeQ4(height uint64, datahash share.DataHash) error {
514526
}
515527

516528
func (s *Store) hashToPath(datahash share.DataHash, ext string) string {
517-
return filepath.Join(s.basepath, blocksPath, datahash.String()) + ext
529+
return filepath.Join(s.basepath, blocksPath, datahash.String()[:2], datahash.String()) + ext
518530
}
519531

520532
func (s *Store) hashToRelativePath(datahash share.DataHash, ext string) string {
521-
return filepath.Join("..", datahash.String()) + ext
533+
return filepath.Join("..", datahash.String()[:2], datahash.String()) + ext
522534
}
523535

524536
func (s *Store) heightToPath(height uint64, ext string) string {

0 commit comments

Comments
 (0)