Skip to content

Commit

Permalink
Disable retargeting for regtest
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarguindzberg committed Jun 9, 2016
1 parent 736fd7d commit 1f6049e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions core/src/main/java/org/bitcoinj/core/NetworkParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public abstract class NetworkParameters {
protected int dumpedPrivateKeyHeader;
protected int interval;
protected int targetTimespan;
protected boolean noRetargeting;
protected byte[] alertSigningKey;
protected int bip32HeaderPub;
protected int bip32HeaderPriv;
Expand Down Expand Up @@ -346,6 +347,15 @@ public int getTargetTimespan() {
return targetTimespan;
}

/**
* Whether to skip retargeting.
* If set to false, the node works as usual: recalculates the difficulty using targetTimespan and interval.
* If set to true, the difficulty is never recalculated
*/
public boolean getNoRetargeting() {
return noRetargeting;
}

/**
* The version codes that prefix addresses which are acceptable on this network. Although Satoshi intended these to
* be used for "versioning", in fact they are today used to discriminate what kind of data is contained in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block
Block prev = storedPrev.getHeader();

// Is this supposed to be a difficulty transition point?
if (!isDifficultyTransitionPoint(storedPrev)) {
if (!isDifficultyTransitionPoint(storedPrev) || getNoRetargeting()) {

// No ... so check the difficulty didn't actually change.
if (nextBlock.getDifficultyTarget() != prev.getDifficultyTarget())
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/bitcoinj/params/MainNetParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public MainNetParams() {
super();
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
noRetargeting = false;
maxTarget = Utils.decodeCompactBits(0x1d00ffffL);
dumpedPrivateKeyHeader = 128;
addressHeader = 0;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/bitcoinj/params/RegTestParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class RegTestParams extends TestNet2Params {
public RegTestParams() {
super();
interval = 10000;
noRetargeting = true;
maxTarget = MAX_TARGET;
subsidyDecreaseBlockCount = 150;
port = 18444;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/bitcoinj/params/TestNet2Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public TestNet2Params() {
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
noRetargeting = false;
maxTarget = Utils.decodeCompactBits(0x1d0fffffL);
dumpedPrivateKeyHeader = 239;
genesisBlock.setTime(1296688602L);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/bitcoinj/params/TestNet3Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public TestNet3Params() {
packetMagic = 0x0b110907;
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
noRetargeting = false;
maxTarget = Utils.decodeCompactBits(0x1d00ffffL);
port = 18333;
addressHeader = 111;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/bitcoinj/params/UnitTestParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public UnitTestParams() {
interval = 10;
dumpedPrivateKeyHeader = 239;
targetTimespan = 200000000; // 6 years. Just a very big number.
noRetargeting = false;
spendableCoinbaseDepth = 5;
subsidyDecreaseBlockCount = 100;
dnsSeeds = null;
Expand Down

0 comments on commit 1f6049e

Please sign in to comment.