Skip to content

Commit

Permalink
Merge pull request #2510 from OffchainLabs/das-fs-backwards-compat
Browse files Browse the repository at this point in the history
Add DAS FS fallback to old layout, fix health check
  • Loading branch information
Tristan-Wilson authored Jul 22, 2024
2 parents 2dbd81c + 903c937 commit 1905917
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions das/local_file_storage_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@ func (s *LocalFileStorageService) Close(ctx context.Context) error {

func (s *LocalFileStorageService) GetByHash(ctx context.Context, key common.Hash) ([]byte, error) {
log.Trace("das.LocalFileStorageService.GetByHash", "key", pretty.PrettyHash(key), "this", s)
var batchPath string
if s.enableLegacyLayout {
batchPath = s.legacyLayout.batchPath(key)
} else {
batchPath = s.layout.batchPath(key)
}

legacyBatchPath := s.legacyLayout.batchPath(key)
batchPath := s.layout.batchPath(key)

data, err := os.ReadFile(batchPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrNotFound
data, err = os.ReadFile(legacyBatchPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrNotFound
}
return nil, err
}
return data, nil
}
return nil, err
}
Expand Down Expand Up @@ -225,7 +229,14 @@ func (s *LocalFileStorageService) String() string {

func (s *LocalFileStorageService) HealthCheck(ctx context.Context) error {
testData := []byte("Test-Data")
err := s.Put(ctx, testData, uint64(time.Now().Add(time.Minute).Unix()))
// Store some data with an expiry time at the start of the epoch.
// If expiry is disabled it will only create an index entry for the
// same timestamp each time the health check happens.
// If expiry is enabled, it will be cleaned up each time the pruning
// runs. There is a slight chance of a race between pruning and the
// Put and Get calls, but systems using the HealthCheck will just retry
// and succeed the next time.
err := s.Put(ctx, testData /* start of epoch */, 0)
if err != nil {
return err
}
Expand Down

0 comments on commit 1905917

Please sign in to comment.