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);
}
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)));
}
}
}
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));
}
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());
}
}
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()));
}
Aggregations