Skip to content

Commit 4fc3ae5

Browse files
committed
fix: clean up
1 parent 9318f24 commit 4fc3ae5

8 files changed

Lines changed: 25 additions & 51 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/ethereum/go-ethereum v1.17.3
1212
github.com/ethersphere/batch-archive v0.0.8
1313
github.com/ethersphere/go-price-oracle-abi v0.6.9
14-
github.com/ethersphere/go-storage-incentives-abi v0.9.3-rc4
14+
github.com/ethersphere/go-storage-incentives-abi v0.9.4
1515
github.com/ethersphere/go-sw3-abi v0.6.9
1616
github.com/ethersphere/langos v1.0.0
1717
github.com/go-playground/validator/v10 v10.19.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ github.com/ethersphere/batch-archive v0.0.8 h1:Y6ipqJfcjLbOn+2Rn5tMrOvrMH7pzF0Yh
250250
github.com/ethersphere/batch-archive v0.0.8/go.mod h1:41BPb192NoK9CYjNB8BAE1J2MtiI/5aq0Wtas5O7A7Q=
251251
github.com/ethersphere/go-price-oracle-abi v0.6.9 h1:bseen6he3PZv5GHOm+KD6s4awaFmVSD9LFx+HpB6rCU=
252252
github.com/ethersphere/go-price-oracle-abi v0.6.9/go.mod h1:sI/Qj4/zJ23/b1enzwMMv0/hLTpPNVNacEwCWjo6yBk=
253-
github.com/ethersphere/go-storage-incentives-abi v0.9.3-rc4 h1:YK9FpiQz29ctU5V46CuwMt+4X5Xn8FTBwy6E2v/ix8s=
254-
github.com/ethersphere/go-storage-incentives-abi v0.9.3-rc4/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
253+
github.com/ethersphere/go-storage-incentives-abi v0.9.4 h1:mSIWXQXg5OQmH10QvXMV5w0vbSibFMaRlBL37gPLTM0=
254+
github.com/ethersphere/go-storage-incentives-abi v0.9.4/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
255255
github.com/ethersphere/go-sw3-abi v0.6.9 h1:TnWLnYkWE5UvC17mQBdUmdkzhPhO8GcqvWy4wvd1QJQ=
256256
github.com/ethersphere/go-sw3-abi v0.6.9/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
257257
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=

pkg/pullsync/pullsync.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ func (s *Syncer) Sync(ctx context.Context, peer swarm.Address, bin uint8, start
345345
}
346346

347347
wantChunkID := addr.ByteString() + string(sum)
348-
349348
if _, ok := wantChunks[wantChunkID]; !ok {
350349
s.logger.Debug("want chunks", "error", ErrUnsolicitedChunk, "peer_address", peer, "chunk_address", addr)
351350
chunkErr = errors.Join(chunkErr, ErrUnsolicitedChunk)
@@ -426,7 +425,6 @@ func (s *Syncer) makeOffer(ctx context.Context, rn pb.Get) (*pb.Offer, []*storer
426425
o.Chunks = make([]*pb.Chunk, 0, len(bincs))
427426
for _, v := range bincs {
428427
o.Chunks = append(o.Chunks, &pb.Chunk{Address: v.Address.Bytes(), Sum: v.Sum})
429-
430428
}
431429
return o, bincs, nil
432430
}

pkg/storage/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func ChunkSumFromParts(batchID, stampHash []byte, ch swarm.Chunk) ([]byte, error
343343
return h.Sum(nil)[:ChunkSumSize], nil
344344
}
345345

346-
// DivergentChunkWins reports whether the incoming chunk should replace the
346+
// DivergentSocChunkWins reports whether the incoming chunk should replace the
347347
// stored one when the two share an address, batch and stamp but wrap different
348348
// content. Both chunks must be single owner chunks; a content addressed chunk
349349
// cannot diverge, since its address is the hash of its own payload.
@@ -352,7 +352,7 @@ func ChunkSumFromParts(batchID, stampHash []byte, ch swarm.Chunk) ([]byte, error
352352
// The rule depends on nothing but the two payloads, so every node in the
353353
// neighborhood converges on the same chunk regardless of the order in which
354354
// they arrive.
355-
func DivergentChunkWins(stored, incoming swarm.Chunk) (bool, error) {
355+
func DivergentSocChunkWins(stored, incoming swarm.Chunk) (bool, error) {
356356
storedAddr, err := wrappedAddress(stored)
357357
if err != nil {
358358
return false, fmt.Errorf("stored chunk: %w", err)

pkg/storage/storage_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestIdentityAddress(t *testing.T) {
7070
data := []byte("data")
7171
cacChunk, err := cac.New(data)
7272
if err != nil {
73-
t.Fatalf("failed to create content addressed chunk: %v", err)
73+
t.Fatalf("create content addressed chunk: %v", err)
7474
}
7575

7676
// Call IdentityAddress with the CAC
@@ -236,7 +236,7 @@ func FuzzChunkSum(f *testing.F) {
236236
})
237237
}
238238

239-
func TestDivergentChunkWins(t *testing.T) {
239+
func TestDivergentSocChunkWins(t *testing.T) {
240240
t.Parallel()
241241

242242
privKey, err := crypto.GenerateSecp256k1Key()
@@ -275,7 +275,7 @@ func TestDivergentChunkWins(t *testing.T) {
275275
t.Run("lower wrapped address wins", func(t *testing.T) {
276276
t.Parallel()
277277

278-
wins, err := storage.DivergentChunkWins(higher, lower)
278+
wins, err := storage.DivergentSocChunkWins(higher, lower)
279279
if err != nil {
280280
t.Fatal(err)
281281
}
@@ -287,7 +287,7 @@ func TestDivergentChunkWins(t *testing.T) {
287287
t.Run("tie-break is antisymmetric", func(t *testing.T) {
288288
t.Parallel()
289289

290-
wins, err := storage.DivergentChunkWins(lower, higher)
290+
wins, err := storage.DivergentSocChunkWins(lower, higher)
291291
if err != nil {
292292
t.Fatal(err)
293293
}
@@ -299,7 +299,7 @@ func TestDivergentChunkWins(t *testing.T) {
299299
t.Run("a chunk does not displace itself", func(t *testing.T) {
300300
t.Parallel()
301301

302-
wins, err := storage.DivergentChunkWins(lower, lower)
302+
wins, err := storage.DivergentSocChunkWins(lower, lower)
303303
if err != nil {
304304
t.Fatal(err)
305305
}
@@ -312,10 +312,10 @@ func TestDivergentChunkWins(t *testing.T) {
312312
t.Parallel()
313313

314314
cac := testingc.GenerateTestRandomChunk()
315-
if _, err := storage.DivergentChunkWins(cac, lower); !errors.Is(err, storage.ErrUnknownChunkType) {
315+
if _, err := storage.DivergentSocChunkWins(cac, lower); !errors.Is(err, storage.ErrUnknownChunkType) {
316316
t.Fatalf("expected ErrUnknownChunkType, got %v", err)
317317
}
318-
if _, err := storage.DivergentChunkWins(lower, cac); !errors.Is(err, storage.ErrUnknownChunkType) {
318+
if _, err := storage.DivergentSocChunkWins(lower, cac); !errors.Is(err, storage.ErrUnknownChunkType) {
319319
t.Fatalf("expected ErrUnknownChunkType, got %v", err)
320320
}
321321
})

pkg/storer/internal/reserve/fuzz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func FuzzChunkBinItemUnmarshal(f *testing.F) {
4747
}
4848
out, err := item.Marshal()
4949
if err != nil {
50-
t.Fatalf("unmarshaled value failed to marshal: %v", err)
50+
t.Fatalf("marshal after unmarshal: %v", err)
5151
}
5252
if !bytes.Equal(out, data) {
5353
t.Fatal("marshal round-trip changed the value")

pkg/storer/internal/reserve/reserve.go

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/ethersphere/bee/v2/pkg/log"
2020
"github.com/ethersphere/bee/v2/pkg/postage"
2121
"github.com/ethersphere/bee/v2/pkg/safe"
22+
"github.com/ethersphere/bee/v2/pkg/soc"
2223
"github.com/ethersphere/bee/v2/pkg/storage"
2324
"github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstamp"
2425
pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning"
@@ -100,7 +101,7 @@ func New(
100101
// the existing chunk if the new chunk has a higher stamp timestamp (regardless of batch type).
101102
// 3. A new chunk that has the same address belonging to the same stamp index with an already stored chunk will overwrite the existing chunk
102103
// if the new chunk has a higher stamp timestamp (regardless of batch type and chunk type, eg CAC & SOC).
103-
// 4. Two different chunk addresses that share the same batch stamp index and timestamp are settled by a tie-break:
104+
// 4. Two different chunk addresses that share the same batch, stamp index and timestamp are settled by a tie-break:
104105
// the lexicographically lower chunk address wins. The loser is rejected; the winner replaces the stored chunk
105106
// through the usual remove-and-store path (including a fresh bin ID for pullsync).
106107
// 5. Two single owner chunks that share an address under different stamps (any batch or stamp
@@ -112,23 +113,12 @@ func (r *Reserve) Put(ctx context.Context, chunk swarm.Chunk) error {
112113
return err
113114
}
114115
if socReplaced {
115-
// A single owner chunk's payload is stored once per address while index
116-
// entries exist per stamp: replacing the payload invalidates the
117-
// divergence checksums of co-resident entries under other stamps. The
118-
// refresh runs after the put transaction, with no locks held, because
119-
// it takes the sibling entries' batch locks (see refreshSiblingSums).
120-
if err := r.refreshSiblingSums(ctx, chunk.Address()); err != nil {
121-
return err
122-
}
116+
return r.refreshSiblingSums(ctx, chunk.Address())
123117
}
124118
return nil
125119
}
126120

127-
// putChunk stores the chunk and reports whether the shared payload of an
128-
// already stored single owner chunk was replaced, in which case the sums of
129-
// co-resident entries must be refreshed by the caller.
130121
func (r *Reserve) putChunk(ctx context.Context, chunk swarm.Chunk) (socReplaced bool, err error) {
131-
// batchID lock, Put vs Eviction
132122
r.multx.Lock(string(chunk.Stamp().BatchID()))
133123
defer r.multx.Unlock(string(chunk.Stamp().BatchID()))
134124

@@ -198,7 +188,7 @@ func (r *Reserve) putChunk(ctx context.Context, chunk swarm.Chunk) (socReplaced
198188
shouldIncReserveSize, err = r.putCAC(ctx, chunk, sum, stampHash, bin)
199189
}
200190
if err != nil {
201-
r.logger.Error(err, "put chunk failed",
191+
r.logger.Error(err, "put chunk",
202192
"address", chunk.Address(), "batch_id", batchHex,
203193
"stamp_hash", stampHashHex, "stamp_index", stampIndexHex,
204194
"stamp_timestamp", stampTS, "chunk_type", chunkType,
@@ -215,7 +205,7 @@ func (r *Reserve) putSOC(ctx context.Context, chunk swarm.Chunk, sum, stampHash
215205
err = r.st.Run(ctx, func(s transaction.Store) error {
216206
oldStampIndex, loaded, err := stampindex.LoadOrStore(s.IndexStore(), reserveScope, chunk)
217207
if err != nil {
218-
return fmt.Errorf("load or store stamp index for chunk %v has fail: %w", chunk, err)
208+
return fmt.Errorf("load or store stamp index for chunk %v: %w", chunk, err)
219209
}
220210

221211
if loaded {
@@ -256,7 +246,7 @@ func (r *Reserve) putCAC(ctx context.Context, chunk swarm.Chunk, sum, stampHash
256246
err = r.st.Run(ctx, func(s transaction.Store) error {
257247
oldStampIndex, loaded, err := stampindex.LoadOrStore(s.IndexStore(), reserveScope, chunk)
258248
if err != nil {
259-
return fmt.Errorf("load or store stamp index for chunk %v has fail: %w", chunk, err)
249+
return fmt.Errorf("load or store stamp index for chunk %v: %w", chunk, err)
260250
}
261251

262252
if loaded {
@@ -374,12 +364,12 @@ func (r *Reserve) resolveStampIndexCollision(
374364

375365
err = r.removeChunk(ctx, s, oldStampIndex.ChunkAddress, oldStampIndex.BatchID, oldStampIndex.StampHash)
376366
if err != nil {
377-
return false, fmt.Errorf("failed removing older chunk %s: %w", oldStampIndex.ChunkAddress, err)
367+
return false, fmt.Errorf("remove older chunk %s: %w", oldStampIndex.ChunkAddress, err)
378368
}
379369

380370
err = stampindex.Store(s.IndexStore(), reserveScope, chunk)
381371
if err != nil {
382-
return false, fmt.Errorf("failed updating stamp index: %w", err)
372+
return false, fmt.Errorf("update stamp index: %w", err)
383373
}
384374

385375
return false, nil
@@ -550,13 +540,13 @@ func (r *Reserve) resolveDivergence(
550540
return r.st.Run(ctx, func(s transaction.Store) error {
551541
stored, err := s.ChunkStore().Get(ctx, chunk.Address())
552542
if err != nil {
553-
return fmt.Errorf("failed loading diverging chunk %s: %w", chunk.Address(), err)
543+
return fmt.Errorf("load diverging chunk %s: %w", chunk.Address(), err)
554544
}
555545
// ChunkStore returns payload only; stamp is in the chunkstamp index.
556546
// stampHash is the same key Has() already confirmed for this put.
557547
stamp, err := chunkstamp.LoadWithStampHash(s.IndexStore(), reserveScope, chunk.Address(), stampHash)
558548
if err != nil {
559-
return fmt.Errorf("failed loading stamp for diverging chunk %s: %w", chunk.Address(), err)
549+
return fmt.Errorf("load stamp for diverging chunk %s: %w", chunk.Address(), err)
560550
}
561551
stored = stored.WithStamp(stamp)
562552

@@ -585,7 +575,7 @@ func (r *Reserve) resolveDivergence(
585575
}
586576
}
587577

588-
wins, err := storage.DivergentChunkWins(stored, chunk)
578+
wins, err := storage.DivergentSocChunkWins(stored, chunk)
589579
if err != nil {
590580
return fmt.Errorf("divergence tie-break for chunk %s: %w", chunk.Address(), err)
591581
}

pkg/storer/reserve.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package storer
66

77
import (
88
"context"
9-
"encoding/binary"
109
"encoding/hex"
1110
"errors"
1211
"fmt"
@@ -311,24 +310,11 @@ func (db *DB) ReservePutter() storage.Putter {
311310
return putterWithMetrics{
312311
storage.PutterFunc(
313312
func(ctx context.Context, chunk swarm.Chunk) error {
314-
stampTS := binary.BigEndian.Uint64(chunk.Stamp().Timestamp())
315-
batchHex := hex.EncodeToString(chunk.Stamp().BatchID())
316313
err := db.reserve.Put(ctx, chunk)
317314
if err != nil {
318-
db.logger.Debug("reserve put error",
319-
"error", err,
320-
"address", chunk.Address(),
321-
"batch_id", batchHex,
322-
"stamp_timestamp", stampTS,
323-
)
315+
db.logger.Debug("reserve put error", "error", err)
324316
return fmt.Errorf("reserve putter.Put: %w", err)
325317
}
326-
db.logger.Debug("reserve put ok",
327-
"address", chunk.Address(),
328-
"batch_id", batchHex,
329-
"stamp_index", hex.EncodeToString(chunk.Stamp().Index()),
330-
"stamp_timestamp", stampTS,
331-
)
332318
db.reserveBinEvents.Trigger(string(db.po(chunk.Address())))
333319
if !db.reserve.IsWithinCapacity() {
334320
db.events.Trigger(reserveOverCapacity)

0 commit comments

Comments
 (0)