3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Add a testnet-in-a-box mode.

Which allows connecting to a peer with only the genesis block.
This commit is contained in:
Matt Corallo 2012-07-14 18:49:46 +02:00 committed by Mike Hearn
parent 2bfe8dfa25
commit 599d4a671c
3 changed files with 10 additions and 2 deletions

View File

@ -114,6 +114,11 @@ public class NetworkParameters implements Serializable {
* Returns the number of blocks between subsidy decreases
*/
private int subsidyDecreaseBlockCount;
/**
* If we are running in testnet-in-a-box mode, we allow connections to nodes with 0 non-genesis blocks
*/
boolean allowEmptyPeerChains;
/**
* The version codes that prefix addresses which are acceptable on this network. Although Satoshi intended these to
@ -213,6 +218,7 @@ public class NetworkParameters implements Serializable {
n.setSpendableCoinbaseDepth(100);
n.setSubsidyDecreaseBlockCount(210000);
n.id = ID_TESTNET;
n.allowEmptyPeerChains = false;
String genesisHash = n.genesisBlock.getHashAsString();
checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"),
genesisHash);
@ -250,6 +256,7 @@ public class NetworkParameters implements Serializable {
n.setSpendableCoinbaseDepth(100);
n.setSubsidyDecreaseBlockCount(210000);
n.id = ID_PRODNET;
n.allowEmptyPeerChains = false;
String genesisHash = n.genesisBlock.getHashAsString();
checkState(genesisHash.equals("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"),
genesisHash);

View File

@ -746,7 +746,7 @@ public class Peer {
// chainHeight should not be zero/negative because we shouldn't have given the user a Peer that is to another
// client-mode node, nor should it be unconnected. If that happens it means the user overrode us somewhere or
// there is a bug in the peer management code.
Preconditions.checkState(chainHeight > 0, "Connected to peer with zero/negative chain height", chainHeight);
Preconditions.checkState(params.allowEmptyPeerChains || chainHeight > 0, "Connected to peer with zero/negative chain height", chainHeight);
return chainHeight - blockChain.getChainHead().getHeight();
}

View File

@ -161,7 +161,8 @@ public class TCPNetworkConnection implements NetworkConnection {
// mode nodes because we can't download the data from them we need to find/verify transactions. Some bogus
// implementations claim to have a block chain in their services field but then report a height of zero, filter
// them out here.
if (!versionMessage.hasBlockChain() || versionMessage.bestHeight <= 0) {
if (!versionMessage.hasBlockChain() ||
(!params.allowEmptyPeerChains && versionMessage.bestHeight <= 0)) {
// Shut down the channel
throw new ProtocolException("Peer does not have a copy of the block chain.");
}