Skip to content

Commit d7cf993

Browse files
refactor: remove act from chunk and soc api
1 parent 6ab12c6 commit d7cf993

4 files changed

Lines changed: 19 additions & 129 deletions

File tree

openapi/Swarm.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
openapi: 3.0.3
22

33
info:
4-
version: 8.1.0
4+
version: 9.0.0
55
title: Bee API
66
description: "API endpoints for interacting with the Swarm network, supporting file operations, messaging, and node management"
77

@@ -345,8 +345,6 @@ paths:
345345
$ref: "SwarmCommon.yaml#/components/parameters/SwarmPostageBatchId"
346346
required: false
347347
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmPostageStamp"
348-
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmAct"
349-
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmActHistoryAddress"
350348
requestBody:
351349
description: Chunk binary data containing at least 8 bytes.
352350
content:
@@ -362,8 +360,6 @@ paths:
362360
description: Tag UID from the request `swarm-tag` header if provided.
363361
schema:
364362
$ref: "SwarmCommon.yaml#/components/schemas/Uid"
365-
"swarm-act-history-address":
366-
$ref: "SwarmCommon.yaml#/components/headers/SwarmActHistoryAddress"
367363
content:
368364
application/json:
369365
schema:
@@ -1013,8 +1009,6 @@ paths:
10131009
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmTagParameter"
10141010
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmPinParameter"
10151011
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmDeferredUpload"
1016-
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmAct"
1017-
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmActHistoryAddress"
10181012
requestBody:
10191013
required: true
10201014
description: The SOC binary data, composed of the span (8 bytes) and up to 4KB of payload.
@@ -1035,8 +1029,6 @@ paths:
10351029
description: Tag UID, returned when an upload session is in use (either because `swarm-tag` was supplied, `swarm-deferred-upload` requested deferred mode, or `swarm-pin` was set).
10361030
schema:
10371031
$ref: "SwarmCommon.yaml#/components/schemas/Uid"
1038-
"swarm-act-history-address":
1039-
$ref: "SwarmCommon.yaml#/components/headers/SwarmActHistoryAddress"
10401032
"400":
10411033
$ref: "SwarmCommon.yaml#/components/responses/400"
10421034
"401":

pkg/api/accesscontrol_test.go

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest"
2727
"github.com/ethersphere/bee/v2/pkg/log"
2828
mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock"
29-
testingsoc "github.com/ethersphere/bee/v2/pkg/soc/testing"
3029
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"
3130
"github.com/ethersphere/bee/v2/pkg/swarm"
3231
"gitlab.com/nolash/go-mockbytes"
@@ -77,16 +76,10 @@ func TestAccessLogicEachEndpointWithAct(t *testing.T) {
7776
storerMock = mockstorer.New()
7877
logger = log.Noop
7978
now = time.Now().Unix()
80-
chunk = swarm.NewChunk(
81-
swarm.MustParseHexAddress("0025737be11979e91654dffd2be817ac1e52a2dadb08c97a7cef12f937e707bc"),
82-
[]byte{72, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 149, 179, 31, 244, 146, 247, 129, 123, 132, 248, 215, 77, 44, 47, 91, 248, 229, 215, 89, 156, 210, 243, 3, 110, 204, 74, 101, 119, 53, 53, 145, 188, 193, 153, 130, 197, 83, 152, 36, 140, 150, 209, 191, 214, 193, 4, 144, 121, 32, 45, 205, 220, 59, 227, 28, 43, 161, 51, 108, 14, 106, 180, 135, 2},
83-
)
84-
g = mockbytes.New(0, mockbytes.MockTypeStandard).WithModulus(255)
85-
bytedata, _ = g.SequentialBytes(swarm.ChunkSize * 2)
86-
tag, _ = storerMock.NewSession()
87-
sch = testingsoc.GenerateMockSOCWithKey(t, []byte("foo"), pk)
88-
dirdata = []byte("Lorem ipsum dolor sit amet")
89-
socResource = func(owner, id, sig string) string { return fmt.Sprintf("/soc/%s/%s?sig=%s", owner, id, sig) }
79+
g = mockbytes.New(0, mockbytes.MockTypeStandard).WithModulus(255)
80+
bytedata, _ = g.SequentialBytes(swarm.ChunkSize * 2)
81+
tag, _ = storerMock.NewSession()
82+
dirdata = []byte("Lorem ipsum dolor sit amet")
9083
)
9184

9285
tc := []struct {
@@ -100,7 +93,6 @@ func TestAccessLogicEachEndpointWithAct(t *testing.T) {
10093
resp struct {
10194
Reference swarm.Address `json:"reference"`
10295
}
103-
direct bool
10496
}{
10597
{
10698
name: "bzz",
@@ -141,27 +133,6 @@ func TestAccessLogicEachEndpointWithAct(t *testing.T) {
141133
expdata: bytedata,
142134
contenttype: "application/octet-stream",
143135
},
144-
{
145-
name: "chunks",
146-
upurl: "/chunks",
147-
downurl: "/chunks",
148-
exphash: "ca8d2d29466e017cba46d383e7e0794d99a141185ec525086037f25fc2093155",
149-
resp: api.ChunkAddressResponse{Reference: swarm.MustParseHexAddress("ca8d2d29466e017cba46d383e7e0794d99a141185ec525086037f25fc2093155")},
150-
data: bytes.NewReader(chunk.Data()),
151-
expdata: chunk.Data(),
152-
contenttype: "binary/octet-stream",
153-
},
154-
{
155-
name: "soc",
156-
upurl: socResource(hex.EncodeToString(sch.Owner), hex.EncodeToString(sch.ID), hex.EncodeToString(sch.Signature)),
157-
downurl: "/chunks",
158-
exphash: "b100d7ce487426b17b98ff779fad4f2dd471d04ab1c8949dd2a1a78fe4a1524e",
159-
resp: api.ChunkAddressResponse{Reference: swarm.MustParseHexAddress("b100d7ce487426b17b98ff779fad4f2dd471d04ab1c8949dd2a1a78fe4a1524e")},
160-
data: bytes.NewReader(sch.WrappedChunk.Data()),
161-
expdata: sch.Chunk().Data(),
162-
contenttype: "binary/octet-stream",
163-
direct: true,
164-
},
165136
}
166137

167138
for _, v := range tc {
@@ -175,35 +146,21 @@ func TestAccessLogicEachEndpointWithAct(t *testing.T) {
175146
jsonhttptest.WithExpectedJSONResponse(v.resp),
176147
jsonhttptest.WithRequestHeader(api.ContentTypeHeader, v.contenttype),
177148
}
178-
if v.name == "soc" {
179-
upTestOpts = append(upTestOpts, jsonhttptest.WithRequestHeader(api.SwarmPinHeader, "true"))
180-
} else {
181-
upTestOpts = append(upTestOpts, jsonhttptest.WithNonEmptyResponseHeader(api.SwarmTagHeader))
182-
}
149+
upTestOpts = append(upTestOpts, jsonhttptest.WithNonEmptyResponseHeader(api.SwarmTagHeader))
183150
expcontenttype := v.contenttype
184151
if v.name == "bzz-dir" {
185152
expcontenttype = "text/plain; charset=utf-8"
186153
upTestOpts = append(upTestOpts, jsonhttptest.WithRequestHeader(api.SwarmCollectionHeader, "True"))
187154
}
188155
t.Run(v.name, func(t *testing.T) {
189-
client, _, _, chanStore := newTestServer(t, testServerOptions{
156+
client, _, _, _ := newTestServer(t, testServerOptions{
190157
Storer: storerMock,
191158
Logger: logger,
192159
Post: mockpost.New(mockpost.WithAcceptAll()),
193160
PublicKey: pk.PublicKey,
194161
AccessControl: mockac.New(),
195-
DirectUpload: v.direct,
196162
})
197163

198-
if chanStore != nil {
199-
chanStore.Subscribe(func(chunk swarm.Chunk) {
200-
err := storerMock.Put(context.Background(), chunk)
201-
if err != nil {
202-
t.Fatal(err)
203-
}
204-
})
205-
}
206-
207164
header := jsonhttptest.Request(t, client, http.MethodPost, v.upurl, http.StatusCreated,
208165
upTestOpts...,
209166
)
@@ -218,7 +175,7 @@ func TestAccessLogicEachEndpointWithAct(t *testing.T) {
218175
jsonhttptest.WithExpectedResponseHeader(api.ContentTypeHeader, expcontenttype),
219176
)
220177

221-
if v.name != "bzz-dir" && v.name != "soc" && v.name != "chunks" {
178+
if v.name != "bzz-dir" {
222179
t.Run("head", func(t *testing.T) {
223180
jsonhttptest.Request(t, client, http.MethodHead, v.downurl+"/"+v.exphash, http.StatusOK,
224181
jsonhttptest.WithRequestHeader(api.SwarmActTimestampHeader, strconv.FormatInt(now, 10)),

pkg/api/chunk.go

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import (
1212
"net/http"
1313
"strconv"
1414

15-
"github.com/ethersphere/bee/v2/pkg/accesscontrol"
1615
"github.com/ethersphere/bee/v2/pkg/cac"
17-
"github.com/ethersphere/bee/v2/pkg/file/redundancy"
1816
"github.com/ethersphere/bee/v2/pkg/soc"
1917
"github.com/ethersphere/bee/v2/pkg/storer"
2018

@@ -33,11 +31,9 @@ func (s *Service) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
3331
logger := s.logger.WithName("post_chunk").Build()
3432

3533
headers := struct {
36-
BatchID []byte `map:"Swarm-Postage-Batch-Id"`
37-
StampSig []byte `map:"Swarm-Postage-Stamp"`
38-
SwarmTag uint64 `map:"Swarm-Tag"`
39-
Act bool `map:"Swarm-Act"`
40-
HistoryAddress swarm.Address `map:"Swarm-Act-History-Address"`
34+
BatchID []byte `map:"Swarm-Postage-Batch-Id"`
35+
StampSig []byte `map:"Swarm-Postage-Stamp"`
36+
SwarmTag uint64 `map:"Swarm-Tag"`
4137
}{}
4238
if response := s.mapStructure(r.Header, &headers); response != nil {
4339
response("invalid header params", logger, w)
@@ -183,28 +179,6 @@ func (s *Service) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
183179
return
184180
}
185181

186-
reference := chunk.Address()
187-
historyReference := swarm.ZeroAddress
188-
if headers.Act {
189-
// Redundancy level is hardcoded; ACT on chunk endpoints is semantically broken and will be removed, see https://github.com/ethersphere/bee/issues/5469.
190-
reference, historyReference, err = s.actEncryptionHandler(r.Context(), putter, reference, headers.HistoryAddress, redundancy.DefaultUploadLevel)
191-
if err != nil {
192-
logger.Debug("access control upload failed", "error", err)
193-
logger.Error(nil, "access control upload failed")
194-
switch {
195-
case errors.Is(err, accesscontrol.ErrNotFound):
196-
jsonhttp.NotFound(w, "act or history entry not found")
197-
case errors.Is(err, accesscontrol.ErrInvalidPublicKey) || errors.Is(err, accesscontrol.ErrSecretKeyInfinity):
198-
jsonhttp.BadRequest(w, "invalid public key")
199-
case errors.Is(err, accesscontrol.ErrUnexpectedType):
200-
jsonhttp.BadRequest(w, "failed to create history")
201-
default:
202-
jsonhttp.InternalServerError(w, errActUpload)
203-
}
204-
return
205-
}
206-
}
207-
208182
err = putter.Done(swarm.ZeroAddress)
209183
if err != nil {
210184
logger.Debug("done split failed", "error", err)
@@ -218,11 +192,8 @@ func (s *Service) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
218192
}
219193

220194
w.Header().Set(AccessControlExposeHeaders, SwarmTagHeader)
221-
if headers.Act {
222-
w.Header().Set(SwarmActHistoryAddressHeader, historyReference.String())
223-
w.Header().Add(AccessControlExposeHeaders, SwarmActHistoryAddressHeader)
224-
}
225-
jsonhttp.Created(w, chunkAddressResponse{Reference: reference})
195+
196+
jsonhttp.Created(w, chunkAddressResponse{Reference: chunk.Address()})
226197
}
227198

228199
func (s *Service) chunkGetHandler(w http.ResponseWriter, r *http.Request) {

pkg/api/soc.go

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313
"net/http"
1414
"strconv"
1515

16-
"github.com/ethersphere/bee/v2/pkg/accesscontrol"
1716
"github.com/ethersphere/bee/v2/pkg/cac"
18-
"github.com/ethersphere/bee/v2/pkg/file/redundancy"
1917
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
2018
"github.com/ethersphere/bee/v2/pkg/postage"
2119
"github.com/ethersphere/bee/v2/pkg/soc"
@@ -50,13 +48,11 @@ func (s *Service) socUploadHandler(w http.ResponseWriter, r *http.Request) {
5048
}
5149

5250
headers := struct {
53-
BatchID []byte `map:"Swarm-Postage-Batch-Id"`
54-
StampSig []byte `map:"Swarm-Postage-Stamp"`
55-
SwarmTag uint64 `map:"Swarm-Tag"`
56-
Pin bool `map:"Swarm-Pin"`
57-
Deferred *bool `map:"Swarm-Deferred-Upload"`
58-
Act bool `map:"Swarm-Act"`
59-
HistoryAddress swarm.Address `map:"Swarm-Act-History-Address"`
51+
BatchID []byte `map:"Swarm-Postage-Batch-Id"`
52+
StampSig []byte `map:"Swarm-Postage-Stamp"`
53+
SwarmTag uint64 `map:"Swarm-Tag"`
54+
Pin bool `map:"Swarm-Pin"`
55+
Deferred *bool `map:"Swarm-Deferred-Upload"`
6056
}{}
6157
if response := s.mapStructure(r.Header, &headers); response != nil {
6258
response("invalid header params", logger, w)
@@ -213,28 +209,6 @@ func (s *Service) socUploadHandler(w http.ResponseWriter, r *http.Request) {
213209
return
214210
}
215211

216-
reference := sch.Address()
217-
historyReference := swarm.ZeroAddress
218-
if headers.Act {
219-
// Redundancy level is hardcoded; ACT on SOC is semantically broken and will be removed, see https://github.com/ethersphere/bee/issues/5469.
220-
reference, historyReference, err = s.actEncryptionHandler(r.Context(), putter, reference, headers.HistoryAddress, redundancy.DefaultUploadLevel)
221-
if err != nil {
222-
logger.Debug("access control upload failed", "error", err)
223-
logger.Error(nil, "access control upload failed")
224-
switch {
225-
case errors.Is(err, accesscontrol.ErrNotFound):
226-
jsonhttp.NotFound(w, "act or history entry not found")
227-
case errors.Is(err, accesscontrol.ErrInvalidPublicKey) || errors.Is(err, accesscontrol.ErrSecretKeyInfinity):
228-
jsonhttp.BadRequest(w, "invalid public key")
229-
case errors.Is(err, accesscontrol.ErrUnexpectedType):
230-
jsonhttp.BadRequest(w, "failed to create history")
231-
default:
232-
jsonhttp.InternalServerError(w, errActUpload)
233-
}
234-
return
235-
}
236-
}
237-
238212
err = putter.Done(sch.Address())
239213
if err != nil {
240214
logger.Debug("done split failed", "error", err)
@@ -247,12 +221,8 @@ func (s *Service) socUploadHandler(w http.ResponseWriter, r *http.Request) {
247221
}
248222

249223
w.Header().Set(AccessControlExposeHeaders, SwarmTagHeader)
250-
if headers.Act {
251-
w.Header().Set(SwarmActHistoryAddressHeader, historyReference.String())
252-
w.Header().Add(AccessControlExposeHeaders, SwarmActHistoryAddressHeader)
253-
}
254224

255-
jsonhttp.Created(w, socPostResponse{Reference: reference})
225+
jsonhttp.Created(w, socPostResponse{Reference: sch.Address()})
256226
}
257227

258228
func (s *Service) socGetHandler(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)