Skip to content

Commit

Permalink
Merge pull request #215 from aionnetwork/fix-207
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
AionJayT authored Mar 17, 2018
2 parents 7e968b7 + 9664b9d commit 34b6097
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,14 @@ public synchronized List<AionTransaction> flush(Map<Address, BigInteger> nonceMa
int cz = currectSize.get();
currectSize.set(cz - getAccuTxSize(accountCache.values().stream().collect(Collectors.toList())));

BigInteger finalBn = bn;
accountCache.entrySet().removeIf(e-> (e.getKey().compareTo(finalBn) < 0) );
Iterator<Map.Entry<BigInteger, AionTransaction>> itr = accountCache.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<BigInteger, AionTransaction> entry = itr.next();
if (entry.getKey().compareTo(bn) < 0) {
itr.remove();
}
}

currectSize.addAndGet(getAccuTxSize(accountCache.values().stream().collect(Collectors.toList())));

if (LOG.isDebugEnabled()) {
Expand Down
21 changes: 11 additions & 10 deletions modAionImpl/src/org/aion/zero/impl/pow/AionPoW.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

import static org.aion.mcf.core.ImportResult.IMPORTED_BEST;

Expand All @@ -65,7 +66,7 @@ public class AionPoW {

protected AtomicBoolean initialized = new AtomicBoolean(false);
protected AtomicBoolean newPendingTxReceived = new AtomicBoolean(false);
protected long lastUpdate = 0;
protected AtomicLong lastUpdate = new AtomicLong(0);

private AtomicBoolean shutDown = new AtomicBoolean();
private static int syncLimit = 128;
Expand Down Expand Up @@ -105,8 +106,8 @@ public void init(IAionBlockchain blockchain, IPendingState<AionTransaction> pend
Thread.sleep(100);

long now = System.currentTimeMillis();
if (now - lastUpdate > 3000 && newPendingTxReceived.compareAndSet(true, false)
|| now - lastUpdate > 10000) { // fallback, when
if (now - lastUpdate.get() > 3000 && newPendingTxReceived.compareAndSet(true, false)
|| now - lastUpdate.get() > 10000) { // fallback, when
// we never
// received any
// events
Expand Down Expand Up @@ -226,6 +227,12 @@ protected synchronized void processSolution(Solution solution) {
*/
protected synchronized void createNewBlockTemplate() {
if (!shutDown.get()) {
// TODO: Validate the trustworthiness of getNetworkBestBlock - can
// it be used in DDOS?
if (this.syncMgr.getNetworkBestBlockNumber() - blockchain.getBestBlock().getNumber() > syncLimit) {
return;
}

if (LOG.isDebugEnabled()) {
LOG.debug("Creating a new block template");
}
Expand All @@ -236,18 +243,12 @@ protected synchronized void createNewBlockTemplate() {

AionBlock newBlock = blockchain.createNewBlock(bestBlock, txs, false);

// TODO: Validate the trustworthiness of getNetworkBestBlock - can
// it be used in DDOS?
if (this.syncMgr.getNetworkBestBlockNumber() - bestBlock.getNumber() > syncLimit) {
return;
}

EventConsensus ev = new EventConsensus(EventConsensus.CALLBACK.ON_BLOCK_TEMPLATE);
ev.setFuncArgs(Collections.singletonList(newBlock));
eventMgr.newEvent(ev);

// update last timestamp
lastUpdate = System.currentTimeMillis();
lastUpdate.set(System.currentTimeMillis());
}
}

Expand Down

0 comments on commit 34b6097

Please sign in to comment.