@@ -475,17 +475,23 @@ private void consumerAdvObjToFetch() {
475475 InvToSend sendPackage = new InvToSend ();
476476 long now = Time .getCurrentMillis ();
477477 advObjToFetch .values ().stream ().sorted (PriorItem ::compareTo ).forEach (idToFetch -> {
478+ Sha256Hash hash = idToFetch .getHash ();
479+ if ( (idToFetch .getType ().equals (InventoryType .TRX ) && TrxCache .getIfPresent (hash ) != null ) ||
480+ (idToFetch .getType ().equals (InventoryType .BLOCK ) && BlockCache .getIfPresent (hash ) != null ) ){
481+ logger .info ("{} {} Already exist." , idToFetch .getType (), hash );
482+ return ;
483+ }
478484 if (idToFetch .getTime () < now - MSG_CACHE_DURATION_IN_BLOCKS * BLOCK_PRODUCED_INTERVAL ) {
479485 logger .info ("This obj is too late to fetch: " + idToFetch );
480- advObjToFetch .remove (idToFetch . getHash () );
486+ advObjToFetch .remove (hash );
481487 }else {
482488 filterActivePeer .stream ()
483- .filter (peer -> peer .getAdvObjSpreadToUs ().containsKey (idToFetch . getHash () ) && sendPackage .getSize (peer ) < MAX_TRX_PER_PEER )
489+ .filter (peer -> peer .getAdvObjSpreadToUs ().containsKey (hash ) && sendPackage .getSize (peer ) < MAX_TRX_PER_PEER )
484490 .sorted (Comparator .comparingInt (peer -> sendPackage .getSize (peer )))
485491 .findFirst ().ifPresent (peer -> {
486492 sendPackage .add (idToFetch , peer );
487493 peer .getAdvObjWeRequested ().put (idToFetch .getItem (), now );
488- advObjToFetch .remove (idToFetch . getHash () );
494+ advObjToFetch .remove (hash );
489495 });
490496 }
491497 });
@@ -645,11 +651,11 @@ public synchronized void disconnectInactive() {
645651
646652
647653 private void onHandleInventoryMessage (PeerConnection peer , InventoryMessage msg ) {
648- msg .getHashList (). forEach ( id -> {
654+ for ( Sha256Hash id : msg .getHashList ()) {
649655 if ( (msg .getInventoryType ().equals (InventoryType .TRX ) && TrxCache .getIfPresent (id ) != null ) ||
650656 (msg .getInventoryType ().equals (InventoryType .BLOCK ) && BlockCache .getIfPresent (id ) != null ) ){
651657 logger .info ("{} {} from peer {} Already exist." , msg .getInventoryType (), id , peer .getNode ().getHost ());
652- return ;
658+ continue ;
653659 }
654660 final boolean [] spreaded = {false };
655661 final boolean [] requested = {false };
@@ -686,7 +692,7 @@ private void onHandleInventoryMessage(PeerConnection peer, InventoryMessage msg)
686692 }
687693 }
688694 }
689- });
695+ }
690696 }
691697
692698 @ Override
0 commit comments