use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxnPoolV1BenchmarkTest method benchmarkSnapshot3.
@Test
public void benchmarkSnapshot3() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
int cnt = 1000;
System.out.println("Gen new transactions --");
long start = System.currentTimeMillis();
for (ECKey aKey21 : key) {
for (int i = 0; i < cnt; i++) {
AionTransaction txn = AionTransaction.create(aKey21, BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(txn, Constant.MIN_ENERGY_CONSUME);
txnl.add(pooledTx);
}
}
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
System.out.println("Adding transactions into pool--");
start = System.currentTimeMillis();
tp.add(txnl);
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
Assert.assertEquals(tp.size(), cnt * key.size());
// sort the inserted txs
System.out.println("Snapshoting --");
start = System.currentTimeMillis();
tp.snapshot();
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
for (ECKey aKey2 : key) {
List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey2.getAddress()));
for (int i = 0; i < cnt; i++) {
Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
}
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxnPoolV1BenchmarkTest method benchmarkSnapshot.
@Test
public void benchmarkSnapshot() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
int cnt = 1000;
for (ECKey aKey1 : key) {
for (int i = 0; i < cnt; i++) {
AionTransaction txn = AionTransaction.create(aKey1, BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(txn, Constant.MIN_ENERGY_CONSUME);
txnl.add(pooledTx);
}
}
tp.add(txnl);
Assert.assertEquals(tp.size(), cnt * key.size());
// sort the inserted txs
long start = System.currentTimeMillis();
tp.snapshot();
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
for (ECKey aKey : key) {
List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey.getAddress()));
for (int i = 0; i < cnt; i++) {
Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
}
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxnPoolV1BenchmarkTest 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(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
int cnt = 1000;
for (ECKey aKey1 : key) {
for (int i = 0; i < cnt; i++) {
AionTransaction txn = AionTransaction.create(aKey1, BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(txn, Constant.MIN_ENERGY_CONSUME);
txnl.add(pooledTx);
}
}
tp.add(txnl);
Assert.assertEquals(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(new AionAddress(aKey.getAddress()));
for (int i = 0; i < cnt; i++) {
Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
}
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method addRepeatedTxn3.
@Test
public void addRepeatedTxn3() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> 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;
PooledTransaction pooledTx = genTransactionWithEnergyPrice(nonce, 1);
txnl.add(pooledTx);
}
tp.add(txnl);
tp.snapshot();
Assert.assertEquals(tp.size(), cnt);
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) 5;
PooledTransaction pooledTx = genTransactionWithEnergyPrice(nonce, 2);
tp.add(pooledTx);
List<AionTransaction> snapshot = tp.snapshot();
Assert.assertEquals(snapshot.size(), cnt);
Assert.assertEquals(snapshot.get(5), pooledTx.tx);
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method testSnapshotAll.
@Test
public void testSnapshotAll() {
List<PooledTransaction> txs = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
AionTransaction tx = AionTransaction.create(key.get(0), BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
txs.add(pooledTx);
}
Properties config = new Properties();
TxPoolV1 tp = new TxPoolV1(config);
tp.add(txs.subList(0, 476));
assertEquals(476, tp.snapshot().size());
assertEquals(476, tp.snapshotAll().size());
tp.remove(txs.subList(0, 100));
assertEquals(376, tp.snapshot().size());
assertEquals(376, tp.snapshotAll().size());
}
Aggregations