mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-18 20:11:01 +00:00
feat: Instead of delisting, push stale nodes to bottom (#161)
This commit is contained in:
@@ -2,7 +2,7 @@ import { Types, Maybe, SortedCollection } from '@dotstats/common';
|
||||
|
||||
export class Node {
|
||||
public static compare(a: Node, b: Node): number {
|
||||
if (a.pinned === b.pinned) {
|
||||
if (a.pinned === b.pinned && a.stale === b.stale) {
|
||||
if (a.height === b.height) {
|
||||
const aPropagation = a.propagationTime == null ? Infinity : a.propagationTime as number;
|
||||
const bPropagation = b.propagationTime == null ? Infinity : b.propagationTime as number;
|
||||
@@ -11,7 +11,10 @@ export class Node {
|
||||
return aPropagation - bPropagation;
|
||||
}
|
||||
} else {
|
||||
return +b.pinned - +a.pinned;
|
||||
const bSort = (b.pinned ? -2 : 0) + +b.stale;
|
||||
const aSort = (a.pinned ? -2 : 0) + +a.stale;
|
||||
|
||||
return aSort - bSort;
|
||||
}
|
||||
|
||||
// Descending sort by block number
|
||||
@@ -26,6 +29,7 @@ export class Node {
|
||||
public readonly validator: Maybe<Types.Address>;
|
||||
public readonly networkId: Maybe<Types.NetworkId>;
|
||||
|
||||
public stale: boolean;
|
||||
public pinned: boolean;
|
||||
public peers: Types.PeerCount;
|
||||
public txs: Types.TransactionCount;
|
||||
@@ -110,6 +114,7 @@ export class Node {
|
||||
this.blockTime = blockTime;
|
||||
this.blockTimestamp = blockTimestamp;
|
||||
this.propagationTime = propagationTime;
|
||||
this.stale = false;
|
||||
|
||||
this.trigger();
|
||||
}
|
||||
@@ -143,6 +148,13 @@ export class Node {
|
||||
}
|
||||
}
|
||||
|
||||
public setStale(stale: boolean) {
|
||||
if (this.stale !== stale) {
|
||||
this.stale = stale;
|
||||
this.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
public subscribe(handler: (node: Node) => void) {
|
||||
this.subscriptions.add(handler);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user