Search in sources :

Example 6 with ITransaction

use of org.aion.base.type.ITransaction in project aion by aionnetwork.

the class TxnPoolTest method benchmarkSnapshot2.

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

       1K new transactions insert to the pool later around 70ms to snap (including sort)
     */
void benchmarkSnapshot2() {
    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 aKey2 : key) {
        Address acc = Address.wrap(aKey2.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(aKey2);
            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.");
    int cnt2 = 100;
    txnl.clear();
    for (ECKey aKey1 : key) {
        for (int i = 0; i < cnt2; i++) {
            ITransaction txn = new AionTransaction(BigInteger.valueOf(cnt + i).toByteArray(), Address.wrap(aKey1.getAddress()), 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 + cnt2) * key.size());
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("2nd 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 + cnt2; 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 7 with ITransaction

use of org.aion.base.type.ITransaction in project aion by aionnetwork.

the class TxnPoolTest method noncebyAccountTest2.

@Test
public void noncebyAccountTest2() {
    Properties config = new Properties();
    config.put("txn-timeout", "10");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txnl = new ArrayList<>();
    int cnt = 100;
    for (ECKey aKey1 : key) {
        Address acc = Address.wrap(aKey1.getAddress());
        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(aKey1);
            txn.setNrgConsume(100L);
            txnl.add(txn);
        }
    }
    tp.add(txnl);
    assertTrue(tp.size() == cnt * key.size());
    // sort the inserted txs
    tp.snapshot();
    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 + 1)));
        }
    }
}
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 8 with ITransaction

use of org.aion.base.type.ITransaction in project aion by aionnetwork.

the class TxnPoolTest method remove2.

@Test
public void remove2() {
    Properties config = new Properties();
    // 100 sec
    config.put("txn-timeout", "100");
    ITxPool<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txl = new ArrayList<>();
    List<ITransaction> txlrm = new ArrayList<>();
    int cnt = 20;
    for (int i = 0; i < cnt; i++) {
        AionTransaction tx = (AionTransaction) genTransaction(BigInteger.valueOf(i).toByteArray());
        tx.setNrgConsume(5000L);
        tx.sign(key.get(0));
        txl.add(tx);
        if (i < 10) {
            txlrm.add(tx);
        }
    }
    List rtn = tp.add(txl);
    assertTrue(rtn.size() == txl.size());
    txl = tp.snapshot();
    assertTrue(txl.size() == cnt);
    rtn = tp.remove(txlrm);
    assertTrue(rtn.size() == 10);
    assertTrue(tp.size() == 10);
}
Also used : ITransaction(org.aion.base.type.ITransaction) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 9 with ITransaction

use of org.aion.base.type.ITransaction in project aion by aionnetwork.

the class TxnPoolTest method remove3.

@Test
public void remove3() {
    Properties config = new Properties();
    // 100 sec
    config.put("txn-timeout", "100");
    ITxPool<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txl = new ArrayList<>();
    List<ITransaction> txlrm = new ArrayList<>();
    int cnt = 20;
    for (int i = 0; i < cnt; i++) {
        AionTransaction tx = (AionTransaction) genTransaction(BigInteger.valueOf(i).toByteArray());
        tx.setNrgConsume(5000L);
        tx.sign(key.get(0));
        txl.add(tx);
        if (i < 10) {
            txlrm.add(tx);
        }
    }
    List rtn = tp.add(txl);
    assertTrue(rtn.size() == txl.size());
    txl = tp.snapshot();
    assertTrue(txl.size() == cnt);
    Map<Address, BigInteger> account = new HashMap<>();
    account.put(txl.get(0).getFrom(), BigInteger.valueOf(10));
    rtn = tp.remove(account);
    assertTrue(rtn.size() == 10);
    assertTrue(tp.size() == 10);
}
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)

Example 10 with ITransaction

use of org.aion.base.type.ITransaction in project aion by aionnetwork.

the class TxnPoolTest method snapshot2.

@Test
public void snapshot2() throws Throwable {
    Properties config = new Properties();
    // 100 sec
    config.put("txn-timeout", "100");
    ITxPool<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> txl = new ArrayList<>();
    int cnt = 26;
    for (int i = 0; i < cnt; i++) {
        AionTransaction txe = (AionTransaction) genTransaction(BigInteger.valueOf(i).toByteArray());
        txe.setNrgConsume(5000L);
        txe.sign(key.get(0));
        txl.add(txe);
    }
    List rtn = tp.add(txl);
    assertTrue(rtn.size() == txl.size());
    txl = tp.snapshot();
    assertTrue(txl.size() == cnt);
}
Also used : ITransaction(org.aion.base.type.ITransaction) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Aggregations

ITransaction (org.aion.base.type.ITransaction)29 AionTransaction (org.aion.zero.types.AionTransaction)26 Test (org.junit.Test)26 BigInteger (java.math.BigInteger)22 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)19 Address (org.aion.base.type.Address)13 ArrayList (java.util.ArrayList)7 ECKey (org.aion.crypto.ECKey)5 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)3 HashMap (java.util.HashMap)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AccountState (org.aion.txpool.common.AccountState)1 TxDependList (org.aion.txpool.common.TxDependList)1