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

Introduce Request Id for binary port communication #315

Merged
merged 20 commits into from
Jun 18, 2024

Conversation

rafal-ch
Copy link

@rafal-ch rafal-ch commented May 27, 2024

This PR introduces the concept of "request id" to the binary port. This is used to dodge an edge case where it may happen that a response which has not been consumed is incorrectly served as a request to the next request.

The corresponding PR in casper-node is here.

Fixes: #312

@rafal-ch rafal-ch changed the title Binary port fixes Introduce Request Id for binary port communication May 27, 2024
@rafal-ch rafal-ch marked this pull request as ready for review May 27, 2024 14:49
@rafal-ch rafal-ch requested review from jacek-casper, zajko and alsrdn May 27, 2024 14:49
Copy link

@jacek-casper jacek-casper left a comment

Choose a reason for hiding this comment

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

lgtm

Cargo.toml Outdated
@@ -31,3 +31,7 @@ toml = "0.5.8"
tracing = { version = "0", default-features = false }
tracing-subscriber = "0"
serde = { version = "1", default-features = false }

[patch.'https://github.com/casper-network/casper-node.git']
casper-binary-port = { path = "../casper-node/binary_port" }
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work in CI, or in any workspace that doesn't have ../casper-node, right?
Wouldn't it be more universal if you pushed your casper-node changes to a branch and refer casper-binary-port to a github branch?

Copy link
Author

Choose a reason for hiding this comment

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

Updated in c1af7cf

@@ -116,6 +118,14 @@ fn resolve_address(address: &str) -> anyhow::Result<SocketAddr> {
.ok_or_else(|| anyhow::anyhow!("failed to resolve address"))
}

fn encode_request(req: &BinaryRequest, id: u16) -> Result<Vec<u8>, bytesrepr::Error> {
let header = BinaryRequestHeader::new(SUPPORTED_PROTOCOL_VERSION, req.tag(), id);
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is a header that has both SUPPORTED_PROTOCOL_VERSION and the request id? Shouldn't it be a wrapper over a vector of headers? A tuple (u8, bytes[]) where the u8 would be a header tag? That would give us flexibility of adding more headers in the future. If we don't do it like that - we're painting ourselves into a corner, aren't we?

Copy link
Author

Choose a reason for hiding this comment

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

I dodged the issue by introducing the "header version" field which is a single u16. Upon handling the request, the binary port component will reject the requests that come with different header version. When we change the header again post 2.0 release, users will need to also upgrade their sidecar installations.

I decided not to support multiple headers because when we're adding a field it usually means that we actually need it for further processing. For example, if we added request id, but we get request w/o request id (from legacy sidecar) we can't properly handle it anyway.

casperlabs-bors-ng bot added a commit to casper-network/casper-node that referenced this pull request Jun 18, 2024
4726: Introduce Request Id for binary port communication r=rafal-ch a=rafal-ch

Heads-up: There are several functional changes in this single PR just because each breaking change to the sidecar requires some coordinated merging effort between node and sidecar. Hence, it's more convenient to deliver such changes in one go.

This PR introduces:
1. the concept of "request id" to the binary port. This is used to dodge an edge case where it may happen that a response which has not been consumed is incorrectly served as a request to the next request. The corresponding PR in casper-sidecar is [here](casper-network/casper-sidecar#315).
2. Binary request header version - this will prevent binary port from trying to parse binary message headers of incompatible types
3. Promote binary port error code from `u8` to `u16`, because we already have nearly 60 error codes
4. Additional unit tests verifying whether the binary message codec can properly handle large quantities of messages.
5. Additional tests to see if protocol version check is respected

Fixes: casper-network/casper-sidecar#312

Co-authored-by: Rafał Chabowski <[email protected]>
casperlabs-bors-ng bot added a commit to casper-network/casper-node that referenced this pull request Jun 18, 2024
4726: Introduce Request Id for binary port communication r=rafal-ch a=rafal-ch

Heads-up: There are several functional changes in this single PR just because each breaking change to the sidecar requires some coordinated merging effort between node and sidecar. Hence, it's more convenient to deliver such changes in one go.

This PR introduces:
1. the concept of "request id" to the binary port. This is used to dodge an edge case where it may happen that a response which has not been consumed is incorrectly served as a request to the next request. The corresponding PR in casper-sidecar is [here](casper-network/casper-sidecar#315).
2. Binary request header version - this will prevent binary port from trying to parse binary message headers of incompatible types
3. Promote binary port error code from `u8` to `u16`, because we already have nearly 60 error codes
4. Additional unit tests verifying whether the binary message codec can properly handle large quantities of messages.
5. Additional tests to see if protocol version check is respected

Fixes: casper-network/casper-sidecar#312

Co-authored-by: Rafał Chabowski <[email protected]>
casperlabs-bors-ng bot added a commit to casper-network/casper-node that referenced this pull request Jun 18, 2024
4726: Introduce Request Id for binary port communication r=rafal-ch a=rafal-ch

Heads-up: There are several functional changes in this single PR just because each breaking change to the sidecar requires some coordinated merging effort between node and sidecar. Hence, it's more convenient to deliver such changes in one go.

This PR introduces:
1. the concept of "request id" to the binary port. This is used to dodge an edge case where it may happen that a response which has not been consumed is incorrectly served as a request to the next request. The corresponding PR in casper-sidecar is [here](casper-network/casper-sidecar#315).
2. Binary request header version - this will prevent binary port from trying to parse binary message headers of incompatible types
3. Promote binary port error code from `u8` to `u16`, because we already have nearly 60 error codes
4. Additional unit tests verifying whether the binary message codec can properly handle large quantities of messages.
5. Additional tests to see if protocol version check is respected

Fixes: casper-network/casper-sidecar#312

Co-authored-by: Rafał Chabowski <[email protected]>
casperlabs-bors-ng bot added a commit to casper-network/casper-node that referenced this pull request Jun 18, 2024
4726: Introduce Request Id for binary port communication r=rafal-ch a=rafal-ch

Heads-up: There are several functional changes in this single PR just because each breaking change to the sidecar requires some coordinated merging effort between node and sidecar. Hence, it's more convenient to deliver such changes in one go.

This PR introduces:
1. the concept of "request id" to the binary port. This is used to dodge an edge case where it may happen that a response which has not been consumed is incorrectly served as a request to the next request. The corresponding PR in casper-sidecar is [here](casper-network/casper-sidecar#315).
2. Binary request header version - this will prevent binary port from trying to parse binary message headers of incompatible types
3. Promote binary port error code from `u8` to `u16`, because we already have nearly 60 error codes
4. Additional unit tests verifying whether the binary message codec can properly handle large quantities of messages.
5. Additional tests to see if protocol version check is respected

Fixes: casper-network/casper-sidecar#312

Co-authored-by: Rafał Chabowski <[email protected]>
@rafal-ch rafal-ch merged commit e25d297 into casper-network:feat-2.0 Jun 18, 2024
2 checks passed
@rafal-ch rafal-ch deleted the binary_port_fixes branch June 18, 2024 16:10
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.

4 participants