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

Fixes the relayer hot loop in the case of error #1281

Merged
merged 3 commits into from
Aug 9, 2023
Merged
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/services/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct Config {

#[allow(missing_docs)]
impl Config {
pub const DEFAULT_LOG_PAGE_SIZE: u64 = 5;
pub const DEFAULT_LOG_PAGE_SIZE: u64 = 10_000;
Copy link
Member

Choose a reason for hiding this comment

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

This is a pretty large increase, couldn't this worsen our rate limiting issues?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should decrease the number of requests=) I used 100_000 locally during synchronization with the network and it was only several requests
image

pub const DEFAULT_DA_FINALIZATION: u64 = 100;
pub const DEFAULT_DA_DEPLOY_HEIGHT: u64 = 0;
pub const DEFAULT_SYNC_MINIMUM_DURATION: Duration = Duration::from_secs(5);
Expand Down
4 changes: 3 additions & 1 deletion crates/services/relayer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ where

let result = run::run(self).await;

if self.shutdown.borrow_and_update().started() && self.synced.borrow().is_some() {
if self.shutdown.borrow_and_update().started()
&& (result.is_err() | self.synced.borrow().is_some())
{
// Sleep the loop so the da node is not spammed.
tokio::time::sleep(
self.config
Expand Down
4 changes: 3 additions & 1 deletion crates/services/relayer/src/service/get_logs/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ struct Expected {
m: Vec<Log>,
}

const DEFAULT_LOG_PAGE_SIZE: u64 = 5;

#[test_case(
Input {
eth_gap: 0..=1,
Expand Down Expand Up @@ -132,7 +134,7 @@ async fn can_paginate_logs(input: Input) -> Expected {
&EthSyncGap::new(*eth_gap.start(), *eth_gap.end()),
contracts,
&eth_node,
Config::DEFAULT_LOG_PAGE_SIZE,
DEFAULT_LOG_PAGE_SIZE,
)
.map_ok(|(_, l)| l)
.try_concat()
Expand Down
4 changes: 3 additions & 1 deletion crates/services/relayer/src/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use futures::TryStreamExt;

use super::*;

const DEFAULT_LOG_PAGE_SIZE: u64 = 5;

#[tokio::test]
async fn can_download_logs() {
let eth_node = MockMiddleware::default();
Expand Down Expand Up @@ -32,7 +34,7 @@ async fn can_download_logs() {
&eth_state.needs_to_sync_eth().unwrap(),
contracts,
&eth_node,
Config::DEFAULT_LOG_PAGE_SIZE,
DEFAULT_LOG_PAGE_SIZE,
)
.map_ok(|(_, l)| l)
.try_concat()
Expand Down
6 changes: 5 additions & 1 deletion crates/services/relayer/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ async fn stop_service_at_the_middle() {
let mock_db = MockDb::default();
let eth_node = MockMiddleware::default();
eth_node.update_data(|data| data.best_block.number = Some(200.into()));
let relayer = new_service_test(eth_node, mock_db.clone(), Default::default());
let config = Config {
log_page_size: 5,
..Default::default()
};
let relayer = new_service_test(eth_node, mock_db.clone(), config);
relayer.start_and_await().await.unwrap();

// Skip the initial requests to start the synchronization.
Expand Down
Loading