Search in sources :

Example 16 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method benchmarkSnapshot.

@Test
public /* 100K new transactions in pool around 1200ms (cold-call)
     */
void benchmarkSnapshot() {
    Properties config = new Properties();
    config.put("txn-timeout", "100");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txnl = new ArrayList<>();
    int cnt = 10000;
    for (ECKey aKey1 : key) {
        Address acc = Address.wrap(aKey1.getAddress());
        for (int i = 0; i < cnt; i++) {
            ITransaction txn = new AionTransaction(BigInteger.valueOf(i).toByteArray(), acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
            ((AionTransaction) txn).sign(aKey1);
            txn.setNrgConsume(100L);
            txnl.add(txn);
        }
    }
    tp.add(txnl);
    assertTrue(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(Address.wrap(aKey.getAddress()));
        for (int i = 0; i < cnt; i++) {
            assertTrue(nl.get(i).equals(BigInteger.valueOf(i)));
        }
    }
}
Also used : Address(org.aion.base.type.Address) ITransaction(org.aion.base.type.ITransaction) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 17 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method snapshot3.

@Test
public // @Ignore
void snapshot3() {
    Properties config = new Properties();
    config.put("txn-timeout", "100");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txnl = new ArrayList<>();
    int cnt = 26;
    for (int i = 0; i < cnt; i++) {
        byte[] nonce = new byte[Long.BYTES];
        nonce[Long.BYTES - 1] = (byte) i;
        ITransaction txn = genTransaction(nonce);
        ((AionTransaction) txn).sign(key.get(0));
        txn.setNrgConsume(i + 1);
        txnl.add(txn);
    }
    tp.add(txnl);
    assertTrue(tp.size() == cnt);
    // sort the inserted txs
    List<ITransaction> txl = tp.snapshot();
    long nonce = 0;
    for (ITransaction tx : txl) {
        assertTrue((new BigInteger(tx.getNonce())).longValue() == nonce++);
    }
}
Also used : ITransaction(org.aion.base.type.ITransaction) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 18 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method benchmarkSnapshot3.

@Test
public /* 1M new transactions with 10000 accounts (100 txs per account)in pool snapshot around 10s (cold-call)
       gen new txns 55s (spent a lot of time to sign tx)
       put txns into pool 2.5s
       snapshot txn 5s
     */
void benchmarkSnapshot3() {
    Properties config = new Properties();
    config.put("txn-timeout", "100");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txnl = new ArrayList<>();
    int cnt = 100;
    System.out.println("Gen new transactions --");
    long start = System.currentTimeMillis();
    for (ECKey aKey21 : key2) {
        Address acc = Address.wrap(aKey21.getAddress());
        for (int i = 0; i < cnt; i++) {
            ITransaction txn = new AionTransaction(BigInteger.valueOf(i).toByteArray(), acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
            ((AionTransaction) txn).sign(aKey21);
            txn.setNrgConsume(100L);
            txnl.add(txn);
        }
    }
    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.");
    assertTrue(tp.size() == cnt * key2.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 : key2) {
        List<BigInteger> nl = tp.getNonceList(Address.wrap(aKey2.getAddress()));
        for (int i = 0; i < cnt; i++) {
            assertTrue(nl.get(i).equals(BigInteger.valueOf(i)));
        }
    }
}
Also used : Address(org.aion.base.type.Address) ITransaction(org.aion.base.type.ITransaction) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 19 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method noncebyAccountTest.

@Test
public void noncebyAccountTest() {
    Properties config = new Properties();
    config.put("txn-timeout", "10");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    Address acc = Address.wrap(key.get(0).getAddress());
    List<ITransaction> txnl = new ArrayList<>();
    int cnt = 100;
    for (int i = 0; i < cnt; i++) {
        byte[] nonce = new byte[Long.BYTES];
        nonce[Long.BYTES - 1] = (byte) (i + 1);
        ITransaction txn = new AionTransaction(nonce, acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
        ((AionTransaction) txn).sign(key.get(0));
        txn.setNrgConsume(100L);
        txnl.add(txn);
    }
    tp.add(txnl);
    assertTrue(tp.size() == cnt);
    // sort the inserted txs
    tp.snapshot();
    List<BigInteger> nl = tp.getNonceList(acc);
    for (int i = 0; i < cnt; i++) {
        assertTrue(nl.get(i).equals(BigInteger.valueOf(i + 1)));
    }
}
Also used : Address(org.aion.base.type.Address) ITransaction(org.aion.base.type.ITransaction) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 20 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method benchmarkSnapshot4.

@Test
public /* 100K new transactions in pool around 350ms (cold-call)
     */
void benchmarkSnapshot4() {
    Properties config = new Properties();
    config.put("txn-timeout", "100");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txnl = new ArrayList<>();
    List<ITransaction> txnlrm = new ArrayList<>();
    int cnt = 100000;
    int rmCnt = 10;
    Address acc = Address.wrap(key.get(0).getAddress());
    System.out.println("gen new transactions...");
    long start = System.currentTimeMillis();
    for (int i = 0; i < cnt; i++) {
        ITransaction txn = new AionTransaction(BigInteger.valueOf(i).toByteArray(), acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
        ((AionTransaction) txn).sign(key.get(0));
        txn.setNrgConsume(100L);
        txnl.add(txn);
        if (i < rmCnt) {
            txnlrm.add(txn);
        }
    }
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    System.out.println("Inserting txns...");
    start = System.currentTimeMillis();
    tp.add(txnl);
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    assertTrue(tp.size() == cnt);
    // sort the inserted txs
    System.out.println("Snapshoting...");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    System.out.println("Removing the first 10 txns...");
    start = System.currentTimeMillis();
    List rm = tp.remove(txnlrm);
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    assertTrue(rm.size() == rmCnt);
    assertTrue(tp.size() == cnt - rmCnt);
    System.out.println("Re-Snapshot after some txns was been removed...");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    List<BigInteger> nl = tp.getNonceList(Address.wrap(key.get(0).getAddress()));
    for (int i = 0; i < nl.size(); i++) {
        assertTrue(nl.get(i).equals(BigInteger.valueOf(i).add(BigInteger.valueOf(rmCnt))));
    }
}
Also used : Address(org.aion.base.type.Address) ITransaction(org.aion.base.type.ITransaction) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Aggregations

TxPoolA0 (org.aion.txpool.zero.TxPoolA0)21 AionTransaction (org.aion.zero.types.AionTransaction)21 Test (org.junit.Test)21 ITransaction (org.aion.base.type.ITransaction)19 BigInteger (java.math.BigInteger)14 Address (org.aion.base.type.Address)9 ECKey (org.aion.crypto.ECKey)7