@@ -460,7 +460,7 @@ func (s *DHT) fetchAndAddLocalKeys(ctx context.Context, hexKeys []string, result
460460}
461461
462462// BatchRetrieve data from the networking using keys. Keys are the base58 encoded
463- func (s * DHT ) BatchRetrieve (ctx context.Context , keys []string , required int32 , localOnly ... bool ) (result map [string ][]byte , err error ) {
463+ func (s * DHT ) BatchRetrieve (ctx context.Context , keys []string , required int32 , txID string , localOnly ... bool ) (result map [string ][]byte , err error ) {
464464 result = make (map [string ][]byte ) // the result of the batch retrieve - keys are b58 encoded (as received in request)
465465 var resMap sync.Map // the result of the batch retrieve - keys are b58 encoded
466466 var foundLocalCount int32 // the number of values found so far
@@ -478,7 +478,7 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
478478
479479 k , err := hex .DecodeString (hexKey )
480480 if err != nil {
481- log .WithContext (ctx ).WithError (err ).WithField ("key" , hexKey ).Error ("failed to decode hex key in resMap.Range" )
481+ log .WithContext (ctx ).WithError (err ).WithField ("key" , hexKey ).WithField ( "txid" , txID ). Error ("failed to decode hex key in resMap.Range" )
482482 return true
483483 }
484484
@@ -501,7 +501,8 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
501501
502502 self := & Node {ID : s .ht .self .ID , IP : s .externalIP , Port : s .ht .self .Port }
503503 self .SetHashedID ()
504- log .WithContext (ctx ).WithField ("self" , self .String ()).Info ("batch retrieve" )
504+ log .WithContext (ctx ).WithField ("self" , self .String ()).
505+ WithField ("txid" , txID ).Info ("batch retrieve" )
505506
506507 // populate hexKeys and hashes
507508 for i , key := range keys {
@@ -512,7 +513,7 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
512513 hashes [i ] = decoded
513514 hexKeys [i ] = hex .EncodeToString (decoded )
514515 }
515- log .WithContext (ctx ).WithField ("self" , self .String ()).Info ("populated keys and hashes" )
516+ log .WithContext (ctx ).WithField ("self" , self .String ()).WithField ( "txid" , txID ). Info ("populated keys and hashes" )
516517
517518 // Add nodes from route table to known nodes map
518519 for _ , node := range s .ht .nodes () {
@@ -531,7 +532,7 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
531532 responses , _ := s .batchFindNode (ctx , hashes [:lenOfKeys ], knownNodes , make (map [string ]bool ))
532533 for response := range responses {
533534 if response .Error != nil {
534- log .WithContext (ctx ).WithError (response .Error ).Error ("batch find node failed on a node" )
535+ log .WithContext (ctx ).WithError (response .Error ).WithField ( "txid" , txID ). Error ("batch find node failed on a node" )
535536 }
536537
537538 if response .Message == nil {
@@ -558,7 +559,7 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
558559 s .addKnownNodes (top6 .Nodes , knownNodes )
559560 }
560561
561- log .WithContext (ctx ).Info ("closest contacts populated, fetching local keys now" )
562+ log .WithContext (ctx ).WithField ( "txid" , txID ). Info ("closest contacts populated, fetching local keys now" )
562563
563564 // remove self from the map
564565 delete (knownNodes , string (self .ID ))
@@ -567,7 +568,7 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
567568 if err != nil {
568569 return nil , fmt .Errorf ("fetch and add local keys: %v" , err )
569570 }
570- log .WithContext (ctx ).WithField ("local-foundCount" , foundLocalCount ).Info ("batch find values count" )
571+ log .WithContext (ctx ).WithField ("txid" , txID ). WithField ( " local-foundCount" , foundLocalCount ).Info ("batch find values count" )
571572
572573 if foundLocalCount >= required {
573574 return result , nil
@@ -586,7 +587,7 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
586587 gctx , cancel := context .WithCancel (ctx )
587588 defer cancel ()
588589
589- log .WithContext (ctx ).WithField ("parallel batches" , parallelBatches ).Info ("begin iterate batch get values" )
590+ log .WithContext (ctx ).WithField ("txid" , txID ). WithField ( " parallel batches" , parallelBatches ).Info ("begin iterate batch get values" )
590591 // Process in batches
591592 for start := 0 ; start < len (keys ); start += batchSize {
592593 end := start + batchSize
@@ -626,12 +627,12 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
626627 }
627628
628629 log .WithContext (gctx ).WithField ("len(fetchMap)" , len (fetchMap )).WithField ("len(hexKeys)" , len (hexKeys )).WithField ("len(keys)" , len (keys )).
629- WithField ("network-found" , networkFound ).Info ("fetch map" )
630+ WithField ("network-found" , networkFound ).WithField ( "txid" , txID ). Info ("fetch map" )
630631
631632 // Iterate through the network to get the values for the current batch
632633 foundCount , _ , batchErr := s .iterateBatchGetValues (gctx , knownNodes , batchKeys , batchHexKeys , fetchMap , & resMap , required , foundLocalCount + networkFound )
633634 if batchErr != nil {
634- log .WithContext (gctx ).WithError (batchErr ).Error ("iterate batch get values failed" )
635+ log .WithContext (gctx ).WithError (batchErr ).WithField ( "txid" , txID ). Error ("iterate batch get values failed" )
635636 }
636637
637638 // Update the global counter for found values
@@ -643,9 +644,9 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
643644 }
644645 }(batchKeys , batchHexKeys )
645646 }
646- log .WithContext (ctx ).Info ("called iterate batch get values - waiting for workers to finish" )
647+ log .WithContext (ctx ).WithField ( "txid" , txID ). Info ("called iterate batch get values - waiting for workers to finish" )
647648 wg .Wait () // Wait for all goroutines to finish
648- log .WithContext (ctx ).Info ("iterate batch get values workers done" )
649+ log .WithContext (ctx ).WithField ( "txid" , txID ). Info ("iterate batch get values workers done" )
649650
650651 return result , nil
651652}
0 commit comments