fix: default redundancy level#5383
Conversation
975f137 to
8c4bbb0
Compare
Apply the redundancy level from request headers to the feed upload pipeline instead of using the default download level. Move redundancy level extraction earlier to use it for both the manifest creation and ACT encryption.
|
I see there are 2 things , please can you check them?
|
|
Thanks @martinconic for your comment, I fixed the bzz endpoint related rlevel issue, it wasn't reference type like on other endpoints... for the chunks/soc endpoints, I just hard-coded these values now, because IMO these don't need ACT feature. I created issue for that #5469 |
|
LGTM, maybe we could add a quick test that uploads the same content to POST /bytes and POST /bzz with no header vs. explicit MEDIUM/NONE and asserts no-header == MEDIUM (and != NONE)? TestStewardshipWithRedundancy only drives POST /bytes with an explicit Swarm-Redundancy-Level header |
Resolves: #5282
Fix: Redundancy Level Validations and Default Handling
Problem Statement
The Bee API had inconsistent handling of redundancy levels across different endpoints:
Swarm-Redundancy-Levelheader was not validated, allowing invalid values to be passed throughredundancy.DefaultLevelinstead of respecting user-provided redundancy levels from request headersSwarm-Redundancy-Levelheader at allChanges Made
1. Added Header Validation (
validate:"omitempty,rLevel")Added validation to all endpoints that accept the
Swarm-Redundancy-Levelheader to ensure values are within the valid range (0-4):pkg/api/accesscontrol.go- All 4 ACT handlerspkg/api/feed.go- Feed post handlerpkg/api/pin.go- Pin root hash handlerpkg/api/stewardship.go- Both stewardship handlers2. Introduced Semantic Default Levels
Created two distinct default redundancy levels in
pkg/file/redundancy/level.go:3. Fixed Hardcoded Redundancy Levels
Replaced hardcoded
redundancy.DefaultLevelwith appropriate context-aware defaults:Upload Operations (use
DefaultUploadLevel)pkg/api/bytes.go- Bytes uploadpkg/api/feed.go- Feed post — manifest now carries the level encodingpkg/api/accesscontrol.go- ACT grantee creation and grant/revokepkg/api/chunk.go- ACT encryption path only (hardcoded; see Notes)pkg/api/soc.go- ACT encryption path only (hardcoded; see Notes)Download Operations (use
DefaultDownloadLevel)pkg/api/bzz.go- BZZ downloadpkg/api/accesscontrol.go- ACT decryption and list granteespkg/api/pin.go- Pinning operationspkg/api/stewardship.go- Stewardship operations (previously no header support)4. Moved
rLevelfrom Traversal Struct toTraverseMethod Parameterpkg/traversal/traversal.gopreviously stored the redundancy level on the service struct at construction time. This was wrong because the sameTraverserinstance can be called from different sessions with different redundancy requirements (e.g. stewardship reupload vs. retrieval check). The level is now passed directly toTraverse(ctx, addr, fn, rLevel).All callers updated accordingly:
pkg/api/pin.gopkg/api/stewardship.gopkg/steward/steward.gopkg/traversal/traversal_test.go5. Updated Steward Interface and Service
steward.InterfacemethodsReuploadandIsRetrievablenow accept aredundancy.Levelparameter, forwarded from the API layerpkg/steward/steward.gousesDefaultDownloadLevelas fallback when no level is provided via headerredundancy.PARANOIDexplicitly (previously no level was passed)pkg/steward/mock/steward.goupdated to match the new interface signatures6. Added
Swarm-Redundancy-LevelHeader to New EndpointsThe following endpoints previously had no support for the header and now accept it as an optional input:
POST /feeds/{owner}/{topic}— controls feed pipeline redundancyGET /stewardship/{reference}— controls traversal redundancy level for retrievability checkPUT /stewardship/{reference}— controls traversal redundancy level for re-uploadPOST /pins/{reference}— controls traversal redundancy level for pinningPOST /grantee— ACT create grantee listGET /grantee/{reference}— ACT read grantee listPATCH /grantee/{reference}— ACT update grantee list7. Updated OpenAPI Documentation
Updated
openapi/Swarm.yamlto document theSwarm-Redundancy-Levelheader across all affected endpoints. TheSwarm-Redundancy-Levelparameter was intentionally not added toPOST /chunksandPOST /soc/{owner}/{id}: ACT on those endpoints is semantically broken and will be removed (see #5469); the redundancy level for the ACT path is hardcoded toDefaultUploadLevelin the meantime.8. Updated Tests
traversal.Newno longer takesrLevel; level now passed toTraverse()redundancy.PARANOIDpassed toReuploadandIsRetrievableImpact
Before
After
Benefits
rLevelis now per-call rather than per-service-instance, enabling correct behaviour when the traverser is reused across different request contextsNotes
POST /chunksandPOST /soc/{owner}/{id}do not exposeSwarm-Redundancy-Level. ACT on raw chunk and SOC endpoints is semantically broken (the payload is never encrypted; ACT only wraps the reference; the SOC GET endpoint has no ACT decryption path) and will be removed in a follow-up — see Remove ACT support from SOC and chunk endpoints #5469. The redundancy level for the ACT code path is hardcoded toDefaultUploadLevelin both handlers until that cleanup is done.Checklist
Description
Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):