Skip to content

Add node priority

Luke Champine requested to merge gateway-persist into gateway-proto

Picking up where #1648 left off, node is now a proper type. It contains a Priority bool to indicate that the node should be prioritized when choosing new peers. I wasn't satisfied with calling it Outbound or Inbound, but I don't think Priority is an amazing name either. Maybe we can come up with something better.

@glendc, I added you as the author of the first commit here to note your contributions in #1648. Hope that's alright. The main departure from #1648 is that addNode still takes just a NetAddress, and g.prioritizeNode was added to set the priority of a node. This seemed reasonable because we may add a node to the node list long before we actually connect to it (and thus want to prioritize it for future connections).

The current priority algorithm is to pick a random node three times, returning the node if it is prioritized, and otherwise falling back to a final random node. "Three" is a magic number here and should probably be proportional to the size of the list, e.g. len(g.nodes)/3. An alternative would be to select randomly from all the prioritized nodes first, and then fallback to the non-prioritized nodes -- but I felt this could cause issues if there were only 1 or 2 prioritized nodes and neither of them were reachable.

This could use more testing.

Merge request reports