@@ -80,7 +80,7 @@ public class NodeImpl extends PeerConnectionDelegate implements Node {
8080 private SyncPool pool ;
8181
8282 private Cache <Sha256Hash , TransactionMessage > TrxCache = CacheBuilder .newBuilder ()
83- .maximumSize (100_000 ).expireAfterWrite (1 , TimeUnit .HOURS )
83+ .maximumSize (100_000 ).expireAfterWrite (1 , TimeUnit .HOURS ). initialCapacity ( 100_000 )
8484 .recordStats ().build ();
8585
8686 private Cache <Sha256Hash , BlockMessage > BlockCache = CacheBuilder .newBuilder ()
@@ -475,17 +475,24 @@ 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+ advObjToFetch .remove (hash );
483+ return ;
484+ }
478485 if (idToFetch .getTime () < now - MSG_CACHE_DURATION_IN_BLOCKS * BLOCK_PRODUCED_INTERVAL ) {
479486 logger .info ("This obj is too late to fetch: " + idToFetch );
480- advObjToFetch .remove (idToFetch . getHash () );
487+ advObjToFetch .remove (hash );
481488 }else {
482489 filterActivePeer .stream ()
483- .filter (peer -> peer .getAdvObjSpreadToUs ().containsKey (idToFetch . getHash () ) && sendPackage .getSize (peer ) < MAX_TRX_PER_PEER )
490+ .filter (peer -> peer .getAdvObjSpreadToUs ().containsKey (hash ) && sendPackage .getSize (peer ) < MAX_TRX_PER_PEER )
484491 .sorted (Comparator .comparingInt (peer -> sendPackage .getSize (peer )))
485492 .findFirst ().ifPresent (peer -> {
486493 sendPackage .add (idToFetch , peer );
487494 peer .getAdvObjWeRequested ().put (idToFetch .getItem (), now );
488- advObjToFetch .remove (idToFetch . getHash () );
495+ advObjToFetch .remove (hash );
489496 });
490497 }
491498 });
@@ -640,11 +647,11 @@ public synchronized void disconnectInactive() {
640647
641648
642649 private void onHandleInventoryMessage (PeerConnection peer , InventoryMessage msg ) {
643- msg .getHashList (). forEach ( id -> {
650+ for ( Sha256Hash id : msg .getHashList ()) {
644651 if ( (msg .getInventoryType ().equals (InventoryType .TRX ) && TrxCache .getIfPresent (id ) != null ) ||
645652 (msg .getInventoryType ().equals (InventoryType .BLOCK ) && BlockCache .getIfPresent (id ) != null ) ){
646653 logger .info ("{} {} from peer {} Already exist." , msg .getInventoryType (), id , peer .getNode ().getHost ());
647- return ;
654+ continue ;
648655 }
649656 final boolean [] spreaded = {false };
650657 final boolean [] requested = {false };
@@ -681,7 +688,7 @@ private void onHandleInventoryMessage(PeerConnection peer, InventoryMessage msg)
681688 }
682689 }
683690 }
684- });
691+ }
685692 }
686693
687694 @ Override
0 commit comments