Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into 2334-network_tests_async
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejBaj authored Sep 14, 2018
2 parents bf16d9e + a4a843c commit b835a01
Show file tree
Hide file tree
Showing 95 changed files with 480 additions and 439 deletions.
2 changes: 1 addition & 1 deletion api/controllers/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ DelegatesController.getForgingStatistics = function(context, next) {
count: reward.count,
},
meta: {
fromTimestamp: filters.start || constants.epochTime.getTime(),
fromTimestamp: filters.start || constants.EPOCH_TIME.getTime(),
toTimestamp: filters.end || Date.now(),
},
links: {},
Expand Down
4 changes: 2 additions & 2 deletions config/betanet/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"wsPort": 5001
},
{
"ip": "betanet-seed-02.lisk.io",
"ip": "betanet-seed-02.lisk-nodes.net",
"wsPort": 5001
},
{
"ip": "betanet-seed-03.lisk.io",
"wsPort": 5001
},
{
"ip": "betanet-seed-04.lisk.io",
"ip": "betanet-seed-04.lisk-nodes.net",
"wsPort": 5001
},
{
Expand Down
146 changes: 78 additions & 68 deletions config/default/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,97 +20,107 @@
* @namespace constants
* @memberof config
* @see Parent: {@link config}
* @property {number} activeDelegates - The default number of delegates allowed to forge a block.
* @property {number} maxVotesPerTransaction - The maximum number of votes allowed in transaction type(3) votes.
* @property {number} blockSlotWindow - The default number of previous blocks to keep in memory.
* @property {number} blockReceiptTimeOut - Seconds to check if the block is fresh or not.
* @property {Date} epochTime - Timestamp indicating the start of lisk core.
* @property {Object} fees - Object representing amount of fees for different types of transactions.
* @property {number} fees.send - Fee for sending a transaction.
* @property {number} fees.vote - Fee for voting a delegate.
* @property {number} fees.secondSignature - Fee for creating a secondSignature.
* @property {number} fees.delegate - Fee for registering as a delegate.
* @property {number} fees.multisignature - Fee for multisignature transaction.
* @property {number} fees.dapp - Fee for registering as a dapp.
* @property {number} ACTIVE_DELEGATES - The default number of delegates allowed to forge a block.
* @property {number} ADDITIONAL_DATA.MIN_LENGTH - Additional data (Min length)
* @property {number} ADDITIONAL_DATA.MAX_LENGTH - Additional data (Max length)
* @property {number} BLOCK_SLOT_WINDOW - The default number of previous blocks to keep in memory.
* @property {number} BLOCK_RECEIPT_TIMEOUT - Seconds to check if the block is fresh or not.
* @property {Date} EPOCH_TIME - Timestamp indicating the start of Lisk Core.
* @property {Object} FEES - Object representing amount of fees for different types of transactions.
* @property {number} FEES.SEND - Fee for sending a transaction.
* @property {number} FEES.VOTE - Fee for voting a delegate.
* @property {number} FEES.SECOND_SIGNATURE - Fee for creating a second signature.
* @property {number} FEES.DELEGATE - Fee for registering as a delegate.
* @property {number} FEES.MULTISIGNATURE - Fee for multisignature transaction.
* @property {number} FEES.DAPP_REGISTRATION - Fee for registering as a dapp.
* @property {number} FEES.DAPP_WITHDRAWAL - ? To be defined
* @property {number} FEES.DAPP_DEPOSIT - ? To be defined
// TODO: Needs additional check to revise max payload length
// for each transaction type for consistency
// FYI: https://lisk.io/documentation/the-lisk-protocol/blocks {Block Payload Section}
* @property {number} maxPayloadLength - Maximum transaction bytes length for 25 transactions in a single block.
* @property {number} maxPeers - Maximum number of peers allowed to connect while broadcasting a block.
* @property {number} maxSharedTxs - Maximum number of in-memory transactions/signatures shared accros peers.
* @property {number} maxTxsPerBlock - Maximum Number of transactions allowed per block.
* @property {number} minBroadhashConsensus - Minimum broadhash consensus(%) among connected {maxPeers} peers.
* @property {string[]} nethashes - For mainnet and testnet.
* @property {number} constants.normalizer - Use this to convert LISK amount to normal value.
* @property {Object} rewards - Object representing LSK rewards milestone.
* @property {number[]} rewards.milestones - Initial 5, and decreasing until 1.
* @property {number} rewards.offset - Start rewards at block (n).
* @property {number} rewards.distance - Distance between each milestone.
* @property {number} totalAmount - Total amount of LSK available in network before rewards milestone started.
* @property {number} unconfirmedTransactionTimeOut - Expiration time for unconfirmed transaction/signatures in transaction pool.
* @property {number} expiryInterval - Transaction pool expiry timer in milliseconds
* @property {number} MAX_PAYLOAD_LENGTH - Maximum transaction bytes length for 25 transactions in a single block.
* @property {number} MAX_PEERS - Maximum number of peers allowed to connect while broadcasting a block.
* @property {number} MAX_SHARED_TRANSACTIONS - Maximum number of in-memory transactions/signatures shared accros peers.
* @property {number} MAX_TRANSACTIONS_PER_BLOCK - Maximum number of transactions allowed per block.
* @property {number} MAX_VOTES_PER_TRANSACTION - The maximum number of votes allowed in transaction type(3) votes.
* @property {number} MIN_BROADHASH_CONSENSUS - Minimum broadhash consensus(%) among connected {MAX_PEERS} peers.
* @property {number} MULTISIG_CONSTRAINTS.MIN.MINIMUM - Minimum allowed number of signatures required to process a multisignature transaction
* @property {number} MULTISIG_CONSTRAINTS.MIN.MAXIMUM - Maximum allowed number of signatures required to process a multisignature transaction
* @property {number} MULTISIG_CONSTRAINTS.LIFETIME.MINIMUM - Minimum timeframe in which a multisignature transaction will exist in memory before the transaction is confirmed
* @property {number} MULTISIG_CONSTRAINTS.LIFETIME.MAXIMUM - Maximum timeframe in which multisignature transaction will exist in memory before the transaction is confirmed
* @property {number} MULTISIG_CONSTRAINTS.KEYSGROUP.MIN_ITEMS - Minimum allowed number of keys inside a Multisignature pool
* @property {number} MULTISIG_CONSTRAINTS.KEYSGROUP.MAX_ITEMS - Maximum allowed number of keys inside a Multisignature pool
* @property {string[]} NETHASHES - For mainnet and testnet.
* @property {number} NORMALIZER - Use this to convert LISK amount to normal value.
* @property {Object} REWARDS - Object representing LSK rewards milestone.
* @property {number[]} REWARDS.MILESTONES - Initial 5, and decreasing until 1.
* @property {number} REWARDS.OFFSET - Start rewards at block (n).
* @property {number} REWARDS.DISTANCE - Distance between each milestone.
* @property {number} TOTAL_AMOUNT - Total amount of LSK available in network before rewards milestone started.
* @property {number} UNCONFIRMED_TRANSACTION_TIMEOUT - Expiration time for unconfirmed transaction/signatures in transaction pool.
* @property {number} EXPIRY_INTERVAL - Transaction pool expiry timer in milliseconds
* @todo Add description for the namespace and the properties.
*/
module.exports = {
activeDelegates: 101,
blockSlotWindow: 5,
additionalData: {
minLength: 1,
maxLength: 64,
ACTIVE_DELEGATES: 101,
BLOCK_SLOT_WINDOW: 5,
ADDITIONAL_DATA: {
MIN_LENGTH: 1,
MAX_LENGTH: 64,
},
blockReceiptTimeOut: 20, // 2 blocks
epochTime: new Date(Date.UTC(2016, 4, 24, 17, 0, 0, 0)),
fees: {
send: '10000000',
vote: '100000000',
secondSignature: '500000000',
delegate: '2500000000',
multisignature: '500000000',
dappRegistration: '2500000000',
dappWithdrawal: '10000000',
dappDeposit: '10000000',
BLOCK_RECEIPT_TIMEOUT: 20, // 2 blocks
EPOCH_TIME: new Date(Date.UTC(2016, 4, 24, 17, 0, 0, 0)),
FEES: {
SEND: '10000000',
VOTE: '100000000',
SECOND_SIGNATURE: '500000000',
DELEGATE: '2500000000',
MULTISIGNATURE: '500000000',
DAPP_REGISTRATION: '2500000000',
DAPP_WITHDRAWAL: '10000000',
DAPP_DEPOSIT: '10000000',
},
maxPayloadLength: 1024 * 1024,
maxPeers: 100,
maxSharedTransactions: 100,
maxTransactionsPerBlock: 25,
maxVotesPerTransaction: 33,
maxVotesPerAccount: 101,
minBroadhashConsensus: 51,
multisigConstraints: {
min: {
minimum: 1,
maximum: 15,
MAX_PAYLOAD_LENGTH: 1024 * 1024,
MAX_PEERS: 100,
MAX_SHARED_TRANSACTIONS: 100,
MAX_TRANSACTIONS_PER_BLOCK: 25,
MAX_VOTES_PER_TRANSACTION: 33,
MAX_VOTES_PER_ACCOUNT: 101,
MIN_BROADHASH_CONSENSUS: 51,
MULTISIG_CONSTRAINTS: {
MIN: {
MINIMUM: 1,
MAXIMUM: 15,
},
lifetime: {
minimum: 1,
maximum: 72,
LIFETIME: {
MINIMUM: 1,
MAXIMUM: 72,
},
keysgroup: {
minItems: 1,
maxItems: 15,
KEYSGROUP: {
MIN_ITEMS: 1,
MAX_ITEMS: 15,
},
},
nethashes: [
NETHASHES: [
// Mainnet
'ed14889723f24ecc54871d058d98ce91ff2f973192075c0155ba2b7b70ad2511',
// Testnet
'da3ed6a45429278bac2666961289ca17ad86595d33b31037615d4b8e8f158bba',
],
normalizer: '100000000',
rewards: {
milestones: [
NORMALIZER: '100000000',
REWARDS: {
MILESTONES: [
'500000000', // Initial Reward
'400000000', // Milestone 1
'300000000', // Milestone 2
'200000000', // Milestone 3
'100000000', // Milestone 4
],
offset: 2160, // Start rewards at first block of the second round
distance: 3000000, // Distance between each milestone
OFFSET: 2160, // Start rewards at first block of the second round
DISTANCE: 3000000, // Distance between each milestone
},
// WARNING: When changing totalAmount you also need to change getBlockRewards(int) SQL function!
totalAmount: '10000000000000000',
unconfirmedTransactionTimeOut: 10800, // 1080 blocks
expiryInterval: 30000,
TOTAL_AMOUNT: '10000000000000000',
UNCONFIRMED_TRANSACTION_TIMEOUT: 10800, // 1080 blocks
EXPIRY_INTERVAL: 30000,
};
10 changes: 5 additions & 5 deletions config/mainnet/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@
"wsPort": 8001
},
{
"ip": "mainnet-seed-02.lisk.io",
"ip": "mainnet-seed-02.lisk-nodes.net",
"wsPort": 8001
},
{
"ip": "mainnet-seed-03.lisk.io",
"wsPort": 8001
},
{
"ip": "mainnet-seed-04.lisk.io",
"ip": "mainnet-seed-04.lisk-nodes.net",
"wsPort": 8001
},
{
"ip": "mainnet-seed-05.lisk.io",
"wsPort": 8001
},
{
"ip": "mainnet-seed-06.lisk.io",
"ip": "mainnet-seed-06.lisk-nodes.net",
"wsPort": 8001
},
{
"ip": "mainnet-seed-07.lisk.io",
"wsPort": 8001
},
{
"ip": "mainnet-seed-08.lisk.io",
"ip": "mainnet-seed-08.lisk-nodes.net",
"wsPort": 8001
},
{
"ip": "mainnet-seed-09.lisk.io",
"wsPort": 8001
},
{
"ip": "mainnet-seed-10.lisk.io",
"ip": "mainnet-seed-10.lisk-nodes.net",
"wsPort": 8001
}
]
Expand Down
4 changes: 2 additions & 2 deletions config/testnet/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"wsPort": 7001
},
{
"ip": "testnet-seed-02.lisk.io",
"ip": "testnet-seed-02.lisk-nodes.net",
"wsPort": 7001
},
{
"ip": "testnet-seed-03.lisk.io",
"wsPort": 7001
},
{
"ip": "testnet-seed-04.lisk.io",
"ip": "testnet-seed-04.lisk-nodes.net",
"wsPort": 7001
},
{
Expand Down
7 changes: 5 additions & 2 deletions helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const _ = require('lodash');
const randomstring = require('randomstring');
const configSchema = require('../schema/config.js');
const z_schema = require('./z_schema.js');
const deepFreeze = require('./deep_freeze_object.js');

const rootPath = path.dirname(path.resolve(__filename, '..'));

Expand Down Expand Up @@ -155,7 +156,9 @@ function Config(packageJson, parseCommandLineOptions = true) {
} else {
appConfig.genesisBlock = genesisBlock;

appConfig.constants = _.merge(defaultConstants, networkConstants);
appConfig.constants = deepFreeze(
_.merge(defaultConstants, networkConstants)
);

appConfig.exceptions = _.merge(defaultExceptions, networkExceptions);

Expand Down Expand Up @@ -282,7 +285,7 @@ function cleanDeep(
*/
function validateForce(configData) {
if (configData.forging.force) {
var index = configData.constants.nethashes.indexOf(configData.nethash);
var index = configData.constants.NETHASHES.indexOf(configData.nethash);

if (index !== -1) {
console.info('Forced forging disabled for nethash', configData.nethash);
Expand Down
17 changes: 17 additions & 0 deletions helpers/deep_freeze_object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

module.exports = function deepFreeze(o) {
Object.freeze(o);

Object.getOwnPropertyNames(o).forEach(prop => {
if (
o[prop] !== null &&
typeof o[prop] === 'object' &&
!Object.isFrozen(o[prop])
) {
deepFreeze(o[prop]);
}
});

return o;
};
18 changes: 3 additions & 15 deletions helpers/slots.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ const constants = global.constants;
* @todo Add description for the module
*/

/**
* Gets constant time from Lisk epoch.
*
* @private
* @returns {number} Lisk epoch time
*/
function beginEpochTime() {
var d = constants.epochTime;

return d;
}

/**
* Calculates time since Lisk epoch.
*
Expand All @@ -50,15 +38,15 @@ function getEpochTime(time) {
time = Date.now();
}

var d = beginEpochTime();
var d = constants.EPOCH_TIME;
var t = d.getTime();

return Math.floor((time - t) / 1000);
}

module.exports = {
interval: 10,
delegates: constants.activeDelegates,
delegates: constants.ACTIVE_DELEGATES,

/**
* Description of the function.
Expand All @@ -83,7 +71,7 @@ module.exports = {
epochTime = this.getTime();
}

var d = beginEpochTime();
var d = constants.EPOCH_TIME;
var t = Math.floor(d.getTime() / 1000) * 1000;

return t + epochTime * 1000;
Expand Down
6 changes: 4 additions & 2 deletions helpers/z_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ var liskFormats = {
if (typeof str !== 'string') {
return false;
}
return Buffer.from(str).length <= global.constants.additionalData.maxLength;
return (
Buffer.from(str).length <= global.constants.ADDITIONAL_DATA.MAX_LENGTH
);
},
/**
* Description of the function.
Expand Down Expand Up @@ -286,7 +288,7 @@ var liskFormats = {
if (value instanceof Bignum) {
return (
value.greaterThanOrEqualTo(0) &&
value.lessThanOrEqualTo(global.constants.totalAmount)
value.lessThanOrEqualTo(global.constants.TOTAL_AMOUNT)
);
}
return false;
Expand Down
Loading

0 comments on commit b835a01

Please sign in to comment.