Skip to content

Commit

Permalink
Move miner client configuration to the configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
colltoaction committed Sep 17, 2018
1 parent a75acd1 commit 3e50191
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -123,6 +124,14 @@ public boolean isMinerClientEnabled() {
return getBoolean("miner.client.enabled", false);
}

public Duration minerClientDelayBetweenBlocks() {
return configFromFiles.getDuration("miner.client.delayBetweenBlocks");
}

public Duration minerClientDelayBetweenRefreshes() {
return configFromFiles.getDuration("miner.client.delayBetweenRefreshes");
}

public boolean isMinerServerEnabled() {
return getBoolean("miner.server.enabled", false);
}
Expand Down
20 changes: 8 additions & 12 deletions rskj-core/src/main/java/co/rsk/mine/MinerClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import co.rsk.config.RskSystemProperties;
import co.rsk.core.Rsk;
import co.rsk.panic.PanicProcessor;
import org.ethereum.config.net.DevNetConfig;
import org.ethereum.config.net.RegTestConfig;
import org.ethereum.rpc.TypeConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -31,6 +29,7 @@

import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.time.Duration;
import java.util.Timer;
import java.util.TimerTask;

Expand All @@ -48,11 +47,10 @@ public class MinerClientImpl implements MinerClient {
private static final Logger logger = LoggerFactory.getLogger("minerClient");
private static final PanicProcessor panicProcessor = new PanicProcessor();

private static final long DELAY_BETWEEN_GETWORK_REFRESH_MS = 1000;

private final Rsk rsk;
private final MinerServer minerServer;
private final RskSystemProperties config;
private final Duration delayBetweenBlocks;
private final Duration delayBetweenRefreshes;

private volatile boolean stop = false;

Expand All @@ -67,12 +65,13 @@ public class MinerClientImpl implements MinerClient {
public MinerClientImpl(Rsk rsk, MinerServer minerServer, RskSystemProperties config) {
this.rsk = rsk;
this.minerServer = minerServer;
this.config = config;
this.delayBetweenBlocks = config.minerClientDelayBetweenBlocks();
this.delayBetweenRefreshes = config.minerClientDelayBetweenRefreshes();
}

public void mine() {
aTimer = new Timer("Refresh work for mining");
aTimer.schedule(createRefreshWork(), 0, DELAY_BETWEEN_GETWORK_REFRESH_MS);
aTimer.schedule(createRefreshWork(), 0, this.delayBetweenRefreshes.toMillis());

Thread doWorkThread = this.createDoWorkThread();
doWorkThread.start();
Expand Down Expand Up @@ -104,11 +103,8 @@ public boolean isMining() {
public void doWork() {
try {
if (mineBlock()) {
if (config.getBlockchainConfig() instanceof RegTestConfig) {
Thread.sleep(500);
}
else if (config.getBlockchainConfig() instanceof DevNetConfig) {
Thread.sleep(20000);
if (!this.delayBetweenBlocks.isZero()) {
Thread.sleep(this.delayBetweenBlocks.toMillis());
}
}
} catch (Exception e) {
Expand Down
7 changes: 7 additions & 0 deletions rskj-core/src/main/resources/config/devnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ peer {
networkId = 44444444
}

miner {
client {
delayBetweenBlocks = 20 seconds
}
}


genesis = devnet-genesis.json

hello.phrase = Dev
Expand Down
7 changes: 6 additions & 1 deletion rskj-core/src/main/resources/config/regtest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ peer {

miner {
server.enabled = true
client.enabled = true

client {
enabled = true
delayBetweenBlocks = 1 second
}

minGasPrice = 0

# this is a secret passphrase that is used to derive the address where the miner gets the reward.
Expand Down
15 changes: 15 additions & 0 deletions rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ peer {
maxActivePeers = 30
}

miner {
server.enabled = false

client {
enabled = false

# The time the miner client will wait after mining a block and before mining the next one.
# This allows mining a sane number of blocks per minute when the difficulty is low (e.g. for regtest).
delayBetweenBlocks = 0 seconds

# The time the miner client will wait to refresh the current work from the miner server
delayBetweenRefreshes = 1 second
}
}

database {
# every time the application starts the existing database will be destroyed and all the data will be downloaded from peers again
# having this set on true does NOT mean that the block chain will start from the last point
Expand Down

0 comments on commit 3e50191

Please sign in to comment.