From b8c7e2042f1a6631ca099e2a0f988fc4e513eda4 Mon Sep 17 00:00:00 2001 From: Acha Bill <57879913+acha-bill@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:16:45 +0100 Subject: [PATCH] feat: redundancy ci (#4591) --- .github/workflows/beekeeper.yml | 3 +++ pkg/api/chunk.go | 28 +++++++++++++++++++++++--- pkg/api/router.go | 2 +- pkg/soc/soc_test.go | 35 +++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/.github/workflows/beekeeper.yml b/.github/workflows/beekeeper.yml index 95a09cfc1dc..b785ebf2f23 100644 --- a/.github/workflows/beekeeper.yml +++ b/.github/workflows/beekeeper.yml @@ -162,6 +162,9 @@ jobs: - name: Test staking id: stake run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks ci-stake + - name: Test redundancy + id: redundancy + run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks ci-redundancy - name: Collect debug artifacts if: failure() run: | diff --git a/pkg/api/chunk.go b/pkg/api/chunk.go index 25e1d6c65ed..df3ef547318 100644 --- a/pkg/api/chunk.go +++ b/pkg/api/chunk.go @@ -13,6 +13,7 @@ import ( "strconv" "github.com/ethersphere/bee/pkg/cac" + "github.com/ethersphere/bee/pkg/soc" "github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/postage" @@ -111,10 +112,31 @@ func (s *Service) chunkUploadHandler(w http.ResponseWriter, r *http.Request) { chunk, err := cac.NewWithDataSpan(data) if err != nil { + // not a valid cac chunk. Check if it's a replica soc chunk. logger.Debug("chunk upload: create chunk failed", "error", err) - logger.Error(nil, "chunk upload: create chunk error") - jsonhttp.InternalServerError(ow, "create chunk error") - return + + // FromChunk only uses the chunk data to recreate the soc chunk. So the address is irrelevant. + sch, err := soc.FromChunk(swarm.NewChunk(swarm.EmptyAddress, data)) + if err != nil { + logger.Debug("chunk upload: create soc chunk from data failed", "error", err) + logger.Error(nil, "chunk upload: create chunk error") + jsonhttp.InternalServerError(ow, "create chunk error") + return + } + chunk, err = sch.Chunk() + if err != nil { + logger.Debug("chunk upload: create chunk from soc failed", "error", err) + logger.Error(nil, "chunk upload: create chunk error") + jsonhttp.InternalServerError(ow, "create chunk error") + return + } + + if !soc.Valid(chunk) { + logger.Debug("chunk upload: invalid soc chunk") + logger.Error(nil, "chunk upload: create chunk error") + jsonhttp.InternalServerError(ow, "create chunk error") + return + } } err = putter.Put(r.Context(), chunk) diff --git a/pkg/api/router.go b/pkg/api/router.go index d4934ca8f09..3e4574ed896 100644 --- a/pkg/api/router.go +++ b/pkg/api/router.go @@ -220,7 +220,7 @@ func (s *Service) mountAPI() { handle("/chunks", jsonhttp.MethodHandler{ "POST": web.ChainHandlers( - jsonhttp.NewMaxBodyBytesHandler(swarm.ChunkWithSpanSize), + jsonhttp.NewMaxBodyBytesHandler(swarm.SocMaxChunkSize), web.FinalHandlerFunc(s.chunkUploadHandler), ), }) diff --git a/pkg/soc/soc_test.go b/pkg/soc/soc_test.go index e4f6fb4e199..105a7cdedde 100644 --- a/pkg/soc/soc_test.go +++ b/pkg/soc/soc_test.go @@ -47,6 +47,41 @@ func TestNew(t *testing.T) { } } +func TestReplica(t *testing.T) { + sig, err := hex.DecodeString("5acd384febc133b7b245e5ddc62d82d2cded9182d2716126cd8844509af65a053deb418208027f548e3e88343af6f84a8772fb3cebc0a1833a0ea7ec0c1348311b") + if err != nil { + t.Fatal(err) + } + + payload := []byte("foo") + ch, err := cac.New(payload) + if err != nil { + t.Fatal(err) + } + + id := make([]byte, swarm.HashSize) + s, err := soc.NewSigned(id, ch, swarm.ReplicasOwner, sig) + if err != nil { + t.Fatal(err) + } + + ch, err = s.Chunk() + if err != nil { + t.Fatal(err) + } + sch, err := soc.FromChunk(swarm.NewChunk(swarm.EmptyAddress, ch.Data())) + if err != nil { + t.Fatal(err) + } + ch, err = sch.Chunk() + if err != nil { + t.Fatal(err) + } + if !soc.Valid(ch) { + t.Fatal("invalid soc chunk") + } +} + func TestNewSigned(t *testing.T) { t.Parallel()