Search in sources :

Example 6 with TimeRecord

use of duckutil.TimeRecord 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);
}
Also used : HashedTrie(snowblossom.lib.trie.HashedTrie) KeyPair(java.security.KeyPair) TransactionOutput(snowblossom.proto.TransactionOutput) TreeMap(java.util.TreeMap) TransactionInput(snowblossom.proto.TransactionInput) MemPool(snowblossom.node.MemPool) Random(java.util.Random) Transaction(snowblossom.proto.Transaction) TimeRecord(duckutil.TimeRecord) Test(org.junit.Test)

Aggregations

TimeRecord (duckutil.TimeRecord)6 BigInteger (java.math.BigInteger)5 DecimalFormat (java.text.DecimalFormat)5 ByteString (com.google.protobuf.ByteString)4 TreeMap (java.util.TreeMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 KeyPair (java.security.KeyPair)1 Map (java.util.Map)1 Random (java.util.Random)1 Test (org.junit.Test)1 HashedTrie (snowblossom.lib.trie.HashedTrie)1 MemPool (snowblossom.node.MemPool)1 Transaction (snowblossom.proto.Transaction)1 TransactionInput (snowblossom.proto.TransactionInput)1 TransactionOutput (snowblossom.proto.TransactionOutput)1