Skip to content

Commit

Permalink
fix: add sleep to allow for header saturation in era1 gossip (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita authored Apr 10, 2024
1 parent 79bcbf8 commit c07be65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions portal-bridge/src/bridge/era1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ use surf::{Client, Config};
use tokio::{
sync::{OwnedSemaphorePermit, Semaphore},
task::JoinHandle,
time::timeout,
time::{sleep, timeout, Duration},
};
use tracing::{debug, error, info, warn};
use trin_metrics::bridge::BridgeMetricsReporter;

use crate::{
api::execution::construct_proof,
bridge::{history::SERVE_BLOCK_TIMEOUT, utils::lookup_epoch_acc},
bridge::{
history::{HEADER_SATURATION_DELAY, SERVE_BLOCK_TIMEOUT},
utils::lookup_epoch_acc,
},
gossip::gossip_history_content,
stats::{HistoryBlockStats, StatsReporter},
types::{
Expand Down Expand Up @@ -309,10 +312,14 @@ impl Era1Bridge {
// since the header might fail validation and we don't want to serve the rest of the
// block. A future improvement would be to have a more fine-grained error
// handling and only cut off gossip if header fails validation
metrics.stop_process_timer(timer);
return Ok(());
}
}
metrics.stop_process_timer(timer);
// Sleep for 10 seconds to allow headers to saturate network,
// since they must be available for body / receipt validation.
sleep(Duration::from_secs(HEADER_SATURATION_DELAY)).await;
let timer = metrics.start_process_timer("construct_and_gossip_block_body");
match Self::construct_and_gossip_block_body(
portal_clients.clone(),
Expand Down
2 changes: 1 addition & 1 deletion portal-bridge/src/bridge/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use trin_validation::{
};

// todo: calculate / test optimal saturation delay
const HEADER_SATURATION_DELAY: u64 = 10; // seconds
pub const HEADER_SATURATION_DELAY: u64 = 10; // seconds
const LATEST_BLOCK_POLL_RATE: u64 = 5; // seconds
pub const EPOCH_SIZE: u64 = EPOCH_SIZE_USIZE as u64;
pub const SERVE_BLOCK_TIMEOUT: Duration = Duration::from_secs(120);
Expand Down

0 comments on commit c07be65

Please sign in to comment.