Search in sources :

Example 31 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class TransactionViewModelTest method updateHeightPrefilledSlotShouldFail.

@Test
public void updateHeightPrefilledSlotShouldFail() throws Exception {
    int count = 4;
    TransactionViewModel[] transactionViewModels = new TransactionViewModel[count];
    Hash hash = getRandomTransactionHash();
    for (int i = 0; ++i < count; ) {
        transactionViewModels[i] = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hash, Hash.NULL_HASH), hash = getRandomTransactionHash());
        transactionViewModels[i].store(tangle);
    }
    transactionViewModels[count - 1].updateHeights(tangle);
    for (int i = count; i > 1; ) {
        assertEquals(0, TransactionViewModel.fromHash(tangle, transactionViewModels[--i].getHash()).getHeight());
    }
}
Also used : Hash(com.iota.iri.model.Hash)

Example 32 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class TransactionViewModelTest method testManyTXInDB.

// @Test
public void testManyTXInDB() throws Exception {
    int i, j;
    LinkedList<Hash> hashes = new LinkedList<>();
    Hash hash;
    hash = getRandomTransactionHash();
    hashes.add(hash);
    long start, diff, diffget;
    long subSumDiff = 0, maxdiff = 0, sumdiff = 0;
    int max = 990 * 1000;
    int interval1 = 50;
    int interval = interval1 * 10;
    log.info("Starting Test. #TX: {}", TransactionViewModel.getNumberOfStoredTransactions(tangle));
    new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(Hash.NULL_HASH, Hash.NULL_HASH), hash).store(tangle);
    TransactionViewModel transactionViewModel;
    boolean pop = false;
    for (i = 0; i++ < max; ) {
        hash = getRandomTransactionHash();
        j = hashes.size();
        transactionViewModel = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hashes.get(seed.nextInt(j)), hashes.get(seed.nextInt(j))), hash);
        start = System.nanoTime();
        transactionViewModel.store(tangle);
        diff = System.nanoTime() - start;
        subSumDiff += diff;
        if (diff > maxdiff) {
            maxdiff = diff;
        }
        hash = hashes.get(seed.nextInt(j));
        start = System.nanoTime();
        TransactionViewModel.fromHash(tangle, hash);
        diffget = System.nanoTime() - start;
        hashes.add(hash);
        if (pop || i > 1000) {
            hashes.removeFirst();
        }
        // log.info("{}", new String(new char[(int) ((diff/ 10000))]).replace('\0', '|'));
        if (i % interval1 == 0) {
            // log.info("{}", new String(new char[(int) (diff / 50000)]).replace('\0', '-'));
            // log.info("{}", new String(new char[(int) ((subSumDiff / interval1 / 100000))]).replace('\0', '|'));
            sumdiff += subSumDiff;
            subSumDiff = 0;
        }
        if (i % interval == 0) {
            log.info("Save time for {}: {} us.\tGet Time: {} us.\tMax time: {} us. Average: {}", i, (diff / 1000), diffget / 1000, (maxdiff / 1000), sumdiff / interval / 1000);
            sumdiff = 0;
            maxdiff = 0;
        }
    }
    log.info("Done. #TX: {}", TransactionViewModel.getNumberOfStoredTransactions(tangle));
}
Also used : Hash(com.iota.iri.model.Hash)

Example 33 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class TransactionViewModelTest method updateHeightShouldWork.

@Test
public void updateHeightShouldWork() throws Exception {
    int count = 4;
    TransactionViewModel[] transactionViewModels = new TransactionViewModel[count];
    Hash hash = getRandomTransactionHash();
    transactionViewModels[0] = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(Hash.NULL_HASH, Hash.NULL_HASH), hash);
    transactionViewModels[0].store(tangle);
    for (int i = 0; ++i < count; ) {
        transactionViewModels[i] = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hash, Hash.NULL_HASH), hash = getRandomTransactionHash());
        transactionViewModels[i].store(tangle);
    }
    transactionViewModels[count - 1].updateHeights(tangle);
    for (int i = count; i > 1; ) {
        assertEquals(i, TransactionViewModel.fromHash(tangle, transactionViewModels[--i].getHash()).getHeight());
    }
}
Also used : Hash(com.iota.iri.model.Hash)

Example 34 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class TipsViewModel method getRandomSolidTipHash.

public Hash getRandomSolidTipHash() {
    synchronized (sync) {
        int size = solidTips.size();
        if (size == 0) {
            return getRandomNonSolidTipHash();
        }
        int index = seed.nextInt(size);
        Iterator<Hash> hashIterator;
        hashIterator = solidTips.iterator();
        Hash hash = null;
        while (index-- >= 0 && hashIterator.hasNext()) {
            hash = hashIterator.next();
        }
        return hash;
    // return solidTips.size() != 0 ? solidTips.get(seed.nextInt(solidTips.size())) : getRandomNonSolidTipHash();
    }
}
Also used : Hash(com.iota.iri.model.Hash)

Example 35 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class Node method weightQueueHashPair.

// TODO generalize these weightQueues
private static ConcurrentSkipListSet<Pair<Hash, Neighbor>> weightQueueHashPair() {
    return new ConcurrentSkipListSet<Pair<Hash, Neighbor>>((transaction1, transaction2) -> {
        Hash tx1 = transaction1.getLeft();
        Hash tx2 = transaction2.getLeft();
        for (int i = Hash.SIZE_IN_BYTES; i-- > 0; ) {
            if (tx1.bytes()[i] != tx2.bytes()[i]) {
                return tx2.bytes()[i] - tx1.bytes()[i];
            }
        }
        return 0;
    });
}
Also used : Hash(com.iota.iri.model.Hash)

Aggregations

Hash (com.iota.iri.model.Hash)75 Test (org.junit.Test)16 TransactionViewModel (com.iota.iri.controllers.TransactionViewModel)12 RocksDBPersistenceProviderTest (com.iota.iri.storage.rocksDB.RocksDBPersistenceProviderTest)12 HttpString (io.undertow.util.HttpString)8 TransactionViewModelTest.getRandomTransactionHash (com.iota.iri.controllers.TransactionViewModelTest.getRandomTransactionHash)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Curl (com.iota.iri.hash.Curl)3 PearlDiver (com.iota.iri.hash.PearlDiver)3 TransactionRequester (com.iota.iri.network.TransactionRequester)3 Converter (com.iota.iri.utils.Converter)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 com.iota.iri (com.iota.iri)2 Configuration (com.iota.iri.conf.Configuration)2 DefaultConfSettings (com.iota.iri.conf.Configuration.DefaultConfSettings)2