Skip to content

Commit

Permalink
Track event each time a proof of uniqueness is submitted (#6024)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Jul 11, 2024
1 parent 3ee0d4a commit b3e1d1c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Uninstall canisters of empty users ([#6018](https://github.com/open-chat-labs/open-chat/pull/6018))
- Add `submit_proof_of_unique_personhood` ([#6023](https://github.com/open-chat-labs/open-chat/pull/6023))

### Changed

- Track event each time a proof of uniqueness is submitted ([#6024](https://github.com/open-chat-labs/open-chat/pull/6024))

## [[2.0.1231](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1231-user_index)] - 2024-07-08

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl RuntimeState {
empty_users_length: self.data.empty_users.len(),
deleted_users: self.data.deleted_users.iter().take(100).map(|u| u.user_id).collect(),
deleted_users_length: self.data.deleted_users.len(),
unique_person_proofs_submitted: self.data.users.unique_person_proofs_submitted(),
}
}
}
Expand Down Expand Up @@ -499,6 +500,7 @@ pub struct Metrics {
pub empty_users_length: usize,
pub deleted_users: Vec<UserId>,
pub deleted_users_length: usize,
pub unique_person_proofs_submitted: u32,
}

#[derive(Serialize, Debug)]
Expand Down
9 changes: 9 additions & 0 deletions backend/canisters/user_index/impl/src/model/user_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct UserMap {
suspended_or_unsuspended_users: BTreeSet<(TimestampMillis, UserId)>,
user_id_to_principal_backup: HashMap<UserId, Principal>,
deleted_users: HashMap<UserId, TimestampMillis>,
#[serde(default)]
unique_person_proofs_submitted: u32,
}

impl UserMap {
Expand Down Expand Up @@ -347,13 +349,20 @@ impl UserMap {

pub fn record_proof_of_unique_personhood(&mut self, user_id: UserId, proof: UniquePersonProof) -> bool {
if let Some(user) = self.users.get_mut(&user_id) {
if user.unique_person_proof.is_none() {
self.unique_person_proofs_submitted += 1;
}
user.unique_person_proof = Some(proof);
true
} else {
false
}
}

pub fn unique_person_proofs_submitted(&self) -> u32 {
self.unique_person_proofs_submitted
}

#[cfg(test)]
pub fn add_test_user(&mut self, user: User) {
let date_created = user.date_created;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{mutate_state, RuntimeState};
use canister_tracing_macros::trace;
use event_store_producer::EventBuilder;
use ic_cdk::update;
use ic_verifiable_credentials::issuer_api::CredentialSpec;
use ic_verifiable_credentials::VcFlowSigners;
use serde::Serialize;
use types::{CanisterId, UniquePersonProof, UniquePersonProofProvider};
use user_index_canister::submit_proof_of_unique_personhood::{Response::*, *};
use utils::time::NANOS_PER_MILLISECOND;
Expand Down Expand Up @@ -49,12 +51,26 @@ fn submit_proof_of_unique_personhood_impl(args: Args, state: &mut RuntimeState)
local_user_index_canister::Event::NotifyUniqueHumanProof(user_id, proof),
None,
);
state.data.event_store_client.push(
EventBuilder::new("proof_of_uniqueness_submitted", now)
.with_user(user_id.to_string(), true)
.with_source(state.env.canister_id().to_string(), false)
.with_json_payload(&EventPayload {
provider: UniquePersonProofProvider::DecideAI,
})
.build(),
);
Success
}
Err(error) => Invalid(format!("{error:?}")),
}
}

#[derive(Serialize)]
struct EventPayload {
provider: UniquePersonProofProvider,
}

#[test]
fn signing_canister_id() {
let canister_id = CanisterId::from_text("qgxyr-pyaaa-aaaah-qdcwq-cai").unwrap();
Expand Down

0 comments on commit b3e1d1c

Please sign in to comment.