Update block immediately after adding a node to the chain

This commit is contained in:
maciejhirsz
2018-07-21 08:30:06 +02:00
parent ef95c3e507
commit 42e7010697
3 changed files with 13 additions and 11 deletions
+2
View File
@@ -45,6 +45,8 @@ export default class Chain {
node.events.on('block', () => this.updateBlock(node)); node.events.on('block', () => this.updateBlock(node));
node.events.on('stats', () => this.feeds.broadcast(Feed.stats(node))); node.events.on('stats', () => this.feeds.broadcast(Feed.stats(node)));
node.events.on('location', (location) => this.feeds.broadcast(Feed.locatedNode(node, location))); node.events.on('location', (location) => this.feeds.broadcast(Feed.locatedNode(node, location)));
this.updateBlock(node);
} }
public addFeed(feed: Feed) { public addFeed(feed: Feed) {
+7 -7
View File
@@ -64,8 +64,6 @@ export default class Node {
this.lastMessage = timestamp(); this.lastMessage = timestamp();
this.socket = socket; this.socket = socket;
let start = Date.now();
socket.on('message', (data) => { socket.on('message', (data) => {
const message = parseMessage(data); const message = parseMessage(data);
@@ -145,6 +143,7 @@ export default class Node {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
cleanup(); cleanup();
socket.close();
socket.terminate(); socket.terminate();
return reject(new Error('Timeout on waiting for system.connected message')); return reject(new Error('Timeout on waiting for system.connected message'));
@@ -206,6 +205,7 @@ export default class Node {
private disconnect() { private disconnect() {
this.socket.removeAllListeners(); this.socket.removeAllListeners();
this.socket.close();
this.socket.terminate(); this.socket.terminate();
this.events.emit('disconnect'); this.events.emit('disconnect');
@@ -237,11 +237,11 @@ export default class Node {
} }
private updateLatency(now: Types.Timestamp) { private updateLatency(now: Types.Timestamp) {
// if (this.pingStart) { if (this.pingStart) {
// console.error(`${this.name} timed out on ping message.`); console.error(`${this.name} timed out on ping message.`);
// this.disconnect(); this.disconnect();
// return; return;
// } }
this.pingStart = now; this.pingStart = now;
this.socket.ping(noop); this.socket.ping(noop);
+4 -4
View File
@@ -11,11 +11,11 @@ export class Connection {
return new Connection(await Connection.socket(), update); return new Connection(await Connection.socket(), update);
} }
private static readonly address = window.location.protocol === 'https:' // private static readonly address = window.location.protocol === 'https:'
? `wss://${window.location.hostname}/feed/` // ? `wss://${window.location.hostname}/feed/`
: `ws://${window.location.hostname}:8080`; // : `ws://${window.location.hostname}:8080`;
// private static readonly address = 'wss://telemetry.polkadot.io/feed/'; private static readonly address = 'wss://telemetry.polkadot.io/feed/';
private static async socket(): Promise<WebSocket> { private static async socket(): Promise<WebSocket> {
let socket = await Connection.trySocket(); let socket = await Connection.trySocket();