Search in sources :

Example 6 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapIndexCandidateSelector method getEntriesPerHeight.

private Map<Long, Map<String, BootstrapDataEntry>> getEntriesPerHeight(List<BootstrapDataIndex> indexes) {
    // the outer map represents the tuples (height, heightEntries)
    // the inner map represents the tuples (source, dbEntry)
    Map<Long, Map<String, BootstrapDataEntry>> entriesPerHeight = new HashMap<>();
    // each iteration is an index from a different source, each index contains many entries
    for (int i = 0; i < indexes.size(); i++) {
        BootstrapDataIndex bdi = indexes.get(i);
        String publicKey = publicKeys.get(i);
        // all the items for this index belongs to the same source
        for (BootstrapDataEntry bde : bdi.getDbs()) {
            Map<String, BootstrapDataEntry> entries = entriesPerHeight.computeIfAbsent(bde.getHeight(), k -> new HashMap<>());
            // if any height is duplicated on a single file the process is stopped
            if (entries.get(publicKey) != null) {
                throw new BootstrapImportException(String.format("There is an invalid file from %s: it has 2 entries from same height %d", publicKey, bde.getHeight()));
            }
            entries.put(publicKey, bde);
        }
    }
    if (entriesPerHeight.isEmpty()) {
        throw new BootstrapImportException("Downloaded files contain no height entries");
    }
    return entriesPerHeight;
}
Also used : BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) BootstrapImportException(co.rsk.db.importer.BootstrapImportException) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex)

Example 7 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapDataVerifierTest method doNotVerifyForDifferentHashes.

@Test(expected = BootstrapImportException.class)
public void doNotVerifyForDifferentHashes() {
    BootstrapDataVerifier bootstrapDataVerifier = new BootstrapDataVerifier();
    HashMap<String, BootstrapDataEntry> entries = new HashMap<>();
    List<String> keys = new ArrayList<>();
    keys.add("04330037e82c177d7108077c80440821e13c1c62105f85e030214b48d7b5dff0b8e7c158b171546a71139e4de56c8535c964514033b89a669a8e87a5e8770c147c");
    keys.add("04dffaa346b18c26230d6050c6ab67f0761ab12136b0dc3a1f1c6ed31890ffac38baa3d8da1df4aa2acc72e45dc3599797ba668666c5395280217f2fd215262b8a");
    keys.add("04bf74915a14e96df0b520a659acc28ae21aada3b0415e35f82f0c7b546338fc48bbfdce858ce3e4690feeb443d7f4955881ba0b793999e4fef7e46732e7fedf02");
    String hash1 = "53cb8e93030183c5ba198433e8cd1f013f3d113e0f4d1756de0d1f124ead155a";
    String hash2 = "87d149cb424c0387656f211d2589fb5b1e16229921309e98588419ccca8a7362";
    String hash3 = "53cb8e93030183c5ba198433e8cd1f013f3d113e0f4d1756de0d1f124ead155c";
    String r1 = "8dba957877d5bdcb26d551dfa2fa509dfe3fe327caf0166130b9f467a0a0c249";
    String s1 = "dab3fdf2031515d2de1d420310c69153fcc356f22b50dfd53c6e13e74e346eee";
    String r2 = "0efa8e0738468e434e443676b5a91fe15b0c416ff7190d8d912dff65161ad33c";
    String s2 = "aae27edef80e137dc1a0e92b6ae7fed0d1dc1b4a0ea8930bad6abec5ca1297c1";
    String r3 = "00";
    String s3 = "00";
    entries.put(keys.get(0), new BootstrapDataEntry(1, "", "dbPath", hash1, new BootstrapDataSignature(r1, s1)));
    entries.put(keys.get(1), new BootstrapDataEntry(1, "", "dbPath", hash2, new BootstrapDataSignature(r2, s2)));
    entries.put(keys.get(2), new BootstrapDataEntry(1, "", "dbPath", hash3, new BootstrapDataSignature(r3, s3)));
    bootstrapDataVerifier.verifyEntries(entries);
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) HashMap(java.util.HashMap) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataDuplicatedEntries.

@Test(expected = BootstrapImportException.class)
public void getMaximumCommonHeightDataDuplicatedEntries() {
    List<String> keys = Arrays.asList("key1", "key2");
    BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
    List<BootstrapDataIndex> indexes = new ArrayList<>();
    ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
    entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    indexes.add(new BootstrapDataIndex(entries));
    indexMCH.getHeightData(indexes);
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) Test(org.junit.Test)

Example 9 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataOneEntry.

@Test(expected = BootstrapImportException.class)
public void getMaximumCommonHeightDataOneEntry() {
    List<String> keys = Arrays.asList("key1", "key2");
    BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
    List<BootstrapDataIndex> indexes = new ArrayList<>();
    ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
    entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    indexes.add(new BootstrapDataIndex(entries));
    indexMCH.getHeightData(indexes);
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) Test(org.junit.Test)

Example 10 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataTwoEntries.

@Test
public void getMaximumCommonHeightDataTwoEntries() {
    List<String> keys = Arrays.asList("key1", "key2");
    BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
    List<BootstrapDataIndex> indexes = new ArrayList<>();
    ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
    ArrayList<BootstrapDataEntry> entries2 = new ArrayList<>();
    entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    entries2.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    indexes.add(new BootstrapDataIndex(entries));
    indexes.add(new BootstrapDataIndex(entries2));
    BootstrapIndexCandidateSelector.HeightCandidate heightCandidate = indexMCH.getHeightData(indexes);
    assertEquals(1, heightCandidate.getHeight());
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) Test(org.junit.Test)

Aggregations

BootstrapDataEntry (co.rsk.db.importer.provider.index.data.BootstrapDataEntry)12 Test (org.junit.Test)10 BootstrapDataSignature (co.rsk.db.importer.provider.index.data.BootstrapDataSignature)9 BootstrapDataIndex (co.rsk.db.importer.provider.index.data.BootstrapDataIndex)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 BootstrapImportException (co.rsk.db.importer.BootstrapImportException)2 BootstrapIndexCandidateSelector (co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector)2 BootstrapIndexRetriever (co.rsk.db.importer.provider.index.BootstrapIndexRetriever)2 BootstrapURLProvider (co.rsk.db.importer.BootstrapURLProvider)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BigInteger (java.math.BigInteger)1 URL (java.net.URL)1 Map (java.util.Map)1 ECDSASignature (org.ethereum.crypto.signature.ECDSASignature)1