@@ -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.
130121func (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 }
0 commit comments