Search in sources :

Example 1 with MrPlow

use of snowblossom.miner.plow.MrPlow in project snowblossom by snowblossomcoin.

the class SpoonTest method startMrPlow.

protected MrPlow startMrPlow(List<Integer> node_ports, AddressSpecHash pool_addr, String network) throws Exception {
    NetworkParams params = NetworkParams.loadFromName(network);
    String plow_db_path = test_folder.newFolder().getPath();
    Map<String, String> config_map = new TreeMap<>();
    StringBuilder uris = new StringBuilder();
    boolean first = true;
    for (int port : node_ports) {
        if (!first)
            uris.append(",");
        uris.append("grpc://localhost:" + port + "/");
        first = false;
    }
    config_map.put("node_uri", uris.toString());
    config_map.put("db_type", "rocksdb");
    config_map.put("db_type", "atomic_file");
    config_map.put("db_path", plow_db_path + "/plowdb");
    config_map.put("pool_fee", "0.01");
    config_map.put("pool_address", pool_addr.toAddressString(params));
    config_map.put("mining_pool_port", "0");
    config_map.put("tls_mining_pool_port", "0");
    config_map.put("tls_key_path", plow_db_path + "/plow_tls");
    config_map.put("network", network);
    config_map.put("min_diff", "11");
    return new MrPlow(new ConfigMem(config_map));
}
Also used : NetworkParams(snowblossom.lib.NetworkParams) MrPlow(snowblossom.miner.plow.MrPlow) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem)

Example 2 with MrPlow

use of snowblossom.miner.plow.MrPlow in project snowblossom by snowblossomcoin.

the class SpoonTestPool method spoonPoolTest.

@Test
public void spoonPoolTest() throws Exception {
    File snow_path = setupSnow();
    Random rnd = new Random();
    int port = 20000 + rnd.nextInt(30000);
    SnowBlossomNode node = startNode(port);
    Thread.sleep(2000);
    KeyPair key_pair = KeyUtil.generateECCompressedKey();
    AddressSpec claim = AddressUtil.getSimpleSpecForKey(key_pair.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr = AddressUtil.getHashForSpec(claim);
    KeyPair key_pair2 = KeyUtil.generateECCompressedKey();
    AddressSpec claim2 = AddressUtil.getSimpleSpecForKey(key_pair2.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr2 = AddressUtil.getHashForSpec(claim2);
    KeyPair key_pair3 = KeyUtil.generateECCompressedKey();
    AddressSpec claim3 = AddressUtil.getSimpleSpecForKey(key_pair3.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr3 = AddressUtil.getHashForSpec(claim3);
    SnowBlossomClient client = startClient(port);
    MrPlow plow = startMrPlow(port, to_addr2);
    Thread.sleep(4000);
    PoolMiner miner = startPoolMiner(plow.getGrpcPort(), to_addr, snow_path);
    Thread.sleep(25000);
    waitForMoreBlocks(node, 10);
    System.out.println("ShareMap: " + plow.getShareManager().getShareMap());
    System.out.println("ShareMap pay: " + plow.getShareManager().getPayRatios());
    // Pool getting paid
    waitForFunds(client, to_addr2, 10);
    // Miner getting paid
    waitForFunds(client, to_addr, 30);
    PoolMiner miner2 = startPoolMiner(plow.getGrpcPort(), to_addr3, snow_path);
    // Second miner getting paid
    waitForFunds(client, to_addr3, 30);
    miner.stop();
    miner2.stop();
    Thread.sleep(500);
    plow.stop();
    node.stop();
}
Also used : PoolMiner(snowblossom.miner.PoolMiner) KeyPair(java.security.KeyPair) SnowBlossomNode(snowblossom.node.SnowBlossomNode) SnowBlossomClient(snowblossom.client.SnowBlossomClient) MrPlow(snowblossom.miner.plow.MrPlow) File(java.io.File) AddressSpecHash(snowblossom.lib.AddressSpecHash) Test(org.junit.Test)

Example 3 with MrPlow

use of snowblossom.miner.plow.MrPlow in project snowblossom by snowblossomcoin.

the class SpoonTestPoolTls method spoonPoolTest.

@Test
public void spoonPoolTest() throws Exception {
    File snow_path = setupSnow();
    Random rnd = new Random();
    int port = 20000 + rnd.nextInt(30000);
    SnowBlossomNode node = startNode(port);
    Thread.sleep(2000);
    KeyPair key_pair = KeyUtil.generateECCompressedKey();
    AddressSpec claim = AddressUtil.getSimpleSpecForKey(key_pair.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr = AddressUtil.getHashForSpec(claim);
    KeyPair key_pair2 = KeyUtil.generateECCompressedKey();
    AddressSpec claim2 = AddressUtil.getSimpleSpecForKey(key_pair2.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr2 = AddressUtil.getHashForSpec(claim2);
    KeyPair key_pair3 = KeyUtil.generateECCompressedKey();
    AddressSpec claim3 = AddressUtil.getSimpleSpecForKey(key_pair3.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr3 = AddressUtil.getHashForSpec(claim3);
    SnowBlossomClient client = startClient(port);
    MrPlow plow = startMrPlow(port, to_addr2);
    Thread.sleep(4000);
    String uri = "grpc+tls://localhost:" + plow.getGrpcTlsPort();
    PoolMiner miner = startPoolMinerUri(uri, to_addr, snow_path, "spoon");
    Thread.sleep(25000);
    waitForMoreBlocks(node, 10);
    System.out.println("ShareMap: " + plow.getShareManager().getShareMap());
    System.out.println("ShareMap pay: " + plow.getShareManager().getPayRatios());
    // Pool getting paid
    waitForFunds(client, to_addr2, 10);
    // Miner getting paid
    waitForFunds(client, to_addr, 30);
    String uri_key = uri + "/?key=" + plow.getTlsKeyId();
    PoolMiner miner2 = startPoolMinerUri(uri_key, to_addr3, snow_path, "spoon");
    // Second miner getting paid
    waitForFunds(client, to_addr3, 30);
    miner.stop();
    miner2.stop();
    Thread.sleep(500);
    plow.stop();
    node.stop();
}
Also used : PoolMiner(snowblossom.miner.PoolMiner) KeyPair(java.security.KeyPair) SnowBlossomNode(snowblossom.node.SnowBlossomNode) SnowBlossomClient(snowblossom.client.SnowBlossomClient) MrPlow(snowblossom.miner.plow.MrPlow) File(java.io.File) AddressSpecHash(snowblossom.lib.AddressSpecHash) Test(org.junit.Test)

Example 4 with MrPlow

use of snowblossom.miner.plow.MrPlow in project snowblossom by snowblossomcoin.

the class ShardTestPlow method shardTest.

/**
 * Run four nodes, each with some sub sets, with no overlap.
 * They have to use trust network to get anywhere.
 * node-0 has no miner and views entire network.
 * using it as an easy way to see that network status
 * and as a p2p networking gateway
 * Also only one miner using a MrPlow that talks to the four nodes.
 */
@Test
public void shardTest() throws Exception {
    File snow_path = setupSnow("regshard");
    String trust_folder_base = test_folder.newFolder().getPath();
    node0 = startNode(0, "regshard", ImmutableMap.of("shards", "0", "trustnet_key_path", trust_folder_base));
    AddressSpecHash trust_addr = node0.getTrustnetAddress();
    String trust_str = AddressUtil.getAddressString("node", trust_addr);
    node1 = startNode(0, "regshard", ImmutableMap.of("shards", "3", "trustnet_key_path", trust_folder_base, "trustnet_signers", trust_str));
    node2 = startNode(0, "regshard", ImmutableMap.of("shards", "4", "trustnet_key_path", trust_folder_base, "trustnet_signers", trust_str));
    node3 = startNode(0, "regshard", ImmutableMap.of("shards", "5", "trustnet_key_path", trust_folder_base, "trustnet_signers", trust_str));
    node4 = startNode(0, "regshard", ImmutableMap.of("shards", "6", "trustnet_key_path", trust_folder_base, "trustnet_signers", trust_str));
    int[] ports = new int[5];
    ports[0] = node0.getServicePorts().get(0);
    ports[1] = node1.getServicePorts().get(0);
    ports[2] = node2.getServicePorts().get(0);
    ports[3] = node3.getServicePorts().get(0);
    ports[4] = node4.getServicePorts().get(0);
    Thread.sleep(100);
    node1.getPeerage().connectPeer("localhost", ports[0]);
    node2.getPeerage().connectPeer("localhost", ports[0]);
    node3.getPeerage().connectPeer("localhost", ports[0]);
    node4.getPeerage().connectPeer("localhost", ports[0]);
    Thread.sleep(3000);
    KeyPair key_pair = KeyUtil.generateECCompressedKey();
    AddressSpec claim = AddressUtil.getSimpleSpecForKey(key_pair.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr = AddressUtil.getHashForSpec(claim);
    KeyPair key_pair_pool = KeyUtil.generateECCompressedKey();
    AddressSpec claim_pool = AddressUtil.getSimpleSpecForKey(key_pair_pool.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr_pool = AddressUtil.getHashForSpec(claim_pool);
    MrPlow plow = startMrPlow(ImmutableList.of(ports[1], ports[2], ports[3], ports[4]), to_addr_pool, "regshard");
    PoolMiner miner1 = startPoolMiner(plow.getGrpcPort(), to_addr, snow_path, "regshard");
    waitForHeight(node1, 3, 36, 100);
    waitForHeight(node2, 4, 36, 80);
    waitForHeight(node3, 5, 36, 80);
    waitForHeight(node4, 6, 36, 80);
    waitForHeight(node0, 3, 36, 100);
    waitForHeight(node0, 4, 36, 80);
    waitForHeight(node0, 5, 36, 80);
    waitForHeight(node0, 6, 36, 80);
    miner1.stop();
    Thread.sleep(500);
    node0.stop();
    node1.stop();
    node2.stop();
    node3.stop();
    node4.stop();
}
Also used : PoolMiner(snowblossom.miner.PoolMiner) KeyPair(java.security.KeyPair) MrPlow(snowblossom.miner.plow.MrPlow) File(java.io.File) AddressSpecHash(snowblossom.lib.AddressSpecHash) Test(org.junit.Test)

Aggregations

MrPlow (snowblossom.miner.plow.MrPlow)4 File (java.io.File)3 KeyPair (java.security.KeyPair)3 Test (org.junit.Test)3 AddressSpecHash (snowblossom.lib.AddressSpecHash)3 PoolMiner (snowblossom.miner.PoolMiner)3 SnowBlossomClient (snowblossom.client.SnowBlossomClient)2 SnowBlossomNode (snowblossom.node.SnowBlossomNode)2 ByteString (com.google.protobuf.ByteString)1 ConfigMem (duckutil.ConfigMem)1 NetworkParams (snowblossom.lib.NetworkParams)1