Search in sources :

Example 6 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxnPoolV1BenchmarkTest method benchmarkSnapshot3.

@Test
public void benchmarkSnapshot3() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000");
    TxPoolV1 tp = new TxPoolV1(config);
    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 1000;
    System.out.println("Gen new transactions --");
    long start = System.currentTimeMillis();
    for (ECKey aKey21 : key) {
        for (int i = 0; i < cnt; i++) {
            AionTransaction txn = AionTransaction.create(aKey21, BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
            PooledTransaction pooledTx = new PooledTransaction(txn, Constant.MIN_ENERGY_CONSUME);
            txnl.add(pooledTx);
        }
    }
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    System.out.println("Adding transactions into pool--");
    start = System.currentTimeMillis();
    tp.add(txnl);
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    Assert.assertEquals(tp.size(), cnt * key.size());
    // sort the inserted txs
    System.out.println("Snapshoting --");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    for (ECKey aKey2 : key) {
        List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey2.getAddress()));
        for (int i = 0; i < cnt; i++) {
            Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
        }
    }
}
Also used : AionAddress(org.aion.types.AionAddress) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) PooledTransaction(org.aion.base.PooledTransaction) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxnPoolV1BenchmarkTest method benchmarkSnapshot.

@Test
public void benchmarkSnapshot() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000");
    TxPoolV1 tp = new TxPoolV1(config);
    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 1000;
    for (ECKey aKey1 : key) {
        for (int i = 0; i < cnt; i++) {
            AionTransaction txn = AionTransaction.create(aKey1, BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
            PooledTransaction pooledTx = new PooledTransaction(txn, Constant.MIN_ENERGY_CONSUME);
            txnl.add(pooledTx);
        }
    }
    tp.add(txnl);
    Assert.assertEquals(tp.size(), cnt * key.size());
    // sort the inserted txs
    long start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    for (ECKey aKey : key) {
        List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey.getAddress()));
        for (int i = 0; i < cnt; i++) {
            Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
        }
    }
}
Also used : AionAddress(org.aion.types.AionAddress) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) PooledTransaction(org.aion.base.PooledTransaction) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxnPoolV1BenchmarkTest method benchmarkSnapshot5.

@Test
public /* 100K new transactions in pool around 350ms (cold-call)

      the second time snapshot is around 35ms
    */
void benchmarkSnapshot5() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000");
    TxPoolV1 tp = new TxPoolV1(config);
    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 1000;
    for (ECKey aKey1 : key) {
        for (int i = 0; i < cnt; i++) {
            AionTransaction txn = AionTransaction.create(aKey1, BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
            PooledTransaction pooledTx = new PooledTransaction(txn, Constant.MIN_ENERGY_CONSUME);
            txnl.add(pooledTx);
        }
    }
    tp.add(txnl);
    Assert.assertEquals(tp.size(), cnt * key.size());
    // sort the inserted txs
    System.out.println("1st time snapshot...");
    long start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("1st time spent: " + (System.currentTimeMillis() - start) + " ms.");
    System.out.println("2nd time snapshot...");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("2nd time spent: " + (System.currentTimeMillis() - start) + " ms.");
    for (ECKey aKey : key) {
        List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey.getAddress()));
        for (int i = 0; i < cnt; i++) {
            Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
        }
    }
}
Also used : AionAddress(org.aion.types.AionAddress) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) PooledTransaction(org.aion.base.PooledTransaction) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxPoolV1Test method addRepeatedTxn3.

@Test
public void addRepeatedTxn3() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
    TxPoolV1 tp = new TxPoolV1(config);
    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 10;
    for (int i = 0; i < cnt; i++) {
        byte[] nonce = new byte[Long.BYTES];
        nonce[Long.BYTES - 1] = (byte) i;
        PooledTransaction pooledTx = genTransactionWithEnergyPrice(nonce, 1);
        txnl.add(pooledTx);
    }
    tp.add(txnl);
    tp.snapshot();
    Assert.assertEquals(tp.size(), cnt);
    byte[] nonce = new byte[Long.BYTES];
    nonce[Long.BYTES - 1] = (byte) 5;
    PooledTransaction pooledTx = genTransactionWithEnergyPrice(nonce, 2);
    tp.add(pooledTx);
    List<AionTransaction> snapshot = tp.snapshot();
    Assert.assertEquals(snapshot.size(), cnt);
    Assert.assertEquals(snapshot.get(5), pooledTx.tx);
}
Also used : ArrayList(java.util.ArrayList) PooledTransaction(org.aion.base.PooledTransaction) AionTransaction(org.aion.base.AionTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxPoolV1Test method testSnapshotAll.

@Test
public void testSnapshotAll() {
    List<PooledTransaction> txs = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        AionTransaction tx = AionTransaction.create(key.get(0), BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
        PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
        txs.add(pooledTx);
    }
    Properties config = new Properties();
    TxPoolV1 tp = new TxPoolV1(config);
    tp.add(txs.subList(0, 476));
    assertEquals(476, tp.snapshot().size());
    assertEquals(476, tp.snapshotAll().size());
    tp.remove(txs.subList(0, 100));
    assertEquals(376, tp.snapshot().size());
    assertEquals(376, tp.snapshotAll().size());
}
Also used : ArrayList(java.util.ArrayList) PooledTransaction(org.aion.base.PooledTransaction) AionTransaction(org.aion.base.AionTransaction) Properties(java.util.Properties) Test(org.junit.Test)

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