@@ -8,6 +8,7 @@ package pullsync
88
99import (
1010 "context"
11+ "encoding/binary"
1112 "encoding/hex"
1213 "errors"
1314 "fmt"
@@ -303,7 +304,32 @@ func (s *Syncer) Sync(ctx context.Context, peer swarm.Address, bin uint8, start
303304 ctr ++
304305 s .metrics .Wanted .Inc ()
305306 bv .Set (i )
307+ s .logger .Debug ("pullsync want chunk" ,
308+ "peer_address" , peer ,
309+ "bin" , bin ,
310+ "offer_idx" , i ,
311+ "chunk_address" , a ,
312+ "sum" , hex .EncodeToString (sum ),
313+ "start" , start ,
314+ "offer_topmost" , topmost ,
315+ )
316+ } else {
317+ s .logger .Debug ("pullsync skip offer, already have sum" ,
318+ "peer_address" , peer ,
319+ "bin" , bin ,
320+ "offer_idx" , i ,
321+ "chunk_address" , a ,
322+ "sum" , hex .EncodeToString (sum ),
323+ "start" , start ,
324+ "offer_topmost" , topmost ,
325+ )
306326 }
327+ } else {
328+ s .logger .Debug ("pullsync skip offer, outside storage radius" ,
329+ "peer_address" , peer ,
330+ "bin" , bin ,
331+ "chunk_address" , a ,
332+ )
307333 }
308334 }
309335
@@ -313,6 +339,7 @@ func (s *Syncer) Sync(ctx context.Context, peer swarm.Address, bin uint8, start
313339 }
314340
315341 chunksToPut := make ([]swarm.Chunk , 0 , ctr )
342+ wanted := ctr
316343
317344 var chunkErr error
318345 for ; ctr > 0 ; ctr -- {
@@ -345,17 +372,53 @@ func (s *Syncer) Sync(ctx context.Context, peer swarm.Address, bin uint8, start
345372 }
346373
347374 wantChunkID := addr .ByteString () + string (sum )
375+ stampHash , hashErr := stamp .Hash ()
376+ stampHashHex := ""
377+ if hashErr == nil {
378+ stampHashHex = hex .EncodeToString (stampHash )
379+ }
348380 if _ , ok := wantChunks [wantChunkID ]; ! ok {
349- s .logger .Debug ("want chunks" , "error" , ErrUnsolicitedChunk , "peer_address" , peer , "chunk_address" , addr )
381+ s .logger .Debug ("pullsync unsolicited delivery" ,
382+ "error" , ErrUnsolicitedChunk ,
383+ "peer_address" , peer ,
384+ "chunk_address" , addr ,
385+ "batch_id" , hex .EncodeToString (stamp .BatchID ()),
386+ "stamp_hash" , stampHashHex ,
387+ "stamp_index" , hex .EncodeToString (stamp .Index ()),
388+ "stamp_timestamp" , binary .BigEndian .Uint64 (stamp .Timestamp ()),
389+ "recomputed_sum" , hex .EncodeToString (sum ),
390+ "bin" , bin ,
391+ "offer_topmost" , topmost ,
392+ )
350393 chunkErr = errors .Join (chunkErr , ErrUnsolicitedChunk )
351394 continue
352395 }
353396
354397 delete (wantChunks , wantChunkID )
355398
399+ s .logger .Debug ("pullsync delivery accepted for want" ,
400+ "peer_address" , peer ,
401+ "chunk_address" , addr ,
402+ "batch_id" , hex .EncodeToString (stamp .BatchID ()),
403+ "stamp_hash" , stampHashHex ,
404+ "stamp_index" , hex .EncodeToString (stamp .Index ()),
405+ "stamp_timestamp" , binary .BigEndian .Uint64 (stamp .Timestamp ()),
406+ "recomputed_sum" , hex .EncodeToString (sum ),
407+ "bin" , bin ,
408+ "offer_topmost" , topmost ,
409+ )
410+
356411 chunk , err := s .validStamp (newChunk .WithStamp (stamp ))
357412 if err != nil {
358- s .logger .Debug ("unverified stamp" , "error" , err , "peer_address" , peer , "chunk_address" , newChunk )
413+ s .logger .Debug ("unverified stamp" ,
414+ "error" , err ,
415+ "peer_address" , peer ,
416+ "chunk_address" , addr ,
417+ "batch_id" , hex .EncodeToString (stamp .BatchID ()),
418+ "stamp_timestamp" , binary .BigEndian .Uint64 (stamp .Timestamp ()),
419+ "bin" , bin ,
420+ "offer_topmost" , topmost ,
421+ )
359422 chunkErr = errors .Join (chunkErr , err )
360423 continue
361424 }
@@ -390,24 +453,66 @@ func (s *Syncer) Sync(ctx context.Context, peer swarm.Address, bin uint8, start
390453 // in case of these errors, no new items are added to the storage, so it
391454 // is safe to continue with the next chunk
392455 if errors .Is (err , storage .ErrOverwriteNewerChunk ) {
393- s .logger .Debug ("overwrite newer chunk" , "error" , err , "peer_address" , peer , "chunk" , c )
456+ s .logger .Debug ("overwrite newer chunk" ,
457+ "error" , err ,
458+ "peer_address" , peer ,
459+ "chunk_address" , c .Address (),
460+ "batch_id" , hex .EncodeToString (c .Stamp ().BatchID ()),
461+ "stamp_timestamp" , binary .BigEndian .Uint64 (c .Stamp ().Timestamp ()),
462+ "bin" , bin ,
463+ )
394464 chunkErr = errors .Join (chunkErr , err )
395465 continue
396466 }
397467 // the chunk diverged from the one already stored and lost the
398468 // tie-break. The neighborhood converges on the stored chunk, so
399469 // this is an expected outcome rather than a sync error.
400470 if errors .Is (err , storage .ErrDivergentChunkRejected ) {
401- s .logger .Debug ("divergent chunk rejected" , "error" , err , "peer_address" , peer , "chunk" , c )
471+ s .logger .Debug ("divergent chunk rejected" ,
472+ "error" , err ,
473+ "peer_address" , peer ,
474+ "chunk_address" , c .Address (),
475+ "batch_id" , hex .EncodeToString (c .Stamp ().BatchID ()),
476+ "stamp_timestamp" , binary .BigEndian .Uint64 (c .Stamp ().Timestamp ()),
477+ "bin" , bin ,
478+ )
402479 s .metrics .DivergentRejected .Inc ()
403480 continue
404481 }
482+ s .logger .Debug ("pullsync reserve put failed" ,
483+ "error" , err ,
484+ "peer_address" , peer ,
485+ "chunk_address" , c .Address (),
486+ "batch_id" , hex .EncodeToString (c .Stamp ().BatchID ()),
487+ "stamp_timestamp" , binary .BigEndian .Uint64 (c .Stamp ().Timestamp ()),
488+ "bin" , bin ,
489+ )
405490 return 0 , 0 , errors .Join (chunkErr , err )
406491 }
492+ s .logger .Debug ("pullsync reserve put ok" ,
493+ "peer_address" , peer ,
494+ "chunk_address" , c .Address (),
495+ "batch_id" , hex .EncodeToString (c .Stamp ().BatchID ()),
496+ "stamp_index" , hex .EncodeToString (c .Stamp ().Index ()),
497+ "stamp_timestamp" , binary .BigEndian .Uint64 (c .Stamp ().Timestamp ()),
498+ "bin" , bin ,
499+ )
407500 chunksPut ++
408501 }
409502 }
410503
504+ if chunkErr != nil {
505+ s .logger .Debug ("pullsync sync finished with chunk errors" ,
506+ "error" , chunkErr ,
507+ "peer_address" , peer ,
508+ "bin" , bin ,
509+ "start" , start ,
510+ "offer_topmost" , topmost ,
511+ "chunks_put" , chunksPut ,
512+ "wanted" , wanted ,
513+ )
514+ }
515+
411516 return topmost , chunksPut , chunkErr
412517}
413518
@@ -424,9 +529,26 @@ func (s *Syncer) makeOffer(ctx context.Context, rn pb.Get) (*pb.Offer, []*storer
424529 o := new (pb.Offer )
425530 o .Topmost = top
426531 o .Chunks = make ([]* pb.Chunk , 0 , len (bincs ))
427- for _ , v := range bincs {
532+ for i , v := range bincs {
428533 o .Chunks = append (o .Chunks , & pb.Chunk {Address : v .Address .Bytes (), Sum : v .Sum })
534+ s .logger .Debug ("pullsync offer chunk" ,
535+ "bin" , rn .Bin ,
536+ "start" , rn .Start ,
537+ "offer_idx" , i ,
538+ "bin_id" , v .BinID ,
539+ "chunk_address" , v .Address ,
540+ "batch_id" , hex .EncodeToString (v .BatchID ),
541+ "stamp_hash" , hex .EncodeToString (v .StampHash ),
542+ "sum" , hex .EncodeToString (v .Sum ),
543+ "offer_topmost" , top ,
544+ )
429545 }
546+ s .logger .Debug ("pullsync offer summary" ,
547+ "bin" , rn .Bin ,
548+ "start" , rn .Start ,
549+ "count" , len (bincs ),
550+ "offer_topmost" , top ,
551+ )
430552 return o , bincs , nil
431553}
432554
@@ -465,7 +587,7 @@ func (s *Syncer) collectAddrs(ctx context.Context, bin uint8, start uint64) ([]*
465587 break LOOP // The stream has been closed.
466588 }
467589
468- chs = append (chs , & storer.BinC {Address : c .Address , BatchID : c .BatchID , StampHash : c .StampHash , Sum : c .Sum })
590+ chs = append (chs , & storer.BinC {Address : c .Address , BinID : c . BinID , BatchID : c .BatchID , StampHash : c .StampHash , Sum : c .Sum })
469591 if c .BinID > topmost {
470592 topmost = c .BinID
471593 }
@@ -516,11 +638,34 @@ func (s *Syncer) processWant(ctx context.Context, bincs []*storer.BinC, w *pb.Wa
516638 s .metrics .SentWanted .Inc ()
517639 ch , err := s .store .ReserveGet (ctx , c .Address , c .BatchID , c .StampHash )
518640 if err != nil {
519- s .logger .Debug ("processing want: unable to find chunk" , "chunk_address" , c .Address , "batch_id" , hex .EncodeToString (c .BatchID ))
641+ s .logger .Debug ("processing want: unable to find chunk" ,
642+ "chunk_address" , c .Address ,
643+ "batch_id" , hex .EncodeToString (c .BatchID ),
644+ "stamp_hash" , hex .EncodeToString (c .StampHash ),
645+ "bin_id" , c .BinID ,
646+ "sum" , hex .EncodeToString (c .Sum ),
647+ "offer_idx" , i ,
648+ )
520649 chunks = append (chunks , swarm .NewChunk (swarm .ZeroAddress , nil ))
521650 s .metrics .MissingChunks .Inc ()
522651 continue
523652 }
653+ stampTS := uint64 (0 )
654+ stampIndex := ""
655+ if ch .Stamp () != nil {
656+ stampTS = binary .BigEndian .Uint64 (ch .Stamp ().Timestamp ())
657+ stampIndex = hex .EncodeToString (ch .Stamp ().Index ())
658+ }
659+ s .logger .Debug ("pullsync deliver chunk" ,
660+ "offer_idx" , i ,
661+ "bin_id" , c .BinID ,
662+ "chunk_address" , c .Address ,
663+ "batch_id" , hex .EncodeToString (c .BatchID ),
664+ "stamp_hash" , hex .EncodeToString (c .StampHash ),
665+ "stamp_index" , stampIndex ,
666+ "stamp_timestamp" , stampTS ,
667+ "sum" , hex .EncodeToString (c .Sum ),
668+ )
524669 chunks = append (chunks , ch )
525670 }
526671 }
0 commit comments