Search in sources :

Example 51 with AionTransaction

use of org.aion.zero.types.AionTransaction 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 52 with AionTransaction

use of org.aion.zero.types.AionTransaction 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 53 with AionTransaction

use of org.aion.zero.types.AionTransaction 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 54 with AionTransaction

use of org.aion.zero.types.AionTransaction 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)

Example 55 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class TxnPoolTest method addTxWithSameNonce.

@Test
public void addTxWithSameNonce() {
    Properties config = new Properties();
    config.put("txn-timeout", "10");
    ITxPool<ITransaction> tp = new TxPoolA0<>(config);
    ITransaction txn = genTransaction(ByteUtils.fromHexString("0000000000000001"));
    txn.setNrgConsume(100);
    List<ITransaction> txnl = new ArrayList<>();
    ((AionTransaction) txn).sign(key.get(0));
    txnl.add(txn);
    ((AionTransaction) txn).sign(key.get(0));
    txnl.add(txn);
    long t = new BigInteger(txn.getTimeStamp()).longValue();
    tp.add(txnl);
    assertTrue(tp.size() == 1);
    List<ITransaction> txl = tp.snapshot();
    assertTrue(txl.size() == 1);
    assertTrue(new BigInteger(txl.get(0).getTimeStamp()).longValue() == t);
}
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)

Aggregations

AionTransaction (org.aion.zero.types.AionTransaction)75 Test (org.junit.Test)44 BigInteger (java.math.BigInteger)30 ITransaction (org.aion.base.type.ITransaction)26 Address (org.aion.base.type.Address)23 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)21 AionBlock (org.aion.zero.impl.types.AionBlock)17 ArrayList (java.util.ArrayList)16 ECKey (org.aion.crypto.ECKey)12 AionTxReceipt (org.aion.zero.types.AionTxReceipt)7 TxRecpt (org.aion.api.server.types.TxRecpt)4 ImportResult (org.aion.mcf.core.ImportResult)4 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)4 ByteString (com.google.protobuf.ByteString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBuffer (java.nio.ByteBuffer)2 java.util (java.util)2 Entry (java.util.Map.Entry)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Collectors (java.util.stream.Collectors)2