Skip to content

Commit

Permalink
Merge pull request #804 from worldcoin/piohei/cleanup
Browse files Browse the repository at this point in the history
Allow only to update latest tree.
  • Loading branch information
piohei authored Oct 24, 2024
2 parents 1d18ba4 + aac2cdf commit 7b26875
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::identity::processor::{
};
use crate::identity::validator::IdentityValidator;
use crate::identity_tree::initializer::TreeInitializer;
use crate::identity_tree::{Hash, RootItem, TreeState, TreeVersionOps};
use crate::identity_tree::{Hash, RootItem, TreeState, TreeVersionReadOps};
use crate::prover::map::initialize_prover_maps;
use crate::prover::repository::ProverRepository;
use crate::prover::{ProverConfig, ProverType};
Expand Down
2 changes: 1 addition & 1 deletion src/identity_tree/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::database::methods::DbMethods;
use crate::database::Database;
use crate::identity::processor::IdentityProcessor;
use crate::identity_tree::{
CanonicalTreeBuilder, Hash, ProcessedStatus, TreeState, TreeUpdate, TreeVersionOps,
CanonicalTreeBuilder, Hash, ProcessedStatus, TreeState, TreeUpdate, TreeVersionReadOps,
TreeWithNextVersion,
};
use crate::utils::tree_updates::dedup_tree_updates;
Expand Down
15 changes: 7 additions & 8 deletions src/identity_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ impl<V: Version<TreeVersion = lazy_merkle_tree::Derived>> TreeVersion<V> {
/// The public-facing API for reading from a tree version. It is implemented for
/// all versions. This being a trait allows us to hide some of the
/// implementation details.
pub trait TreeVersionOps {
fn update(&self, leaf_index: usize, element: Hash);

pub trait TreeVersionReadOps {
/// Returns the current tree root.
fn get_root(&self) -> Hash;
/// Returns the next free leaf.
Expand All @@ -413,14 +411,10 @@ pub trait TreeVersionOps {
fn get_leaf(&self, leaf: usize) -> Hash;
}

impl<V: Version> TreeVersionOps for TreeVersion<V>
impl<V: Version> TreeVersionReadOps for TreeVersion<V>
where
TreeVersionData<V::TreeVersion>: BasicTreeOps,
{
fn update(&self, leaf_index: usize, element: Hash) {
self.get_data().update(leaf_index, element);
}

fn get_root(&self) -> Hash {
self.get_data().get_root()
}
Expand Down Expand Up @@ -456,6 +450,11 @@ impl<V: Version> TreeVersion<V> {
}

impl TreeVersion<Latest> {
/// Updates tree by inserting element at leaf index.
pub fn update(&self, leaf_index: usize, element: Hash) {
self.get_data().update(leaf_index, element);
}

/// Appends many identities to the tree, returns a list with the root, proof
/// of inclusion and leaf index
#[must_use]
Expand Down
2 changes: 1 addition & 1 deletion src/task_monitor/tasks/create_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::database;
use crate::database::methods::DbMethods as _;
use crate::database::Database;
use crate::identity_tree::{
AppliedTreeUpdate, Hash, Intermediate, TreeVersion, TreeVersionOps, TreeWithNextVersion,
AppliedTreeUpdate, Hash, Intermediate, TreeVersion, TreeVersionReadOps, TreeWithNextVersion,
};
use crate::prover::identity::Identity;
use crate::prover::repository::ProverRepository;
Expand Down
2 changes: 1 addition & 1 deletion src/task_monitor/tasks/delete_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::info;
use crate::app::App;
use crate::database::methods::DbMethods;
use crate::database::types::DeletionEntry;
use crate::identity_tree::{Hash, TreeVersionOps};
use crate::identity_tree::{Hash, TreeVersionReadOps};

// Deletion here differs from insert_identites task. This is because two
// different flows are created for both tasks. Due to how our prover works
Expand Down
2 changes: 1 addition & 1 deletion src/task_monitor/tasks/insert_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing::info;
use crate::app::App;
use crate::database::methods::DbMethods as _;
use crate::database::IsolationLevel;
use crate::identity_tree::TreeVersionOps;
use crate::identity_tree::TreeVersionReadOps;

// Insertion here differs from delete_identities task. This is because two
// different flows are created for both tasks. We need to insert identities as
Expand Down
4 changes: 2 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub mod prelude {
AppConfig, Config, DatabaseConfig, OzDefenderConfig, ProvidersConfig, RelayerConfig,
ServerConfig, TreeConfig, TxSitterConfig,
};
pub use signup_sequencer::identity_tree::{Hash, TreeVersionOps};
pub use signup_sequencer::identity_tree::{Hash, TreeVersionReadOps};
pub use signup_sequencer::prover::ProverType;
pub use signup_sequencer::server;
pub use signup_sequencer::shutdown::Shutdown;
Expand Down Expand Up @@ -76,7 +76,7 @@ use futures::stream::FuturesUnordered;
use futures::StreamExt;
use reqwest::{Body, Client, Method, Request, RequestBuilder, StatusCode};
use semaphore::poseidon_tree::Proof;
use signup_sequencer::identity_tree::{InclusionProof, TreeState, TreeVersionOps};
use signup_sequencer::identity_tree::{InclusionProof, TreeState, TreeVersionReadOps};
use signup_sequencer::server::data::{
AddBatchSizeRequest, DeletionRequest, InclusionProofRequest, InclusionProofResponse,
InsertCommitmentRequest, RemoveBatchSizeRequest, VerifySemaphoreProofRequest,
Expand Down

0 comments on commit 7b26875

Please sign in to comment.