Skip to content

Commit

Permalink
Fix reset timer operations announcement & remove limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Oct 6, 2022
1 parent e0aa2f3 commit d7c6ed4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion massa-network-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-speed-limit = { git = "https://github.com/adrien-zinger/async-speed-limit", rev = "36d79e0", features = ["default", "tokio"] }
enum-map = { version = "2.4", features = ["serde"] }
futures = "0.3"
itertools = "0.10"
Expand Down
13 changes: 6 additions & 7 deletions massa-network-worker/src/binders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crate::messages::{MessageDeserializer, MessageSerializer};

use super::messages::Message;
use async_speed_limit::{clock::StandardClock, Limiter, Resource};
use massa_models::{
error::ModelsError,
serialization::{DeserializeMinBEInt, SerializeMinBEInt},
Expand All @@ -18,7 +17,7 @@ use tracing::warn;

/// Used to serialize and send data.
pub struct WriteBinder {
write_half: Resource<WriteHalf, StandardClock>,
write_half: WriteHalf,
message_index: u64,
max_message_size: u32,
}
Expand All @@ -29,9 +28,9 @@ impl WriteBinder {
/// # Argument
/// * `write_half`: writer half.
/// * `limit`: limit max bytes per second write
pub fn new(write_half: WriteHalf, limit: f64, max_message_size: u32) -> Self {
pub fn new(write_half: WriteHalf, _limit: f64, max_message_size: u32) -> Self {
WriteBinder {
write_half: <Limiter>::new(limit).limit(write_half),
write_half,
message_index: 0,
max_message_size,
}
Expand Down Expand Up @@ -65,7 +64,7 @@ impl WriteBinder {

/// Used to receive and deserialize data.
pub struct ReadBinder {
read_half: Resource<ReadHalf, StandardClock>,
read_half: ReadHalf,
message_index: u64,
buf: Vec<u8>,
cursor: usize,
Expand All @@ -82,12 +81,12 @@ impl ReadBinder {
/// * `limit`: limit max bytes per second read.
pub fn new(
read_half: ReadHalf,
limit: f64,
_limit: f64,
max_message_size: u32,
message_deserializer: MessageDeserializer,
) -> Self {
ReadBinder {
read_half: <Limiter>::new(limit).limit(read_half),
read_half,
message_index: 0,
buf: Vec::new(),
cursor: 0,
Expand Down
7 changes: 7 additions & 0 deletions massa-protocol-worker/src/protocol_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ impl ProtocolWorker {
async fn announce_ops(&mut self, timer: &mut Pin<&mut Sleep>) {
// Quit if empty to avoid iterating on nodes
if self.operations_to_announce.is_empty() {
// Reset timer.
let now = Instant::now();
let next_tick = now
.checked_add(self.config.operation_announcement_interval.into())
// .ok_or(TimeError::TimeOverflowError)?;
.unwrap();
timer.set(sleep_until(next_tick));
return;
}
let operation_ids = mem::take(&mut self.operations_to_announce);
Expand Down

0 comments on commit d7c6ed4

Please sign in to comment.