Search in sources :

Example 21 with PooledTransaction

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());
}
Also used : PooledTransaction(org.aion.base.PooledTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 22 with PooledTransaction

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));
}
Also used : PooledTransaction(org.aion.base.PooledTransaction) AionTransaction(org.aion.base.AionTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 23 with PooledTransaction

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();
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) AionTransaction(org.aion.base.AionTransaction) PooledTransaction(org.aion.base.PooledTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 24 with PooledTransaction

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;
    }
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) BigInteger(java.math.BigInteger) PooledTransaction(org.aion.base.PooledTransaction)

Example 25 with PooledTransaction

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;
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) PooledTransaction(org.aion.base.PooledTransaction)

Aggregations

PooledTransaction (org.aion.base.PooledTransaction)55 ArrayList (java.util.ArrayList)40 Properties (java.util.Properties)40 AionTransaction (org.aion.base.AionTransaction)40 Test (org.junit.Test)40 BigInteger (java.math.BigInteger)16 AionAddress (org.aion.types.AionAddress)16 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)11 HashMap (java.util.HashMap)5 ECKey (org.aion.crypto.ECKey)5 AionTxExecSummary (org.aion.base.AionTxExecSummary)3 List (java.util.List)2 AionTxReceipt (org.aion.base.AionTxReceipt)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 Stack (java.util.Stack)1 TreeMap (java.util.TreeMap)1 Block (org.aion.zero.impl.types.Block)1