Skip to content

Commit

Permalink
merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
0xForerunner committed May 24, 2024
2 parents 84d7912 + 6cdf164 commit a50ef3b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ semaphore = { git = "https://github.com/worldcoin/semaphore-rs", rev = "5170c422
similar-asserts = "1.5.0"
test-case = "3.0"
testcontainers = "0.15.0"
testcontainers-modules = { version = "0.3.7", features = ["postgres"] }
testcontainers-modules = { version = "0.3.7", features = ["postgres"] }
tracing-subscriber = "0.3.11"
tracing-test = "0.2"

Expand Down
53 changes: 49 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ docker pull postgres

### Local Node

You'll need to run a local node like geth. Start up a new chain and take note of the dev addresses. You can follow instructions [here](https://book.getfoundry.sh/anvil/).
You'll need to run a local node like geth or [ganache](https://archive.trufflesuite.com/ganache/). Start up a new chain and take note of the dev addresses. You can follow instructions [here](https://book.getfoundry.sh/anvil/).

### Worldcoin id contracts

Expand All @@ -90,11 +90,56 @@ you will have a generated a keys file that is used by semaphore-mtb. If your dep
docker run --rm -ti -p 5432:5432 -e POSTGRES_PASSWORD=password postgres
```

Now you are ready to start up sequencer service!
### TX sitter

TX sitter is a service providing API for signup-sequencer to submit transactions on blockchain.

Clone [tx-sitter-monolith](https://github.com/worldcoin/tx-sitter-monolith) and follow build instructions

### Signup-sequencer

Now you need to create a `config.toml` file for signup-sequencer:

```toml
[app]
provers_urls ='[]'

[tree]

[network]
# Address of WorldIDIdentityManager contract on blockchain.
# If you are using anvil the default address should work.
identity_manager_address = "0x48483748eb0446A16cAE79141D0688e3F624Cb73"

[providers]
# Blockchain API URL (anvil or geth)
primary_network_provider = "http://localhost:8545"

[relayer]
kind = "tx_sitter"
# URL of TX-sitter API + API token
tx_sitter_url = "http://localhost:3000/1/api/G5CKNF3BTS2hRl60bpdYMNPqXvXsP-QZd2lrtmgctsnllwU9D3Z4D8gOt04M0QNH"
tx_sitter_address = "0x1d7ffed610cc4cdC097ecDc835Ae5FEE93C9e3Da"
tx_sitter_gas_limit = 2000000

[database]
database = "postgres://postgres:password@localhost:5432/sequencer?sslmode=disable"

[server]
# Port to run signup-sequencer API on
address = "0.0.0.0:8080"
```

The daemon will try to create temporary files in `/data`. If your machine does not have it you could create it:

```shell
mkdir signup_sequencer_data
sudo ln -sf `pwd`/signup_sequencer_data /data
```

And then run the daemon:
```shell
TREE_DEPTH=*your tree depth (eg. 16)* cargo run -- --batch-size *batch size for semaphore-mtb (eg. 3)* --batch-timeout-seconds 10 --database postgres://postgres:password@0.0.0.0:5432 --identity-manager-address *address from worldcoin id contracts identity manager*
--signing-key *private key you used to deploy smart contracts*
cargo run config.toml
```

## Tests
Expand Down
11 changes: 11 additions & 0 deletions src/task_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod tasks;
const TREE_INIT_BACKOFF: Duration = Duration::from_secs(5);
const PROCESS_IDENTITIES_BACKOFF: Duration = Duration::from_secs(5);
const FINALIZE_IDENTITIES_BACKOFF: Duration = Duration::from_secs(5);
const QUEUE_MONITOR_BACKOFF: Duration = Duration::from_secs(5);
const INSERT_IDENTITIES_BACKOFF: Duration = Duration::from_secs(5);
const DELETE_IDENTITIES_BACKOFF: Duration = Duration::from_secs(5);

Expand Down Expand Up @@ -131,6 +132,16 @@ impl TaskMonitor {
);
handles.push(finalize_identities_handle);

// Report length of the queue of identities
let app = self.app.clone();
let queue_monitor = move || tasks::monitor_queue::monitor_queue(app.clone());
let queue_monitor_handle = crate::utils::spawn_monitored_with_backoff(
queue_monitor,
shutdown_sender.clone(),
QUEUE_MONITOR_BACKOFF,
);
handles.push(queue_monitor_handle);

// Process identities
let app = self.app.clone();
let wake_up_notify = base_wake_up_notify.clone();
Expand Down
3 changes: 0 additions & 3 deletions src/task_monitor/tasks/finalize_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::contracts::IdentityManager;
use crate::database::query::DatabaseQuery as _;
use crate::database::Database;
use crate::identity_tree::{Canonical, Intermediate, TreeVersion, TreeWithNextVersion};
use crate::task_monitor::TaskMonitor;
use crate::utils::retry_tx;

pub async fn finalize_roots(app: Arc<App>) -> anyhow::Result<()> {
Expand Down Expand Up @@ -163,8 +162,6 @@ async fn finalize_mainnet_roots(
let updates_count = processed_tree.apply_updates_up_to(post_root.into());

info!(updates_count, ?pre_root, ?post_root, "Mined tree updated");

TaskMonitor::log_identities_queues(database).await?;
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/task_monitor/tasks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod delete_identities;
pub mod finalize_identities;
pub mod insert_identities;
pub mod monitor_queue;
pub mod monitor_txs;
pub mod process_identities;
15 changes: 15 additions & 0 deletions src/task_monitor/tasks/monitor_queue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::sync::Arc;

use tokio::time::{sleep, Duration};

use crate::task_monitor::{App, TaskMonitor};

// How often send metrics for idenity queue length
const QUEUE_MONITORING_PERIOD: Duration = Duration::from_secs(1);

pub async fn monitor_queue(app: Arc<App>) -> anyhow::Result<()> {
loop {
TaskMonitor::log_identities_queues(&app.database).await?;
sleep(QUEUE_MONITORING_PERIOD).await;
}
}

0 comments on commit a50ef3b

Please sign in to comment.