From 4c3f6491d6e884d7c9fc57a8e6c8594b70258564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Rodr=C3=ADguez?= <_@kevinrodriguez.io> Date: Thu, 12 Sep 2024 21:28:31 -0600 Subject: [PATCH] Add force flag to TreeWorkerArgs for complete reindexing (#148) * feat: allows complete reindex * chore: allow deprecated borsh package --------- Co-authored-by: Kyle Espinola --- backfill/src/worker/tree.rs | 38 ++++++++++++++++++++++----------- blockbuster/src/lib.rs | 1 + tools/acc_forwarder/src/main.rs | 1 + 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/backfill/src/worker/tree.rs b/backfill/src/worker/tree.rs index e75917e52..e6db2b8d9 100644 --- a/backfill/src/worker/tree.rs +++ b/backfill/src/worker/tree.rs @@ -27,6 +27,9 @@ pub struct TreeWorkerArgs { #[clap(flatten)] pub program_transformer_worker: ProgramTransformerWorkerArgs, + + #[clap(long, env, default_value = "false")] + pub force: bool, } impl TreeWorkerArgs { pub fn start( @@ -44,6 +47,7 @@ impl TreeWorkerArgs { let program_transformer_worker_args = self.program_transformer_worker.clone(); let signature_worker_args = self.signature_worker.clone(); let gap_worker_args = self.gap_worker.clone(); + let force = self.force; tokio::spawn(async move { let (metadata_json_download_worker, metadata_json_download_sender) = @@ -67,23 +71,31 @@ impl TreeWorkerArgs { .map(TryInto::try_into) .collect::, _>>()?; - let upper_known_seq = cl_audits_v2::Entity::find() - .filter(cl_audits_v2::Column::Tree.eq(tree.pubkey.as_ref().to_vec())) - .order_by_desc(cl_audits_v2::Column::Seq) - .one(&conn) - .await?; - - let lower_known_seq = cl_audits_v2::Entity::find() - .filter(cl_audits_v2::Column::Tree.eq(tree.pubkey.as_ref().to_vec())) - .order_by_asc(cl_audits_v2::Column::Seq) - .one(&conn) - .await?; + let upper_known_seq = if force { + None + } else { + cl_audits_v2::Entity::find() + .filter(cl_audits_v2::Column::Tree.eq(tree.pubkey.as_ref().to_vec())) + .order_by_desc(cl_audits_v2::Column::Seq) + .one(&conn) + .await? + }; + + let lower_known_seq = if force { + None + } else { + cl_audits_v2::Entity::find() + .filter(cl_audits_v2::Column::Tree.eq(tree.pubkey.as_ref().to_vec())) + .order_by_asc(cl_audits_v2::Column::Seq) + .one(&conn) + .await? + }; if let Some(upper_seq) = upper_known_seq { let signature = Signature::try_from(upper_seq.tx.as_ref())?; - gaps.push(TreeGapFill::new(tree.pubkey, None, Some(signature))); - } else if tree.seq > 0 { + // Reprocess the entire tree if force is true or if the tree has a seq of 0 to keep the current behavior + } else if force || tree.seq > 0 { gaps.push(TreeGapFill::new(tree.pubkey, None, None)); } diff --git a/blockbuster/src/lib.rs b/blockbuster/src/lib.rs index 983c72897..e8e6eeedf 100644 --- a/blockbuster/src/lib.rs +++ b/blockbuster/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(deprecated)] pub mod error; pub mod instruction; pub mod program_handler; diff --git a/tools/acc_forwarder/src/main.rs b/tools/acc_forwarder/src/main.rs index 3c7c96279..c4345aaf2 100644 --- a/tools/acc_forwarder/src/main.rs +++ b/tools/acc_forwarder/src/main.rs @@ -1,3 +1,4 @@ +#![allow(deprecated)] use { anyhow::Context, clap::Parser,