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

Move initial consistency checks to a background task #43

Merged
merged 1 commit into from
Jan 3, 2024
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
24 changes: 16 additions & 8 deletions bundler/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::collections::{hash_map::Entry, HashMap};

use bundler_client::types::{
BlockGasSummary, DataIntentFull, DataIntentId, DataIntentStatus, DataIntentSummary,
SyncStatusBlock,
};
use ethers::{
signers::LocalWallet,
types::{Address, BlockNumber},
types::{Address, BlockNumber, H256},
};
use eyre::{bail, eyre, Result};
use futures::{stream, StreamExt, TryStreamExt};
Expand Down Expand Up @@ -150,17 +152,23 @@ impl AppData {
let anchor_block_number = { self.sync.read().await.get_anchor().number };
let intents = fetch_all_intents_with_inclusion_not_finalized(&self.db_pool).await?;

// Cache to prevent fetching the same transaction for the same intent
let mut tx_cache: HashMap<H256, Option<u64>> = <_>::default();
let mut ids_with_inclusion_finalized = vec![];

for (id, tx_hash) in intents {
// TODO: cache fetch of the same transaction
if let Some(tx) = self.provider.get_transaction(tx_hash).await? {
if let Some(inclusion_block_number) = tx.block_number {
if inclusion_block_number.as_u64() <= anchor_block_number {
// intent was included in a block equal or ancestor of finalized anchor
// block
ids_with_inclusion_finalized.push(id);
}

if let Entry::Vacant(e) = tx_cache.entry(tx_hash) {
let tx = self.provider.get_transaction(tx_hash).await?;
e.insert(tx.and_then(|tx| tx.block_number.map(|n| n.as_u64())));
}

if let Some(Some(inclusion_block_number)) = tx_cache.get(&tx_hash) {
if inclusion_block_number <= &anchor_block_number {
// intent was included in a block equal or ancestor of finalized anchor
// block
ids_with_inclusion_finalized.push(id);
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions bundler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
blob_sender_task(self.data.clone()),
block_subscriber_task(self.data.clone()),
remote_node_tracker_task(self.data.clone()),
run_consistency_checks_task(self.data.clone()),
push_metrics_task(self.data.config.metrics_push.clone()),
)?;
Ok(())
Expand All @@ -365,3 +366,17 @@
&trusted_setup.g2_points(),
)?)
}

async fn run_consistency_checks_task(data: Arc<AppData>) -> Result<()> {

Check warning on line 370 in bundler/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bundler/src/lib.rs#L370

Added line #L370 was not covered by tests
match data
.initial_consistency_check_intents_with_inclusion_finalized()
.await
{
Ok(ids_with_inclusion_finalized) => {
info!("Completed initial consistency checks for intents with inclusion finalzied");
debug!("ids_with_inclusion_finalized {ids_with_inclusion_finalized:?}",);
}
Err(e) => error!("Error doing initial consistency checks for intents {e:?}"),
};
Ok(())
}

Check warning on line 382 in bundler/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bundler/src/lib.rs#L382

Added line #L382 was not covered by tests
Loading