Search in sources :

Example 6 with Address

use of org.aion.base.type.Address 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 7 with Address

use of org.aion.base.type.Address 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 8 with Address

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

the class AionContractDetailsTest method testExternalStorageSerialization.

@Test
public void testExternalStorageSerialization() {
    Address address = Address.wrap(RandomUtils.nextBytes(Address.ADDRESS_LEN));
    byte[] code = RandomUtils.nextBytes(512);
    Map<DataWord, DataWord> elements = new HashMap<>();
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    IByteArrayKeyValueDatabase externalStorage = repository.getDetailsDatabase();
    AionContractDetailsImpl original = new AionContractDetailsImpl(0, 1000000);
    original.setExternalStorageDataSource(externalStorage);
    original.setAddress(address);
    original.setCode(code);
    original.externalStorage = true;
    for (int i = 0; i < IN_MEMORY_STORAGE_LIMIT / 64 + 10; i++) {
        DataWord key = new DataWord(RandomUtils.nextBytes(16));
        DataWord value = new DataWord(RandomUtils.nextBytes(16));
        elements.put(key, value);
        original.put(key, value);
    }
    original.syncStorage();
    byte[] rlp = original.getEncoded();
    AionContractDetailsImpl deserialized = new AionContractDetailsImpl();
    deserialized.setExternalStorageDataSource(externalStorage);
    deserialized.decode(rlp);
    assertEquals(deserialized.externalStorage, true);
    assertTrue(address.equals(deserialized.getAddress()));
    assertEquals(ByteUtil.toHexString(code), ByteUtil.toHexString(deserialized.getCode()));
    Map<DataWord, DataWord> storage = deserialized.getStorage();
    assertEquals(elements.size(), storage.size());
    for (DataWord key : elements.keySet()) {
        assertEquals(elements.get(key), storage.get(key));
    }
    DataWord deletedKey = elements.keySet().iterator().next();
    deserialized.put(deletedKey, DataWord.ZERO);
    deserialized.put(new DataWord(RandomUtils.nextBytes(16)), DataWord.ZERO);
}
Also used : Address(org.aion.base.type.Address) IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) HashMap(java.util.HashMap) DataWord(org.aion.mcf.vm.types.DataWord) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionContractDetailsImpl(org.aion.zero.db.AionContractDetailsImpl) Test(org.junit.Test)

Example 9 with Address

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

the class AionContractDetailsTest method test_2.

@Test
public void test_2() throws Exception {
    byte[] code = ByteUtil.hexStringToBytes("7c0100000000000000000000000000000000000000000000000000000000600035046333d546748114610065578063430fe5f01461007c5780634d432c1d1461008d578063501385b2146100b857806357eb3b30146100e9578063dbc7df61146100fb57005b6100766004356024356044356102f0565b60006000f35b61008760043561039e565b60006000f35b610098600435610178565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b6100c96004356024356044356101a0565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b6100f1610171565b8060005260206000f35b610106600435610133565b8360005282602052816040528073ffffffffffffffffffffffffffffffffffffffff1660605260806000f35b5b60006020819052908152604090208054600182015460028301546003909301549192909173ffffffffffffffffffffffffffffffffffffffff1684565b5b60015481565b5b60026020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604081206002015481908302341080156101fe575073ffffffffffffffffffffffffffffffffffffffff8516600090815260208190526040812054145b8015610232575073ffffffffffffffffffffffffffffffffffffffff85166000908152602081905260409020600101548390105b61023b57610243565b3391506102e8565b6101966103ca60003973ffffffffffffffffffffffffffffffffffffffff3381166101965285166101b68190526000908152602081905260408120600201546101d6526101f68490526102169080f073ffffffffffffffffffffffffffffffffffffffff8616600090815260208190526040902060030180547fffffffffffffffffffffffff0000000000000000000000000000000000000000168217905591508190505b509392505050565b73ffffffffffffffffffffffffffffffffffffffff33166000908152602081905260408120548190821461032357610364565b60018054808201909155600090815260026020526040902080547fffffffffffffffffffffffff000000000000000000000000000000000000000016331790555b50503373ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090209081556001810192909255600290910155565b3373ffffffffffffffffffffffffffffffffffffffff166000908152602081905260409020600201555600608061019660043960048051602451604451606451600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000908116909517815560018054909516909317909355600355915561013390819061006390396000f3007c0100000000000000000000000000000000000000000000000000000000600035046347810fe381146100445780637e4a1aa81461005557806383d2421b1461006957005b61004f6004356100ab565b60006000f35b6100636004356024356100fc565b60006000f35b61007460043561007a565b60006000f35b6001543373ffffffffffffffffffffffffffffffffffffffff9081169116146100a2576100a8565b60078190555b50565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905550565b6001543373ffffffffffffffffffffffffffffffffffffffff9081169116146101245761012f565b600582905560068190555b505056");
    Address address = Address.wrap(RandomUtils.nextBytes(Address.ADDRESS_LEN));
    byte[] key_0 = ByteUtil.hexStringToBytes("18d63b70aa690ad37cb50908746c9a55");
    byte[] val_0 = ByteUtil.hexStringToBytes("00000000000000000000000000000064");
    byte[] key_1 = ByteUtil.hexStringToBytes("18d63b70aa690ad37cb50908746c9a56");
    byte[] val_1 = ByteUtil.hexStringToBytes("0000000000000000000000000000000c");
    byte[] key_2 = ByteUtil.hexStringToBytes("5a448d1967513482947d1d3f6104316f");
    byte[] val_2 = ByteUtil.hexStringToBytes("00000000000000000000000000000000");
    byte[] key_3 = ByteUtil.hexStringToBytes("5a448d1967513482947d1d3f61043171");
    byte[] val_3 = ByteUtil.hexStringToBytes("00000000000000000000000000000014");
    byte[] key_4 = ByteUtil.hexStringToBytes("18d63b70aa690ad37cb50908746c9a54");
    byte[] val_4 = ByteUtil.hexStringToBytes("00000000000000000000000000000000");
    byte[] key_5 = ByteUtil.hexStringToBytes("5a448d1967513482947d1d3f61043170");
    byte[] val_5 = ByteUtil.hexStringToBytes("00000000000000000000000000000078");
    byte[] key_6 = ByteUtil.hexStringToBytes("c83a08bbccc01a0644d599ccd2a7c2e0");
    byte[] val_6 = ByteUtil.hexStringToBytes("8fbec874791c4e3f9f48a59a44686efe");
    byte[] key_7 = ByteUtil.hexStringToBytes("5aa541c6c03f602a426f04ae47508bb8");
    byte[] val_7 = ByteUtil.hexStringToBytes("7a657031000000000000000000000000");
    byte[] key_8 = ByteUtil.hexStringToBytes("5aa541c6c03f602a426f04ae47508bb9");
    byte[] val_8 = ByteUtil.hexStringToBytes("000000000000000000000000000000c8");
    byte[] key_9 = ByteUtil.hexStringToBytes("5aa541c6c03f602a426f04ae47508bba");
    byte[] val_9 = ByteUtil.hexStringToBytes("0000000000000000000000000000000a");
    byte[] key_10 = ByteUtil.hexStringToBytes("00000000000000000000000000000001");
    byte[] val_10 = ByteUtil.hexStringToBytes("00000000000000000000000000000003");
    byte[] key_11 = ByteUtil.hexStringToBytes("5aa541c6c03f602a426f04ae47508bbb");
    byte[] val_11 = ByteUtil.hexStringToBytes("194bcfc3670d8a1613e5b0c790036a35");
    byte[] key_12 = ByteUtil.hexStringToBytes("aee92919b8c3389af86ef24535e8a28c");
    byte[] val_12 = ByteUtil.hexStringToBytes("cfe293a85bef5915e1a7acb37bf0c685");
    byte[] key_13 = ByteUtil.hexStringToBytes("65c996598dc972688b7ace676c89077b");
    byte[] val_13 = ByteUtil.hexStringToBytes("d6ee27e285f2de7b68e8db25cf1b1063");
    AionContractDetailsImpl contractDetails = new AionContractDetailsImpl();
    contractDetails.setCode(code);
    contractDetails.setAddress(address);
    contractDetails.put(new DataWord(key_0), new DataWord(val_0));
    contractDetails.put(new DataWord(key_1), new DataWord(val_1));
    contractDetails.put(new DataWord(key_2), new DataWord(val_2));
    contractDetails.put(new DataWord(key_3), new DataWord(val_3));
    contractDetails.put(new DataWord(key_4), new DataWord(val_4));
    contractDetails.put(new DataWord(key_5), new DataWord(val_5));
    contractDetails.put(new DataWord(key_6), new DataWord(val_6));
    contractDetails.put(new DataWord(key_7), new DataWord(val_7));
    contractDetails.put(new DataWord(key_8), new DataWord(val_8));
    contractDetails.put(new DataWord(key_9), new DataWord(val_9));
    contractDetails.put(new DataWord(key_10), new DataWord(val_10));
    contractDetails.put(new DataWord(key_11), new DataWord(val_11));
    contractDetails.put(new DataWord(key_12), new DataWord(val_12));
    contractDetails.put(new DataWord(key_13), new DataWord(val_13));
    byte[] data = contractDetails.getEncoded();
    AionContractDetailsImpl contractDetails_ = new AionContractDetailsImpl(data);
    assertEquals(ByteUtil.toHexString(code), ByteUtil.toHexString(contractDetails_.getCode()));
    assertTrue(address.equals(contractDetails_.getAddress()));
    assertEquals(ByteUtil.toHexString(val_1), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_1)).getData()));
    assertEquals(ByteUtil.toHexString(val_2), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_2)).getData()));
    assertEquals(ByteUtil.toHexString(val_3), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_3)).getData()));
    assertEquals(ByteUtil.toHexString(val_4), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_4)).getData()));
    assertEquals(ByteUtil.toHexString(val_5), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_5)).getData()));
    assertEquals(ByteUtil.toHexString(val_6), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_6)).getData()));
    assertEquals(ByteUtil.toHexString(val_7), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_7)).getData()));
    assertEquals(ByteUtil.toHexString(val_8), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_8)).getData()));
    assertEquals(ByteUtil.toHexString(val_9), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_9)).getData()));
    assertEquals(ByteUtil.toHexString(val_10), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_10)).getData()));
    assertEquals(ByteUtil.toHexString(val_11), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_11)).getData()));
    assertEquals(ByteUtil.toHexString(val_12), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_12)).getData()));
    assertEquals(ByteUtil.toHexString(val_13), ByteUtil.toHexString(contractDetails_.get(new DataWord(key_13)).getData()));
}
Also used : Address(org.aion.base.type.Address) DataWord(org.aion.mcf.vm.types.DataWord) AionContractDetailsImpl(org.aion.zero.db.AionContractDetailsImpl) Test(org.junit.Test)

Example 10 with Address

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

the class AionContractDetailsTest method testExternalStorageTransition.

@Test
public void testExternalStorageTransition() {
    Address address = Address.wrap(RandomUtils.nextBytes(Address.ADDRESS_LEN));
    byte[] code = RandomUtils.nextBytes(512);
    Map<DataWord, DataWord> elements = new HashMap<>();
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    IByteArrayKeyValueDatabase externalStorage = repository.getDetailsDatabase();
    AionContractDetailsImpl original = new AionContractDetailsImpl(0, 1000000);
    original.setExternalStorageDataSource(externalStorage);
    original.setAddress(address);
    original.setCode(code);
    for (int i = 0; i < IN_MEMORY_STORAGE_LIMIT / 64 + 10; i++) {
        DataWord key = new DataWord(RandomUtils.nextBytes(16));
        DataWord value = new DataWord(RandomUtils.nextBytes(16));
        elements.put(key, value);
        original.put(key, value);
    }
    original.syncStorage();
    assertTrue(!externalStorage.isEmpty());
    IContractDetails deserialized = deserialize(original.getEncoded(), externalStorage);
    // adds keys for in-memory storage limit overflow
    for (int i = 0; i < 10; i++) {
        DataWord key = new DataWord(RandomUtils.nextBytes(16));
        DataWord value = new DataWord(RandomUtils.nextBytes(16));
        elements.put(key, value);
        deserialized.put(key, value);
    }
    deserialized.syncStorage();
    assertTrue(!externalStorage.isEmpty());
    deserialized = deserialize(deserialized.getEncoded(), externalStorage);
    Map<DataWord, DataWord> storage = deserialized.getStorage();
    assertEquals(elements.size(), storage.size());
    for (DataWord key : elements.keySet()) {
        assertEquals(elements.get(key), storage.get(key));
    }
}
Also used : IContractDetails(org.aion.base.db.IContractDetails) Address(org.aion.base.type.Address) IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) HashMap(java.util.HashMap) DataWord(org.aion.mcf.vm.types.DataWord) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionContractDetailsImpl(org.aion.zero.db.AionContractDetailsImpl) Test(org.junit.Test)

Aggregations

Address (org.aion.base.type.Address)61 Test (org.junit.Test)34 BigInteger (java.math.BigInteger)29 AionTransaction (org.aion.zero.types.AionTransaction)23 ITransaction (org.aion.base.type.ITransaction)14 ECKey (org.aion.crypto.ECKey)13 DataWord (org.aion.mcf.vm.types.DataWord)11 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)10 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)9 IRepositoryCache (org.aion.base.db.IRepositoryCache)8 HashMap (java.util.HashMap)6 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)5 ByteUtil.toHexString (org.aion.base.util.ByteUtil.toHexString)5 AccountState (org.aion.mcf.core.AccountState)5 AionBlock (org.aion.zero.impl.types.AionBlock)5 ArrayList (java.util.ArrayList)4 ImportResult (org.aion.mcf.core.ImportResult)4 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 IRepository (org.aion.base.db.IRepository)3 AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)3