Search in sources :

Example 1 with HashedTrie

use of snowblossom.lib.trie.HashedTrie 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 HashedTrie

use of snowblossom.lib.trie.HashedTrie 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 HashedTrie

use of snowblossom.lib.trie.HashedTrie 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 HashedTrie

use of snowblossom.lib.trie.HashedTrie in project snowblossom by snowblossomcoin.

the class ForBenefitOfUtil method getIdList.

/**
 * returns a list of outputs that are marked with the name 'name' in ascending
 * order of confirmation height.  So oldest first.
 */
public static TxOutList getIdList(ByteString type, ByteString name, DB node_db, BlockSummary head) {
    HashedTrie db = node_db.getChainIndexTrie();
    ByteString trie_root = head.getChainIndexTrieHash();
    // TODO - filter by currently valid utxos
    ByteString name_hash = normalizeAndHash(name);
    TxOutList.Builder list = TxOutList.newBuilder();
    ByteString search_key = ID_MAP_PREFIX.concat(type).concat(name_hash);
    TreeMap<ByteString, ByteString> map = db.getDataMap(trie_root, search_key, 10000);
    for (Map.Entry<ByteString, ByteString> me : map.entrySet()) {
        ByteString tx_info = me.getKey().substring(search_key.size() + 4);
        list.addOutList(getOutpoint(tx_info, me.getValue()));
    }
    return filterByCurrent(list.build(), node_db, head);
}
Also used : HashedTrie(snowblossom.lib.trie.HashedTrie) ByteString(com.google.protobuf.ByteString) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 5 with HashedTrie

use of snowblossom.lib.trie.HashedTrie in project snowblossom by snowblossomcoin.

the class ForBenefitOfUtil method getFBOList.

/**
 * Return a list of outputs that are marked in favor of 'spec_hash'
 */
public static TxOutList getFBOList(AddressSpecHash spec_hash, DB node_db, BlockSummary head) {
    HashedTrie db = node_db.getChainIndexTrie();
    ByteString trie_root = head.getChainIndexTrieHash();
    // TODO - filter by currently valid utxos
    TxOutList.Builder list = TxOutList.newBuilder();
    ByteString search_key = FBO_MAP_PREFIX.concat(spec_hash.getBytes());
    TreeMap<ByteString, ByteString> map = db.getDataMap(trie_root, search_key, 10000);
    for (Map.Entry<ByteString, ByteString> me : map.entrySet()) {
        ByteString tx_info = me.getKey().substring(search_key.size());
        list.addOutList(getOutpoint(tx_info, me.getValue()));
    }
    return filterByCurrent(list.build(), node_db, head);
}
Also used : HashedTrie(snowblossom.lib.trie.HashedTrie) ByteString(com.google.protobuf.ByteString) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

HashedTrie (snowblossom.lib.trie.HashedTrie)12 KeyPair (java.security.KeyPair)6 Test (org.junit.Test)6 MemPool (snowblossom.node.MemPool)6 Transaction (snowblossom.proto.Transaction)6 TransactionInput (snowblossom.proto.TransactionInput)6 TransactionOutput (snowblossom.proto.TransactionOutput)6 ByteString (com.google.protobuf.ByteString)3 TreeMap (java.util.TreeMap)3 Map (java.util.Map)2 TrieDBMem (snowblossom.lib.trie.TrieDBMem)2 TimeRecord (duckutil.TimeRecord)1 TimeRecordAuto (duckutil.TimeRecordAuto)1 File (java.io.File)1 Random (java.util.Random)1 TrieDBMap (snowblossom.lib.trie.TrieDBMap)1 TrieDBRocks (snowblossom.lib.trie.TrieDBRocks)1