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

Bootstrap/use read loop #3885

Merged
merged 17 commits into from
May 4, 2023
Merged

Bootstrap/use read loop #3885

merged 17 commits into from
May 4, 2023

Conversation

Ben-PH
Copy link
Contributor

@Ben-PH Ben-PH commented Apr 28, 2023

  • document all added functions
  • try in sandbox /simulation/labnet
  • unit tests on the added/changed features
    • make tests compile
    • make tests pass
  • add logs allowing easy debugging in case the changes caused problems
  • if the API has changed, update the API specification

Copy link
Contributor Author

@Ben-PH Ben-PH left a comment

Choose a reason for hiding this comment

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

In reference to #3842 (comment)

also sends message from server in a single message, making better use of the channel. This was done in this PR as the inefficiency was revealed while refining the peek helper method.

@Ben-PH Ben-PH self-assigned this Apr 28, 2023
@Ben-PH Ben-PH added the bootstrap Issues related to the bootstrap label Apr 28, 2023
@Ben-PH Ben-PH marked this pull request as ready for review April 28, 2023 17:38
@Ben-PH Ben-PH mentioned this pull request Apr 28, 2023
3 tasks
@Ben-PH Ben-PH requested a review from modship April 28, 2023 17:43
@Ben-PH Ben-PH linked an issue Apr 28, 2023 that may be closed by this pull request
25 tasks
@Ben-PH Ben-PH mentioned this pull request Apr 28, 2023
25 tasks
@Ben-PH Ben-PH requested a review from modship May 3, 2023 11:49
pub(crate) use client::*;
pub(crate) use server::*;

trait BindingReadExact: io::Read {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for a side-by-side view of this diff, you can exclude the fmt and module re-arrangement commit.

Comment on lines +78 to +86
// read the known-len component of the message
let known_len = SIGNATURE_SIZE_BYTES + self.size_field_len;
let mut known_len_buff = vec![0u8; known_len];
// TODO: handle a partial read
self.read_exact_timeout(&mut known_len_buff, deadline)
.map_err(|(err, _consumed)| err)?;

// construct the signature
let sig_array = known_len_buff.as_slice()[0..SIGNATURE_SIZE_BYTES]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

see conversation here: #3842 for motivation behind reverting the use of peek. Original intent was to make the very notion of needing to handle a partial read, as far as the stream state is concerned, as obsolete. If this approach could be valuable, using it now is very premature

Comment on lines -200 to 214
// send signature
self.duplex.set_write_timeout(duration)?;
self.duplex.write_all(&sig.to_bytes())?;
// construct msg length, and convert to bytes
let msg_len_bytes = msg_len.to_be_bytes_min(self.max_bootstrap_message_size)?;

// send message length
{
let msg_len_bytes = msg_len.to_be_bytes_min(self.max_bootstrap_message_size)?;
self.duplex.write_all(&msg_len_bytes)?;
}
// organize the bytes into a sendable array
let stream_data = [sig.to_bytes().as_slice(), &msg_len_bytes, &msg_bytes].concat();

// send message
self.duplex.write_all(&msg_bytes)?;
// send the data
self.duplex.set_write_timeout(duration)?;
self.duplex.write_all(&stream_data)?;

// save prev sig
// update prev sig
self.prev_message = Some(Hash::compute_from(&sig.to_bytes()));
Copy link
Contributor Author

@Ben-PH Ben-PH May 3, 2023

Choose a reason for hiding this comment

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

Should make for more efficient use of the stream, at the expense of slight latency increase, as the first byte gets sent a touch later.

However, by collecting all data into a single buffer to be sent, it simplifies the code, and makes testing easier (test_bootstrap_server was failing on timeout, and this change fixed that).

@Ben-PH
Copy link
Contributor Author

Ben-PH commented May 3, 2023

Request re-review as many changes were made in response to #3885

@Ben-PH Ben-PH requested a review from damip May 3, 2023 12:01
@AurelienFT AurelienFT changed the base branch from testnet_22 to testnet_23 May 4, 2023 10:29
@Ben-PH Ben-PH merged commit 1e65518 into testnet_23 May 4, 2023
@AurelienFT AurelienFT deleted the bootstrap/use-read-loop branch May 29, 2023 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bootstrap Issues related to the bootstrap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bootstrap improvements tracking issue
2 participants