3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 10:45:51 +00:00

Fixed the TestNet3Params.checkDifficultyTransitions method (logic error in a previous refactor).

This commit is contained in:
Kalpesh Parmar 2015-06-02 23:43:57 +01:00 committed by Mike Hearn
parent 7e66944753
commit 2fbd14cc97
2 changed files with 11 additions and 5 deletions

View File

@ -21,7 +21,6 @@ import java.math.BigInteger;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.Utils;
@ -32,8 +31,6 @@ import org.bitcoinj.store.BlockStoreException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkState;
/**
* Parameters for Bitcoin-like networks.
*/
@ -49,13 +46,22 @@ public abstract class AbstractBitcoinNetParams extends NetworkParameters {
super();
}
/**
* Checks if we are at a difficulty transition point.
* @param storedPrev The previous stored block
* @return If this is a difficulty transition point
*/
protected boolean isDifficultyTransitionPoint(StoredBlock storedPrev) {
return ((storedPrev.getHeight() + 1) % this.getInterval()) == 0;
}
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
final BlockStore blockStore) throws VerificationException, BlockStoreException {
Block prev = storedPrev.getHeader();
// Is this supposed to be a difficulty transition point?
if ((storedPrev.getHeight() + 1) % this.getInterval() != 0) {
if (!isDifficultyTransitionPoint(storedPrev)) {
// No ... so check the difficulty didn't actually change.
if (nextBlock.getDifficultyTarget() != prev.getDifficultyTarget())

View File

@ -85,7 +85,7 @@ public class TestNet3Params extends AbstractBitcoinNetParams {
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
final BlockStore blockStore) throws VerificationException, BlockStoreException {
if (nextBlock.getTime().after(testnetDiffDate)) {
if (!isDifficultyTransitionPoint(storedPrev) && nextBlock.getTime().after(testnetDiffDate)) {
Block prev = storedPrev.getHeader();
// After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty