Skip to content

Commit

Permalink
add txcache check when the new tx come from the network
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Mar 29, 2018
1 parent dc827a0 commit a48b98f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ public synchronized List<AionTransaction> addPendingTransactions(List<AionTransa
BigInteger bestNonce = bestNonce(tx.getFrom());

if (txNonce.compareTo(bestNonce) > 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);
Expand Down Expand Up @@ -709,6 +714,10 @@ private List<AionTransaction> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ public List<AionTransaction> flush(Map<Address, BigInteger> 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<Address> getCacheTxAccount() {
return new HashSet<>(this.cacheTxMap.keySet());
Expand Down

0 comments on commit a48b98f

Please sign in to comment.