Skip to content

Commit

Permalink
Merge branch 'master' into bump-local-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
gacevicljubisa authored Nov 3, 2024
2 parents 6786026 + e161ee8 commit 32a3a27
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beekeeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
REPLICA: 3
RUN_TYPE: "PR RUN"
SETUP_CONTRACT_IMAGE: "ethersphere/bee-localchain"
SETUP_CONTRACT_IMAGE_TAG: "0.9.2-rc1"
SETUP_CONTRACT_IMAGE_TAG: "0.9.2-rc6"
BEELOCAL_BRANCH: "update-k3s-0.30.3"
BEEKEEPER_BRANCH: "update-k8s-0.30.3"
BEEKEEPER_METRICS_ENABLED: false
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/coreos/go-semver v0.3.0
github.com/ethereum/go-ethereum v1.14.3
github.com/ethersphere/go-price-oracle-abi v0.2.0
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc6
github.com/ethersphere/go-sw3-abi v0.6.5
github.com/ethersphere/langos v1.0.0
github.com/go-playground/validator/v10 v10.11.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ github.com/ethereum/go-ethereum v1.14.3 h1:5zvnAqLtnCZrU9uod1JCvHWJbPMURzYFHfc2e
github.com/ethereum/go-ethereum v1.14.3/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
github.com/ethersphere/go-price-oracle-abi v0.2.0 h1:wtIcYLgNZHY4BjYwJCnu93SvJdVAZVvBaKinspyyHvQ=
github.com/ethersphere/go-price-oracle-abi v0.2.0/go.mod h1:sI/Qj4/zJ23/b1enzwMMv0/hLTpPNVNacEwCWjo6yBk=
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1 h1:Cf3LFlz87FqlTqcuN4q4Hry4iUaAbbroaFxpCgHVhtY=
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc6 h1:3s6c2w9JrToXdiX9vSGxatmRUBzOe57joZk1Xf4SWHU=
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc6/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-sw3-abi v0.6.5 h1:M5dcIe1zQYvGpY2K07UNkNU9Obc4U+A1fz68Ho/Q+XE=
github.com/ethersphere/go-sw3-abi v0.6.5/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (s *Service) statusGetNeighborhoods(w http.ResponseWriter, r *http.Request)
neighborhoods = append(neighborhoods, statusNeighborhoodResponse{
Neighborhood: n.Neighborhood.String(),
ReserveSizeWithinRadius: n.ReserveSizeWithinRadius,
Proximity: swarm.Proximity(s.overlay.Bytes(), n.Neighborhood.Bytes()),
Proximity: n.Proximity,
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/postage/postagecontract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (c *postageContract) sendApproveTransaction(ctx context.Context, amount *bi
To: &c.bzzTokenAddress,
Data: callData,
GasPrice: sctx.GetGasPrice(ctx),
GasLimit: 65000,
GasLimit: max(sctx.GetGasLimit(ctx), c.gasLimit),
Value: big.NewInt(0),
Description: approveDescription,
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/soc/soc.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ func (s *SOC) Sign(signer crypto.Signer) (swarm.Chunk, error) {
return s.Chunk()
}

// UnwrapCAC extracts the CAC inside the SOC.
func UnwrapCAC(sch swarm.Chunk) (swarm.Chunk, error) {
chunkData := sch.Data()
if len(chunkData) < swarm.SocMinChunkSize {
return nil, errWrongChunkSize
}

cursor := swarm.HashSize + swarm.SocSignatureSize
ch, err := cac.NewWithDataSpan(chunkData[cursor:])
if err != nil {
return nil, err
}

return ch, nil
}

// FromChunk recreates a SOC representation from swarm.Chunk data.
func FromChunk(sch swarm.Chunk) (*SOC, error) {
chunkData := sch.Data()
Expand Down
9 changes: 9 additions & 0 deletions pkg/soc/soc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ func TestFromChunk(t *testing.T) {
if !ch.Equal(recoveredSOC.WrappedChunk()) {
t.Fatalf("wrapped chunk mismatch. got %s want %s", recoveredSOC.WrappedChunk().Address(), ch.Address())
}

unwrapped, err := soc.UnwrapCAC(sch)
if err != nil {
t.Fatal(err)
}

if !ch.Equal(unwrapped) {
t.Fatalf("wrapped chunk mismatch. got %s want %s", recoveredSOC.WrappedChunk().Address(), ch.Address())
}
}

func TestCreateAddress(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storageincentives/staking/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (c *contract) sendApproveTransaction(ctx context.Context, amount *big.Int)
To: &c.bzzTokenAddress,
Data: callData,
GasPrice: sctx.GetGasPrice(ctx),
GasLimit: 65000,
GasLimit: max(sctx.GetGasLimit(ctx), c.gasLimit),
Value: big.NewInt(0),
Description: approveDescription,
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/storer/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,23 +500,27 @@ func (db *DB) SubscribeBin(ctx context.Context, bin uint8, start uint64) (<-chan
type NeighborhoodStat struct {
Neighborhood swarm.Neighborhood
ReserveSizeWithinRadius int
Proximity uint8
}

func (db *DB) NeighborhoodsStat(ctx context.Context) ([]*NeighborhoodStat, error) {

radius := db.StorageRadius()

networkRadius := radius + uint8(db.reserveOptions.capacityDoubling)
responsibilityRadius := radius + uint8(db.reserveOptions.capacityDoubling)

prefixes := neighborhoodPrefixes(db.baseAddr, int(radius), db.reserveOptions.capacityDoubling)
neighs := make([]*NeighborhoodStat, len(prefixes))
for i, n := range prefixes {
neighs[i] = &NeighborhoodStat{swarm.NewNeighborhood(n, networkRadius), 0}
neighs[i] = &NeighborhoodStat{
Neighborhood: swarm.NewNeighborhood(n, responsibilityRadius),
ReserveSizeWithinRadius: 0,
Proximity: min(responsibilityRadius, swarm.Proximity(n.Bytes(), db.baseAddr.Bytes()))}
}

err := db.reserve.IterateChunksItems(0, func(ch *reserve.ChunkBinItem) (bool, error) {
for _, n := range neighs {
if swarm.Proximity(ch.Address.Bytes(), n.Neighborhood.Bytes()) >= networkRadius {
if swarm.Proximity(ch.Address.Bytes(), n.Neighborhood.Bytes()) >= responsibilityRadius {
n.ReserveSizeWithinRadius++
break
}
Expand Down
41 changes: 24 additions & 17 deletions pkg/storer/reserve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,11 @@ func TestNeighborhoodStats(t *testing.T) {
t.Parallel()

const (
chunkCountPerPO = 16
maxPO = 5
networkRadius uint8 = 4
doublingFactor uint8 = 2
localRadius uint8 = networkRadius - doublingFactor
chunkCountPerPO = 16
maxPO = 5
committedDepth uint8 = 4
doublingFactor uint8 = 2
responsibiliyDepth uint8 = committedDepth - doublingFactor
)

mustParse := func(s string) swarm.Address {
Expand Down Expand Up @@ -706,10 +706,10 @@ func TestNeighborhoodStats(t *testing.T) {
testF := func(t *testing.T, st *storer.DB) {
t.Helper()

putChunks(baseAddr, int(networkRadius), st)
putChunks(sister1, int(networkRadius), st)
putChunks(sister2, int(networkRadius), st)
putChunks(sister3, int(networkRadius), st)
putChunks(baseAddr, int(committedDepth), st)
putChunks(sister1, int(committedDepth), st)
putChunks(sister2, int(committedDepth), st)
putChunks(sister3, int(committedDepth), st)

neighs, err := st.NeighborhoodsStat(context.Background())
if err != nil {
Expand All @@ -726,12 +726,19 @@ func TestNeighborhoodStats(t *testing.T) {
}
}

if !neighs[0].Neighborhood.Equal(swarm.NewNeighborhood(baseAddr, networkRadius)) ||
!neighs[1].Neighborhood.Equal(swarm.NewNeighborhood(sister1, networkRadius)) ||
!neighs[2].Neighborhood.Equal(swarm.NewNeighborhood(sister2, networkRadius)) ||
!neighs[3].Neighborhood.Equal(swarm.NewNeighborhood(sister3, networkRadius)) {
if !neighs[0].Neighborhood.Equal(swarm.NewNeighborhood(baseAddr, committedDepth)) ||
!neighs[1].Neighborhood.Equal(swarm.NewNeighborhood(sister1, committedDepth)) ||
!neighs[2].Neighborhood.Equal(swarm.NewNeighborhood(sister2, committedDepth)) ||
!neighs[3].Neighborhood.Equal(swarm.NewNeighborhood(sister3, committedDepth)) {
t.Fatal("chunk addresses do not match")
}

if neighs[0].Proximity != committedDepth ||
neighs[1].Proximity != 3 ||
neighs[2].Proximity != 2 ||
neighs[3].Proximity != 2 {
t.Fatalf("wrong proximity")
}
}

t.Run("disk", func(t *testing.T) {
Expand All @@ -742,8 +749,8 @@ func TestNeighborhoodStats(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storer.StartReserveWorker(context.Background(), pullerMock.NewMockRateReporter(0), networkRadiusFunc(localRadius))
err = spinlock.Wait(time.Minute, func() bool { return storer.StorageRadius() == localRadius })
storer.StartReserveWorker(context.Background(), pullerMock.NewMockRateReporter(0), networkRadiusFunc(responsibiliyDepth))
err = spinlock.Wait(time.Minute, func() bool { return storer.StorageRadius() == responsibiliyDepth })
if err != nil {
t.Fatal(err)
}
Expand All @@ -757,8 +764,8 @@ func TestNeighborhoodStats(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storer.StartReserveWorker(context.Background(), pullerMock.NewMockRateReporter(0), networkRadiusFunc(localRadius))
err = spinlock.Wait(time.Minute, func() bool { return storer.StorageRadius() == localRadius })
storer.StartReserveWorker(context.Background(), pullerMock.NewMockRateReporter(0), networkRadiusFunc(responsibiliyDepth))
err = spinlock.Wait(time.Minute, func() bool { return storer.StorageRadius() == responsibiliyDepth })
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 32a3a27

Please sign in to comment.