Search in sources :

Example 6 with AionTransaction

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

the class TxnPoolTest method testRemove2.

@Test
public void testRemove2() {
    ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519);
    ECKey key = ECKeyFac.inst().create();
    List<AionTransaction> txs = new ArrayList<>();
    for (int i = 0; i < 95; i++) {
        AionTransaction tx = new AionTransaction(BigInteger.valueOf(i).toByteArray(), Address.wrap(key.getAddress()), Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
        tx.sign(key);
        tx.setNrgConsume(100L);
        txs.add(tx);
    }
    Properties config = new Properties();
    ITxPool<AionTransaction> tp = new TxPoolA0<>(config);
    tp.add(txs.subList(0, 26));
    assertEquals(26, tp.snapshot().size());
    assertEquals(26, tp.snapshotAll().size());
    tp.remove(txs.subList(0, 13));
    assertEquals(13, tp.snapshot().size());
    assertEquals(13, tp.snapshotAll().size());
    tp.add(txs.subList(26, 70));
    assertEquals(57, tp.snapshot().size());
    assertEquals(57, tp.snapshotAll().size());
    tp.remove(txs.subList(13, 40));
    assertEquals(30, tp.snapshot().size());
    assertEquals(30, tp.snapshotAll().size());
    // assume we don't remove tx 40
    tp.remove(txs.subList(41, 70));
    assertEquals(1, tp.snapshot().size());
    assertEquals(1, tp.snapshotAll().size());
}
Also used : ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 7 with AionTransaction

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

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

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

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

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