mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-11 23:31:08 +00:00
Handle too many validators properly (#151)
* Revert debug flag * Remove dead code * Disallow subscribing if too many validators
This commit is contained in:
committed by
Maciej Hirsz
parent
7add77137a
commit
ce9538485a
@@ -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<Chain> {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<WebSocket> {
|
||||
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() {
|
||||
|
||||
@@ -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<Consensus.Props, {}> {
|
||||
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 <div className="Consensus">
|
||||
<div className="tooManyAuthorities">
|
||||
<p>
|
||||
Too many authorities.</p>
|
||||
<p>
|
||||
Won't display for more than {AUTHORITIES_LIMIT} authorities
|
||||
Won't display for more than {VIS_AUTHORITIES_LIMIT} authorities
|
||||
to protect your browser.
|
||||
</p>
|
||||
</div>;
|
||||
|
||||
Reference in New Issue
Block a user