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

Add versioning to request response protocols #2362

Merged
merged 28 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ab26a0b
Add a module for versioning the request response protocols in the p2p…
acerone85 Oct 15, 2024
c9ba074
Record the latest compatible version for the request response protoco…
acerone85 Oct 15, 2024
b3d3219
P2PService uses peer manager information to determine the version of …
acerone85 Oct 15, 2024
8817d88
Remove argument from Protocol::V1 and minor improvements to tests
acerone85 Oct 16, 2024
2ad29e4
Merge branch 'master' into 1311-return-better-error-messages-from-p2p…
acerone85 Oct 16, 2024
aedda11
Merge branch 'master' into 1311-return-better-error-messages-from-p2p…
acerone85 Oct 16, 2024
1855350
Add changelog entry
acerone85 Oct 16, 2024
1fa98a4
Fix compilation error
acerone85 Oct 16, 2024
6cebf0e
Placate Clippy
acerone85 Oct 16, 2024
939939d
Version PostcardCodec
acerone85 Oct 16, 2024
e8c563c
Revert "Revert changes"
acerone85 Oct 17, 2024
f50a4d3
P2P Service: Add /fuel/req_res/0.0.2 that sends error codes in respon…
acerone85 Oct 17, 2024
77841f0
Prefer V2 over V1 when peers support both versions of the protocol
acerone85 Oct 21, 2024
7160034
Changelog
acerone85 Oct 21, 2024
b2b5b3c
PostcardProtocol default implementation is now derived
acerone85 Oct 21, 2024
93b4d06
Add tests to check serialization and deserialization of responses
acerone85 Oct 21, 2024
06e4177
Formatting
acerone85 Oct 21, 2024
0729a87
Merge branch 'master' into 1311-return-better-error-messages-from-p2p…
acerone85 Oct 22, 2024
273bb34
Remove TODO comment around ResponseMessageErrorCode definition
acerone85 Oct 22, 2024
0865da6
Rename LegacyResponseMessage into V1ResponseMessage
acerone85 Oct 22, 2024
52290e7
Rename ResponseMessage into V2ResponseMessage
acerone85 Oct 22, 2024
50f92ae
Rename Request/Response protocol version constant variables
acerone85 Oct 22, 2024
b710d8d
Refine TODO to remove NetworkCodec trait and reference github issue
acerone85 Oct 22, 2024
8534f84
Refine todos for error codes and add github issue when missing
acerone85 Oct 22, 2024
cec899c
Add Given, When, Then sections to tests
acerone85 Oct 22, 2024
319ec8a
Remove trailing space in TODO comment
acerone85 Oct 22, 2024
4280781
Use matches! macro in tests
acerone85 Oct 22, 2024
6276af5
Give more meaningful names to tests
acerone85 Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added
- [2321](https://github.com/FuelLabs/fuel-core/pull/2321): New metrics for the txpool: "The size of transactions in the txpool" (`txpool_tx_size`), "The time spent by a transaction in the txpool in seconds" (`txpool_tx_time_in_txpool_seconds`), The number of transactions in the txpool (`txpool_number_of_transactions`), "The number of transactions pending verification before entering the txpool" (`txpool_number_of_transactions_pending_verification`), "The number of executable transactions in the txpool" (`txpool_number_of_executable_transactions`), "The time it took to select transactions for inclusion in a block in nanoseconds" (`txpool_select_transaction_time_nanoseconds`), The time it took to insert a transaction in the txpool in milliseconds (`txpool_insert_transaction_time_milliseconds`).
- [2362](https://github.com/FuelLabs/fuel-core/pull/2362): Added a new request_response protocol version `/fuel/req_res/0.0.2`. In comparison with `/fuel/req/0.0.1`, which returns an empty response when a request cannot be fulfilled, this version returns more meaningful error codes. Nodes still support the version `0.0.1` of the protocol to guarantee backward compatibility with fuel-core nodes. Empty responses received from nodes using the old protocol `/fuel/req/0.0.1` are automatically converted into an error `ProtocolV1EmptyResponse` with error code 0, which is also the only error code implemented. More specific error codes will be added in the future.

## [Version 0.40.0]

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/fuel-core/src/p2p_test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use fuel_core_p2p::{
p2p_service::FuelP2PEvent,
request_response::messages::{
RequestMessage,
ResponseMessage,
V2ResponseMessage,
},
service::to_message_acceptance,
};
Expand Down Expand Up @@ -178,7 +178,7 @@ impl Bootstrap {
if request_message == RequestMessage::TxPoolAllTransactionsIds {
let _ = bootstrap.send_response_msg(
request_id,
ResponseMessage::TxPoolAllTransactionsIds(Some(vec![])),
V2ResponseMessage::TxPoolAllTransactionsIds(Ok(vec![])),
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/services/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ rayon = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_with = { workspace = true }
sha2 = "0.10"
strum = { workspace = true }
strum_macros = { workspace = true }
thiserror = "1.0.47"
tokio = { workspace = true, features = ["sync"] }
tracing = { workspace = true }
Expand Down
15 changes: 8 additions & 7 deletions crates/services/p2p/src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
peer_report,
request_response::messages::{
RequestMessage,
ResponseMessage,
V2ResponseMessage,
},
};
use fuel_core_types::fuel_types::BlockHeight;
Expand Down Expand Up @@ -112,15 +112,16 @@ impl FuelBehaviour {
BlockHeight::default(),
);

let req_res_protocol =
core::iter::once((codec.get_req_res_protocol(), ProtocolSupport::Full));
let req_res_protocol = codec
.get_req_res_protocols()
.map(|protocol| (protocol, ProtocolSupport::Full));

let req_res_config = request_response::Config::default()
.with_request_timeout(p2p_config.set_request_timeout)
.with_max_concurrent_streams(p2p_config.max_concurrent_streams);

let request_response = request_response::Behaviour::with_codec(
codec,
codec.clone(),
req_res_protocol,
req_res_config,
);
Expand Down Expand Up @@ -165,9 +166,9 @@ impl FuelBehaviour {

pub fn send_response_msg(
&mut self,
channel: ResponseChannel<ResponseMessage>,
message: ResponseMessage,
) -> Result<(), ResponseMessage> {
channel: ResponseChannel<V2ResponseMessage>,
message: V2ResponseMessage,
) -> Result<(), V2ResponseMessage> {
self.request_response.send_response(channel, message)
}

Expand Down
10 changes: 7 additions & 3 deletions crates/services/p2p/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
},
request_response::messages::{
RequestMessage,
ResponseMessage,
V2ResponseMessage,
},
};
use libp2p::request_response;
Expand All @@ -28,18 +28,22 @@ pub trait GossipsubCodec {
) -> Result<Self::ResponseMessage, io::Error>;
}

// TODO: https://github.com/FuelLabs/fuel-core/issues/2368
// Remove this trait
/// Main Codec trait
/// Needs to be implemented and provided to FuelBehaviour
pub trait NetworkCodec:
GossipsubCodec<
RequestMessage = GossipsubBroadcastRequest,
ResponseMessage = GossipsubMessage,
> + request_response::Codec<Request = RequestMessage, Response = ResponseMessage>
> + request_response::Codec<Request = RequestMessage, Response = V2ResponseMessage>
+ Clone
+ Send
+ 'static
{
/// Returns RequestResponse's Protocol
/// Needed for initialization of RequestResponse Behaviour
fn get_req_res_protocol(&self) -> <Self as request_response::Codec>::Protocol;
fn get_req_res_protocols(
&self,
) -> impl Iterator<Item = <Self as request_response::Codec>::Protocol>;
}
Loading
Loading