use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method timeout2.
@Test
public void timeout2() {
Properties config = new Properties();
// still 10 sec
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "1");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = getMockTransaction(30000L);
tp.add(txnl);
tp.snapshot(TimeUnit.MICROSECONDS.toSeconds(txnl.get(0).tx.getTimeStampBI().longValue()) + 10);
Assert.assertEquals(1, tp.size());
tp.snapshot(TimeUnit.MICROSECONDS.toSeconds(txnl.get(0).tx.getTimeStampBI().longValue()) + 11);
Assert.assertEquals(0, tp.size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method addTxWithSameNonce.
@Test
public void addTxWithSameNonce() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
TxPoolV1 tp = new TxPoolV1(config);
PooledTransaction pooledTx = genTransaction(BigInteger.ONE.toByteArray(), Constant.MIN_ENERGY_CONSUME + 100);
PooledTransaction pooledTx2 = genTransaction(BigInteger.ONE.toByteArray(), Constant.MIN_ENERGY_CONSUME + 101);
tp.add(Collections.singletonList(pooledTx));
tp.add(Collections.singletonList(pooledTx2));
Assert.assertEquals(1, tp.size());
List<AionTransaction> txl = tp.snapshot();
Assert.assertEquals(1, txl.size());
Assert.assertEquals(pooledTx.tx, txl.get(0));
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class AionPendingStateImpl method rerunTxsInPool.
private void rerunTxsInPool(Block block) {
addRepayTxToTxPool();
List<AionTransaction> pendingTxl = txPool.snapshotAll();
LOGGER_TX.info("rerunTxsInPool - snapshotAll tx[{}]", pendingTxl.size());
if (!pendingTxl.isEmpty()) {
for (AionTransaction tx : pendingTxl) {
LOGGER_TX.debug("rerunTxsInPool - loop: {}", tx);
AionTxExecSummary txSum = executeTx(tx);
AionTxReceipt receipt = txSum.getReceipt();
receipt.setTransaction(tx);
if (txSum.isRejected()) {
LOGGER_TX.debug("Invalid transaction in txPool: {}", tx);
txPool.remove(new PooledTransaction(tx, receipt.getEnergyUsed()));
removeBackupDBPendingTx(tx.getTransactionHash());
fireTxUpdate(receipt, PendingTransactionState.DROPPED, block);
} else {
if (repayTransaction.contains(tx)) {
txPool.updatePoolTransaction(new PooledTransaction(tx, receipt.getEnergyUsed()));
}
fireTxUpdate(receipt, PendingTransactionState.PENDING, block);
}
}
}
repayTransaction.clear();
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1 method checkRepayTransaction.
private ByteArrayWrapper checkRepayTransaction(AionTransaction tx) {
AionAddress sender = tx.getSenderAddress();
BigInteger nonce = tx.getNonceBI();
long price = tx.getEnergyPrice();
Map<BigInteger, ByteArrayWrapper> accountInfo = accountView.get(sender);
if (accountInfo != null) {
ByteArrayWrapper oldTx = accountInfo.get(nonce);
if (oldTx == null) {
LOG_TXPOOL.trace("Cannot find the tx has same sender and the nonce in the pool. {}", tx);
return null;
}
PooledTransaction pTx = poolTransactions.get(oldTx);
LOG_TXPOOL.debug("Original tx[{}], Repay tx[{}]", pTx.tx, tx);
long pTxPrice = pTx.tx.getEnergyPrice();
return (price >= pTxPrice * 2) ? oldTx : ByteArrayWrapper.wrap(tx.getTransactionHash());
} else {
LOG_TXPOOL.trace("Cannot find the tx has same sender in the pool. {}", tx);
return null;
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1 method clearOutDateTransaction.
List<PooledTransaction> clearOutDateTransaction(long outDateTime) {
List<PooledTransaction> clearedTransactions = new ArrayList<>();
for (Set<ByteArrayWrapper> set : timeView.headMap(outDateTime).values()) {
for (ByteArrayWrapper txHash : set) {
PooledTransaction removedTx = poolTransactions.remove(txHash);
if (removedTx == null) {
LOG_TXPOOL.debug("Did not find the transaction hash:{} in the pool", txHash);
continue;
}
LOG_TXPOOL.debug("Removing tx[{}]", removedTx.tx);
Set<ByteArrayWrapper> feeSet = feeView.get(removedTx.tx.getEnergyPrice());
feeSet.remove(txHash);
if (feeSet.isEmpty()) {
feeView.remove(removedTx.tx.getEnergyPrice());
}
SortedMap<BigInteger, ByteArrayWrapper> accountInfo = accountView.get(removedTx.tx.getSenderAddress());
accountInfo.remove(removedTx.tx.getNonceBI());
if (accountInfo.isEmpty()) {
accountView.remove(removedTx.tx.getSenderAddress());
}
clearedTransactions.add(removedTx);
LOG_TXPOOL.debug("Removed tx[{}]", removedTx.tx);
}
}
timeView.headMap(outDateTime).clear();
return clearedTransactions;
}
Aggregations