forked from Qortal/qortal
BlockChain.isTestNet now BlockChain.isTestChain.
Added Settings.isTestNet. Disabled ArbitraryDataManager for now.
This commit is contained in:
parent
1d81c4db6b
commit
915eebb8e5
@ -784,7 +784,7 @@ public class Block {
|
|||||||
* Returns whether Block's timestamp is valid.
|
* Returns whether Block's timestamp is valid.
|
||||||
* <p>
|
* <p>
|
||||||
* Used by BlockGenerator to check whether it's time to forge new block,
|
* Used by BlockGenerator to check whether it's time to forge new block,
|
||||||
* and also used by Block.isValid for checks (if not testnet).
|
* and also used by Block.isValid for checks (if not a testchain).
|
||||||
*
|
*
|
||||||
* @return ValidationResult.OK if timestamp valid, or some other ValidationResult otherwise.
|
* @return ValidationResult.OK if timestamp valid, or some other ValidationResult otherwise.
|
||||||
* @throws DataException
|
* @throws DataException
|
||||||
@ -844,8 +844,8 @@ public class Block {
|
|||||||
if (this.blockData.getTimestamp() <= parentBlockData.getTimestamp())
|
if (this.blockData.getTimestamp() <= parentBlockData.getTimestamp())
|
||||||
return ValidationResult.TIMESTAMP_OLDER_THAN_PARENT;
|
return ValidationResult.TIMESTAMP_OLDER_THAN_PARENT;
|
||||||
|
|
||||||
// These checks are disabled for testnet
|
// These checks are disabled for testchains
|
||||||
if (!BlockChain.getInstance().isTestNet()) {
|
if (!BlockChain.getInstance().isTestChain()) {
|
||||||
ValidationResult timestampResult = this.isTimestampValid();
|
ValidationResult timestampResult = this.isTimestampValid();
|
||||||
|
|
||||||
if (timestampResult != ValidationResult.OK)
|
if (timestampResult != ValidationResult.OK)
|
||||||
|
@ -48,7 +48,7 @@ public class BlockChain {
|
|||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
private boolean isTestNet = false;
|
private boolean isTestChain = false;
|
||||||
/** Maximum coin supply. */
|
/** Maximum coin supply. */
|
||||||
private BigDecimal maxBalance;
|
private BigDecimal maxBalance;
|
||||||
|
|
||||||
@ -204,8 +204,8 @@ public class BlockChain {
|
|||||||
|
|
||||||
// Getters / setters
|
// Getters / setters
|
||||||
|
|
||||||
public boolean isTestNet() {
|
public boolean isTestChain() {
|
||||||
return this.isTestNet;
|
return this.isTestChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getUnitFee() {
|
public BigDecimal getUnitFee() {
|
||||||
|
@ -150,7 +150,7 @@ public class BlockGenerator extends Thread {
|
|||||||
|
|
||||||
for (Block testBlock : newBlocks) {
|
for (Block testBlock : newBlocks) {
|
||||||
// Is new block's timestamp valid yet?
|
// Is new block's timestamp valid yet?
|
||||||
// We do a separate check as some timestamp checks are skipped for testnet
|
// We do a separate check as some timestamp checks are skipped for testchains
|
||||||
if (testBlock.isTimestampValid() != ValidationResult.OK)
|
if (testBlock.isTimestampValid() != ValidationResult.OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -308,8 +308,8 @@ public class BlockGenerator extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void generateTestingBlock(Repository repository, PrivateKeyAccount generator) throws DataException {
|
public static void generateTestingBlock(Repository repository, PrivateKeyAccount generator) throws DataException {
|
||||||
if (!BlockChain.getInstance().isTestNet()) {
|
if (!BlockChain.getInstance().isTestChain()) {
|
||||||
LOGGER.warn("Attempt to generating testing block but not in testnet mode!");
|
LOGGER.warn("Ignoring attempt to generate testing block for non-test chain!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@ public class GenesisBlock extends Block {
|
|||||||
|
|
||||||
// Timestamp of zero means "now" but only valid for test nets!
|
// Timestamp of zero means "now" but only valid for test nets!
|
||||||
if (info.timestamp == 0) {
|
if (info.timestamp == 0) {
|
||||||
if (!blockchain.isTestNet()) {
|
if (!blockchain.isTestChain()) {
|
||||||
LOGGER.error("Genesis timestamp of zero (i.e. now) not valid for non-testnet blockchain configs");
|
LOGGER.error("Genesis timestamp of zero (i.e. now) not valid for non-test blockchain configs");
|
||||||
throw new RuntimeException("Genesis timestamp of zero (i.e. now) not valid for non-testnet blockchain configs");
|
throw new RuntimeException("Genesis timestamp of zero (i.e. now) not valid for non-test blockchain configs");
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will only take effect if there is no current genesis block in blockchain
|
// This will only take effect if there is no current genesis block in blockchain
|
||||||
|
@ -152,12 +152,6 @@ public class Controller extends Thread {
|
|||||||
return String.format(repositoryUrlTemplate, Settings.getInstance().getRepositoryPath());
|
return String.format(repositoryUrlTemplate, Settings.getInstance().getRepositoryPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getMessageMagic() {
|
|
||||||
return new byte[] {
|
|
||||||
0x12, 0x34, 0x56, 0x78
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getBuildTimestamp() {
|
public long getBuildTimestamp() {
|
||||||
return this.buildTimestamp;
|
return this.buildTimestamp;
|
||||||
}
|
}
|
||||||
@ -257,8 +251,8 @@ public class Controller extends Thread {
|
|||||||
Controller.getInstance().start();
|
Controller.getInstance().start();
|
||||||
|
|
||||||
// Arbitrary transaction data manager
|
// Arbitrary transaction data manager
|
||||||
LOGGER.info("Starting arbitrary-transaction data manager");
|
// LOGGER.info("Starting arbitrary-transaction data manager");
|
||||||
ArbitraryDataManager.getInstance().start();
|
// ArbitraryDataManager.getInstance().start();
|
||||||
|
|
||||||
// Auto-update service
|
// Auto-update service
|
||||||
LOGGER.info("Starting auto-update");
|
LOGGER.info("Starting auto-update");
|
||||||
@ -393,8 +387,8 @@ public class Controller extends Thread {
|
|||||||
AutoUpdate.getInstance().shutdown();
|
AutoUpdate.getInstance().shutdown();
|
||||||
|
|
||||||
// Arbitrary transaction data manager
|
// Arbitrary transaction data manager
|
||||||
LOGGER.info("Shutting down arbitrary-transaction data manager");
|
// LOGGER.info("Shutting down arbitrary-transaction data manager");
|
||||||
ArbitraryDataManager.getInstance().shutdown();
|
// ArbitraryDataManager.getInstance().shutdown();
|
||||||
|
|
||||||
LOGGER.info("Shutting down controller");
|
LOGGER.info("Shutting down controller");
|
||||||
this.interrupt();
|
this.interrupt();
|
||||||
|
@ -66,6 +66,9 @@ public class Network extends Thread {
|
|||||||
/** Maximum time since last successful connection before a peer is potentially considered "old", in milliseconds. */
|
/** Maximum time since last successful connection before a peer is potentially considered "old", in milliseconds. */
|
||||||
private static final long OLD_PEER_CONNECTION_PERIOD = 7 * 24 * 60 * 60 * 1000; // ms
|
private static final long OLD_PEER_CONNECTION_PERIOD = 7 * 24 * 60 * 60 * 1000; // ms
|
||||||
|
|
||||||
|
private static final byte[] MAINNET_MESSAGE_MAGIC = new byte[] { 0x12, 0x34, 0x56, 0x78 };
|
||||||
|
private static final byte[] TESTNET_MESSAGE_MAGIC = new byte[] { 0x78, 0x56, 0x34, 0x12 };
|
||||||
|
|
||||||
private static final String[] INITIAL_PEERS = new String[] {
|
private static final String[] INITIAL_PEERS = new String[] {
|
||||||
"node1.qora.org",
|
"node1.qora.org",
|
||||||
"node2.qora.org",
|
"node2.qora.org",
|
||||||
@ -164,6 +167,10 @@ public class Network extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getMessageMagic() {
|
||||||
|
return Settings.getInstance().isTestNet() ? TESTNET_MESSAGE_MAGIC : MAINNET_MESSAGE_MAGIC;
|
||||||
|
}
|
||||||
|
|
||||||
// Initial setup
|
// Initial setup
|
||||||
|
|
||||||
public static void installInitialPeers(Repository repository) throws DataException {
|
public static void installInitialPeers(Repository repository) throws DataException {
|
||||||
|
@ -2,8 +2,8 @@ package org.qora.network.message;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.qora.controller.Controller;
|
|
||||||
import org.qora.crypto.Crypto;
|
import org.qora.crypto.Crypto;
|
||||||
|
import org.qora.network.Network;
|
||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ public abstract class Message {
|
|||||||
byte[] messageMagic = new byte[MAGIC_LENGTH];
|
byte[] messageMagic = new byte[MAGIC_LENGTH];
|
||||||
in.readFully(messageMagic);
|
in.readFully(messageMagic);
|
||||||
|
|
||||||
if (!Arrays.equals(messageMagic, Controller.getInstance().getMessageMagic()))
|
if (!Arrays.equals(messageMagic, Network.getInstance().getMessageMagic()))
|
||||||
// Didn't receive correct Message "magic"
|
// Didn't receive correct Message "magic"
|
||||||
throw new MessageException("Received incorrect message 'magic'");
|
throw new MessageException("Received incorrect message 'magic'");
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ public abstract class Message {
|
|||||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
|
|
||||||
// Magic
|
// Magic
|
||||||
bytes.write(Controller.getInstance().getMessageMagic());
|
bytes.write(Network.getInstance().getMessageMagic());
|
||||||
|
|
||||||
bytes.write(Ints.toByteArray(this.type.value));
|
bytes.write(Ints.toByteArray(this.type.value));
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import org.qora.block.BlockChain;
|
|||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
public static final int DEFAULT_LISTEN_PORT = 9084;
|
public static final int DEFAULT_LISTEN_PORT = 9084;
|
||||||
|
public static final int DEFAULT_TESTNET_PORT = 9184;
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(Settings.class);
|
private static final Logger LOGGER = LogManager.getLogger(Settings.class);
|
||||||
private static final String SETTINGS_FILENAME = "settings.json";
|
private static final String SETTINGS_FILENAME = "settings.json";
|
||||||
@ -62,7 +63,8 @@ public class Settings {
|
|||||||
private boolean autoUpdateEnabled = true;
|
private boolean autoUpdateEnabled = true;
|
||||||
|
|
||||||
// Peer-to-peer related
|
// Peer-to-peer related
|
||||||
private int listenPort = DEFAULT_LISTEN_PORT;
|
private boolean isTestNet = false;
|
||||||
|
private Integer listenPort;
|
||||||
private String bindAddress = "::"; // Use IPv6 wildcard to listen on all local addresses
|
private String bindAddress = "::"; // Use IPv6 wildcard to listen on all local addresses
|
||||||
/** Minimum number of peers to allow block generation / synchronization. */
|
/** Minimum number of peers to allow block generation / synchronization. */
|
||||||
private int minBlockchainPeers = 3;
|
private int minBlockchainPeers = 3;
|
||||||
@ -220,7 +222,7 @@ public class Settings {
|
|||||||
return this.apiRestricted;
|
return this.apiRestricted;
|
||||||
|
|
||||||
// Not set in config file, so restrict if not testnet
|
// Not set in config file, so restrict if not testnet
|
||||||
return !BlockChain.getInstance().isTestNet();
|
return !BlockChain.getInstance().isTestChain();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isApiLoggingEnabled() {
|
public boolean isApiLoggingEnabled() {
|
||||||
@ -239,8 +241,15 @@ public class Settings {
|
|||||||
return this.maxTransactionTimestampFuture;
|
return this.maxTransactionTimestampFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTestNet() {
|
||||||
|
return this.isTestNet;
|
||||||
|
}
|
||||||
|
|
||||||
public int getListenPort() {
|
public int getListenPort() {
|
||||||
return this.listenPort;
|
if (this.listenPort != null)
|
||||||
|
return this.listenPort;
|
||||||
|
|
||||||
|
return this.isTestNet ? DEFAULT_TESTNET_PORT : DEFAULT_LISTEN_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBindAddress() {
|
public String getBindAddress() {
|
||||||
|
@ -53,7 +53,7 @@ public class SettingsTests {
|
|||||||
BlockChain blockchain = unmarshaller.unmarshal(json, BlockChain.class).getValue();
|
BlockChain blockchain = unmarshaller.unmarshal(json, BlockChain.class).getValue();
|
||||||
|
|
||||||
System.out.println("BlockChain settings:");
|
System.out.println("BlockChain settings:");
|
||||||
System.out.println(String.format("TestNet: %s", yn(blockchain.isTestNet())));
|
System.out.println(String.format("TestChain: %s", yn(blockchain.isTestChain())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"isTestNet": true,
|
"isTestChain": true,
|
||||||
"maxBalance": "10000000000",
|
"maxBalance": "10000000000",
|
||||||
"blockDifficultyInterval": 10,
|
"blockDifficultyInterval": 10,
|
||||||
"minBlockTime": 30,
|
"minBlockTime": 30,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"isTestNet": true,
|
"isTestChain": true,
|
||||||
"maxBalance": "10000000000",
|
"maxBalance": "10000000000",
|
||||||
"blockDifficultyInterval": 10,
|
"blockDifficultyInterval": 10,
|
||||||
"minBlockTime": 30,
|
"minBlockTime": 30,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user