Commit 01447412 authored by Eriksson Monteiro's avatar Eriksson Monteiro

update millix node

parent cd58213f
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -25,26 +25,35 @@ class _rKclyiLtHx0dx55M extends Endpoint {
database.applyShards((shardID) => {
const transactionRepository = database.getRepository('transaction', shardID);
return transactionRepository.getWalletBalance(wallet.defaultKeyIdentifier, true);
}).then(balances => _.sum(balances)).then(stable => database.applyShards((shardID) => {
const transactionRepository = database.getRepository('transaction', shardID);
return transactionRepository.getWalletBalance(wallet.defaultKeyIdentifier, false);
}).then(balances => _.sum(balances)).then(unstable => wallet.getTransactionCount().then(transactionCount => res.send({
balance : {
stable,
unstable
},
network : {
online : network.initialized,
peer_count: network.registeredClients.length
},
log : {
log_count : logManager.lastIdx,
backlog_count: logManager.backLogSize
},
transaction: {
transaction_count: transactionCount
}
})))).catch(e => res.send({
}).then(balances => _.sum(balances)).then(stable => {
return database.applyShards((shardID) => {
const transactionRepository = database.getRepository('transaction', shardID);
return transactionRepository.getWalletBalance(wallet.defaultKeyIdentifier, false);
}).then(balances => _.sum(balances)).then(unstable => {
return wallet.getTransactionCount().then(transactionCount => {
return database.getRepository('transaction').countWalletUnstableTransactions(wallet.defaultKeyIdentifier).then(pendingTransactionCount => {
res.send({
balance : {
stable,
unstable
},
network : {
online : network.initialized,
peer_count: network.registeredClients.length
},
log : {
log_count : logManager.lastIdx,
backlog_count: logManager.backLogSize
},
transaction: {
transaction_count : transactionCount,
transaction_pending_validation: pendingTransactionCount
}
});
});
});
});
}).catch(e => res.send({
api_status : 'fail',
api_message: `unexpected generic api error: (${e})`
}));
......
......@@ -736,6 +736,7 @@ export const TRANSACTION_OUTPUT_REFRESH_OLDER_THAN = 10;
export const TRANSACTION_OUTPUT_EXPIRE_OLDER_THAN = 10;
export const NODE_CONNECTION_INBOUND_MAX = 30;
export const NODE_CONNECTION_OUTBOUND_MAX = 30;
export const NODE_CONNECTION_PUBLIC_PERCENT = 0.2;
export const HEARTBEAT_TIMEOUT = 10 * 1000;
export const HEARTBEAT_RESPONSE_TIMEOUT = 60 * 1000;
export const WALLET_STARTUP_ADDRESS_BALANCE_SCAN_COUNT = 100;
......@@ -771,7 +772,7 @@ export const DATABASE_ENGINE = 'sqlite';
export const DATABASE_CONNECTION = {};
export const MILLIX_CIRCULATION = 9e15;
export const NODE_MILLIX_BUILD_DATE = 1631097631;
export const NODE_MILLIX_VERSION = '1.11.7-tangled';
export const NODE_MILLIX_VERSION = '1.11.8-tangled';
export const DATA_BASE_DIR_MAIN_NETWORK = './millix-tangled';
export const DATA_BASE_DIR_TEST_NETWORK = './millix-tangled';
let DATA_BASE_DIR = MODE_TEST_NETWORK ? DATA_BASE_DIR_TEST_NETWORK : DATA_BASE_DIR_MAIN_NETWORK;
......@@ -857,6 +858,7 @@ export default {
CONSENSUS_VALIDATION_RETRY_WAIT_TIME,
CONSENSUS_VALIDATION_PARALLEL_PROCESS_MAX,
CONSENSUS_VALIDATION_PARALLEL_REQUEST_MAX,
NODE_CONNECTION_PUBLIC_PERCENT,
CONSENSUS_ROUND_NODE_COUNT,
TRANSACTION_FEE_PROXY,
TRANSACTION_FEE_NETWORK,
......
......@@ -235,12 +235,12 @@ export class Database {
}
console.log('Database initialized');
resolve();
this.databaseMillix.run('PRAGMA journal_mode = MEMORY', () => this.databaseMillix.run('PRAGMA synchronous = OFF', () => resolve()));
});
});
}
else {
resolve();
this.databaseMillix.run('PRAGMA journal_mode = MEMORY', () => this.databaseMillix.run('PRAGMA synchronous = OFF', () => resolve()));
}
});
......
......@@ -177,6 +177,33 @@ export default class Transaction {
});
}
countWalletUnstableTransactions(addressKeyIdentifier) {
return new Promise((resolve, reject) => {
this.database.get('SELECT COUNT(1) as transaction_count FROM (SELECT * FROM (SELECT `transaction`.* FROM `transaction` ' +
'INNER JOIN transaction_input ON transaction_input.transaction_id = `transaction`.transaction_id ' +
'INNER JOIN transaction_output ON transaction_output.transaction_id = transaction_input.transaction_id ' +
'WHERE transaction_input.address_key_identifier = ?1 AND transaction_output.is_stable = 0 ORDER BY transaction_date ASC LIMIT ' + config.CONSENSUS_VALIDATION_PARALLEL_PROCESS_MAX + ') ' +
'UNION SELECT * FROM (SELECT `transaction`.* FROM `transaction` ' +
'INNER JOIN transaction_output ON transaction_output.transaction_id = `transaction`.transaction_id ' +
'WHERE transaction_output.address_key_identifier = ?1 AND transaction_output.is_stable = 0 ORDER BY transaction_date ASC LIMIT ' + config.CONSENSUS_VALIDATION_PARALLEL_PROCESS_MAX + ') ' +
'UNION SELECT * FROM (SELECT `transaction`.* FROM transaction_input ' +
'INNER JOIN `transaction` ON `transaction`.transaction_id = transaction_input.transaction_id ' +
'WHERE output_transaction_id IN (SELECT transaction_id FROM transaction_output WHERE address_key_identifier = ?1 ' +
'AND is_stable = 1 AND is_spent = 1 AND status = 2) AND +`transaction`.is_stable = 0 ORDER BY transaction_date ASC LIMIT ' + config.CONSENSUS_VALIDATION_PARALLEL_PROCESS_MAX + ')) ',
[
addressKeyIdentifier
],
(err, row) => {
if (err) {
console.log(err);
return reject(err);
}
return resolve(row.transaction_count || 0);
});
});
}
getTransactionByOutputAddress(address, fromTimestamp) {
return new Promise((resolve, reject) => {
let dateTime = Math.floor(fromTimestamp.getTime() / 1000);
......
......@@ -119,12 +119,12 @@ export default class Shard {
}
console.log('[shard] database initialized');
this.database.shardID = this.shardID;
resolve();
this.database.run('PRAGMA journal_mode = MEMORY', () => this.database.run('PRAGMA synchronous = OFF', () => resolve()));
});
});
}
else {
resolve();
this.database.run('PRAGMA journal_mode = MEMORY', () => this.database.run('PRAGMA synchronous = OFF', () => resolve()));
}
});
});
......
......@@ -126,6 +126,6 @@ db.initialize()
});
}
});
//millix v1.11.7-tangled
//millix v1.11.8-tangled
\ No newline at end of file
......@@ -18,6 +18,7 @@ import DHT from 'bittorrent-dht';
import signature from '../core/crypto/signature';
import NatAPI from 'nat-api';
import statistics from '../core/statistics';
import console from '../core/console';
const WebSocketServer = Server;
......@@ -496,7 +497,7 @@ class Network {
.then(() => eventBus.emit('node_list_update'))
.catch(() => eventBus.emit('node_list_update'));
if(config.NODE_NAT_PMP_CHECK) {
if (config.NODE_NAT_PMP_CHECK) {
peer.sendNATCheck({
url: config.WEBSOCKET_PROTOCOL + this.nodePublicIp + ':' + config.NODE_PORT
}, ws);
......@@ -604,7 +605,30 @@ class Network {
}
hasInboundConnectionsSlotAvailable() {
return (_.keys(this._inboundRegistry).length + this._bidirectionaOutboundConnectionCount) < config.NODE_CONNECTION_INBOUND_MAX;
return (_.keys(this._inboundRegistry).length + this._bidirectionaOutboundConnectionCount) < config.NODE_CONNECTION_INBOUND_MAX || this._hasToDropPublicNodeConnection();
}
_hasToDropPublicNodeConnection() {
const totalInboundConnections = (_.keys(this._inboundRegistry).length + this._bidirectionaOutboundConnectionCount);
const count = this._countPublicNodesOnInboundSlots();
return count >= Math.floor(config.NODE_CONNECTION_PUBLIC_PERCENT * config.NODE_CONNECTION_INBOUND_MAX) && totalInboundConnections >= config.NODE_CONNECTION_INBOUND_MAX;
}
_countPublicNodesOnInboundSlots() {
return _.filter(_.flatten(_.values(this._inboundRegistry)), ws => ws.nodeIsPublic === true).length;
}
_dropOldestPublicNodeConnection() {
const peerToDisconnect = _.minBy(_.filter(_.flatten(_.values(this._inboundRegistry)), peer => peer.nodeIsPublic), peer => peer.createTime);
if (peerToDisconnect && peerToDisconnect.close) {
console.log(`[peer-rotation] drop with node id ${peerToDisconnect.nodeID} - ${peerToDisconnect.node}`);
if (peerToDisconnect.readyState === WebSocket.CLOSED || peerToDisconnect.readyState === WebSocket.CLOSING) {
network._unregisterWebsocket(peerToDisconnect);
}
else {
peerToDisconnect.close();
}
}
}
hasOutboundConnectionsSlotAvailable() {
......@@ -643,6 +667,36 @@ class Network {
registry[nodeID] = [ws];
}
if (ws.inBound) {
// check if node is public
async.retry({
times : 3,
interval: 500
}, (callback) => {
this._natCheckTryConnect(ws.node)
.then(() => callback())
.catch(() => callback(true));
}, (err) => {
if (err) {
// private node
ws.nodeIsPublic = false;
}
else {
// public node
ws.nodeIsPublic = true;
if (this._hasToDropPublicNodeConnection()) {
this._dropOldestPublicNodeConnection();
}
}
const nodeRepository = database.getRepository('node');
nodeRepository.addNodeAttribute(ws.nodeID, 'node_connection', JSON.stringify({public: ws.nodeIsPublic}))
.then(_ => _)
.catch(_ => _);
});
}
console.log('[network] node ' + ws.node + ' registered with node id ' + nodeID);
return true;
}
......@@ -717,7 +771,16 @@ class Network {
}
_requestAllNodeAttribute(nodeID, ws) {
const attributeNameList = _.filter(['shard_protocol', 'transaction_count', 'peer_count', 'job_list', 'address_default', 'node_about', 'peer_connection', 'transaction_fee'], attributeName => {
const attributeNameList = _.filter([
'shard_protocol',
'transaction_count',
'peer_count',
'job_list',
'address_default',
'node_about',
'peer_connection',
'transaction_fee'
], attributeName => {
if (!peer.nodeAttributeCache[nodeID] || !peer.nodeAttributeCache[nodeID][attributeName]) {
return true;
}
......@@ -756,7 +819,7 @@ class Network {
.then(() => eventBus.emit('node_list_update'))
.catch(() => eventBus.emit('node_list_update'));
if(config.NODE_NAT_PMP_CHECK) {
if (config.NODE_NAT_PMP_CHECK) {
peer.sendNATCheck({
url: config.WEBSOCKET_PROTOCOL + this.nodePublicIp + ':' + config.NODE_PORT
}, ws);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment