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

P2p protocol versioning support #1182

Merged
merged 6 commits into from
Sep 15, 2023
Merged

P2p protocol versioning support #1182

merged 6 commits into from
Sep 15, 2023

Conversation

ImplOfAnImpl
Copy link
Contributor

@ImplOfAnImpl ImplOfAnImpl commented Sep 14, 2023

This PR supersedes https://git.mintlayer.org/mintlayer/mintlayer-core/-/merge_requests/1129

Original description:

  1. NetworkProtocolVersion was made a newtype and renamed to ProtocolVersion; SupportedProtocolVersion was added on top of that, which is an enum.

  2. peer_v2.rs is currently a copy of peer_v1.rs;

    Some common code was moved to the peer_common module:

    • KnownTransactions encapsulate the rolling filter of known transactions;
    • peer_common::handle_result is identical to the old Peer::handle_result;
  3. All sync manager tests are run for all existing versions of the protocol. To simplify this, I added a helper function for_each_protocol_version. The idea is that the tests don't need to know what versions are currently available and still be run for all of them. Unfortunately, this doesn't work for tests that expect a panic, so for them I had to list the existing versions explicitly via rstest's #[case] attribute.

  4. There also some artefacts of earlier experiments:

    • The CategorizedMessage enum and categorize method of backend's Message, which simplify the conversion of Message to the front-end message types.
    • The cmd_to_peer_man_msg test function (which uses CategorizedMessage under the hood) is used in tests in order to avoid directly matching against Message (which I was actively changing at the moment).
    • The assert_matches/assert_matches_return_val macros (used by and in conjunction with cmd_to_peer_man_msg)

    All those changes are not really needed by the current implementation, but they are kind of useful, so I kept them.

P.S. There was no need to disable V2 for old peers, because they don't really mind (they only check that the received protocol version is bigger than the minimum).

KnownTransactions and handle_result were moved out of peer.rs to reduce code duplication between peers;
peer.rs was duplicated into peer_v2.rs, BlockSyncManager chooses one based on the protocol version;
NetworkProtocolVersion is now a newtype; SupportedProtocolVersion was introduced;
NETWORK_PROTOCOL_CURRENT was renamed to CURRENT_PROTOCOL_VERSION and NetworkProtocolVersion to ProtocolVersion;
CategorizedMessage and some test utilities were added (this is an artifact of previous experiments);
… now use a separate TEST_PROTOCOL_VERSION constant; for_each_protocol_version was moved to public test utils.
@ImplOfAnImpl ImplOfAnImpl changed the title P2p protocol v2 P2p protocol versioning support Sep 14, 2023
ImplOfAnImpl and others added 3 commits September 14, 2023 16:25
…version

P2p: handling bad handshake and version
…e the CURRENT_PROTOCOL_VERSION constant from the rest of the code; the constant was renamed to PREFERRED_PROTOCOL_VERSION
@TheQuantumPhysicist TheQuantumPhysicist merged commit 15be5eb into master Sep 15, 2023
23 checks passed
@TheQuantumPhysicist TheQuantumPhysicist deleted the p2p_protocol_v2 branch September 15, 2023 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants