Skip to content

Commit

Permalink
#12 provide some info about pool on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
de-luxe committed Mar 1, 2016
1 parent 9285c7a commit 25a1b1c
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 64 deletions.
17 changes: 17 additions & 0 deletions src/main/java/burstcoin/jminer/CommandLineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import burstcoin.jminer.core.network.Network;
import burstcoin.jminer.core.network.event.NetworkDevResultConfirmedEvent;
import burstcoin.jminer.core.network.event.NetworkLastWinnerEvent;
import burstcoin.jminer.core.network.event.NetworkPoolInfoEvent;
import burstcoin.jminer.core.network.event.NetworkResultConfirmedEvent;
import burstcoin.jminer.core.network.event.NetworkResultErrorEvent;
import burstcoin.jminer.core.network.event.NetworkStateChangeEvent;
Expand Down Expand Up @@ -297,6 +298,21 @@ public void onApplicationEvent(ReaderDriveInterruptedEvent event)
}
});

context.addApplicationListener(new ApplicationListener<NetworkPoolInfoEvent>()
{
@Override
public void onApplicationEvent(NetworkPoolInfoEvent event)
{
String value = event.getPoolBalanceNQT();
String amount = value.length() > 8 ? value.substring(0, value.length() - 8) : value;
value = event.getPoolForgedBalanceNQT();
String totalForget = value.length() > 8 ? value.substring(0, value.length() - 8) : value;
LOG.info("-------------------------------------------------------");
LOG.info("POOL account '" + event.getPoolAccountRS() + "', assigned miners '" + event.getPoolNumberOfMiningAccounts() + "'");
LOG.info(" balance '" + amount + " BURST', total mined '" + totalForget + " BURST'");
}
});

LOG.info("");
LOG.info(" Burstcoin (BURST)");
LOG.info(" __ __ GPU assisted PoC-Miner");
Expand All @@ -309,6 +325,7 @@ public void onApplicationEvent(ReaderDriveInterruptedEvent event)
LOG.info(" openCL checker: BURST-QHCJ-9HB5-PTGC-5Q8J9");

Network network = context.getBean(Network.class);
network.checkPoolInfo();
network.startMining();
}

Expand Down
78 changes: 28 additions & 50 deletions src/main/java/burstcoin/jminer/core/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import burstcoin.jminer.core.network.model.DevPoolResult;
import burstcoin.jminer.core.network.task.NetworkRequestLastWinnerTask;
import burstcoin.jminer.core.network.task.NetworkRequestMiningInfoTask;
import burstcoin.jminer.core.network.task.NetworkRequestPoolInfoTask;
import burstcoin.jminer.core.network.task.NetworkSubmitDevPoolNoncesTask;
import burstcoin.jminer.core.network.task.NetworkSubmitPoolNonceTask;
import burstcoin.jminer.core.network.task.NetworkSubmitSoloNonceTask;
Expand All @@ -47,9 +48,6 @@
import java.util.Timer;
import java.util.TimerTask;

/**
* The type Network.
*/
@Component
@Scope("singleton")
public class Network
Expand Down Expand Up @@ -83,9 +81,6 @@ public class Network
private long blockNumber;
private Timer timer;

/**
* Post construct.
*/
@PostConstruct
protected void postConstruct()
{
Expand Down Expand Up @@ -131,15 +126,26 @@ protected void postConstruct()
}
this.defaultTargetDeadline = CoreProperties.getTargetDeadline();
this.connectionTimeout = CoreProperties.getConnectionTimeout();
}

// startMining();
@Override
@EventListener
public void handleMessage(NetworkStateChangeEvent event)
{
blockNumber = event.getBlockNumber();
}

public void checkNetworkState()
{
String server = poolMining ? poolServer : soloServer;
if(!StringUtils.isEmpty(server))
{
NetworkRequestMiningInfoTask networkRequestMiningInfoTask = context.getBean(NetworkRequestMiningInfoTask.class);
networkRequestMiningInfoTask.init(server, blockNumber, poolMining, connectionTimeout, defaultTargetDeadline, devPool);
networkPool.execute(networkRequestMiningInfoTask);
}
}

/**
* Check last winner.
*
* @param blockNumber the block number
*/
public void checkLastWinner(long blockNumber)
{
// find winner of lastBlock on new round, if server available
Expand All @@ -152,14 +158,16 @@ public void checkLastWinner(long blockNumber)
}
}

/**
* Commit result.
*
* @param blockNumber the block number
* @param calculatedDeadline the calculated deadline
* @param nonce the nonce
* @param chunkPartStartNonce the chunk part start nonce
*/
public void checkPoolInfo()
{
if(CoreProperties.isPoolMining() && !walletServer.equals("disabled"))
{
NetworkRequestPoolInfoTask networkRequestPoolInfoTask = context.getBean(NetworkRequestPoolInfoTask.class);
networkRequestPoolInfoTask.init(walletServer, numericAccountId, connectionTimeout);
networkPool.execute(networkRequestPoolInfoTask);
}
}

public void commitResult(long blockNumber, long calculatedDeadline, long nonce, long chunkPartStartNonce, long totalCapacity)
{
if(poolMining)
Expand Down Expand Up @@ -188,43 +196,13 @@ public void commitResult(long blockNumber, long calculatedDeadline, long nonce,
}
}

/**
* Commit dev result.
*
* @param blockNumber the block number
* @param devPoolResults the dev pool results
*/
public void commitDevResult(long blockNumber, List<DevPoolResult> devPoolResults)
{
NetworkSubmitDevPoolNoncesTask networkSubmitDevPoolNoncesTask = context.getBean(NetworkSubmitDevPoolNoncesTask.class);
networkSubmitDevPoolNoncesTask.init(blockNumber, numericAccountId, poolServer, connectionTimeout, devPoolResults);
networkPool.execute(networkSubmitDevPoolNoncesTask);
}

@Override
@EventListener
public void handleMessage(NetworkStateChangeEvent event)
{
blockNumber = event.getBlockNumber();
}

/**
* Check network state.
*/
public void checkNetworkState()
{
String server = poolMining ? poolServer : soloServer;
if(!StringUtils.isEmpty(server))
{
NetworkRequestMiningInfoTask networkRequestMiningInfoTask = context.getBean(NetworkRequestMiningInfoTask.class);
networkRequestMiningInfoTask.init(server, blockNumber, poolMining, connectionTimeout, defaultTargetDeadline, devPool);
networkPool.execute(networkRequestMiningInfoTask);
}
}

/**
* Start mining.
*/
public void startMining()
{
timer.schedule(new TimerTask()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

package burstcoin.jminer.core.network.event;

import org.springframework.context.ApplicationEvent;


public class NetworkPoolInfoEvent
extends ApplicationEvent
{
private String poolAccountRS;
private String poolBalanceNQT;
private String poolForgedBalanceNQT;
private int poolNumberOfMiningAccounts; // todo find active

public NetworkPoolInfoEvent(String poolAccountRS, String poolBalanceNQT, String poolForgedBalanceNQT, int poolNumberOfMiningAccounts)
{
super(poolAccountRS);

this.poolAccountRS = poolAccountRS;
this.poolBalanceNQT = poolBalanceNQT;
this.poolForgedBalanceNQT = poolForgedBalanceNQT;
this.poolNumberOfMiningAccounts = poolNumberOfMiningAccounts;
}

public String getPoolAccountRS()
{
return poolAccountRS;
}

public String getPoolBalanceNQT()
{
return poolBalanceNQT;
}

public String getPoolForgedBalanceNQT()
{
return poolForgedBalanceNQT;
}

public int getPoolNumberOfMiningAccounts()
{
return poolNumberOfMiningAccounts;
}
}
58 changes: 58 additions & 0 deletions src/main/java/burstcoin/jminer/core/network/model/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

package burstcoin.jminer.core.network.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.io.Serializable;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Account
implements Serializable
{
private String accountRS;
private String balanceNQT;
private String forgedBalanceNQT;

private long requestProcessingTime;

public String getAccountRS()
{
return accountRS;
}

public String getBalanceNQT()
{
return balanceNQT;
}

public String getForgedBalanceNQT()
{
return forgedBalanceNQT;
}

public long getRequestProcessingTime()
{
return requestProcessingTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

package burstcoin.jminer.core.network.model;


import java.io.Serializable;
import java.util.List;

public class AccountsWithRewardRecipient
implements Serializable
{
private List<String> accounts;

private long requestProcessingTime;

public List<String> getAccounts()
{
return accounts;
}

public long getRequestProcessingTime()
{
return requestProcessingTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

package burstcoin.jminer.core.network.model;

import java.io.Serializable;

public class RewardRecipient
implements Serializable
{
// accountId of reward recipient
private String rewardRecipient;

private long requestProcessingTime;

public String getRewardRecipient()
{
return rewardRecipient;
}

public long getRequestProcessingTime()
{
return requestProcessingTime;
}
}
Loading

0 comments on commit 25a1b1c

Please sign in to comment.