From a48b98f9e18f3248b8f813b2996b16e62e58be02 Mon Sep 17 00:00:00 2001 From: AionJayT Date: Thu, 29 Mar 2018 16:50:48 -0400 Subject: [PATCH] add txcache check when the new tx come from the network --- .../aion/zero/impl/blockchain/AionPendingStateImpl.java | 9 +++++++++ .../org/aion/zero/impl/blockchain/PendingTxCache.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java b/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java index 382b77a819..9e8a83f6df 100644 --- a/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java +++ b/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java @@ -260,6 +260,11 @@ public synchronized List addPendingTransactions(List 0) { + + if (!isInTxCache(tx.getFrom(), tx.getNonceBI())) { + AionImpl.inst().broadcastTransactions(Collections.singletonList(tx)); + } + addToTxCache(tx); LOG.debug("Adding transaction to cache: from = {}, nonce = {}", tx.getFrom(), txNonce); @@ -709,6 +714,10 @@ private List addToTxCache(AionTransaction tx) { return this.pendingTxCache.addCacheTx(tx); } + private boolean isInTxCache(Address addr, BigInteger nonce) { + return this.pendingTxCache.isInCache(addr, nonce); + } + @Override public void shutDown() { ees.shutdown(); diff --git a/modAionImpl/src/org/aion/zero/impl/blockchain/PendingTxCache.java b/modAionImpl/src/org/aion/zero/impl/blockchain/PendingTxCache.java index 086a17d955..f9d66ed1f4 100644 --- a/modAionImpl/src/org/aion/zero/impl/blockchain/PendingTxCache.java +++ b/modAionImpl/src/org/aion/zero/impl/blockchain/PendingTxCache.java @@ -202,6 +202,13 @@ public List flush(Map nonceMap) { return processableTx; } + public boolean isInCache(Address addr , BigInteger nonce) { + if (this.cacheTxMap.get(addr) != null) { + return (this.cacheTxMap.get(addr).get(nonce) != null); + } + + return false; + } Set
getCacheTxAccount() { return new HashSet<>(this.cacheTxMap.keySet());