Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]P2PNodesManager: Refine computation of Timeout and nodes choice/disconnection #12720

Closed
wants to merge 7 commits into from

Conversation

turbolay
Copy link
Collaborator

This currently includes only the refactoring, the actual computations are not made.

The idea is to keep track of node performances and total blocks downloaded by the nodes, so we can make an informed choice whether to keep it or to disconnect it, to protect privacy while downloading fast.

@kiminuo I'm really interested into what you think of the concept. If it looks good for you, I can go ahead and do some ground work on the actual algorithms. You can also do it if you want :)

var p2pSourceData = new P2pSourceData(statusCode, duration, node, connectedNodes);
await P2PNodesManager.NotifyDownloadFinishedAsync(p2pSourceData).ConfigureAwait(false);
return new P2pBlockResponse(Block: block, p2pSourceData);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed logging for now, we can log again in P2PNodesManager. I'd prefer not logging from here, maybe only in case of a success.

@@ -21,10 +24,23 @@ public P2PNodesManager(Network network, NodesGroup nodes, bool isTorEnabled)
private Network Network { get; }
private NodesGroup Nodes { get; }
private bool IsTorEnabled { get; }
private int NodeTimeouts { get; set; }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This information is still stored but at another place, NodeMetadata.Durations

public int? Score { get; set; } = null;
}

public async Task<Node?> GetBestNodeAsync(CancellationToken cancellationToken)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: This should provide the node with the lowest score or a node that doesn't yet have a score.

{
DisconnectNode(node, reason);
return;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case there is no information that we can save, it simply means that there were no nodes.

@kiminuo
Copy link
Collaborator

kiminuo commented Mar 26, 2024

I think that the ideas are mostly good but I would place the code elsewhere.

The idea behind BDS and removing SmartBlockProvider was to have clean API that allows to consume the API for various purposes. This PR would add some stuff that one might / might not want add unnecessary coupling.

The hieararchy as I see it:

  1. P2pBlockProvider has TryGetBlockWithSourceDataAsync method that allows to specify a P2P node (via P2pSourceRequest). That was done specifically so that one can ask a specific P2P node for data (blocks). This is one building block (being able to get data from one P2P node).
  2. BlockDownloadService allows you to specify a specific P2P node so that again you don't need to rely on some magic.
  3. WalletFilterProcessor has KeepTryingToGetBlockAsync that decides where to get blocks from and defines the "strategy". This is second building block which allows you to say "I want to get block from this source and this node".

And yes, the API is not 100 per cent correct but that should not be a reason to hard-wire stuff.

So to keep the system agile, I would recommend to implement your "behavior"/"strategy" on top of BlockDownloadService without touching lower layers (i.e. modify KeepTryingToGetBlockAsync or implement a new method similar to KeepTryingToGetBlockAsync). Then you can actually easily switch between the two implementations by a flag or something. I'm not sure if there are any roadblocks for doing that but that's the envisioned road forward (at least by me when working on those refactorings).

@turbolay
Copy link
Collaborator Author

turbolay commented May 2, 2024

This PR is still relevant, and should be finished, I'm closing it simply because I will not maintain it in a foreseeable future

@turbolay turbolay closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants