Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: feed wrap should download the wrapped chunk from the network #4929

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ FETCH:
jsonhttp.NotFound(w, "no update found")
return
}
wc, err := feeds.GetWrappedChunk(ctx, s.storer.ChunkStore(), ch)
wc, err := feeds.GetWrappedChunk(ctx, s.storer.Download(cache), ch)
if err != nil {
logger.Debug("bzz download: mapStructure feed update failed", "error", err)
logger.Error(nil, "bzz download: mapStructure feed update failed")
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *Service) feedGetHandler(w http.ResponseWriter, r *http.Request) {
return
}

wc, err := feeds.GetWrappedChunk(r.Context(), s.storer.ChunkStore(), ch)
wc, err := feeds.GetWrappedChunk(r.Context(), s.storer.Download(false), ch)
if err != nil {
logger.Error(nil, "wrapped chunk cannot be retrieved")
jsonhttp.NotFound(w, "wrapped chunk cannot be retrieved")
Expand Down
13 changes: 5 additions & 8 deletions pkg/feeds/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package feeds

import (
"context"
"encoding/binary"
"errors"
"fmt"
"time"
Expand Down Expand Up @@ -60,7 +59,7 @@ func GetWrappedChunk(ctx context.Context, getter storage.Getter, ch swarm.Chunk)
// possible values right now:
// unencrypted ref: span+timestamp+ref => 8+8+32=48
// encrypted ref: span+timestamp+ref+decryptKey => 8+8+64=80
_, ref, err := LegacyPayload(wc)
ref, err := legacyPayload(wc)
if err != nil {
if errors.Is(err, errNotLegacyPayload) {
return wc, nil
Expand All @@ -84,14 +83,12 @@ func FromChunk(ch swarm.Chunk) (swarm.Chunk, error) {
return s.WrappedChunk(), nil
}

// LegacyPayload returns back the referenced chunk and datetime from the legacy feed payload
func LegacyPayload(wrappedChunk swarm.Chunk) (uint64, swarm.Address, error) {
// legacyPayload returns back the referenced chunk and datetime from the legacy feed payload
func legacyPayload(wrappedChunk swarm.Chunk) (swarm.Address, error) {
cacData := wrappedChunk.Data()
if !(len(cacData) == 16+swarm.HashSize || len(cacData) == 16+swarm.HashSize*2) {
return 0, swarm.ZeroAddress, errNotLegacyPayload
return swarm.ZeroAddress, errNotLegacyPayload
}
address := swarm.NewAddress(cacData[16:])
at := binary.BigEndian.Uint64(cacData[8:16])

return at, address, nil
return swarm.NewAddress(cacData[16:]), nil
}
Loading