Search in sources :

Example 1 with TransactionInput

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

the class MemPoolTest method testBasicTxNoInput.

@Test
public void testBasicTxNoInput() 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 = UtxoUpdateBuffer.EMPTY;
    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());
    try {
        mem_pool.addTransaction(tx, false);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertTrue(e.getMessage(), e.getMessage().startsWith("Unable to find source tx"));
    }
}
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 2 with TransactionInput

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

the class MemPoolTest method testBasicTxNoDoubleInput.

@Test
public void testBasicTxNoDoubleInput() 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(200000L).build();
    Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in, 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());
    try {
        mem_pool.addTransaction(tx, 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 3 with TransactionInput

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

the class MemPoolTest method testBasicTxYes.

@Test
public void testBasicTxYes() 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);
    // Then has our transaction
    Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
    mem_pool.rebuildPriorityMap(utxo_root);
    // Still has our transaction
    Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
    mem_pool.rebuildPriorityMap(UtxoUpdateBuffer.EMPTY);
    // That transaction is impossible now
    Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
    mem_pool.rebuildPriorityMap(utxo_root);
    // And does not come back
    Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
    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());
    mem_pool.addTransaction(tx2, false);
    // And the outputs are freed up
    Assert.assertEquals(1, 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 4 with TransactionInput

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

the class MemPool method rebuildPriorityMap.

public synchronized void rebuildPriorityMap(ChainHash new_utxo_root) {
    logger.log(Level.FINE, String.format("Mempool.rebuildPriorityMap(%s)", new_utxo_root));
    utxo_for_pri_map = new_utxo_root;
    priority_map.clear();
    LinkedList<ChainHash> remove_list = new LinkedList<>();
    for (TransactionMempoolInfo info : known_transactions.values()) {
        Transaction tx = info.tx;
        TXCluster cluster;
        try {
            cluster = buildTXCluster(tx);
        } catch (ValidationException e) {
            cluster = null;
        }
        if (cluster == null) {
            remove_list.add(new ChainHash(tx.getTxHash()));
            TransactionInner inner = TransactionUtil.getInner(tx);
            for (TransactionInput in : inner.getInputsList()) {
                String key = HexUtil.getHexString(in.getSrcTxId()) + ":" + in.getSrcTxOutIdx();
                claimed_outputs.remove(key);
            }
        } else {
            double ratio = (double) cluster.total_fee / (double) cluster.total_size;
            priority_map.put(ratio, cluster);
        }
    }
    logger.log(Level.FINER, String.format("Removing %d transactions from mempool", remove_list.size()));
    for (ChainHash h : remove_list) {
        TransactionMempoolInfo info = known_transactions.remove(h);
        for (AddressSpecHash spec_hash : info.involved_addresses) {
            address_tx_map.remove(spec_hash, h);
        }
    }
    logger.log(Level.FINER, String.format("Remaining in mempool: %d", known_transactions.size()));
}
Also used : Transaction(snowblossom.proto.Transaction) TransactionInner(snowblossom.proto.TransactionInner) ByteString(com.google.protobuf.ByteString) TransactionInput(snowblossom.proto.TransactionInput)

Example 5 with TransactionInput

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

the class MonitorTool method sendNotices.

private void sendNotices(AddressSpecHash hash, ByteString tx_hash) {
    ByteString key = hash.getBytes().concat(tx_hash);
    synchronized (processed_tx) {
        if (processed_tx.contains(key))
            return;
    }
    Transaction tx = stub_holder.getBlockingStub().getTransaction(RequestTransaction.newBuilder().setTxHash(tx_hash).build());
    TransactionInner inner = TransactionUtil.getInner(tx);
    int idx = 0;
    for (TransactionInput in : inner.getInputsList()) {
        if (hash.getBytes().equals(in.getSpecHash())) {
            monitor_interface.onOutbound(tx, idx);
        }
        idx++;
    }
    idx = 0;
    for (TransactionOutput out : inner.getOutputsList()) {
        if (hash.getBytes().equals(out.getRecipientSpecHash())) {
            monitor_interface.onInbound(tx, idx);
        }
        idx++;
    }
    synchronized (processed_tx) {
        processed_tx.add(key);
    }
}
Also used : TransactionOutput(snowblossom.proto.TransactionOutput) Transaction(snowblossom.proto.Transaction) RequestTransaction(snowblossom.proto.RequestTransaction) ByteString(com.google.protobuf.ByteString) TransactionInner(snowblossom.proto.TransactionInner) TransactionInput(snowblossom.proto.TransactionInput)

Aggregations

TransactionInput (snowblossom.proto.TransactionInput)12 TransactionOutput (snowblossom.proto.TransactionOutput)10 Transaction (snowblossom.proto.Transaction)9 KeyPair (java.security.KeyPair)6 Test (org.junit.Test)6 HashedTrie (snowblossom.lib.trie.HashedTrie)6 MemPool (snowblossom.node.MemPool)6 TransactionInner (snowblossom.proto.TransactionInner)5 ByteString (com.google.protobuf.ByteString)4 Random (java.util.Random)2 MetricLog (duckutil.MetricLog)1 TimeRecord (duckutil.TimeRecord)1 TreeMap (java.util.TreeMap)1 AddressSpec (snowblossom.proto.AddressSpec)1 BlockHeader (snowblossom.proto.BlockHeader)1 RequestTransaction (snowblossom.proto.RequestTransaction)1