mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 19:55:51 +00:00
Fixed the TestNet3Params.checkDifficultyTransitions method (logic error in a previous refactor).
This commit is contained in:
parent
7e66944753
commit
2fbd14cc97
@ -21,7 +21,6 @@ import java.math.BigInteger;
|
|||||||
import org.bitcoinj.core.Block;
|
import org.bitcoinj.core.Block;
|
||||||
import org.bitcoinj.core.Coin;
|
import org.bitcoinj.core.Coin;
|
||||||
import org.bitcoinj.core.NetworkParameters;
|
import org.bitcoinj.core.NetworkParameters;
|
||||||
import org.bitcoinj.core.Sha256Hash;
|
|
||||||
import org.bitcoinj.core.StoredBlock;
|
import org.bitcoinj.core.StoredBlock;
|
||||||
import org.bitcoinj.core.Transaction;
|
import org.bitcoinj.core.Transaction;
|
||||||
import org.bitcoinj.core.Utils;
|
import org.bitcoinj.core.Utils;
|
||||||
@ -32,8 +31,6 @@ import org.bitcoinj.store.BlockStoreException;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters for Bitcoin-like networks.
|
* Parameters for Bitcoin-like networks.
|
||||||
*/
|
*/
|
||||||
@ -49,13 +46,22 @@ public abstract class AbstractBitcoinNetParams extends NetworkParameters {
|
|||||||
super();
|
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
|
@Override
|
||||||
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
|
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
|
||||||
final BlockStore blockStore) throws VerificationException, BlockStoreException {
|
final BlockStore blockStore) throws VerificationException, BlockStoreException {
|
||||||
Block prev = storedPrev.getHeader();
|
Block prev = storedPrev.getHeader();
|
||||||
|
|
||||||
// Is this supposed to be a difficulty transition point?
|
// 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.
|
// No ... so check the difficulty didn't actually change.
|
||||||
if (nextBlock.getDifficultyTarget() != prev.getDifficultyTarget())
|
if (nextBlock.getDifficultyTarget() != prev.getDifficultyTarget())
|
||||||
|
@ -85,7 +85,7 @@ public class TestNet3Params extends AbstractBitcoinNetParams {
|
|||||||
@Override
|
@Override
|
||||||
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
|
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
|
||||||
final BlockStore blockStore) throws VerificationException, BlockStoreException {
|
final BlockStore blockStore) throws VerificationException, BlockStoreException {
|
||||||
if (nextBlock.getTime().after(testnetDiffDate)) {
|
if (!isDifficultyTransitionPoint(storedPrev) && nextBlock.getTime().after(testnetDiffDate)) {
|
||||||
Block prev = storedPrev.getHeader();
|
Block prev = storedPrev.getHeader();
|
||||||
|
|
||||||
// After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty
|
// After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty
|
||||||
|
Loading…
x
Reference in New Issue
Block a user