use of snowblossom.lib.trie.HashedTrie in project snowblossom by snowblossomcoin.
the class MemPoolTest method testSimpleChain.
@Test
public void testSimpleChain() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in_a = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = utxo_buffer.commit();
TransactionOutput out_a = TransactionOutput.newBuilder().setRecipientSpecHash(in_a.getSpecHash()).setValue(100000L).build();
Transaction tx_a = TransactionUtil.createTransaction(ImmutableList.of(in_a), ImmutableList.of(out_a), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.addTransaction(tx_a, false);
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TransactionInput in_b = TransactionInput.newBuilder().setSpecHash(in_a.getSpecHash()).setSrcTxId(tx_a.getTxHash()).setSrcTxOutIdx(0).build();
TransactionOutput out_b = TransactionOutput.newBuilder().setRecipientSpecHash(in_a.getSpecHash()).setValue(100000L).build();
Transaction tx_b = TransactionUtil.createTransaction(ImmutableList.of(in_b), ImmutableList.of(out_b), keys);
mem_pool.addTransaction(tx_b, false);
Assert.assertEquals(2, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TransactionInput in_c = TransactionInput.newBuilder().setSpecHash(in_a.getSpecHash()).setSrcTxId(tx_b.getTxHash()).setSrcTxOutIdx(0).build();
TransactionOutput out_c = TransactionOutput.newBuilder().setRecipientSpecHash(in_a.getSpecHash()).setValue(100000L).build();
Transaction tx_c = TransactionUtil.createTransaction(ImmutableList.of(in_c), ImmutableList.of(out_c), keys);
mem_pool.addTransaction(tx_c, false);
Assert.assertEquals(3, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
}
use of snowblossom.lib.trie.HashedTrie in project snowblossom by snowblossomcoin.
the class MemPoolTest method testStormChain.
@Test
public void testStormChain() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
Random rnd = new Random();
TreeMap<Double, InputInfo> ready_inputs = new TreeMap<>();
AddressSpecHash address = null;
for (int i = 0; i < 100; i++) {
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
System.out.println("Source tx: " + new ChainHash(in.getSrcTxId()));
InputInfo ii = new InputInfo();
ii.in = in;
ii.value = 100000L;
ready_inputs.put(rnd.nextDouble(), ii);
address = new AddressSpecHash(in.getSpecHash());
}
ChainHash utxo_root = utxo_buffer.commit();
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100), 10000000);
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TimeRecord tr = new TimeRecord();
TimeRecord.setSharedRecord(tr);
for (int i = 0; i < 500; i++) {
long t1 = System.nanoTime();
InputInfo ia = ready_inputs.pollFirstEntry().getValue();
InputInfo ib = ready_inputs.pollFirstEntry().getValue();
InputInfo ic = ready_inputs.pollFirstEntry().getValue();
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(address.getBytes()).setValue(100000L).build();
System.out.println("Selected inputs: " + ia + " " + ib + " " + ic);
long t3 = System.nanoTime();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(ia.in, ib.in, ic.in), ImmutableList.of(out, out, out), keys);
TimeRecord.record(t3, "create_tx");
System.out.println("Intermediate transaction: " + new ChainHash(tx.getTxHash()));
long t2 = System.nanoTime();
mem_pool.addTransaction(tx, false);
TimeRecord.record(t2, "mem_pool");
for (int j = 0; j < 3; j++) {
TransactionInput in = TransactionInput.newBuilder().setSpecHash(address.getBytes()).setSrcTxId(tx.getTxHash()).setSrcTxOutIdx(j).build();
System.out.println(String.format("Adding output %s:%d", new ChainHash(tx.getTxHash()).toString(), j));
InputInfo ii = new InputInfo();
ii.in = in;
ii.value = 100000L;
ready_inputs.put(rnd.nextDouble(), ii);
}
TimeRecord.record(t1, "tx");
}
long t4 = System.nanoTime();
Assert.assertEquals(500, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TimeRecord.record(t4, "get_block_tx_list");
tr.printReport(System.out);
}
Aggregations