Search in sources :

Example 11 with AionTransaction

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

Example 12 with AionTransaction

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

the class TxnPoolTest 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("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
    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(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 13 with AionTransaction

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

the class TxnPoolTest method addRepeatedTxn3.

@Test
public void addRepeatedTxn3() {
    Properties config = new Properties();
    config.put("txn-timeout", "10");
    ITxPool<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> 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;
        ITransaction txn = genTransaction(nonce);
        ((AionTransaction) txn).sign(key.get(0));
        txn.setNrgConsume(50);
        txnl.add(txn);
    }
    tp.add(txnl);
    tp.snapshot();
    assertTrue(tp.size() == cnt);
    byte[] nonce = new byte[Long.BYTES];
    nonce[Long.BYTES - 1] = (byte) 5;
    ITransaction txn = genTransaction(nonce);
    ((AionTransaction) txn).sign(key.get(0));
    txn.setNrgConsume(500);
    tp.add(txn);
    List<ITransaction> snapshot = tp.snapshot();
    assertTrue(snapshot.size() == cnt);
    assertTrue(snapshot.get(5).equals(txn));
}
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 14 with AionTransaction

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

the class AionBlock method parseTxs.

private void parseTxs(RLPList txTransactions) {
    this.txsState = new TrieImpl(null);
    for (int i = 0; i < txTransactions.size(); i++) {
        RLPElement transactionRaw = txTransactions.get(i);
        this.transactionsList.add(new AionTransaction(transactionRaw.getRLPData()));
        this.txsState.update(RLP.encodeInt(i), transactionRaw.getRLPData());
    }
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) RLPElement(org.aion.rlp.RLPElement) AionTransaction(org.aion.zero.types.AionTransaction)

Example 15 with AionTransaction

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

the class BlockchainEnergyTest method testEnergyUsageRecorded.

@Test
public void testEnergyUsageRecorded() {
    final int DEFAULT_TX_AMOUNT = 21000;
    final Address RECEIPT_ADDR = Address.wrap("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE");
    StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder().withDefaultAccounts().withValidatorConfiguration("simple").build();
    StandaloneBlockchain bc = bundle.bc;
    // TODO: where is the 21000 defined? bad to define magic variables
    int amount = (int) (bc.getGenesis().getNrgLimit() / DEFAULT_TX_AMOUNT);
    // (byte[] nonce, byte[] from, byte[] to, byte[] value, byte[] data, byte[] nrg, byte[] nrgPrice)
    List<AionTransaction> txs = new ArrayList<>();
    for (int i = 0; i < amount; i++) {
        // this transaction should send one (1) AION coin from acc[0] to RECEIPT_ADDR
        AionTransaction atx = new AionTransaction(ByteUtil.intToBytes(i), RECEIPT_ADDR, BigInteger.ONE.toByteArray(), ByteUtil.EMPTY_BYTE_ARRAY, 21000L, BigInteger.valueOf(5).multiply(BigInteger.TEN.pow(9)).longValue());
        atx.sign(bundle.privateKeys.get(0));
        txs.add(atx);
    }
    AionBlock block = bc.createNewBlock(bc.getBestBlock(), txs, true);
    ImportResult result = bc.tryToConnect(block);
    assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
    // proceed with connecting the next block, should observe an increase in energyLimit
    AionBlock secondBlock = bc.createNewBlock(bc.getBestBlock(), Collections.EMPTY_LIST, true);
    assertThat(secondBlock.getNrgLimit()).isEqualTo(block.getNrgLimit());
    System.out.println(String.format("%d > %d", secondBlock.getNrgLimit(), block.getNrgLimit()));
}
Also used : ImportResult(org.aion.mcf.core.ImportResult) Address(org.aion.base.type.Address) ArrayList(java.util.ArrayList) AionTransaction(org.aion.zero.types.AionTransaction) AionBlock(org.aion.zero.impl.types.AionBlock) 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