forked from Qortal/qortal
Block size and transaction expiry period now in BlockChain config
Block.MAX_BLOCK_BYTES now BlockChain.getMaxBlockSize() Network.MAXIMUM_MESSAGE_SIZE now Network.getMaxMessageSize() as it depends on block size (above).
This commit is contained in:
parent
e009147956
commit
a1cfe31574
@ -145,10 +145,6 @@ public class Block {
|
|||||||
|
|
||||||
// Other useful constants
|
// Other useful constants
|
||||||
|
|
||||||
/** Maximum size of block in bytes */
|
|
||||||
// TODO push this out to blockchain config file
|
|
||||||
public static final int MAX_BLOCK_BYTES = 1048576;
|
|
||||||
|
|
||||||
private static final BigInteger MAX_DISTANCE;
|
private static final BigInteger MAX_DISTANCE;
|
||||||
static {
|
static {
|
||||||
byte[] maxValue = new byte[Transformer.PUBLIC_KEY_LENGTH];
|
byte[] maxValue = new byte[Transformer.PUBLIC_KEY_LENGTH];
|
||||||
@ -606,7 +602,7 @@ public class Block {
|
|||||||
|
|
||||||
// Check there is space in block
|
// Check there is space in block
|
||||||
try {
|
try {
|
||||||
if (BlockTransformer.getDataLength(this) + TransactionTransformer.getDataLength(transactionData) > MAX_BLOCK_BYTES)
|
if (BlockTransformer.getDataLength(this) + TransactionTransformer.getDataLength(transactionData) > BlockChain.getInstance().getMaxBlockSize())
|
||||||
return false;
|
return false;
|
||||||
} catch (TransformationException e) {
|
} catch (TransformationException e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -52,6 +52,8 @@ public class BlockChain {
|
|||||||
private boolean isTestChain = false;
|
private boolean isTestChain = false;
|
||||||
/** Maximum coin supply. */
|
/** Maximum coin supply. */
|
||||||
private BigDecimal maxBalance;
|
private BigDecimal maxBalance;
|
||||||
|
/** Transaction expiry period, starting from transaction's timestamp, in milliseconds. */
|
||||||
|
private long transactionExpiryPeriod;
|
||||||
|
|
||||||
private BigDecimal unitFee;
|
private BigDecimal unitFee;
|
||||||
private BigDecimal maxBytesPerUnitFee;
|
private BigDecimal maxBytesPerUnitFee;
|
||||||
@ -65,6 +67,8 @@ public class BlockChain {
|
|||||||
private long maxBlockTime;
|
private long maxBlockTime;
|
||||||
/** Maximum acceptable timestamp disagreement offset in milliseconds. */
|
/** Maximum acceptable timestamp disagreement offset in milliseconds. */
|
||||||
private long blockTimestampMargin;
|
private long blockTimestampMargin;
|
||||||
|
/** Maximum block size, in bytes. */
|
||||||
|
private int maxBlockSize;
|
||||||
|
|
||||||
/** Whether transactions with txGroupId of NO_GROUP are allowed */
|
/** Whether transactions with txGroupId of NO_GROUP are allowed */
|
||||||
private boolean requireGroupForApproval;
|
private boolean requireGroupForApproval;
|
||||||
@ -241,6 +245,10 @@ public class BlockChain {
|
|||||||
return this.maxBalance;
|
return this.maxBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getTransactionExpiryPeriod() {
|
||||||
|
return this.transactionExpiryPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
public int getBlockDifficultyInterval() {
|
public int getBlockDifficultyInterval() {
|
||||||
return this.blockDifficultyInterval;
|
return this.blockDifficultyInterval;
|
||||||
}
|
}
|
||||||
@ -257,6 +265,10 @@ public class BlockChain {
|
|||||||
return this.blockTimestampMargin;
|
return this.blockTimestampMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxBlockSize() {
|
||||||
|
return this.maxBlockSize;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns true if approval-needing transaction types require a txGroupId other than NO_GROUP. */
|
/** Returns true if approval-needing transaction types require a txGroupId other than NO_GROUP. */
|
||||||
public boolean getRequireGroupForApproval() {
|
public boolean getRequireGroupForApproval() {
|
||||||
return this.requireGroupForApproval;
|
return this.requireGroupForApproval;
|
||||||
|
@ -33,7 +33,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.qora.block.Block;
|
import org.qora.block.BlockChain;
|
||||||
import org.qora.controller.Controller;
|
import org.qora.controller.Controller;
|
||||||
import org.qora.data.block.BlockData;
|
import org.qora.data.block.BlockData;
|
||||||
import org.qora.data.network.PeerData;
|
import org.qora.data.network.PeerData;
|
||||||
@ -78,9 +78,6 @@ public class Network extends Thread {
|
|||||||
/** Maximum time allowed for handshake to complete, in milliseconds. */
|
/** Maximum time allowed for handshake to complete, in milliseconds. */
|
||||||
private static final long HANDSHAKE_TIMEOUT = 60 * 1000; // ms
|
private static final long HANDSHAKE_TIMEOUT = 60 * 1000; // ms
|
||||||
|
|
||||||
/** Maximum message size (bytes). Needs to be at least maximum block size + MAGIC + message type, etc. */
|
|
||||||
/* package */ static final int MAXIMUM_MESSAGE_SIZE = 4 + 1 + 4 + Block.MAX_BLOCK_BYTES;
|
|
||||||
|
|
||||||
private static final byte[] MAINNET_MESSAGE_MAGIC = new byte[] { 0x51, 0x4f, 0x52, 0x54 }; // QORT
|
private static final byte[] MAINNET_MESSAGE_MAGIC = new byte[] { 0x51, 0x4f, 0x52, 0x54 }; // QORT
|
||||||
private static final byte[] TESTNET_MESSAGE_MAGIC = new byte[] { 0x71, 0x6f, 0x72, 0x54 }; // qorT
|
private static final byte[] TESTNET_MESSAGE_MAGIC = new byte[] { 0x71, 0x6f, 0x72, 0x54 }; // qorT
|
||||||
|
|
||||||
@ -100,6 +97,7 @@ public class Network extends Thread {
|
|||||||
public static final byte[] ZERO_PEER_ID = new byte[PEER_ID_LENGTH];
|
public static final byte[] ZERO_PEER_ID = new byte[PEER_ID_LENGTH];
|
||||||
|
|
||||||
private final byte[] ourPeerId;
|
private final byte[] ourPeerId;
|
||||||
|
private final int maxMessageSize;
|
||||||
private List<Peer> connectedPeers;
|
private List<Peer> connectedPeers;
|
||||||
private List<PeerAddress> selfPeers;
|
private List<PeerAddress> selfPeers;
|
||||||
|
|
||||||
@ -152,6 +150,8 @@ public class Network extends Thread {
|
|||||||
// Set bit to make sure our peer ID is not 0
|
// Set bit to make sure our peer ID is not 0
|
||||||
ourPeerId[ourPeerId.length - 1] |= 0x01;
|
ourPeerId[ourPeerId.length - 1] |= 0x01;
|
||||||
|
|
||||||
|
maxMessageSize = 4 + 1 + 4 + BlockChain.getInstance().getMaxBlockSize();
|
||||||
|
|
||||||
minOutboundPeers = Settings.getInstance().getMinOutboundPeers();
|
minOutboundPeers = Settings.getInstance().getMinOutboundPeers();
|
||||||
maxPeers = Settings.getInstance().getMaxPeers();
|
maxPeers = Settings.getInstance().getMaxPeers();
|
||||||
|
|
||||||
@ -189,6 +189,11 @@ public class Network extends Thread {
|
|||||||
return this.ourPeerId;
|
return this.ourPeerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Maximum message size (bytes). Needs to be at least maximum block size + MAGIC + message type, etc. */
|
||||||
|
/* package */ int getMaxMessageSize() {
|
||||||
|
return this.maxMessageSize;
|
||||||
|
}
|
||||||
|
|
||||||
// Peer lists
|
// Peer lists
|
||||||
|
|
||||||
public List<Peer> getConnectedPeers() {
|
public List<Peer> getConnectedPeers() {
|
||||||
|
@ -293,7 +293,7 @@ public class Peer {
|
|||||||
this.connectionTimestamp = NTP.getTime();
|
this.connectionTimestamp = NTP.getTime();
|
||||||
this.socketChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
this.socketChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
||||||
this.socketChannel.configureBlocking(false);
|
this.socketChannel.configureBlocking(false);
|
||||||
this.byteBuffer = ByteBuffer.allocate(Network.MAXIMUM_MESSAGE_SIZE);
|
this.byteBuffer = ByteBuffer.allocate(Network.getInstance().getMaxMessageSize());
|
||||||
this.replyQueues = Collections.synchronizedMap(new HashMap<Integer, BlockingQueue<Message>>());
|
this.replyQueues = Collections.synchronizedMap(new HashMap<Integer, BlockingQueue<Message>>());
|
||||||
this.pendingMessages = new LinkedBlockingQueue<Message>();
|
this.pendingMessages = new LinkedBlockingQueue<Message>();
|
||||||
}
|
}
|
||||||
|
@ -305,8 +305,8 @@ public abstract class Transaction {
|
|||||||
// More information
|
// More information
|
||||||
|
|
||||||
public static long getDeadline(TransactionData transactionData) {
|
public static long getDeadline(TransactionData transactionData) {
|
||||||
// 24 hour deadline to include transaction in a block
|
// Calculate deadline to include transaction in a block
|
||||||
return transactionData.getTimestamp() + (24 * 60 * 60 * 1000);
|
return transactionData.getTimestamp() + BlockChain.getInstance().getTransactionExpiryPeriod();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDeadline() {
|
public long getDeadline() {
|
||||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.qora.account.PublicKeyAccount;
|
import org.qora.account.PublicKeyAccount;
|
||||||
import org.qora.block.Block;
|
import org.qora.block.Block;
|
||||||
|
import org.qora.block.BlockChain;
|
||||||
import org.qora.data.at.ATStateData;
|
import org.qora.data.at.ATStateData;
|
||||||
import org.qora.data.block.BlockData;
|
import org.qora.data.block.BlockData;
|
||||||
import org.qora.data.transaction.TransactionData;
|
import org.qora.data.transaction.TransactionData;
|
||||||
@ -89,7 +90,7 @@ public class BlockTransformer extends Transformer {
|
|||||||
if (version >= 2 && byteBuffer.remaining() < BASE_LENGTH + AT_BYTES_LENGTH - VERSION_LENGTH)
|
if (version >= 2 && byteBuffer.remaining() < BASE_LENGTH + AT_BYTES_LENGTH - VERSION_LENGTH)
|
||||||
throw new TransformationException("Byte data too short for V2+ Block");
|
throw new TransformationException("Byte data too short for V2+ Block");
|
||||||
|
|
||||||
if (byteBuffer.remaining() > Block.MAX_BLOCK_BYTES)
|
if (byteBuffer.remaining() > BlockChain.getInstance().getMaxBlockSize())
|
||||||
throw new TransformationException("Byte data too long for Block");
|
throw new TransformationException("Byte data too long for Block");
|
||||||
|
|
||||||
long timestamp = byteBuffer.getLong();
|
long timestamp = byteBuffer.getLong();
|
||||||
@ -116,7 +117,7 @@ public class BlockTransformer extends Transformer {
|
|||||||
if (version >= 2) {
|
if (version >= 2) {
|
||||||
int atBytesLength = byteBuffer.getInt();
|
int atBytesLength = byteBuffer.getInt();
|
||||||
|
|
||||||
if (atBytesLength > Block.MAX_BLOCK_BYTES)
|
if (atBytesLength > BlockChain.getInstance().getMaxBlockSize())
|
||||||
throw new TransformationException("Byte data too long for Block's AT info");
|
throw new TransformationException("Byte data too long for Block's AT info");
|
||||||
|
|
||||||
ByteBuffer atByteBuffer = byteBuffer.slice();
|
ByteBuffer atByteBuffer = byteBuffer.slice();
|
||||||
@ -185,7 +186,7 @@ public class BlockTransformer extends Transformer {
|
|||||||
if (byteBuffer.remaining() < transactionLength)
|
if (byteBuffer.remaining() < transactionLength)
|
||||||
throw new TransformationException("Byte data too short for Block Transaction");
|
throw new TransformationException("Byte data too short for Block Transaction");
|
||||||
|
|
||||||
if (transactionLength > Block.MAX_BLOCK_BYTES)
|
if (transactionLength > BlockChain.getInstance().getMaxBlockSize())
|
||||||
throw new TransformationException("Byte data too long for Block Transaction");
|
throw new TransformationException("Byte data too long for Block Transaction");
|
||||||
|
|
||||||
byte[] transactionBytes = new byte[transactionLength];
|
byte[] transactionBytes = new byte[transactionLength];
|
||||||
@ -208,7 +209,7 @@ public class BlockTransformer extends Transformer {
|
|||||||
|
|
||||||
int conciseSetLength = byteBuffer.getInt();
|
int conciseSetLength = byteBuffer.getInt();
|
||||||
|
|
||||||
if (conciseSetLength > Block.MAX_BLOCK_BYTES)
|
if (conciseSetLength > BlockChain.getInstance().getMaxBlockSize())
|
||||||
throw new TransformationException("Byte data too long for online account info");
|
throw new TransformationException("Byte data too long for online account info");
|
||||||
|
|
||||||
if ((conciseSetLength & 3) != 0)
|
if ((conciseSetLength & 3) != 0)
|
||||||
@ -230,7 +231,7 @@ public class BlockTransformer extends Transformer {
|
|||||||
onlineAccountsTimestamp = byteBuffer.getLong();
|
onlineAccountsTimestamp = byteBuffer.getLong();
|
||||||
|
|
||||||
final int signaturesByteLength = onlineAccountsSignaturesCount * Transformer.SIGNATURE_LENGTH;
|
final int signaturesByteLength = onlineAccountsSignaturesCount * Transformer.SIGNATURE_LENGTH;
|
||||||
if (signaturesByteLength > Block.MAX_BLOCK_BYTES)
|
if (signaturesByteLength > BlockChain.getInstance().getMaxBlockSize())
|
||||||
throw new TransformationException("Byte data too long for online accounts signatures");
|
throw new TransformationException("Byte data too long for online accounts signatures");
|
||||||
|
|
||||||
onlineAccountsSignatures = new byte[signaturesByteLength];
|
onlineAccountsSignatures = new byte[signaturesByteLength];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user