Skip to content

Commit

Permalink
fix: feed wrap should download the wrapped chunk from the network (et…
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Dec 13, 2024
1 parent fc11edd commit b8e5c2d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
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
}

0 comments on commit b8e5c2d

Please sign in to comment.