Search in sources :

Example 11 with Transaction

use of snowblossom.proto.Transaction in project snowblossom by snowblossomcoin.

the class TxBroadcaster method run.

public void run() {
    while (true) {
        try {
            Transaction tx = queue.poll(2, TimeUnit.DAYS);
            if (tx != null) {
                rate_limit.waitForRate(1.0);
                peerage.broadcastTransaction(tx);
            }
        } catch (Throwable t) {
            logger.warning("TxBroadcast: " + t);
        }
    }
}
Also used : Transaction(snowblossom.proto.Transaction)

Example 12 with Transaction

use of snowblossom.proto.Transaction in project snowblossom by snowblossomcoin.

the class MemPoolTest method testBasicTxDoubleSpend.

@Test
public void testBasicTxDoubleSpend() throws Exception {
    HashedTrie utxo_trie = newMemoryTrie();
    KeyPair keys = KeyUtil.generateECCompressedKey();
    UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
    TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
    ChainHash utxo_root = utxo_buffer.commit();
    TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(100000L).build();
    Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out), keys);
    MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
    mem_pool.rebuildPriorityMap(utxo_root);
    // Pool starts empty
    Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
    mem_pool.addTransaction(tx, false);
    TransactionOutput out_a = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(50000L).build();
    Transaction tx2 = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out_a, out_a), keys);
    Assert.assertNotEquals(tx.getTxHash(), tx2.getTxHash());
    try {
        mem_pool.addTransaction(tx2, false);
        Assert.fail();
    } catch (ValidationException e) {
        System.out.println(e);
    }
}
Also used : HashedTrie(snowblossom.lib.trie.HashedTrie) KeyPair(java.security.KeyPair) TransactionOutput(snowblossom.proto.TransactionOutput) Transaction(snowblossom.proto.Transaction) TransactionInput(snowblossom.proto.TransactionInput) MemPool(snowblossom.node.MemPool) Test(org.junit.Test)

Example 13 with Transaction

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

Example 14 with Transaction

use of snowblossom.proto.Transaction 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

Transaction (snowblossom.proto.Transaction)14 TransactionInput (snowblossom.proto.TransactionInput)9 TransactionOutput (snowblossom.proto.TransactionOutput)8 KeyPair (java.security.KeyPair)6 Test (org.junit.Test)6 HashedTrie (snowblossom.lib.trie.HashedTrie)6 MemPool (snowblossom.node.MemPool)6 ByteString (com.google.protobuf.ByteString)4 TransactionInner (snowblossom.proto.TransactionInner)3 MetricLog (duckutil.MetricLog)2 BlockSummary (snowblossom.proto.BlockSummary)2 ImportedBlock (snowblossom.proto.ImportedBlock)2 TimeRecord (duckutil.TimeRecord)1 TimeRecordAuto (duckutil.TimeRecordAuto)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 SnowBlossomClient (snowblossom.client.SnowBlossomClient)1 AddressSpecHash (snowblossom.lib.AddressSpecHash)1