From ba1ac68e8db9cfeebd37d1f22145ab017c10c7b0 Mon Sep 17 00:00:00 2001 From: 0xKitsune <0xKitsune@protonmail.com> Date: Tue, 14 Nov 2023 10:30:44 -0500 Subject: [PATCH] removed shadow tree mod --- bin/load_test/shadow_tree/mod.rs | 145 ------------------------------- 1 file changed, 145 deletions(-) delete mode 100644 bin/load_test/shadow_tree/mod.rs diff --git a/bin/load_test/shadow_tree/mod.rs b/bin/load_test/shadow_tree/mod.rs deleted file mode 100644 index cc2bd679..00000000 --- a/bin/load_test/shadow_tree/mod.rs +++ /dev/null @@ -1,145 +0,0 @@ -use std::fmt::{self}; -use std::sync::Arc; -use std::time::Duration; - -use ethers::providers::{Http, Middleware, Provider}; -use ethers::types::H160; -use ethers_throttle::ThrottledProvider; -use semaphore::lazy_merkle_tree::Canonical; -use tokio::task::JoinHandle; -use tracing::instrument; -use url::Url; -use world_tree::tree::error::TreeAvailabilityError; -use world_tree::tree::tree_data::TreeData; -use world_tree::tree::tree_updater::TreeUpdater; -use world_tree::tree::{Hash, PoseidonTree}; - -use crate::utils::Profile; -use crate::SHADOW_TREE; - -pub type ShadowTreeError = - TreeAvailabilityError>>; - -pub struct ShadowWorldTree { - pub tree_data: Arc, - pub tree_updater: Arc>, -} - -impl ShadowWorldTree { - /// Initializes a new instance of `WorldTree`. - /// - /// # Arguments - /// - /// * `tree` - The `PoseidonTree` used for the merkle tree representation. - /// * `tree_history_size` - The number of historical tree roots to keep in memory. - /// * `address` - The smart contract address of the `WorldIDIdentityManager`. - /// * `creation_block` - The block number at which the contract was deployed. - /// * `middleware` - Provider to interact with Ethereum. - pub fn new( - tree: PoseidonTree, - tree_history_size: usize, - address: H160, - creation_block: u64, - window_size: u64, - middleware: Arc, - ) -> Self { - Self { - tree_data: Arc::new(TreeData::new(tree, tree_history_size)), - tree_updater: Arc::new(TreeUpdater::new( - address, - creation_block, - window_size, - middleware, - )), - } - } - - /// Spawns a task that continually syncs the `TreeData` to the state at the chain head. - #[instrument(skip(self))] - pub fn spawn(&self) -> JoinHandle>> { - let tree_data = self.tree_data.clone(); - let tree_updater = self.tree_updater.clone(); - - tokio::spawn(async move { - tree_updater.sync_to_head(&tree_data).await?; - - loop { - tree_updater.sync_to_head(&tree_data).await?; - - tokio::time::sleep(Duration::from_secs(5)).await; - } - }) - } -} - -impl Default for ShadowWorldTree>> { - fn default() -> Self { - let default_tree = PoseidonTree::::new_with_dense_prefix( - 0, - 0, - &Hash::default(), - ); - - let http_provider = - Http::new(Url::parse("localhost").expect("Could not parse url")); - let throttled_http_provider = - ThrottledProvider::new(http_provider, 0, None); - - let middleware = Arc::new(Provider::new(throttled_http_provider)); - - Self { - tree_data: Arc::new(TreeData::new(default_tree, 0)), - tree_updater: Arc::new(TreeUpdater::new( - H160::default(), - 0, - 0, - middleware, - )), - } - } -} - -pub async fn initialize_shadow_tree( - profile: &Profile, -) -> eyre::Result>> { - let http_provider = - ethers::providers::Http::new(Url::parse(&profile.rpc_endpoint)?); - - let throttled_http_provider = - ThrottledProvider::new(http_provider, profile.throttle, None); - - let middleware = Arc::new(Provider::new(throttled_http_provider)); - - let tree = PoseidonTree::::new_with_dense_prefix( - profile.tree_depth, - profile.dense_prefix_depth, - &Hash::default(), - ); - - let shadow_tree = Arc::new(ShadowWorldTree::new( - tree, - profile.tree_history_size, - profile.address, - profile.creation_block, - profile.window_size, - middleware, - )); - - // Sync to head - let tree_data = &shadow_tree.tree_data; - let tree_updater = &shadow_tree.tree_updater; - tree_updater.sync_to_head(tree_data).await?; - - let handles = shadow_tree.spawn(); - - SHADOW_TREE - .set(shadow_tree) - .expect("Could not set shadow tree"); - - Ok(handles) -} -impl fmt::Debug for ShadowWorldTree { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("noop") - } -}