mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-12 19:11:01 +00:00
Show validator address for nodes (#37)
Show validator address for nodes
This commit is contained in:
@@ -20,7 +20,8 @@ export default class Node {
|
||||
public readonly chain: Types.ChainLabel;
|
||||
public readonly implementation: Types.NodeImplementation;
|
||||
public readonly version: Types.NodeVersion;
|
||||
public readonly pubkey: Maybe<Types.NodePubKey>;
|
||||
public readonly address: Maybe<Types.Address>;
|
||||
public readonly authority: boolean;
|
||||
|
||||
public readonly events = new EventEmitter() as EventEmitter & NodeEvents;
|
||||
|
||||
@@ -52,17 +53,19 @@ export default class Node {
|
||||
config: string,
|
||||
implentation: Types.NodeImplementation,
|
||||
version: Types.NodeVersion,
|
||||
pubkey: Maybe<Types.NodePubKey>,
|
||||
address: Maybe<Types.Address>,
|
||||
authority: boolean,
|
||||
messages: Array<Message>,
|
||||
) {
|
||||
this.ip = ip;
|
||||
this.id = getId(pubkey);
|
||||
this.id = getId(address);
|
||||
this.name = name;
|
||||
this.chain = chain;
|
||||
this.config = config;
|
||||
this.implementation = implentation;
|
||||
this.version = version;
|
||||
this.pubkey = pubkey;
|
||||
this.address = address;
|
||||
this.authority = authority;
|
||||
this.lastMessage = timestamp();
|
||||
this.socket = socket;
|
||||
|
||||
@@ -93,10 +96,12 @@ export default class Node {
|
||||
this.pingStart = 0 as Types.Timestamp;
|
||||
});
|
||||
|
||||
// Handle cached messages
|
||||
for (const message of messages) {
|
||||
this.onMessage(message);
|
||||
}
|
||||
process.nextTick(() => {
|
||||
// Handle cached messages
|
||||
for (const message of messages) {
|
||||
this.onMessage(message);
|
||||
}
|
||||
});
|
||||
|
||||
locate(ip).then((location) => {
|
||||
if (!location) {
|
||||
@@ -128,9 +133,9 @@ export default class Node {
|
||||
if (message.msg === "system.connected") {
|
||||
cleanup();
|
||||
|
||||
const { name, chain, config, implementation, version, pubkey } = message;
|
||||
const { name, chain, config, implementation, version, pubkey, authority } = message;
|
||||
|
||||
resolve(new Node(ip, socket, name, chain, config, implementation, version, pubkey, messages));
|
||||
resolve(new Node(ip, socket, name, chain, config, implementation, version, pubkey, authority === true, messages));
|
||||
} else {
|
||||
if (messages.length === 10) {
|
||||
messages.shift();
|
||||
@@ -162,7 +167,9 @@ export default class Node {
|
||||
}
|
||||
|
||||
public nodeDetails(): Types.NodeDetails {
|
||||
return [this.name, this.implementation, this.version];
|
||||
const authority = this.authority ? this.address : null;
|
||||
|
||||
return [this.name, this.implementation, this.version, authority];
|
||||
}
|
||||
|
||||
public nodeStats(): Types.NodeStats {
|
||||
@@ -196,7 +203,7 @@ export default class Node {
|
||||
this.socket.close();
|
||||
this.socket.terminate();
|
||||
|
||||
refreshId(this.pubkey, this.id);
|
||||
refreshId(this.address, this.id);
|
||||
|
||||
this.events.emit('disconnect');
|
||||
}
|
||||
|
||||
@@ -34,42 +34,43 @@ interface MessageBase {
|
||||
}
|
||||
|
||||
export interface BestBlock {
|
||||
best: Types.BlockHash,
|
||||
height: Types.BlockNumber,
|
||||
ts: Date,
|
||||
best: Types.BlockHash;
|
||||
height: Types.BlockNumber;
|
||||
ts: Date;
|
||||
}
|
||||
|
||||
interface SystemConnected {
|
||||
msg: 'system.connected',
|
||||
name: Types.NodeName,
|
||||
chain: Types.ChainLabel,
|
||||
config: string,
|
||||
implementation: Types.NodeImplementation,
|
||||
version: Types.NodeVersion,
|
||||
pubkey: Maybe<Types.NodePubKey>,
|
||||
export interface SystemConnected {
|
||||
msg: 'system.connected';
|
||||
name: Types.NodeName;
|
||||
chain: Types.ChainLabel;
|
||||
config: string;
|
||||
implementation: Types.NodeImplementation;
|
||||
version: Types.NodeVersion;
|
||||
pubkey: Maybe<Types.Address>;
|
||||
authority: Maybe<boolean>;
|
||||
}
|
||||
|
||||
export interface SystemInterval extends BestBlock {
|
||||
msg: 'system.interval',
|
||||
txcount: Types.TransactionCount,
|
||||
peers: Types.PeerCount,
|
||||
status: 'Idle' | string, // TODO: 'Idle' | ...?
|
||||
msg: 'system.interval';
|
||||
txcount: Types.TransactionCount;
|
||||
peers: Types.PeerCount;
|
||||
status: 'Idle' | string; // TODO: 'Idle' | ...?
|
||||
}
|
||||
|
||||
interface NodeStart extends BestBlock {
|
||||
msg: 'node.start',
|
||||
export interface NodeStart extends BestBlock {
|
||||
msg: 'node.start';
|
||||
}
|
||||
|
||||
interface BlockImport extends BestBlock {
|
||||
msg: 'block.import',
|
||||
export interface BlockImport extends BestBlock {
|
||||
msg: 'block.import';
|
||||
}
|
||||
|
||||
// Union type
|
||||
export type Message = MessageBase & (
|
||||
SystemConnected |
|
||||
SystemInterval |
|
||||
NodeStart |
|
||||
BlockImport
|
||||
| SystemConnected
|
||||
| SystemInterval
|
||||
| NodeStart
|
||||
| BlockImport
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ interface NodeIdCache {
|
||||
}
|
||||
|
||||
const nextId = idGenerator<Types.NodeId>();
|
||||
const idCache = new Map<Types.NodePubKey, NodeIdCache>();
|
||||
const idCache = new Map<Types.Address, NodeIdCache>();
|
||||
|
||||
function clearCache() {
|
||||
const now = timestamp();
|
||||
@@ -25,7 +25,7 @@ function clearCache() {
|
||||
|
||||
clearCache();
|
||||
|
||||
export function getId(pubkey: Maybe<Types.NodePubKey>): Types.NodeId {
|
||||
export function getId(pubkey: Maybe<Types.Address>): Types.NodeId {
|
||||
if (!pubkey) {
|
||||
return nextId();
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export function getId(pubkey: Maybe<Types.NodePubKey>): Types.NodeId {
|
||||
return id;
|
||||
}
|
||||
|
||||
export function refreshId(pubkey: Maybe<Types.NodePubKey>, id: Types.NodeId) {
|
||||
export function refreshId(pubkey: Maybe<Types.Address>, id: Types.NodeId) {
|
||||
if (!pubkey) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user