Skip to content

Commit

Permalink
added restart round on changed miningInfo for same blockheight (optio…
Browse files Browse the repository at this point in the history
…nal feature) can be disabled by updateMiningInfo=false
  • Loading branch information
de-luxe committed Jul 9, 2017
1 parent 5be3bba commit ee386e1
Show file tree
Hide file tree
Showing 21 changed files with 333 additions and 57 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ e.g. on short disconnect or connected peers busy etc.

recommitDeadlines=true


## OpenCL
The miner uses openCL for most of the mining calculations, ensure it is setup correctly.
Instructions can be found e.g. here (thanks cryo):
Expand Down Expand Up @@ -159,6 +160,14 @@ interval of asking wallet/pool for mining info (in ms), to check for new block

refreshInterval=2000

### updateMiningInfo (default=true)
restart round on new generationSignature for same round
as long as equal miningInfo was not already finished
(it may happen that miningInfo changes, and changes back later)
false value will disable this feature

updateMiningInfo=false

### connectionTimeout (default:12000)
increase the 'connectionTimeout' on network problems. this timeout is used for all network requests.
if you use pool or online-wallet, the 12 sec. default may cause timeout on committing nonces
Expand Down Expand Up @@ -211,7 +220,25 @@ e.g. you see in logs, that 'drive-c' and 'drive-d' slow down this mining setup:
read 'C:/data/drive-c' (3TB 996GB) in '35s 390ms'
read 'C:/data/drive-d' (3TB 996GB) in '35s 685ms'

### logPatternConsole & logPatternFile
patterns for logfile and cosole output can be different
only needed if you want to configure your own log pattern e.g.
following would show colored time and message on console:

logPatternConsole=%blue(%d{HH:mm:ss.SSS}) %green(%msg%n)

only time and message for logfile:

logPatternFile=%d{HH:mm:ss.SSS} %msg%n

For all options please read from docs:
https://logback.qos.ch/manual/layouts.html#ClassicPatternLayout

### showSkippedDeadlines (default:true)
set this to 'true' to show found deadlines below targetDeadline configure or
provided by pool (overwriting the targetDeadline specified in jminer.properties)

showSkippedDeadlines=false


## Miner Memory Usage
Expand Down
5 changes: 5 additions & 0 deletions jminer.default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ deviceId=
# refreshInterval - interval of asking wallet/pool for mining info (in ms),
# (default:2000) to check for new block
#
# updateMiningInfo - restart round on new generationSignature for same round
# (default=true) as long as equal miningInfo was not already finished
# (it may happen that miningInfo changes, and changes back later)
#
# connectionTimeout - increase the 'connectionTimeout' on network problems.
# (default:12000) this timeout is used for all network requests.
# if you use pool or online-wallet, the 12 sec. default may
Expand All @@ -151,6 +155,7 @@ deviceId=
# Docs: https://logback.qos.ch/manual/layouts.html#ClassicPatternLayout
# -----------------------------------------------------------------------------------
refreshInterval=2000
updateMiningInfo=true
connectionTimeout=12000

debug=
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/burstcoin/jminer/JMinerCommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
import burstcoin.jminer.core.reader.event.ReaderDriveInterruptedEvent;
import burstcoin.jminer.core.reader.event.ReaderProgressChangedEvent;
import burstcoin.jminer.core.round.event.RoundFinishedEvent;
import burstcoin.jminer.core.round.event.RoundGenSigAlreadyMinedEvent;
import burstcoin.jminer.core.round.event.RoundGenSigUpdatedEvent;
import burstcoin.jminer.core.round.event.RoundSingleResultEvent;
import burstcoin.jminer.core.round.event.RoundSingleResultSkippedEvent;
import burstcoin.jminer.core.round.event.RoundStartedEvent;
import burstcoin.jminer.core.round.event.RoundStoppedEvent;
import nxt.util.Convert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
Expand All @@ -61,6 +64,7 @@ public class JMinerCommandLine
private static final String M_UNIT = CoreProperties.isByteUnitDecimal() ? "MB" : "MiB";

private static long blockNumber;
private static byte[] generationSignature;
private static int progressLogStep;
private static long previousRemainingCapacity = 0;
private static long previousElapsedTime = 0;
Expand Down Expand Up @@ -160,6 +164,7 @@ public void onApplicationEvent(NetworkLastWinnerEvent event)
public void onApplicationEvent(NetworkStateChangeEvent event)
{
blockNumber = event.getBlockNumber();
generationSignature = event.getGenerationSignature();
}
});

Expand All @@ -171,12 +176,31 @@ public void onApplicationEvent(RoundStartedEvent event)
progressLogStep = NUMBER_OF_PROGRESS_LOGS_PER_ROUND;

LOG.info("-------------------------------------------------------");
LOG.info("START block '" + event.getBlockNumber() + "', "
+ "scoopNumber '" + event.getScoopNumber() + "', "
+ "capacity '" + event.getCapacity() / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR + " " + G_UNIT + "'"
LOG.info(event.isRestart() ? "RE-" : "" + "START block '" + event.getBlockNumber() + "', "
+ "scoopNumber '" + event.getScoopNumber() + "', "
+ "capacity '" + event.getCapacity() / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR + " " + G_UNIT + "'"
);
String target = event.getTargetDeadline() == Long.MAX_VALUE ? "N/A" : String.valueOf(event.getTargetDeadline());
LOG.info(" targetDeadline '" + target + "', " + "baseTarget '" + String.valueOf(event.getBaseTarget()) + "'");
LOG.info(" targetDeadline '" + target + "', " + "baseTarget '" + String.valueOf(event.getBaseTarget()) + "', "
+ "genSig '" + Convert.toHexString(generationSignature).substring(0, 6) + "..'");
}
});

context.addApplicationListener(new ApplicationListener<RoundGenSigUpdatedEvent>()
{
@Override
public void onApplicationEvent(RoundGenSigUpdatedEvent event)
{
LOG.info("MiningInfo for block '" + event.getBlockNumber() + "' has changed, restarting round ...");
}
});

context.addApplicationListener(new ApplicationListener<RoundGenSigAlreadyMinedEvent>()
{
@Override
public void onApplicationEvent(RoundGenSigAlreadyMinedEvent event)
{
LOG.info("MiningInfo for block '" + event.getBlockNumber() + "' has changed back to previously successful mined.");
}
});

Expand Down Expand Up @@ -236,7 +260,8 @@ public void onApplicationEvent(ReaderProgressChangedEvent event)
@Override
public void onApplicationEvent(RoundSingleResultEvent event)
{
LOG.info("dl '" + event.getCalculatedDeadline() + "' send (" + (event.isPoolMining() ? "pool" : "solo") + ") [nonce '"+event.getNonce().toString()+"']");
LOG.info(
"dl '" + event.getCalculatedDeadline() + "' send (" + (event.isPoolMining() ? "pool" : "solo") + ") [nonce '" + event.getNonce().toString() + "']");
}
});

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/burstcoin/jminer/core/CoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package burstcoin.jminer.core;


import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.ssl.SslContextFactory;
Expand All @@ -38,7 +37,7 @@
* The type Core config.
*/
@Configuration
@ComponentScan(basePackages = "burstcoin.jminer.core")
@ComponentScan(basePackages = {"burstcoin.jminer.core"})
public class CoreConfig
{
@Bean(name = "readerPool")
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/burstcoin/jminer/core/CoreProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class CoreProperties
private static final boolean DEFAULT_DEBUG = false;
private static final boolean DEFAULT_TRIGGER_SERVER = false;
private static final boolean DEFAULT_WRITE_LOG_FILE = false;
private static final boolean DEFAULT_UPDATE_MINING_INFO = true;
private static final String DEFAULT_LOG_FILE_PATH = "log/jminer.log.txt";

static
Expand Down Expand Up @@ -104,6 +105,7 @@ public class CoreProperties
private static String logFilePath;
private static String logPatternFile;
private static String logPatternConsole;
private static Boolean updateMiningInfo;

private CoreProperties()
{
Expand Down Expand Up @@ -404,6 +406,15 @@ public static boolean isListPlotFiles()
return listPlotFiles;
}

public static boolean isUpdateMiningInfo()
{
if(updateMiningInfo == null)
{
updateMiningInfo = asBoolean("updateMiningInfo", DEFAULT_UPDATE_MINING_INFO);
}
return updateMiningInfo;
}

public static boolean isShowDriveInfo()
{
if(showDriveInfo == null)
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/burstcoin/jminer/core/checker/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
* The type Checker.
*/
Expand Down Expand Up @@ -65,15 +67,15 @@ public void reconfigure(long blockNumber, byte[] generationSignature)
@EventListener
public void handleMessage(ReaderLoadedPartEvent event)
{
if(blockNumber == event.getBlockNumber())
if(blockNumber == event.getBlockNumber() && Arrays.equals(generationSignature, event.getGenerationSignature()))
{
OCLCheckerTask oclCheckerTask = context.getBean(OCLCheckerTask.class);
oclCheckerTask.init(event.getBlockNumber(), generationSignature, event.getScoops(), event.getChunkPartStartNonce());
checkTaskExecutor.execute(oclCheckerTask);
}
else
{
LOG.trace("skipped check scoop ... old block ...");
LOG.trace("skipped check scoop ... outdated mining info...");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
*/
public class CheckerResultEvent
{
private byte[] generationSignature;
private BigInteger chunkPartStartNonce;

private long blockNumber;
private BigInteger nonce;
private BigInteger result;

public CheckerResultEvent(long blockNumber, BigInteger chunkPartStartNonce, BigInteger nonce, BigInteger result)
public CheckerResultEvent(long blockNumber, byte[] generationSignature, BigInteger chunkPartStartNonce, BigInteger nonce, BigInteger result)
{
this.generationSignature = generationSignature;
this.chunkPartStartNonce = chunkPartStartNonce;
this.blockNumber = blockNumber;

Expand All @@ -63,4 +65,9 @@ public BigInteger getChunkPartStartNonce()
{
return chunkPartStartNonce;
}

public byte[] getGenerationSignature()
{
return generationSignature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void run()
BigInteger nonce = chunkPartStartNonce.add(BigInteger.valueOf(lowestNonce));

BigInteger result = calculateResult(scoops, generationSignature, lowestNonce);
publisher.publishEvent(new CheckerResultEvent(blockNumber, chunkPartStartNonce, nonce, result));
publisher.publishEvent(new CheckerResultEvent(blockNumber, generationSignature, chunkPartStartNonce, nonce, result));
}

private BigInteger calculateResult(byte[] scoops, byte[] generationSignature, int nonce)
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/burstcoin/jminer/core/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class Network

private long blockNumber;
private Timer timer;
private byte[] generationSignature;

@PostConstruct
protected void postConstruct()
Expand Down Expand Up @@ -127,6 +128,7 @@ protected void postConstruct()
public void handleMessage(NetworkStateChangeEvent event)
{
blockNumber = event.getBlockNumber();
generationSignature = event.getGenerationSignature();
}

public void checkNetworkState()
Expand All @@ -135,7 +137,7 @@ public void checkNetworkState()
if(!StringUtils.isEmpty(server))
{
NetworkRequestMiningInfoTask networkRequestMiningInfoTask = context.getBean(NetworkRequestMiningInfoTask.class);
networkRequestMiningInfoTask.init(server, blockNumber, poolMining, connectionTimeout, defaultTargetDeadline);
networkRequestMiningInfoTask.init(server, blockNumber, generationSignature, poolMining, connectionTimeout, defaultTargetDeadline);
networkPool.execute(networkRequestMiningInfoTask);
}
}
Expand Down Expand Up @@ -178,14 +180,14 @@ public void commitResult(long blockNumber, long calculatedDeadline, BigInteger n
if(poolMining)
{
NetworkSubmitPoolNonceTask networkSubmitPoolNonceTask = context.getBean(NetworkSubmitPoolNonceTask.class);
networkSubmitPoolNonceTask.init(blockNumber, numericAccountId, poolServer, connectionTimeout, nonce,
networkSubmitPoolNonceTask.init(blockNumber, generationSignature, numericAccountId, poolServer, connectionTimeout, nonce,
chunkPartStartNonce, calculatedDeadline, totalCapacity, result);
networkPool.execute(networkSubmitPoolNonceTask);
}
else
{
NetworkSubmitSoloNonceTask networkSubmitSoloNonceTask = context.getBean(NetworkSubmitSoloNonceTask.class);
networkSubmitSoloNonceTask.init(blockNumber, passPhrase, soloServer, connectionTimeout, nonce, chunkPartStartNonce, calculatedDeadline, result);
networkSubmitSoloNonceTask.init(blockNumber, generationSignature, passPhrase, soloServer, connectionTimeout, nonce, chunkPartStartNonce, calculatedDeadline, result);
networkPool.execute(networkSubmitSoloNonceTask);

if(CoreProperties.isRecommitDeadlines() && calculatedDeadline < 1200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class NetworkResultConfirmedEvent
extends ApplicationEvent
{
private long blockNumber;
private byte[] generationSignature;
private long deadline;
private BigInteger nonce;

Expand All @@ -48,11 +49,12 @@ public class NetworkResultConfirmedEvent
* @param nonce the nonce
* @param chunkPartStartNonce the chunk part start nonce
*/
public NetworkResultConfirmedEvent(long blockNumber, long deadline, BigInteger nonce, BigInteger chunkPartStartNonce, BigInteger result)
public NetworkResultConfirmedEvent(long blockNumber, byte[] generationSignature, long deadline, BigInteger nonce, BigInteger chunkPartStartNonce, BigInteger result)
{
super(blockNumber);

this.blockNumber = blockNumber;
this.generationSignature = generationSignature;
this.deadline = deadline;
this.nonce = nonce;

Expand Down Expand Up @@ -104,4 +106,9 @@ public BigInteger getResult()
{
return result;
}

public byte[] getGenerationSignature()
{
return generationSignature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class NetworkResultErrorEvent
extends ApplicationEvent
{
private long blockNumber;
private byte[] generationSignature;
private BigInteger nonce;

private long calculatedDeadline;
Expand All @@ -50,11 +51,12 @@ public class NetworkResultErrorEvent
* @param strangeDeadline the strange deadline
* @param chunkPartStartNonce the chunk part start nonce
*/
public NetworkResultErrorEvent(long blockNumber, BigInteger nonce, long calculatedDeadline, long strangeDeadline, BigInteger chunkPartStartNonce, BigInteger result)
public NetworkResultErrorEvent(long blockNumber, byte[] generationSignature, BigInteger nonce, long calculatedDeadline, long strangeDeadline, BigInteger chunkPartStartNonce, BigInteger result)
{
super(blockNumber);

this.blockNumber = blockNumber;
this.generationSignature = generationSignature;
this.nonce = nonce;
this.calculatedDeadline = calculatedDeadline;
this.strangeDeadline = strangeDeadline;
Expand Down Expand Up @@ -117,4 +119,9 @@ public BigInteger getResult()
{
return result;
}

public byte[] getGenerationSignature()
{
return generationSignature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ public class NetworkRequestMiningInfoTask
@Autowired
private ApplicationEventPublisher publisher;

private byte[] generationSignature;
private long blockNumber;
private String server;

private boolean poolMining;
private long connectionTimeout;
private long defaultTargetDeadline;

public void init(String server, long blockNumber, boolean poolMining, long connectionTimeout, long defaultTargetDeadline)
public void init(String server, long blockNumber, byte[] generationSignature, boolean poolMining, long connectionTimeout,
long defaultTargetDeadline)
{
this.server = server;
this.generationSignature = generationSignature;
this.blockNumber = blockNumber;
this.poolMining = poolMining;
this.connectionTimeout = connectionTimeout;
Expand Down
Loading

0 comments on commit ee386e1

Please sign in to comment.