feat: Instead of delisting, push stale nodes to bottom (#161)

This commit is contained in:
Maciej Hirsz
2019-07-02 14:52:06 +02:00
committed by GitHub
parent c817a16d31
commit 983919fd87
8 changed files with 70 additions and 32 deletions
+3 -12
View File
@@ -29,13 +29,12 @@ export default class Chain {
}
public get nodeCount(): Types.NodeCount {
return this.count as Types.NodeCount;
return this.nodes.size as Types.NodeCount;
}
public addNode(node: Node) {
console.log(`[${this.label}] new node: ${node.name}`);
this.count += 1;
this.nodes.add(node);
this.feeds.broadcast(Feed.addedNode(node));
@@ -83,12 +82,7 @@ export default class Chain {
node.events.removeAllListeners();
this.nodes.delete(node);
if (!node.isStale) {
this.count -= 1;
this.feeds.broadcast(Feed.removedNode(node));
}
this.feeds.broadcast(Feed.removedNode(node));
this.events.emit('disconnect', this.nodeCount);
if (this.height === node.best.number) {
@@ -97,8 +91,7 @@ export default class Chain {
}
public staleNode(node: Node) {
this.count -= 1;
this.feeds.broadcast(Feed.removedNode(node));
this.feeds.broadcast(Feed.staleNode(node));
if (this.height === node.best.number) {
this.downgradeBlock();
@@ -174,8 +167,6 @@ export default class Chain {
if (node.isStale) {
node.isStale = false;
this.feeds.broadcast(Feed.addedNode(node));
this.count += 1;
} else {
this.feeds.broadcast(Feed.imported(node));
}
+7
View File
@@ -65,6 +65,13 @@ export default class Feed {
};
}
public static staleNode(node: Node): FeedMessage.Message {
return {
action: Actions.StaleNode,
payload: node.id
}
}
public static locatedNode(node: Node, location: Location): FeedMessage.Message {
return {
action: Actions.LocatedNode,