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(rpc-server): optimistic status is not working correctly #385

Merged
merged 1 commit into from
Dec 29, 2024
Merged
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
33 changes: 20 additions & 13 deletions rpc-server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,28 @@ async fn task_update_optimistic_block_regularly(
// Task to check optimistic block status
async fn task_optimistic_block_status() {
tracing::info!("Task to check optimistic block status started");
let mut last_optimistic = crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY
.with_label_values(&["optimistic"])
.get();
loop {
// check every second
tokio::time::sleep(std::time::Duration::from_secs(1)).await;

// get the current final block height
let current_final = crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY
.with_label_values(&["final"])
.get();

// get the current optimistic block height
let current_optimistic = crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY
.with_label_values(&["optimistic"])
.get();

// When an optimistic block is not updated, or it is lower than the final block
// we need to mark that optimistic updating is not working
if crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY
.with_label_values(&["optimistic"])
.get()
<= crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY
.with_label_values(&["final"])
.get()
&& !crate::metrics::OPTIMISTIC_UPDATING.is_not_working()
if current_optimistic <= current_final
|| current_optimistic <= last_optimistic
&& !crate::metrics::OPTIMISTIC_UPDATING.is_not_working()
{
tracing::warn!(
"Optimistic block in is not updated or optimistic block less than final block"
Expand All @@ -254,17 +263,15 @@ async fn task_optimistic_block_status() {

// When an optimistic block is updated, and it is greater than the final block
// we need to mark that optimistic updating is working
if crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY
.with_label_values(&["optimistic"])
.get()
> crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY
.with_label_values(&["final"])
.get()
if current_optimistic > current_final
&& current_optimistic > last_optimistic
&& crate::metrics::OPTIMISTIC_UPDATING.is_not_working()
{
crate::metrics::OPTIMISTIC_UPDATING.set_working();
tracing::info!("Optimistic block updating is resumed.");
}

last_optimistic = current_optimistic;
}
}

Expand Down
Loading