diff --git a/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java b/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java index 00970f4450..77330f8ab6 100644 --- a/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java +++ b/modAionImpl/src/org/aion/zero/impl/blockchain/AionPendingStateImpl.java @@ -193,7 +193,7 @@ public int getPendingTxSize() { } @Override - public synchronized List getPendingTransactions() { + public List getPendingTransactions() { return this.txPool.snapshot(); } @@ -353,70 +353,70 @@ private IAionBlock findCommonAncestor(IAionBlock b1, IAionBlock b2) { @Override public void processBest(AionBlock newBlock, List receipts) { - synchronized (this) { - if (getBestBlock() != null && !getBestBlock().isParentOf(newBlock)) { - // need to switch the state to another fork + if (getBestBlock() != null && !getBestBlock().isParentOf(newBlock)) { - IAionBlock commonAncestor = findCommonAncestor(getBestBlock(), newBlock); + // need to switch the state to another fork - if (LOG.isDebugEnabled()) { - LOG.debug("New best block from another fork: " + newBlock.getShortDescr() + ", old best: " - + getBestBlock().getShortDescr() + ", ancestor: " + commonAncestor.getShortDescr()); - } - - // first return back the transactions from forked blocks - IAionBlock rollback = getBestBlock(); - while (!rollback.isEqual(commonAncestor)) { - - List atl = rollback.getTransactionsList(); - if (!atl.isEmpty()) { - this.txPool.add(atl); - } + IAionBlock commonAncestor = findCommonAncestor(getBestBlock(), newBlock); - rollback = blockchain.getBlockByHash(rollback.getParentHash()); - } + if (LOG.isDebugEnabled()) { + LOG.debug("New best block from another fork: " + newBlock.getShortDescr() + ", old best: " + + getBestBlock().getShortDescr() + ", ancestor: " + commonAncestor.getShortDescr()); + } - // rollback the state snapshot to the ancestor - pendingState = repository.getSnapshotTo(commonAncestor.getStateRoot()).startTracking(); + // first return back the transactions from forked blocks + IAionBlock rollback = getBestBlock(); + while (!rollback.isEqual(commonAncestor)) { - // next process blocks from new fork - IAionBlock main = newBlock; - List mainFork = new ArrayList<>(); - while (!main.isEqual(commonAncestor)) { - mainFork.add(main); - main = blockchain.getBlockByHash(main.getParentHash()); + List atl = rollback.getTransactionsList(); + if (!atl.isEmpty()) { + this.txPool.add(atl); } - // processing blocks from ancestor to new block - for (int i = mainFork.size() - 1; i >= 0; i--) { - processBestInternal(mainFork.get(i), null); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("PendingStateImpl.processBest: " + newBlock.getShortDescr()); - } - processBestInternal(newBlock, receipts); + rollback = blockchain.getBlockByHash(rollback.getParentHash()); } - best = newBlock; + // rollback the state snapshot to the ancestor + pendingState = repository.getSnapshotTo(commonAncestor.getStateRoot()).startTracking(); - if (LOG.isTraceEnabled()) { - LOG.trace("PendingStateImpl.processBest: updateState"); + // next process blocks from new fork + IAionBlock main = newBlock; + List mainFork = new ArrayList<>(); + while (!main.isEqual(commonAncestor)) { + mainFork.add(main); + main = blockchain.getBlockByHash(main.getParentHash()); } - updateState(best); - if (LOG.isTraceEnabled()) { - LOG.trace("PendingStateImpl.processBest: nonceMgr.flush()"); + // processing blocks from ancestor to new block + for (int i = mainFork.size() - 1; i >= 0; i--) { + processBestInternal(mainFork.get(i), null); } - nonceMgr.flush(); - - if (LOG.isTraceEnabled()) { - LOG.trace("PendingStateImpl.processBest: txPool.updateBlkNrgLimit"); + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("PendingStateImpl.processBest: " + newBlock.getShortDescr()); } - txPool.updateBlkNrgLimit(best.getNrgLimit()); + processBestInternal(newBlock, receipts); + } + + best = newBlock; + + if (LOG.isTraceEnabled()) { + LOG.trace("PendingStateImpl.processBest: updateState"); + } + updateState(best); + + if (LOG.isTraceEnabled()) { + LOG.trace("PendingStateImpl.processBest: nonceMgr.flush()"); + } + nonceMgr.flush(); + + if (LOG.isTraceEnabled()) { + LOG.trace("PendingStateImpl.processBest: txPool.updateBlkNrgLimit"); } + txPool.updateBlkNrgLimit(best.getNrgLimit()); + IEvent evtChange = new EventTx(EventTx.CALLBACK.PENDINGTXSTATECHANGE0); this.evtMgr.newEvent(evtChange); } @@ -579,7 +579,7 @@ public List newTransactions(List txSet) { * account address * @return transaction nonce. */ - public synchronized Map.Entry bestNonceSet(Address addr) { + public Map.Entry bestNonceSet(Address addr) { return this.txPool.bestNonceSet(addr); } diff --git a/modAionImpl/src/org/aion/zero/impl/pow/AionPoW.java b/modAionImpl/src/org/aion/zero/impl/pow/AionPoW.java index 3764893aaa..071b5836ca 100644 --- a/modAionImpl/src/org/aion/zero/impl/pow/AionPoW.java +++ b/modAionImpl/src/org/aion/zero/impl/pow/AionPoW.java @@ -179,10 +179,9 @@ public void onPendingTxReceived(ITransaction tx) { * @param solution * The generated equihash solution */ - protected synchronized void processSolution(Solution solution) { + protected void processSolution(Solution solution) { if (!shutDown.get()) { if (LOG.isDebugEnabled()) { - LOG.debug("New solution: block hash [{}]", Hex.toHexString(solution.getBlock().getHash())); LOG.debug("Best block num [{}]", blockchain.getBestBlock().getNumber()); LOG.debug("Best block nonce [{}]", Hex.toHexString(blockchain.getBestBlock().getNonce())); LOG.debug("Best block hash [{}]", Hex.toHexString(blockchain.getBestBlock().getHash())); @@ -242,10 +241,6 @@ protected synchronized void createNewBlockTemplate() { return; } - if (LOG.isDebugEnabled()) { - LOG.debug("New template: block hash [{}]", Hex.toHexString(newBlock.getHash())); - } - EventConsensus ev = new EventConsensus(EventConsensus.CALLBACK.ON_BLOCK_TEMPLATE); ev.setFuncArgs(Collections.singletonList(newBlock)); eventMgr.newEvent(ev); diff --git a/modTxPoolImpl/src/org/aion/txpool/zero/TxPoolA0.java b/modTxPoolImpl/src/org/aion/txpool/zero/TxPoolA0.java index f8d3ce9d0a..2d2a2377ff 100644 --- a/modTxPoolImpl/src/org/aion/txpool/zero/TxPoolA0.java +++ b/modTxPoolImpl/src/org/aion/txpool/zero/TxPoolA0.java @@ -219,8 +219,8 @@ public synchronized List remove(List txs) { this.updateAccPoolState(); this.updateFeeMap(); - if (LOG.isDebugEnabled()) { - LOG.debug("TxPoolA0.remove TX remove [{}] removed [{}]", txs.size(), removedTxl.size()); + if (LOG.isInfoEnabled()) { + LOG.info("TxPoolA0.remove TX remove [{}] removed [{}]", txs.size(), removedTxl.size()); } return removedTxl; @@ -262,12 +262,10 @@ public synchronized List snapshot() { int cnt_txSz = blkSizeLimit; long cnt_nrg = blkNrgLimit.get(); Set snapshotSet = new HashSet<>(); - for (Entry>> e : this.getFeeView() .entrySet()) { Map> tpl = e.getValue(); - for (Entry> pair : tpl.entrySet()) { // Check the small nonce tx must been picked before put the high nonce tx ByteArrayWrapper dependTx = pair.getValue().getDependTx(); @@ -300,6 +298,9 @@ public synchronized List snapshot() { LOG.error("Snapshot txn exception", ex.toString()); } + if (LOG.isInfoEnabled()) { + LOG.info("TxPoolA0.snapshot return [{}] TX", rtn.size()); + } return rtn; } } else { @@ -307,6 +308,7 @@ public synchronized List snapshot() { LOG.warn("Reach blockLimit: txSize[{}], nrgConsume[{}], txn_number[{}]", cnt_txSz, cnt_nrg, rtn.size()); } + return rtn; } } @@ -314,8 +316,9 @@ public synchronized List snapshot() { } } - if (LOG.isDebugEnabled()) { - LOG.debug("TxPoolA0.snapshot return [{}] TX", rtn.size()); + + if (LOG.isInfoEnabled()) { + LOG.info("TxPoolA0.snapshot return [{}] TX", rtn.size()); } return rtn;