diff --git a/packages/backend/src/Aggregator.ts b/packages/backend/src/Aggregator.ts index b13d908..01974c7 100644 --- a/packages/backend/src/Aggregator.ts +++ b/packages/backend/src/Aggregator.ts @@ -47,23 +47,6 @@ export default class Aggregator { } }); - feed.events.on('subscribe-consensus-info', (label: Types.ChainLabel) => { - const chain = this.chains.get(label); - - if (chain) { - feed.sendMessage(Feed.subscribedTo(label)); - chain.addFeed(feed); - } - }); - - feed.events.on('unsubscribe-consensus-info', (label: Types.ChainLabel) => { - const chain = this.chains.get(label); - - if (chain) { - chain.removeFeed(feed); - feed.sendMessage(Feed.unsubscribedFrom(label)); - } - }); } public getExistingChain(label: Types.ChainLabel) : Maybe { diff --git a/packages/frontend/src/AfgHandling.ts b/packages/frontend/src/AfgHandling.ts index 33cd2c1..635baef 100644 --- a/packages/frontend/src/AfgHandling.ts +++ b/packages/frontend/src/AfgHandling.ts @@ -1,6 +1,7 @@ import { Types } from '@dotstats/common'; import { State, UpdateBound } from './state'; +// Number of blocks which are kept in memory const BLOCKS_LIMIT = 50; export class AfgHandling { diff --git a/packages/frontend/src/Connection.ts b/packages/frontend/src/Connection.ts index bec2600..ec35dc0 100644 --- a/packages/frontend/src/Connection.ts +++ b/packages/frontend/src/Connection.ts @@ -3,6 +3,7 @@ import { State, Update, Node, UpdateBound } from './state'; import { PersistentSet } from './persist'; import { getHashData, setHashData } from './utils'; import { AfgHandling } from './AfgHandling'; +import { VIS_AUTHORITIES_LIMIT } from '../../frontend/src/components/Consensus'; const { Actions } = FeedMessage; @@ -14,13 +15,11 @@ export class Connection { return new Connection(await Connection.socket(), update, pins); } - private static readonly debug: number = 2; - - private static readonly address1 = window.location.protocol === 'https:' + private static readonly address = window.location.protocol === 'https:' ? `wss://${window.location.hostname}/feed/` : `ws://${window.location.hostname}:8080`; - private static readonly address2 = 'wss://telemetry.polkadot.io/feed/'; + // private static readonly address = 'wss://telemetry.polkadot.io/feed/'; private static async socket(): Promise { let socket = await Connection.trySocket(); @@ -54,7 +53,7 @@ export class Connection { resolve(null); } - const socket = new WebSocket(Connection.debug === 1 ? Connection.address1 : Connection.address2); + const socket = new WebSocket(Connection.address); socket.addEventListener('open', onSuccess); socket.addEventListener('error', onFailure); @@ -93,9 +92,11 @@ export class Connection { } public subscribeConsensus(chain: Types.ChainLabel) { - setHashData({ chain }); - this.resubscribeSendFinality = true; - this.socket.send(`send-finality:${chain}`); + if (this.state.authorities.length <= VIS_AUTHORITIES_LIMIT) { + setHashData({chain}); + this.resubscribeSendFinality = true; + this.socket.send(`send-finality:${chain}`); + } } public resetConsensus() { diff --git a/packages/frontend/src/components/Consensus/Consensus.tsx b/packages/frontend/src/components/Consensus/Consensus.tsx index 6747387..b8e4303 100644 --- a/packages/frontend/src/components/Consensus/Consensus.tsx +++ b/packages/frontend/src/components/Consensus/Consensus.tsx @@ -8,7 +8,9 @@ import { State as AppState } from '../../state'; import './Consensus.css'; -const AUTHORITIES_LIMIT = 10; +// Maximum number of authorities the visualization is +// allowed of processing. +export const VIS_AUTHORITIES_LIMIT = 10; export namespace Consensus { export interface Props { @@ -165,13 +167,13 @@ export class Consensus extends React.Component { this.state.lastConsensusInfo = JSON.stringify(this.props.appState.consensusInfo); const lastBlocks = this.props.appState.consensusInfo; - if (this.props.appState.authorities.length > AUTHORITIES_LIMIT) { + if (this.props.appState.authorities.length > VIS_AUTHORITIES_LIMIT) { return

Too many authorities.

- Won't display for more than {AUTHORITIES_LIMIT} authorities + Won't display for more than {VIS_AUTHORITIES_LIMIT} authorities to protect your browser.

;