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

fix(consensus): remove the Clone trait bound from StreamData #2746

Open
wants to merge 1 commit into
base: guyn/streams/self_argument_to_inbound_send
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion crates/sequencing/papyrus_consensus/src/stream_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CHANNEL_BUFFER_LENGTH: usize = 100;
// Drop the struct when:
// (1) receiver on the other end is dropped,
// (2) fin message is received and all messages are sent.
#[derive(Debug, Clone)]
#[derive(Debug)]
struct StreamData<
T: Clone + Into<Vec<u8>> + TryFrom<Vec<u8>, Error = ProtobufConversionError> + 'static,
> {
Expand Down
48 changes: 12 additions & 36 deletions crates/sequencing/papyrus_consensus/src/stream_handler_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ mod tests {
);
let range: Vec<u64> = (1..6).collect();
let keys: Vec<u64> = stream_handler.inbound_stream_data[&(peer_id, stream_id)]
.clone()
.message_buffer
.into_keys()
.keys()
.copied()
.collect();
assert!(do_vecs_match_unordered(&keys, &range));

Expand Down Expand Up @@ -255,20 +255,14 @@ mod tests {
let mut stream_handler = join_handle.await.expect("Task should succeed");

let values = [(peer_id.clone(), 1), (peer_id.clone(), 10), (peer_id.clone(), 127)];
assert!(
stream_handler
.inbound_stream_data
.clone()
.into_keys()
.all(|item| values.contains(&item))
);
assert!(stream_handler.inbound_stream_data.keys().all(|item| values.contains(item)));

// We have all message from 1 to 9 buffered.
assert!(do_vecs_match_unordered(
&stream_handler.inbound_stream_data[&(peer_id.clone(), stream_id1)]
.message_buffer
.clone()
.into_keys()
.keys()
.copied()
.collect::<Vec<_>>(),
&(1..10).collect::<Vec<_>>()
));
Expand All @@ -277,8 +271,8 @@ mod tests {
assert!(do_vecs_match_unordered(
&stream_handler.inbound_stream_data[&(peer_id.clone(), stream_id2)]
.message_buffer
.clone()
.into_keys()
.keys()
.copied()
.collect::<Vec<_>>(),
&(1..6).collect::<Vec<_>>()
));
Expand All @@ -287,8 +281,8 @@ mod tests {
assert!(do_vecs_match_unordered(
&stream_handler.inbound_stream_data[&(peer_id.clone(), stream_id3)]
.message_buffer
.clone()
.into_keys()
.keys()
.copied()
.collect::<Vec<_>>(),
&(1..10).collect::<Vec<_>>()
));
Expand Down Expand Up @@ -329,13 +323,7 @@ mod tests {

// stream_id1 should be gone
let values = [(peer_id.clone(), 1), (peer_id.clone(), 10)];
assert!(
stream_handler
.inbound_stream_data
.clone()
.into_keys()
.all(|item| values.contains(&item))
);
assert!(stream_handler.inbound_stream_data.keys().all(|item| values.contains(item)));

// Send the last message on stream_id2:
send(&mut network_sender, &inbound_metadata, make_test_message(stream_id2, 0, false)).await;
Expand All @@ -356,13 +344,7 @@ mod tests {

// Stream_id2 should also be gone.
let values = [(peer_id.clone(), 1)];
assert!(
stream_handler
.inbound_stream_data
.clone()
.into_keys()
.all(|item| values.contains(&item))
);
assert!(stream_handler.inbound_stream_data.keys().all(|item| values.contains(item)));

// Send the last message on stream_id3:
send(&mut network_sender, &inbound_metadata, make_test_message(stream_id3, 0, false)).await;
Expand All @@ -381,13 +363,7 @@ mod tests {

// Stream_id3 should still be there, because we didn't send a fin.
let values = [(peer_id.clone(), 1)];
assert!(
stream_handler
.inbound_stream_data
.clone()
.into_keys()
.all(|item| values.contains(&item))
);
assert!(stream_handler.inbound_stream_data.keys().all(|item| values.contains(item)));

// But the buffer should be empty, as we've successfully drained it all.
assert!(
Expand Down
Loading