Skip to content

Conversation

@insumity
Copy link
Contributor

@insumity insumity commented Aug 12, 2025

Closes: #1164

We introduce a check so that a peer only sends values of at most cfg.sync.max_response_size.
The retrieval of the right amount of values is performed when handling the Effect::GetDecidedValues effect in the engine and not in sync in order to avoid sending a huge amount of values to sync and then have sync do the retrieval.

We manually tested these changes by running the tests from the value_sync.rs file and looking at the logs. With testing, we identified an issue where in case a syncing peer got a partial response (i.e., some of the values) back, it immediately re-requests the exact same range - because the partial values are not yet processed by the consensus engine - flooding the network. We fixed this issue in this PR.


PR author checklist

For all contributors

For external contributors

@insumity insumity self-assigned this Aug 12, 2025
@insumity insumity requested review from hvanz and kirdatatjana August 12, 2025 10:14
@insumity insumity marked this pull request as ready for review August 12, 2025 11:45
@hvanz hvanz requested a review from ancazamfir August 14, 2025 11:31
Comment on lines +290 to +291
const MAX_BYTES_PER_ADDRESS: usize = 32;
const MAX_BYTES_PER_SIGNATURE: usize = 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would declare these variables close to the declarations of the address and signature types. Also, each app will have its own definition of address and signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I fully follow your comment: Are you suggesting contacting the app to receive the sizes of addresses and signatures? If not, where exactly would you declare those constants?

Copy link
Contributor

@romac romac Aug 21, 2025

Choose a reason for hiding this comment

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

We could add them as static const to the Address and SigningScheme traits.

Copy link
Contributor

Choose a reason for hiding this comment

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

But that's pretty brittle as well, and could break things if the upper bound is not tight enough, eg. some application uses a signature scheme with variable-size signatures and defines Signature::MAX_SIZE to a large value just in case.

Copy link
Contributor

@romac romac Aug 21, 2025

Choose a reason for hiding this comment

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

The best way would probably be to encode the commit certificate (or even the full sync response) using the (Network)Codec and use the actual computed size. Not great for performance, we should probably either measure the impact upfront, or go with it and only optimize this if we see too big a perf impact. What do you think?

Copy link
Contributor Author

@insumity insumity Aug 21, 2025

Choose a reason for hiding this comment

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

The best way would probably be to encode the commit certificate (or even the full sync response) using the (Network)Codec and use the actual computed size.

I agree this is the right away to go about it. I'll rewrite the PR to take this into account.

if stored_peer_id != &peer_id {
warn!(
%request_id, peer.actual = %peer_id, peer.expected = %stored_peer_id,
"Received response from different peer than expected"
Copy link
Contributor

@romac romac Aug 21, 2025

Choose a reason for hiding this comment

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

We should probably use this PR to abort processing the response in the case where we got a response from another peer than the one we expected.

@romac romac requested a review from hvanz August 21, 2025 08:48
@romac
Copy link
Contributor

romac commented Aug 21, 2025

It would be good to add an integration test that exercises the new code path.

@circlefin circlefin deleted a comment from codecov bot Aug 21, 2025
@insumity
Copy link
Contributor Author

insumity commented Aug 21, 2025

Thanks you very much for the updates and your comments @romac.

It would be good to add an integration test that exercises the new code path.

I'll do that, and will also look into the network codec to get the actual size as you suggest. Just a note that I’ll probably only be able to look into this tomorrow afternoon and early next week (doubt I can finish it by tomorrow).

@romac
Copy link
Contributor

romac commented Aug 21, 2025

Just a note that I’ll probably only be able to look into this tomorrow afternoon and early next week (doubt I can finish it by tomorrow).

No problem, thank you!

@romac
Copy link
Contributor

romac commented Aug 28, 2025

Superseded by #1184

@romac romac closed this Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

work in progress Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(code): Limit the number of values in sync response to cfg.sync.max_response_size

5 participants