Skip to content
module

neo3.network.convenience.nodemanager

P2P network node manager.

Classes
  • NodeManager Convenience class that helps establish and maintain a pool of active connections to NEO nodes.It will track the node quality and swap them out if considered bad as to always try and keep a healty pool.
class

neo3.network.convenience.nodemanager.NodeManager(*args, **kwds)

Bases
neo3.singleton._Singleton

Convenience class that helps establish and maintain a pool of active connections to NEO nodes.It will track the node quality and swap them out if considered bad as to always try and keep a healty pool.

Attention: This class is singleton.

Attributes
  • max_clients THe maximum number of clients to have connected at any time.
  • min_clients Nodemanager.MAX_NODE_ERROR_COUNT times then recovery logic will trigger.
  • nodes (list) A list of nodes that we're actively using to request data from.
  • queued_addresses (A list of host) port addresses that have a task pending to connect to, but are not fully processed.
Methods
  • get_least_failed_node(ri) (Optional) Return the node with the least fail count for the target item as specified in the RequestInfo.
  • get_node_addresses() (list) Return the addresses of connected nodes.
  • get_node_by_nodeid(nodeid) (Optional) Return the node instance matching the provided nodeid.
  • get_node_with_height(height) (Optional) Return a node that has a chain height of at least height.
  • increase_node_error_count(nodeid) Utility function to increase a node's error_response_count param by 1 and disconnect the node if it exceedsthe threshold set by NodeManager.MAX_NODE_ERROR_COUNT.
  • increase_node_timeout_count(nodeid) Utility function to increase a node's timeout_count param by 1 and disconnect the node if it exceeds thethreshold set by NodeManager.MAX_NODE_ERROR_COUNT.
  • shutdown() Gracefully shutdown the node manager.
  • start() Start the node manager services.

Return the node with the least fail count for the target item as specified in the RequestInfo.

Parameters
  • ri (RequestInfo) the info object indicating which header or block we filter on.
Returns (Optional)

None if there are no connected nodes that can provide the target information as specified in the RequestInfo.Node instance with the lowest failure count.

method

get_node_addresses() → list

Return the addresses of connected nodes.

method

get_node_by_nodeid(nodeid) → Optional

Return the node instance matching the provided nodeid.

method

get_node_with_height(height)

Return a node that has a chain height of at least height.

Parameters
  • height (int) the minimal block height a node must have.
Returns (Optional)

None if there are no nodes in the current pool that match the criteria.Node instance sorted by weight to avoid hitting the same node every time.

method

increase_node_error_count(nodeid)

Utility function to increase a node's error_response_count param by 1 and disconnect the node if it exceedsthe threshold set by NodeManager.MAX_NODE_ERROR_COUNT.

Parameters
  • nodeid (`NeoNode.nodeid`) the specific node to update.

Utility function to increase a node's timeout_count param by 1 and disconnect the node if it exceeds thethreshold set by NodeManager.MAX_NODE_ERROR_COUNT.

Parameters
  • nodeid (`NeoNode.nodeid`) the specific node to update.
method

shutdown()

Gracefully shutdown the node manager.

Disconnects all active nodes and stops service tasks.

Note

This depents on asyncio's Task canceling logic. It waits for all tasks to be cancelled and/or stopped before returning.

method

start()

Start the node manager services.

This does 2 things.

1. Connect to the seed list addresses provided in the configuration.
2. Try to maintain a pool of connected nodes according to the `min/max clients` configuration settings and
   monitor that they don't get stuck.