use of org.aion.base.type.ITransaction 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)));
}
}
}
use of org.aion.base.type.ITransaction 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)));
}
}
}
use of org.aion.base.type.ITransaction 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);
}
use of org.aion.base.type.ITransaction 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);
}
use of org.aion.base.type.ITransaction 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);
}
Aggregations