3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 18:25:51 +00:00

Don't validate difficulty transitions on the testnet as there was a recent rule change, and nobody cares about security on testnet anyway.

This commit is contained in:
Mike Hearn 2012-04-06 18:41:40 +02:00
parent 40e4ac0a49
commit b008cd0388
2 changed files with 16 additions and 1 deletions

View File

@ -207,7 +207,8 @@ public class BlockChain {
// Create a new StoredBlock from this block. It will throw away the transaction data so when block goes // Create a new StoredBlock from this block. It will throw away the transaction data so when block goes
// out of scope we will reclaim the used memory. // out of scope we will reclaim the used memory.
StoredBlock newStoredBlock = storedPrev.build(block); StoredBlock newStoredBlock = storedPrev.build(block);
checkDifficultyTransitions(storedPrev, newStoredBlock); if (params.checkBlockDifficulty)
checkDifficultyTransitions(storedPrev, newStoredBlock);
blockStore.put(newStoredBlock); blockStore.put(newStoredBlock);
connectBlock(newStoredBlock, storedPrev, block.transactions); connectBlock(newStoredBlock, storedPrev, block.transactions);
} }

View File

@ -94,6 +94,11 @@ public class NetworkParameters implements Serializable {
* signatures using it. * signatures using it.
*/ */
public byte[] alertSigningKey; public byte[] alertSigningKey;
/**
* Whether to check block difficulty on this network. The rules for testnet have changed and become
* quite complicated, so don't bother verifying them. It's only a useful security check on the main network.
*/
public boolean checkBlockDifficulty;
/** /**
* See getId(). This may be null for old deserialized wallets. In that case we derive it heuristically * See getId(). This may be null for old deserialized wallets. In that case we derive it heuristically
@ -153,6 +158,7 @@ public class NetworkParameters implements Serializable {
n.genesisBlock.setDifficultyTarget(0x1d07fff8L); n.genesisBlock.setDifficultyTarget(0x1d07fff8L);
n.genesisBlock.setNonce(384568319); n.genesisBlock.setNonce(384568319);
n.id = ID_TESTNET; n.id = ID_TESTNET;
n.checkBlockDifficulty = false;
String genesisHash = n.genesisBlock.getHashAsString(); String genesisHash = n.genesisBlock.getHashAsString();
checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"), checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"),
genesisHash); genesisHash);
@ -182,6 +188,7 @@ public class NetworkParameters implements Serializable {
n.genesisBlock.setTime(1231006505L); n.genesisBlock.setTime(1231006505L);
n.genesisBlock.setNonce(2083236893); n.genesisBlock.setNonce(2083236893);
n.id = ID_PRODNET; n.id = ID_PRODNET;
n.checkBlockDifficulty = true;
String genesisHash = n.genesisBlock.getHashAsString(); String genesisHash = n.genesisBlock.getHashAsString();
checkState(genesisHash.equals("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"), checkState(genesisHash.equals("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"),
genesisHash); genesisHash);
@ -197,6 +204,7 @@ public class NetworkParameters implements Serializable {
n.genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET); n.genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET);
n.interval = 10; n.interval = 10;
n.targetTimespan = 200000000; // 6 years. Just a very big number. n.targetTimespan = 200000000; // 6 years. Just a very big number.
n.checkBlockDifficulty = true;
n.id = "com.google.bitcoin.unittest"; n.id = "com.google.bitcoin.unittest";
return n; return n;
} }
@ -216,6 +224,12 @@ public class NetworkParameters implements Serializable {
return id; return id;
} }
public boolean equals(Object other) {
if (!(other instanceof NetworkParameters)) return false;
NetworkParameters o = (NetworkParameters) other;
return o.getId().equals(getId());
}
/** Returns the network parameters for the given string ID or NULL if not recognized. */ /** Returns the network parameters for the given string ID or NULL if not recognized. */
public static NetworkParameters fromID(String id) { public static NetworkParameters fromID(String id) {
if (id.equals(ID_PRODNET)) { if (id.equals(ID_PRODNET)) {