Search in sources :

Example 1 with SnowFieldInfo

use of snowblossom.lib.SnowFieldInfo in project snowblossom by snowblossomcoin.

the class FieldScan method scan.

public void scan(boolean report) {
    TreeMap<Integer, SnowMerkleProof> fmap = new TreeMap<>();
    for (Map.Entry<Integer, String> me : params.getFieldSeeds().entrySet()) {
        int field_number = me.getKey();
        SnowFieldInfo info = params.getSnowFieldInfo(field_number);
        String name = me.getValue();
        File field_folder = new File(path, name);
        if (field_folder.exists() && field_folder.isDirectory()) {
            try {
                double precacheGig = config.getDoubleWithDefault("memfield_precache_gb", 0);
                int minDepthToDisk = config.getIntWithDefault("min_depth_to_disk", 0);
                boolean memfield = config.getBoolean("memfield");
                long precache = 0;
                if (precacheGig > 0.01) {
                    memfield = false;
                    precache = (long) (precacheGig * 1024.0 * 1024.0 * 1024.0);
                }
                logger.info("creating field: " + field_folder + " memfield=" + memfield + ", precache=" + precache + ", minDepthToDisk=" + minDepthToDisk);
                SnowMerkleProof proof = new SnowMerkleProof(field_folder, name, memfield, precache, minDepthToDisk);
                for (int i = 0; i < 64; i++) {
                    checkField(field_number, proof);
                }
                fmap.put(field_number, proof);
                logger.info(String.format("Snow field %d %s (%s) is working", field_number, name, info.getName()));
            } catch (Throwable e) {
                logger.info(String.format("Unable to load %s, error: %s", name, e.toString()));
            }
        } else {
            logger.info(String.format("Not loading %d %s (%s), directory not present: %s", field_number, name, info.getName(), field_folder));
        }
    }
    availible_fields = ImmutableSortedMap.copyOf(fmap);
}
Also used : TreeMap(java.util.TreeMap) SnowFieldInfo(snowblossom.lib.SnowFieldInfo) TreeMap(java.util.TreeMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) File(java.io.File)

Example 2 with SnowFieldInfo

use of snowblossom.lib.SnowFieldInfo in project snowblossom by snowblossomcoin.

the class FieldScan method checkField.

private void checkField(int field_number, SnowMerkleProof proof) throws java.io.IOException {
    SplittableRandom rnd = new SplittableRandom();
    long max = proof.getTotalWords();
    long check = rnd.nextLong(max);
    SnowPowProof p = proof.getProof(check);
    SnowFieldInfo info = params.getSnowFieldInfo(field_number);
    if (!Validation.checkProof(p, info.getMerkleRootHash(), info.getLength())) {
        throw new RuntimeException("proof check failed");
    }
}
Also used : SnowFieldInfo(snowblossom.lib.SnowFieldInfo) SnowPowProof(snowblossom.proto.SnowPowProof) SplittableRandom(java.util.SplittableRandom)

Example 3 with SnowFieldInfo

use of snowblossom.lib.SnowFieldInfo in project snowblossom by snowblossomcoin.

the class AutoSnowFall method run.

public void run() {
    try {
        SnowFieldInfo field_info = params.getSnowFieldInfo(field);
        logger.info(String.format("Started automatic snowfall of field %d - %s", field, field_info.getName()));
        String path_name = params.getFieldSeeds().get(field);
        File field_dir = new File(snow_path, path_name);
        File snow_file = new File(field_dir, path_name + ".snow");
        field_dir.mkdirs();
        new SnowFall(snow_file.getPath(), path_name, field_info.getLength());
        logger.info(String.format("Snow field written: %s", snow_file.getPath()));
        logger.info("Starting merkle deck files");
        SnowMerkle merk = new SnowMerkle(field_dir, path_name, true);
        ByteString found_root = merk.getRootHash();
        if (field_info.getMerkleRootHash().equals(found_root)) {
            logger.info(String.format("Field %d - %s successfully matches hash %s", field, field_info.getName(), merk.getRootHashStr()));
        } else {
            logger.info("Hash mismatch for field");
        }
        done = true;
    } catch (Exception e) {
        logger.log(Level.WARNING, "Exception in autosnow: " + e);
    }
}
Also used : SnowMerkle(snowblossom.lib.SnowMerkle) SnowFieldInfo(snowblossom.lib.SnowFieldInfo) ByteString(com.google.protobuf.ByteString) SnowFall(snowblossom.lib.SnowFall) ByteString(com.google.protobuf.ByteString) File(java.io.File)

Example 4 with SnowFieldInfo

use of snowblossom.lib.SnowFieldInfo in project snowblossom by snowblossomcoin.

the class SpoonTest method setupSnow.

protected File setupSnow(String network) throws Exception {
    TreeMap<String, String> config_map = new TreeMap<>();
    config_map.put("network", network);
    NetworkParams params = NetworkParams.loadFromConfig(new ConfigMem(config_map));
    String test_folder_base = test_folder.newFolder().getPath();
    File snow_path = new File(test_folder.newFolder(), "snow");
    for (int i = 0; i < 4; i++) {
        SnowFieldInfo info = params.getSnowFieldInfo(i);
        String name = network + "." + i;
        File field_path = new File(snow_path, name);
        field_path.mkdirs();
        File field = new File(field_path, name + ".snow");
        new SnowFall(field.getPath(), name, info.getLength());
        ByteString root_hash = new SnowMerkle(field_path, name, true).getRootHash();
        Assert.assertEquals(info.getMerkleRootHash(), root_hash);
    }
    return snow_path;
}
Also used : SnowMerkle(snowblossom.lib.SnowMerkle) SnowFieldInfo(snowblossom.lib.SnowFieldInfo) ByteString(com.google.protobuf.ByteString) NetworkParams(snowblossom.lib.NetworkParams) SnowFall(snowblossom.lib.SnowFall) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem) File(java.io.File)

Aggregations

SnowFieldInfo (snowblossom.lib.SnowFieldInfo)4 File (java.io.File)3 ByteString (com.google.protobuf.ByteString)2 SnowFall (snowblossom.lib.SnowFall)2 SnowMerkle (snowblossom.lib.SnowMerkle)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ConfigMem (duckutil.ConfigMem)1 Map (java.util.Map)1 SplittableRandom (java.util.SplittableRandom)1 TreeMap (java.util.TreeMap)1 NetworkParams (snowblossom.lib.NetworkParams)1 SnowPowProof (snowblossom.proto.SnowPowProof)1