Skip to content

Commit

Permalink
fix: epoch finder
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed May 28, 2024
1 parent d114125 commit b8d6ee2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 15 additions & 4 deletions pkg/feeds/epochs/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package epochs
import (
"context"
"errors"
"fmt"

"github.com/ethersphere/bee/v2/pkg/feeds"
storage "github.com/ethersphere/bee/v2/pkg/storage"
Expand Down Expand Up @@ -58,7 +57,7 @@ func (f *finder) common(ctx context.Context, at int64, after uint64) (*epoch, sw

// at is a non-concurrent recursive Finder function to find the version update chunk at time `at`
func (f *finder) at(ctx context.Context, at uint64, e *epoch, ch swarm.Chunk) (swarm.Chunk, error) {
_, err := f.getter.Get(ctx, e)
uch, err := f.getter.Get(ctx, e)
if err != nil {
// error retrieving
if !errors.Is(err, storage.ErrNotFound) {
Expand All @@ -71,8 +70,20 @@ func (f *finder) at(ctx context.Context, at uint64, e *epoch, ch swarm.Chunk) (s
// traverse earlier branch
return f.at(ctx, e.start-1, e.left(), ch)
}

return nil, fmt.Errorf("not implemented")
// epoch found
// check if timestamp is later then target
ts := e.length() * e.start
if ts > at {
if e.isLeft() {
return ch, nil
}
return f.at(ctx, e.start-1, e.left(), ch)
}
if e.level == 0 { // matching update time or finest resolution
return uch, nil
}
// continue traversing based on at
return f.at(ctx, at, e.childAt(at), uch)
}

type result struct {
Expand Down
1 change: 0 additions & 1 deletion pkg/feeds/epochs/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

func TestFinder_FLAKY(t *testing.T) {
t.Parallel()
t.Skip() // TODO fix epoch based feeds

testf := func(t *testing.T, finderf func(storage.Getter, *feeds.Feed) feeds.Lookup, updaterf func(putter storage.Putter, signer crypto.Signer, topic []byte) (feeds.Updater, error)) {
t.Helper()
Expand Down

0 comments on commit b8d6ee2

Please sign in to comment.