Skip to content

Commit

Permalink
feat: redundancy ci (#4591)
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill authored Feb 29, 2024
1 parent fd46f75 commit b8c7e20
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/beekeeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
28 changes: 25 additions & 3 deletions pkg/api/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
})
Expand Down
35 changes: 35 additions & 0 deletions pkg/soc/soc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit b8c7e20

Please sign in to comment.