Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add versioning to request response protocols (#2362)
## Linked Issues/PRs <!-- List of related issues/PRs --> Related issue: #1311 ## Context The P2P service uses the [request_response](https://docs.rs/libp2p-request-response/latest/libp2p_request_response/) protocol to let peer request information (e.g. block headers, or transactions in the tx pool) from other peers. Currently, the P2P service provides a protocol `/fuel/req_res/0.0.1`, which defines responses to have an `Option` value. When a request from a peer is unsuccessful, we send a `None` value as a response, wrapped around the relevant response type. In practice, we want to be able to send more meaningful information in responses when requests are unsuccessful, in the form of error codes. This requires implementing a new version of the protocol `/fuel/req_res/0.0.2` where Response messages are changed to contain error codes. Because we want to be backward compatible with peers that will only use the version `0.0.1` of the protocol, we must account for requests sent by, and responses sent to, those peers. ## Description - Rename the `ResponseMessage` type in the P2P service to `LegacyResponseMessage` - Add a `ResponseMessageErrorCode` enum, which for now only contains a `LegacyNodeEmptyResponse` enum. - Implement a new `ResponseMessage` type that returns a `Result<_, ResponseMessageErrorCode>` wrapped around enum variants - Change P2P service to use the neq `ResponseMessage` type. Responses previously returned as `None` are now returned as `Err<LegacyNodeEmptyResponse>`. - Change the `PostcardCodec` to serialize and deserialize according to two different versions of the `/fuel/req_res` protocol: `/fuel/req_res/0.0.1` and `/fuel/req_res/0.0.2`. - Serialization and deserialization of responses using `/fuel/req_res/0.0.1` are performed by first converting a `ResponseMessage` into a `LegacyResponseMessage` and vicecersa, thus preserving backward-compatibility - Change the req_res behaviour used by the `P2P` service to use both version of the req_res protocol. ### TODO (here or in different PRs) - [ ] Investigate how protocols are exchanged during peer handshakes. We don't want two nodes that both understand `/fuel/req_res/0.0.2` to communicate using `/fuel/req_res/0.0.1`. - [ ] Add more meaningful error codes. ## Checklist - [ ] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [ ] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else?
- Loading branch information