Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@gavofyork
Copy link
Member

@gavofyork gavofyork commented Jul 20, 2018

This changes the peer/SyncIo/NetworkContext API to make it more declarative and less instructive. There are no changes to logic (expect, I think in one instance), but semantics are tweaked to make it clear that it's not up the high-level (Substrate protocol) to manage the peer set first-hand. Rather the high-level can inform the libp2p about certain (non-)events that could only be knowable by the high-level API, such as invalid or non-existent responses, badly formatted queries or inconsistent data. The lower, libp2p, layer can then decide what course of action to take.

Rather than two separate functions (which is something of a pain), there is a single API for reporting high-level misbehaviour information on a peer: report_peer. There is always a reason given when calling reporting, and that reason implies a Severity, which semantically informs substrate-libp2p on what course of action to take in response (e.g. lowering a reputation score, simple disconnect, temporary ban or permanent ban).

I envisage that further information could be added to Severity down the line in order to express richer concepts of misbehaviour, but for now it's just three options (Bad, which bans the peer; Useless and Timeout, which currently both just disconnect the peer but don't attempt to prevent further connections).

One immediately useful point of this PR is to ensure that all explicit peer disconnections come with an information notice including a reason for why they have been disconnected.

@gavofyork gavofyork requested a review from tomaka July 20, 2018 17:12
@gavofyork gavofyork added the A0-please_review Pull request needs code review. label Jul 20, 2018
if let (&Some(ref client_version), &Some(ref remote_address)) = (&peer_info.client_version, &peer_info.remote_address) {
info!(target: "network", "Disconnected peer {} (version: {}, address: {}). {}", peer_id, client_version, remote_address, reason);
} else {
info!(target: "network", "Disconnected peer {}. {}", peer_id, reason);
Copy link
Contributor

Choose a reason for hiding this comment

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

info! is always printed on stdout even if logging is not enabled, right?
If so then that's probably too high.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the point. Disconnections are hugely problematic right now.

@tomaka tomaka added A5-grumble and removed A0-please_review Pull request needs code review. labels Jul 21, 2018
@gavofyork
Copy link
Member Author

Should be somewhat less verbose now.

@gavofyork gavofyork added A0-please_review Pull request needs code review. and removed A5-grumble labels Jul 21, 2018
}

/// Get the info on a peer, if there's an active connection.
pub fn peer_info(&self, who: PeerId) -> Option<PeerInfo> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should be merged with session_info, but I haven't looked at how the higher-level layers use session_info().

@tomaka tomaka added A6-mustntgrumble and removed A0-please_review Pull request needs code review. labels Jul 21, 2018
@gavofyork gavofyork merged commit 1cac554 into master Jul 21, 2018
@gavofyork gavofyork deleted the gav-refactor-net branch July 21, 2018 14:13
liuchengxu added a commit to chainx-org/substrate that referenced this pull request Aug 23, 2021
`id` of ChainX mainnet is _chainx_.
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
paritytech#394)

* WIP DispatchError generic param

* main crate now compiling with new E generic param for DispatchError

* Remove E param from RpcClient since it doesn't really need it

* Point to generated DispatchError in codegen so no need for additional param there

* More error hunting; cargo check --all-targets passes now

* Use our own RuntimeVersion struct (for now) to avoid error decoding into sp_version::RuntimeVersion

* cargo fmt

* fix docs and expose private documented thing that I think should be pub

* move error info to compile time so that we can make DispatchError a little nicer to work with

* cargo fmt

* clippy

* Rework error handling to remove <E> param in most cases

* fix Error doc ambiguity (hopefully)

* doc tweaks

* docs: remove dismbiguation thing that isn't needed now

* One more Error<E> that can be a BasicError

* rewrite pallet errors thing into normal loops to tidy

* tidy errors codegen a little

* tidy examples/custom_type_derives.rs a little

* cargo fmt

* silcnce clippy in example
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
* Add error information back into metadata to roll back removal in paritytech#394

* Go back to obtaining runtime error info

* re-do codegen too to check that it's all gravy

* Convert DispatchError module errors into a module variant to make them easier to work with

* Fix broken doc link
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants