Skip to content

Commit

Permalink
Bump date_updated after submitting proof of uniqueness (#6135)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Jul 29, 2024
1 parent 263cfe5 commit d7e60c2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
6 changes: 6 additions & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Fixed

- Bump `date_updated` after submitting proof of uniqueness ([#6135](https://github.com/open-chat-labs/open-chat/pull/6135))

## [[2.0.1265](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1265-user_index)] - 2024-07-29

### Changed

- Register the AirdropBot user ([#6129](https://github.com/open-chat-labs/open-chat/pull/6129))
Expand Down
13 changes: 2 additions & 11 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use types::{
};
use utils::canister::{CanistersRequiringUpgrade, FailedUpgradeCount};
use utils::canister_event_sync_queue::CanisterEventSyncQueue;
use utils::consts::{DEV_TEAM_DFX_PRINCIPAL, IC_ROOT_KEY};
use utils::consts::DEV_TEAM_DFX_PRINCIPAL;
use utils::env::Environment;
use utils::time::{MonthKey, DAY_IN_MS};

Expand Down Expand Up @@ -283,7 +283,6 @@ struct Data {
pub notifications_index_canister_id: CanisterId,
pub identity_canister_id: CanisterId,
pub proposals_bot_canister_id: CanisterId,
#[serde(default = "init_airdrop_bot_canister_id")]
pub airdrop_bot_canister_id: CanisterId,
pub canisters_requiring_upgrade: CanistersRequiringUpgrade,
pub total_cycles_spent_on_canisters: Cycles,
Expand Down Expand Up @@ -318,19 +317,11 @@ struct Data {
pub empty_users: HashSet<UserId>,
pub chit_leaderboard: ChitLeaderboard,
pub deleted_users: Vec<DeletedUser>,
#[serde(with = "serde_bytes", skip_deserializing, default = "ic_root_key")]
#[serde(with = "serde_bytes")]
pub ic_root_key: Vec<u8>,
pub identity_canister_user_sync_queue: VecDeque<(Principal, Option<UserId>)>,
}

fn ic_root_key() -> Vec<u8> {
IC_ROOT_KEY.to_vec()
}

fn init_airdrop_bot_canister_id() -> CanisterId {
Principal::from_text("62rh2-kiaaa-aaaaf-bmy5q-cai").unwrap()
}

impl Data {
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand Down
15 changes: 1 addition & 14 deletions backend/canisters/user_index/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::lifecycle::{init_env, init_state};
use crate::memory::get_upgrades_memory;
use crate::{mutate_state, Data};
use crate::Data;
use canister_logger::LogEntry;
use canister_tracing_macros::trace;
use ic_cdk::post_upgrade;
use stable_memory::get_reader;
use tracing::info;
use types::UserType;
use user_index_canister::post_upgrade::Args;
use utils::cycles::init_cycles_dispenser_client;

Expand All @@ -24,17 +23,5 @@ fn post_upgrade(args: Args) {
init_cycles_dispenser_client(data.cycles_dispenser_canister_id, data.test_mode);
init_state(env, data, args.wasm_version);

mutate_state(|state| {
// Register the AirdropBot
state.data.users.register(
state.data.airdrop_bot_canister_id,
state.data.airdrop_bot_canister_id.into(),
"AirdropBot".to_string(),
0,
None,
UserType::OcControlledBot,
);
});

info!(version = %args.wasm_version, "Post-upgrade complete");
}
8 changes: 7 additions & 1 deletion backend/canisters/user_index/impl/src/model/user_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,18 @@ impl UserMap {
}
}

pub fn record_proof_of_unique_personhood(&mut self, user_id: UserId, proof: UniquePersonProof) -> bool {
pub fn record_proof_of_unique_personhood(
&mut self,
user_id: UserId,
proof: UniquePersonProof,
now: TimestampMillis,
) -> 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);
user.date_updated = now;
true
} else {
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ fn handle_event(event: Event, state: &mut RuntimeState) {
}
Event::NotifyUniquePersonProof(ev) => {
let (user_id, proof) = *ev;
state.data.users.record_proof_of_unique_personhood(user_id, proof.clone());
state
.data
.users
.record_proof_of_unique_personhood(user_id, proof.clone(), state.env.now());
state.push_event_to_all_local_user_indexes(
LocalUserIndexEvent::NotifyUniquePersonProof(user_id, proof),
Some(caller),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ fn submit_proof_of_unique_personhood_impl(args: Args, state: &mut RuntimeState)
now,
) {
Ok(proof) => {
state.data.users.record_proof_of_unique_personhood(user_id, proof.clone());
state
.data
.users
.record_proof_of_unique_personhood(user_id, proof.clone(), now);
state.push_event_to_all_local_user_indexes(
local_user_index_canister::Event::NotifyUniquePersonProof(user_id, proof),
None,
Expand Down

0 comments on commit d7e60c2

Please sign in to comment.