Draft
Conversation
7 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/chunk.go- Chunk upload handler (for ACT encryption only; ACT on raw chunk endpoints is debatable and may be removed in a future refactor)pkg/api/feed.go- Feed post handlerpkg/api/pin.go- Pin root hash handlerpkg/api/soc.go- SOC upload handler (for ACT encryption only; not related to SOC dispersed replica behaviour — noted in OpenAPI docs)pkg/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 onlypkg/api/soc.go- ACT encryption path onlyDownload 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 /chunks— applies to ACT encryption onlyPOST /soc/{owner}/{id}— applies to ACT encryption only (OpenAPI description clarifies this is not related to SOC dispersed replicas)POST /feeds/{owner}/{topic}— applies to ACT encryptionGET /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. Where the header only affects ACT encryption (not the primary upload/download behaviour of the endpoint), this is explicitly noted in the parameter description.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
Swarm-Redundancy-Levelheader onPOST /chunksandPOST /soc/{owner}/{id}exclusively controls the ACT encryption redundancy. The chunk itself is not uploaded with erasure coding. Whether ACT should be supported on raw chunk/SOC endpoints at all is an open question for future consideration.Checklist
Description
Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):