Skip to content

Commit

Permalink
Revert pending state update optimization; revert snapshotAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
iamyulong committed Mar 23, 2018
1 parent f8c3386 commit 6708ddc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -554,35 +554,20 @@ private AionTxInfo getTransactionInfo(byte[] txHash, byte[] blockHash) {

private void updateState(IAionBlock block) {

List<AionTransaction> poolTxs = this.txPool.snapshotAll();
if (LOG.isDebugEnabled()) {
LOG.debug("updateState - snapshotAll tx[{}]", poolTxs.size());
}

IRepositoryCache oldPs = pendingState.startTracking();
Set<Address> accs = getTxsAccounts(block.getTransactionsList());
for (Address addr : getTxsAccounts(poolTxs)) {
if (!accs.contains(addr)) {
oldPs.getAccountState(addr);
}
}
pendingState = repository.startTracking();

pendingState.rollback();
oldPs.flush();
List<AionTransaction> pendingTxl = this.txPool.snapshotAll();

for (AionTransaction tx : poolTxs) {
if (LOG.isDebugEnabled()) {
LOG.debug("updateState - snapshotAll tx[{}]", pendingTxl.size());
}
for (AionTransaction tx : pendingTxl) {
if (LOG.isTraceEnabled()) {
LOG.trace("updateState reCheck poolTx: " + tx.toString());
}

AionTxReceipt receipt;
if (accs.contains(tx.getFrom())) {
AionTxExecSummary txSum = executeTx(tx, false);
receipt = txSum.getReceipt();
} else {
receipt = new AionTxReceipt();
LOG.debug("updateState - loop: " + tx.toString());
}

AionTxExecSummary txSum = executeTx(tx, false);
AionTxReceipt receipt = txSum.getReceipt();
receipt.setTransaction(tx);
fireTxUpdate(receipt, PendingTransactionState.PENDING, block);
}
Expand Down
33 changes: 5 additions & 28 deletions modTxPoolImpl/src/org/aion/txpool/zero/TxPoolA0.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,6 @@ public void updateBlkNrgLimit(long nrg) {
}
}

@Override
public synchronized List<TX> snapshotAll() {
List<TX> rtn = new ArrayList<>();

Map<Address, AccountState> accs = this.getFullAcc();
for (AccountState as : accs.values()) {
for(AbstractMap.SimpleEntry<ByteArrayWrapper, BigInteger> ae : as.getMap().values()) {
rtn.add(this.getMainMap().get(ae.getKey()).getTx());
}
}

LOG.info("TxPoolA0.snapshotAll return [{}] TX, poolSize[{}]", rtn.size(), getMainMap().size());

return rtn;
}

@Override
public TX getPoolTx(Address from, BigInteger txNonce) {
AbstractMap.SimpleEntry<ByteArrayWrapper, BigInteger> entry = this.getAccView(from).getMap().get(txNonce);
Expand All @@ -290,6 +274,11 @@ public List<TX> snapshot() {
return snapshot(false);
}

@Override
public synchronized List<TX> snapshotAll() {
return snapshot(true);
}

private synchronized List<TX> snapshot(boolean getAll) {
List<TX> rtn = new ArrayList<>();

Expand Down Expand Up @@ -428,16 +417,4 @@ private void removeTimeoutTxn() {
}

}












}

0 comments on commit 6708ddc

Please sign in to comment.