fix ws ping and add wait calculation
This commit is contained in:
parent
c70021a28a
commit
3666108e15
|
@ -60,7 +60,10 @@ class BlockchainConnector {
|
|||
this.logger.error(message);
|
||||
}
|
||||
|
||||
const protocol = (this.contractsConfig.deployment.type === "rpc") ? this.contractsConfig.deployment.protocol : 'ws';
|
||||
let protocol = this.contractsConfig.deployment.protocol;
|
||||
if (!protocol) {
|
||||
protocol = (this.contractsConfig.deployment.type === "rpc") ? 'http' : 'ws';
|
||||
}
|
||||
|
||||
this.web3Endpoint = utils.buildUrl(protocol, this.contractsConfig.deployment.host, this.contractsConfig.deployment.port);//`${protocol}://${this.contractsConfig.deployment.host}:${this.contractsConfig.deployment.port}`;
|
||||
|
||||
|
@ -83,7 +86,7 @@ class BlockchainConnector {
|
|||
if (!networkId && constants.blockchain.networkIds[self.blockchainConfig.networkType]) {
|
||||
networkId = constants.blockchain.networkIds[self.blockchainConfig.networkType];
|
||||
}
|
||||
if (id.toString() !== networkId.toString()) {
|
||||
if (networkId && id.toString() !== networkId.toString()) {
|
||||
self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {
|
||||
realId: id,
|
||||
configId: networkId
|
||||
|
|
|
@ -53,6 +53,12 @@ class ENS {
|
|||
});
|
||||
}
|
||||
], (err, results) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
if (!results[0] || !results[1] || !results[2]) {
|
||||
return cb(__('Aborting ENS setup as some of the contracts did not deploy properly'));
|
||||
}
|
||||
// result[0] => ENSRegistry; result[1] => FIFSRegistrar; result[2] => FIFSRegistrar
|
||||
let config = {
|
||||
env: self.env,
|
||||
|
|
|
@ -16,6 +16,13 @@ class TransactionTracker {
|
|||
|
||||
onBlockHeader(blockHeader) {
|
||||
this.events.request("blockchain:block:byNumber", blockHeader.hash, (err, block) => {
|
||||
if (err) {
|
||||
return this.logger.error('Error getting block header', err);
|
||||
}
|
||||
// Don't know why, but sometimes we receive nothing
|
||||
if (!block || !block.transactions) {
|
||||
return;
|
||||
}
|
||||
block.transactions.forEach(transaction => {
|
||||
if (this.transactions[transaction.hash]) {
|
||||
Object.assign(this.transactions[transaction.hash], transaction, {endTimestamp: block.timestamp, wait: block.timestamp - this.transactions[transaction.hash].startTimestamp});
|
||||
|
@ -23,6 +30,26 @@ class TransactionTracker {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
calculateGasPriceSpeeds() {
|
||||
return Object.keys(this.transactions).reduce((acc, transactionHash) => {
|
||||
const transaction = this.transactions[transactionHash];
|
||||
if (!transaction.gasPrice) {
|
||||
return acc;
|
||||
}
|
||||
if (!acc[transaction.gasPrice]) {
|
||||
acc[transaction.gasPrice] = {
|
||||
nbTxs: 0,
|
||||
totalWait: 0
|
||||
};
|
||||
}
|
||||
acc[transaction.gasPrice].nbTxs++;
|
||||
acc[transaction.gasPrice].totalWait += transaction.wait;
|
||||
acc[transaction.gasPrice].averageWait = acc[transaction.gasPrice].totalWait / acc[transaction.gasPrice].nbTxs;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TransactionTracker;
|
||||
|
|
|
@ -88,7 +88,36 @@ function getJson(url, cb) {
|
|||
httpGetJson(url, cb);
|
||||
}
|
||||
|
||||
function testWebSocket(wsUri, cb) {
|
||||
const W3CWebSocket = require('websocket').w3cwebsocket;
|
||||
const websocket = new W3CWebSocket(wsUri);
|
||||
|
||||
let calledBack = false;
|
||||
function callback(err) {
|
||||
if (calledBack) {
|
||||
return;
|
||||
}
|
||||
websocket.close();
|
||||
calledBack = true;
|
||||
cb(err);
|
||||
}
|
||||
|
||||
websocket.onopen = function(_evt) {
|
||||
callback();
|
||||
};
|
||||
websocket.onclose = function(_evt) {
|
||||
callback('ws connection closed');
|
||||
};
|
||||
websocket.onerror = function(evt) {
|
||||
callback(evt.message|| evt);
|
||||
};
|
||||
}
|
||||
|
||||
function pingEndpoint(host, port, type, protocol, origin, callback) {
|
||||
if (type === 'ws') {
|
||||
port = port ? ':' + port : '';
|
||||
return testWebSocket(`${protocol}://${host}${port}`, callback);
|
||||
}
|
||||
const options = {
|
||||
protocolVersion: 13,
|
||||
perMessageDeflate: true,
|
||||
|
@ -96,15 +125,6 @@ function pingEndpoint(host, port, type, protocol, origin, callback) {
|
|||
host: host,
|
||||
port: port
|
||||
};
|
||||
if (type === 'ws') {
|
||||
options.headers = {
|
||||
'Sec-WebSocket-Version': 13,
|
||||
Connection: 'Upgrade',
|
||||
Upgrade: 'websocket',
|
||||
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
|
||||
Origin: origin
|
||||
};
|
||||
}
|
||||
let req;
|
||||
// remove trailing api key from infura, ie rinkeby.infura.io/nmY8WtT4QfEwz2S7wTbl
|
||||
if (options.host.indexOf('/') > -1) {
|
||||
|
@ -447,50 +467,6 @@ function interceptLogs(consoleContext, logger) {
|
|||
};
|
||||
}
|
||||
|
||||
function compact(array) {
|
||||
return array.filter(n => n);
|
||||
}
|
||||
|
||||
function groupBy(array, key) {
|
||||
return array.reduce(function(rv, x) {
|
||||
(rv[x[key]] = rv[x[key]] || []).push(x);
|
||||
return rv;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function sample(array) {
|
||||
return array[Math.floor(Math.random() * array.length)];
|
||||
}
|
||||
|
||||
function last(array) {
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
||||
function interceptLogs(consoleContext, logger) {
|
||||
let context = {};
|
||||
context.console = consoleContext;
|
||||
|
||||
context.console.log = function() {
|
||||
logger.info(normalizeInput(arguments));
|
||||
};
|
||||
context.console.warn = function() {
|
||||
logger.warn(normalizeInput(arguments));
|
||||
};
|
||||
context.console.info = function() {
|
||||
logger.info(normalizeInput(arguments));
|
||||
};
|
||||
context.console.debug = function() {
|
||||
// TODO: ue JSON.stringify
|
||||
logger.debug(normalizeInput(arguments));
|
||||
};
|
||||
context.console.trace = function() {
|
||||
logger.trace(normalizeInput(arguments));
|
||||
};
|
||||
context.console.dir = function() {
|
||||
logger.dir(normalizeInput(arguments));
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
joinPath,
|
||||
dirname,
|
||||
|
|
|
@ -92,6 +92,7 @@
|
|||
"viz.js": "^1.8.1",
|
||||
"web3": "1.0.0-beta.34",
|
||||
"webpack": "^4.16.1",
|
||||
"websocket": "^1.0.26",
|
||||
"window-size": "^1.1.0"
|
||||
},
|
||||
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
||||
|
|
Loading…
Reference in New Issue