Skip to content

Commit 60f2e08

Browse files
authored
revert: feed legacy payload header (#5029) (#5160)
1 parent 6b606aa commit 60f2e08

File tree

9 files changed

+31
-65
lines changed

9 files changed

+31
-65
lines changed

openapi/Swarm.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,12 +1036,6 @@ paths:
10361036
$ref: "SwarmCommon.yaml#/components/schemas/FeedType"
10371037
required: false
10381038
description: "Feed indexing scheme (default: sequence)"
1039-
- in: header
1040-
name: legacy-feed-resolution
1041-
schema:
1042-
type: boolean
1043-
required: false
1044-
description: "Resolves feed payloads in legacy structure (timestamp, content address)."
10451039
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmOnlyRootChunkParameter"
10461040
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmCache"
10471041
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmRedundancyStrategyParameter"

pkg/api/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ const (
7878
SwarmSocSignatureHeader = "Swarm-Soc-Signature"
7979
SwarmFeedIndexHeader = "Swarm-Feed-Index"
8080
SwarmFeedIndexNextHeader = "Swarm-Feed-Index-Next"
81-
SwarmLegacyFeedResolve = "Swarm-Feed-Legacy-Resolve"
8281
SwarmOnlyRootChunk = "Swarm-Only-Root-Chunk"
8382
SwarmCollectionHeader = "Swarm-Collection"
8483
SwarmPostageBatchIdHeader = "Swarm-Postage-Batch-Id"

pkg/api/bzz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ FETCH:
433433
jsonhttp.NotFound(w, "no update found")
434434
return
435435
}
436-
wc, err := feeds.GetWrappedChunk(ctx, s.storer.Download(cache), ch, false)
436+
wc, err := feeds.GetWrappedChunk(ctx, s.storer.Download(cache), ch)
437437
if err != nil {
438438
logger.Debug("bzz download: mapStructure feed update failed", "error", err)
439439
logger.Error(nil, "bzz download: mapStructure feed update failed")

pkg/api/bzz_test.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/ethersphere/bee/v2/pkg/manifest"
2727
mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock"
2828
mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock"
29-
testingsoc "github.com/ethersphere/bee/v2/pkg/soc/testing"
3029
"github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore"
3130
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"
3231
"github.com/ethersphere/bee/v2/pkg/swarm"
@@ -795,22 +794,16 @@ func TestFeedIndirection(t *testing.T) {
795794
t.Fatalf("expected file reference, did not got any")
796795
}
797796

798-
// get root chunk of data
799-
// and wrap it in a feed
800-
rootCh, err := storer.ChunkStore().Get(context.Background(), resp.Reference)
801-
if err != nil {
802-
t.Fatal(err)
803-
}
804-
socRootCh := testingsoc.GenerateMockSOC(t, rootCh.Data()[swarm.SpanSize:]).Chunk()
805-
806-
// now use the "content" root chunk to mock the feed lookup
797+
// now use the "content" to mock the feed lookup
807798
// also, use the mocked mantaray chunks that unmarshal
808799
// into a real manifest with the mocked feed values when
809800
// called from the bzz endpoint. then call the bzz endpoint with
810801
// the pregenerated feed root manifest hash
811802

803+
feedUpdate := toChunk(t, 121212, resp.Reference.Bytes())
804+
812805
var (
813-
look = newMockLookup(-1, 0, socRootCh, nil, &id{}, nil)
806+
look = newMockLookup(-1, 0, feedUpdate, nil, &id{}, nil)
814807
factory = newMockFactory(look)
815808
bzzDownloadResource = func(addr, path string) string { return "/bzz/" + addr + "/" + path }
816809
ctx = context.Background()
@@ -820,6 +813,7 @@ func TestFeedIndirection(t *testing.T) {
820813
Logger: logger,
821814
Feeds: factory,
822815
})
816+
err := storer.Cache().Put(ctx, feedUpdate)
823817
if err != nil {
824818
t.Fatal(err)
825819
}

pkg/api/feed.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ func (s *Service) feedGetHandler(w http.ResponseWriter, r *http.Request) {
6565
}
6666

6767
headers := struct {
68-
OnlyRootChunk bool `map:"Swarm-Only-Root-Chunk"`
69-
LegacyFeedResolve bool `map:"Swarm-Feed-Legacy-Resolve"`
68+
OnlyRootChunk bool `map:"Swarm-Only-Root-Chunk"`
7069
}{}
7170
if response := s.mapStructure(r.Header, &headers); response != nil {
7271
response("invalid header params", logger, w)
@@ -103,7 +102,7 @@ func (s *Service) feedGetHandler(w http.ResponseWriter, r *http.Request) {
103102
return
104103
}
105104

106-
wc, err := feeds.GetWrappedChunk(r.Context(), s.storer.Download(false), ch, headers.LegacyFeedResolve)
105+
wc, err := feeds.GetWrappedChunk(r.Context(), s.storer.Download(false), ch)
107106
if err != nil {
108107
logger.Error(nil, "wrapped chunk cannot be retrieved")
109108
jsonhttp.NotFound(w, "wrapped chunk cannot be retrieved")

pkg/api/feed_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ func TestFeed_Get(t *testing.T) {
7777

7878
jsonhttptest.Request(t, client, http.MethodGet, feedResource(ownerString, "aabbcc", "12"), http.StatusOK,
7979
jsonhttptest.WithExpectedResponse(mockWrappedCh.Data()[swarm.SpanSize:]),
80-
jsonhttptest.WithRequestHeader(api.SwarmLegacyFeedResolve, "true"),
8180
jsonhttptest.WithExpectedResponseHeader(api.SwarmFeedIndexHeader, hex.EncodeToString(idBytes)),
8281
jsonhttptest.WithExpectedResponseHeader(api.AccessControlExposeHeaders, api.SwarmFeedIndexHeader),
8382
jsonhttptest.WithExpectedResponseHeader(api.AccessControlExposeHeaders, api.SwarmFeedIndexNextHeader),
@@ -87,7 +86,7 @@ func TestFeed_Get(t *testing.T) {
8786
)
8887
})
8988

90-
t.Run("latest with legacy payload", func(t *testing.T) {
89+
t.Run("latest", func(t *testing.T) {
9190
t.Parallel()
9291

9392
var (
@@ -104,7 +103,6 @@ func TestFeed_Get(t *testing.T) {
104103
)
105104

106105
jsonhttptest.Request(t, client, http.MethodGet, feedResource(ownerString, "aabbcc", ""), http.StatusOK,
107-
jsonhttptest.WithRequestHeader(api.SwarmLegacyFeedResolve, "true"),
108106
jsonhttptest.WithExpectedResponse(mockWrappedCh.Data()[swarm.SpanSize:]),
109107
jsonhttptest.WithExpectedContentLength(len(mockWrappedCh.Data()[swarm.SpanSize:])),
110108
jsonhttptest.WithExpectedResponseHeader(api.SwarmFeedIndexHeader, hex.EncodeToString(idBytes)),
@@ -163,9 +161,7 @@ func TestFeed_Get(t *testing.T) {
163161
})
164162
)
165163

166-
jsonhttptest.Request(t, client, http.MethodGet, feedResource(ownerString, "aabbcc", ""), http.StatusNotFound,
167-
jsonhttptest.WithRequestHeader(api.SwarmLegacyFeedResolve, "true"),
168-
)
164+
jsonhttptest.Request(t, client, http.MethodGet, feedResource(ownerString, "aabbcc", ""), http.StatusNotFound)
169165
})
170166

171167
t.Run("bigger payload than one chunk", func(t *testing.T) {

pkg/feeds/getter.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (f *Getter) Get(ctx context.Context, i Index) (swarm.Chunk, error) {
5050
return f.getter.Get(ctx, addr)
5151
}
5252

53-
func GetWrappedChunk(ctx context.Context, getter storage.Getter, ch swarm.Chunk, legacyResolve bool) (swarm.Chunk, error) {
53+
func GetWrappedChunk(ctx context.Context, getter storage.Getter, ch swarm.Chunk) (swarm.Chunk, error) {
5454
wc, err := FromChunk(ch)
5555
if err != nil {
5656
return nil, err
@@ -59,15 +59,16 @@ func GetWrappedChunk(ctx context.Context, getter storage.Getter, ch swarm.Chunk,
5959
// possible values right now:
6060
// unencrypted ref: span+timestamp+ref => 8+8+32=48
6161
// encrypted ref: span+timestamp+ref+decryptKey => 8+8+64=80
62-
if legacyResolve {
63-
ref, err := legacyPayload(wc)
64-
if err != nil {
65-
return nil, err
66-
}
67-
wc, err = getter.Get(ctx, ref)
68-
if err != nil {
69-
return nil, err
62+
ref, err := legacyPayload(wc)
63+
if err != nil {
64+
if errors.Is(err, errNotLegacyPayload) {
65+
return wc, nil
7066
}
67+
return nil, err
68+
}
69+
wc, err = getter.Get(ctx, ref)
70+
if err != nil {
71+
return nil, err
7172
}
7273

7374
return wc, nil

pkg/feeds/getter_test.go

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,18 @@ import (
1717
func TestGetWrappedChunk(t *testing.T) {
1818
storer := mockstorer.New()
1919

20-
data := []byte("data")
2120
// new format (wraps chunk)
22-
ch := soctesting.GenerateMockSOC(t, data).Chunk()
23-
wch, err := GetWrappedChunk(context.Background(), storer.ChunkStore(), ch, false)
21+
ch := soctesting.GenerateMockSOC(t, []byte("data")).Chunk()
22+
wch, err := GetWrappedChunk(context.Background(), storer.ChunkStore(), ch)
2423
if err != nil {
2524
t.Fatal(err)
2625
}
2726

28-
if !bytes.Equal(wch.Data()[8:], data) {
27+
if !bytes.Equal(wch.Data()[8:], []byte("data")) {
2928
t.Fatal("data mismatch")
3029
}
3130

3231
// old format
33-
err = storer.Put(context.Background(), wch)
34-
if err != nil {
35-
t.Fatal(err)
36-
}
37-
3832
tt := []struct {
3933
name string
4034
addr []byte
@@ -55,30 +49,19 @@ func TestGetWrappedChunk(t *testing.T) {
5549
binary.BigEndian.PutUint64(timestamp, 1)
5650
ch = soctesting.GenerateMockSOC(t, append(timestamp, tc.addr...)).Chunk()
5751

58-
wch, err = GetWrappedChunk(context.Background(), storer.ChunkStore(), ch, true)
52+
err = storer.Put(context.Background(), wch)
5953
if err != nil {
6054
t.Fatal(err)
6155
}
6256

63-
if !bytes.Equal(wch.Data()[8:], data) {
57+
wch, err = GetWrappedChunk(context.Background(), storer.ChunkStore(), ch)
58+
if err != nil {
59+
t.Fatal(err)
60+
}
61+
62+
if !bytes.Equal(wch.Data()[8:], []byte("data")) {
6463
t.Fatal("data mismatch")
6564
}
6665
})
6766
}
68-
69-
t.Run("returns feed legacy payload", func(t *testing.T) {
70-
timestamp := make([]byte, 8)
71-
binary.BigEndian.PutUint64(timestamp, 1)
72-
feedChData := append(timestamp, wch.Address().Bytes()...)
73-
ch = soctesting.GenerateMockSOC(t, feedChData).Chunk()
74-
75-
wch, err = GetWrappedChunk(context.Background(), storer.ChunkStore(), ch, false)
76-
if err != nil {
77-
t.Fatal(err)
78-
}
79-
80-
if !bytes.Equal(wch.Data()[8:], feedChData) {
81-
t.Fatal("data should be similar as old legacy feed payload format.")
82-
}
83-
})
8467
}

pkg/node/bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func getLatestSnapshot(
336336
return nil, err
337337
}
338338

339-
return feeds.GetWrappedChunk(ctx, st, u, false)
339+
return feeds.GetWrappedChunk(ctx, st, u)
340340
}
341341

342342
func batchStoreExists(s storage.StateStorer) (bool, error) {

0 commit comments

Comments
 (0)