Skip to content

Commit

Permalink
Merge branch 'master' into merge_agent_worker
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs authored Dec 13, 2024
2 parents b9afafd + d2221a9 commit 196d8a7
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 163 deletions.
2 changes: 2 additions & 0 deletions backend/canisters/airdrop_bot/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1510](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1510-airdrop_bot)] - 2024-12-13

### Changed

- Make `ChannelId` comparisons use their 32bit representation ([#6885](https://github.com/open-chat-labs/open-chat/pull/6885))
Expand Down
6 changes: 6 additions & 0 deletions backend/canisters/community/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

- Fix `RoleChanged` events which were serialized under the wrong name (part 2) ([#7059](https://github.com/open-chat-labs/open-chat/pull/7059))

## [[2.0.1515](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1515-community)] - 2024-12-13

### Added

- Update community bot config ([#7018](https://github.com/open-chat-labs/open-chat/pull/7018))
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/community/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ struct Data {
user_cache: UserCache,
user_event_sync_queue: GroupedTimerJobQueue<UserEventBatch>,
stable_memory_keys_to_garbage_collect: Vec<BaseKeyPrefix>,
#[serde(default)]
bots: GroupBots,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fn post_upgrade(args: Args) {
let (mut data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
msgpack::deserialize(reader).unwrap();

canister_logger::init_with_logs(data.test_mode, errors, logs, traces);
data.members.move_member_ids_into_channel_links_map();
data.events.fix_role_changed_events();

canister_logger::init_with_logs(data.test_mode, errors, logs, traces);

let env = init_env(data.rng_seed);
init_state(env, data, args.wasm_version);

Expand Down
31 changes: 26 additions & 5 deletions backend/canisters/community/impl/src/model/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use serde::{Deserialize, Serialize};
use tracing::info;
use types::{
AvatarChanged, BannerChanged, BotAdded, BotRemoved, BotUpdated, ChannelDeleted, ChannelId, ChatId, CommunityMembersRemoved,
CommunityPermissionsChanged, CommunityRoleChanged, CommunityUsersBlocked, CommunityVisibilityChanged, EventIndex,
CommunityPermissionsChanged, CommunityRole, CommunityUsersBlocked, CommunityVisibilityChanged, EventIndex,
EventWrapperInternal, GroupCreated, GroupDescriptionChanged, GroupFrozen, GroupInviteCodeChanged, GroupNameChanged,
GroupRulesChanged, GroupUnfrozen, PrimaryLanguageChanged, TimestampMillis, UserId, UsersInvited, UsersUnblocked,
GroupUnfrozen, PrimaryLanguageChanged, TimestampMillis, UserId, UsersInvited, UsersUnblocked,
};
use user_canister::token_swap_status::CandidType;

mod stable_memory;

Expand Down Expand Up @@ -75,7 +76,7 @@ pub enum CommunityEventInternal {
#[serde(rename = "dc", alias = "DescriptionChanged")]
DescriptionChanged(Box<GroupDescriptionChanged>),
#[serde(rename = "rc", alias = "RulesChanged")]
RulesChanged(Box<GroupRulesChanged>),
RulesChanged(Box<types::GroupRulesChanged>),
#[serde(rename = "ac", alias = "AvatarChanged")]
AvatarChanged(Box<AvatarChanged>),
#[serde(rename = "bc", alias = "BannerChanged")]
Expand All @@ -85,7 +86,7 @@ pub enum CommunityEventInternal {
#[serde(rename = "mr", alias = "MembersRemoved")]
MembersRemoved(Box<CommunityMembersRemoved>),
#[serde(rename = "rl", alias = "RoleChanged")]
RoleChanged(Box<CommunityRoleChanged>),
RoleChanged(Box<types::CommunityRoleChanged>),
#[serde(rename = "ub", alias = "UsersBlocked")]
UsersBlocked(Box<CommunityUsersBlocked>),
#[serde(rename = "uu", alias = "UsersUnblocked")]
Expand Down Expand Up @@ -123,6 +124,21 @@ pub enum RulesChangedOrRoleChanged {
RoleChanged(CommunityRoleChanged),
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
pub struct GroupRulesChanged {
pub enabled: bool,
pub prev_enabled: bool,
pub changed_by: UserId,
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
pub struct CommunityRoleChanged {
pub user_ids: Vec<UserId>,
pub changed_by: UserId,
pub old_role: CommunityRole,
pub new_role: CommunityRole,
}

impl CommunityEvents {
pub fn fix_role_changed_events(&mut self) {
let mut count_updated = 0;
Expand All @@ -134,7 +150,12 @@ impl CommunityEvents {
timestamp: event_wrapper.timestamp,
correlation_id: 0,
expires_at: event_wrapper.expires_at,
event: CommunityEventInternal::RoleChanged(Box::new(role)),
event: CommunityEventInternal::RoleChanged(Box::new(types::CommunityRoleChanged {
user_ids: role.user_ids,
changed_by: role.changed_by,
old_role: role.old_role,
new_role: role.new_role,
})),
});
count_updated += 1;
}
Expand Down
45 changes: 2 additions & 43 deletions backend/canisters/community/impl/src/model/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use crate::model::user_groups::{UserGroup, UserGroups};
use candid::Principal;
use constants::calculate_summary_updates_data_removal_cutoff;
use group_community_common::{Member, MemberUpdate, Members};
use principal_to_user_id_map::{deserialize_principal_to_user_id_map_from_heap, PrincipalToUserIdMap};
use principal_to_user_id_map::PrincipalToUserIdMap;
use rand::RngCore;
use serde::de::{SeqAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde::{Deserialize, Serialize};
use std::collections::btree_map::Entry::Vacant;
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Formatter;
use types::{
is_default, ChannelId, CommunityMember, CommunityPermissions, CommunityRole, PushIfNotContains, TimestampMillis,
Timestamped, UserId, UserType, Version,
Expand All @@ -24,15 +22,11 @@ const MAX_MEMBERS_PER_COMMUNITY: u32 = 100_000;
#[derive(Serialize, Deserialize)]
pub struct CommunityMembers {
members_map: MembersStableStorage,
#[serde(alias = "member_channel_links", deserialize_with = "deserialize_members_and_channels")]
members_and_channels: BTreeMap<UserId, Vec<ChannelId>>,
member_channel_links_removed: BTreeMap<(UserId, ChannelId), TimestampMillis>,
user_groups: UserGroups,
// This includes the userIds of community members and also users invited to the community
#[serde(deserialize_with = "deserialize_principal_to_user_id_map_from_heap")]
principal_to_user_id_map: PrincipalToUserIdMap,
#[deprecated]
member_ids: Vec<UserId>,
owners: BTreeSet<UserId>,
admins: BTreeSet<UserId>,
bots: BTreeMap<UserId, UserType>,
Expand All @@ -46,15 +40,6 @@ pub struct CommunityMembers {
}

impl CommunityMembers {
pub fn move_member_ids_into_channel_links_map(&mut self) {
#[allow(deprecated)]
for user_id in std::mem::take(&mut self.member_ids) {
if let Vacant(e) = self.members_and_channels.entry(user_id) {
e.insert(Vec::new());
}
}
}

pub fn new(
creator_principal: Principal,
creator_user_id: UserId,
Expand Down Expand Up @@ -86,7 +71,6 @@ impl CommunityMembers {
member_channel_links_removed: BTreeMap::new(),
user_groups: UserGroups::default(),
principal_to_user_id_map,
member_ids: Vec::new(),
owners: [creator_user_id].into_iter().collect(),
admins: BTreeSet::new(),
bots: if creator_user_type.is_bot() {
Expand Down Expand Up @@ -839,31 +823,6 @@ impl From<&CommunityMemberInternal> for CommunityMember {
}
}

struct MemberChannelLinksVisitor;

impl<'de> Visitor<'de> for MemberChannelLinksVisitor {
type Value = BTreeMap<UserId, Vec<ChannelId>>;

fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
formatter.write_str("a sequence")
}

fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let mut map: BTreeMap<UserId, Vec<ChannelId>> = BTreeMap::new();
while let Some((user_id, channel_id)) = seq.next_element()? {
map.entry(user_id).or_default().push(channel_id);
}
Ok(map)
}
}

fn deserialize_members_and_channels<'de, D: Deserializer<'de>>(d: D) -> Result<BTreeMap<UserId, Vec<ChannelId>>, D::Error> {
d.deserialize_seq(MemberChannelLinksVisitor)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/cycles_dispenser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1511](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1511-cycles_dispenser)] - 2024-12-13

### Changed

- Expose size of each virtual stable memory in metrics ([#6981](https://github.com/open-chat-labs/open-chat/pull/6981))
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/escrow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1512](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1512-escrow)] - 2024-12-13

### Added

- Add an error log with http endpoint ([#6608](https://github.com/open-chat-labs/open-chat/pull/6608))
Expand Down
7 changes: 3 additions & 4 deletions backend/canisters/escrow/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ fn post_upgrade(args: Args) {
let memory = get_upgrades_memory();
let reader = get_reader(&memory);

let (data, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>) = msgpack::deserialize(reader).unwrap();
let (data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
msgpack::deserialize(reader).unwrap();

// TODO: After release change this to
// let (data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) = msgpack::deserialize(reader).unwrap();
canister_logger::init_with_logs(data.test_mode, Vec::new(), logs, traces);
canister_logger::init_with_logs(data.test_mode, errors, logs, traces);

let env = init_env(data.rng_seed);
init_cycles_dispenser_client(data.cycles_dispenser_canister_id, data.test_mode);
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1516](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1516-group)] - 2024-12-13

### Added

- Update group bot config ([#7018](https://github.com/open-chat-labs/open-chat/pull/7018))
Expand Down
3 changes: 1 addition & 2 deletions backend/canisters/group/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use instruction_counts_log::{InstructionCountEntry, InstructionCountFunctionId,
use model::user_event_batch::UserEventBatch;
use msgpack::serialize_then_unwrap;
use notifications_canister::c2c_push_notification;
use principal_to_user_id_map::{deserialize_principal_to_user_id_map_from_heap, PrincipalToUserIdMap};
use principal_to_user_id_map::PrincipalToUserIdMap;
use serde::{Deserialize, Serialize};
use serde_bytes::ByteBuf;
use stable_memory_map::{BaseKeyPrefix, ChatEventKeyPrefix};
Expand Down Expand Up @@ -475,7 +475,6 @@ impl RuntimeState {
#[derive(Serialize, Deserialize)]
struct Data {
pub chat: GroupChatCore,
#[serde(deserialize_with = "deserialize_principal_to_user_id_map_from_heap")]
pub principal_to_user_id_map: PrincipalToUserIdMap,
pub group_index_canister_id: CanisterId,
pub local_group_index_canister_id: CanisterId,
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1509](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1509-group_index)] - 2024-12-13

### Changed

- Expose size of each virtual stable memory in metrics ([#6981](https://github.com/open-chat-labs/open-chat/pull/6981))
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/local_group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1514](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1514-local_group_index)] - 2024-12-13

### Added

- Expose the cycles top-ups of Group/Community canisters ([#7053](https://github.com/open-chat-labs/open-chat/pull/7053))
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1513](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1513-local_user_index)] - 2024-12-13

### Added

- Expose the cycles top-ups of User canisters ([#7053](https://github.com/open-chat-labs/open-chat/pull/7053))
Expand Down
6 changes: 0 additions & 6 deletions backend/canisters/local_user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ impl RuntimeState {
struct Data {
pub local_users: LocalUserMap,
pub global_users: GlobalUserMap,
#[serde(default)]
pub bots: BotsMap,
pub child_canister_wasms: ChildCanisterWasms<ChildCanisterType>,
pub user_index_canister_id: CanisterId,
Expand All @@ -300,7 +299,6 @@ struct Data {
pub cycles_dispenser_canister_id: CanisterId,
pub escrow_canister_id: CanisterId,
pub internet_identity_canister_id: CanisterId,
#[serde(default = "website_canister_id")]
pub website_canister_id: CanisterId,
pub canisters_requiring_upgrade: CanistersRequiringUpgrade,
pub canister_pool: canister::Pool,
Expand All @@ -324,10 +322,6 @@ struct Data {
pub cycles_balance_check_queue: VecDeque<UserId>,
}

fn website_canister_id() -> CanisterId {
CanisterId::from_text("6hsbt-vqaaa-aaaaf-aaafq-cai").unwrap()
}

#[derive(Serialize, Deserialize)]
pub struct FailedMessageUsers {
pub sender: UserId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::lifecycle::{init_env, init_state};
use crate::memory::{get_stable_memory_map_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 local_user_index_canister::post_upgrade::Args;
use stable_memory::get_reader;
use tracing::info;
use types::CanisterId;
use utils::cycles::init_cycles_dispenser_client;

#[post_upgrade]
Expand All @@ -28,10 +27,4 @@ fn post_upgrade(args: Args) {
init_state(env, data, args.wasm_version);

info!(version = %args.wasm_version, "Post-upgrade complete");

mutate_state(|state| {
if state.data.test_mode {
state.data.website_canister_id = CanisterId::from_text("pfs7b-iqaaa-aaaaf-abs7q-cai").unwrap();
}
})
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use candid::Principal;
use local_user_index_canister::GlobalUser;
use principal_to_user_id_map::{deserialize_principal_to_user_id_map_from_heap, PrincipalToUserIdMap};
use principal_to_user_id_map::PrincipalToUserIdMap;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use types::{TimestampMillis, UniquePersonProof, UserId, UserType};

#[derive(Serialize, Deserialize, Default)]
pub struct GlobalUserMap {
user_id_to_principal: HashMap<UserId, Principal>,
#[serde(deserialize_with = "deserialize_principal_to_user_id_map_from_heap")]
principal_to_user_id: PrincipalToUserIdMap,
unique_person_proofs: HashMap<UserId, UniquePersonProof>,
platform_moderators: HashSet<UserId>,
#[serde(alias = "bots")]
legacy_bots: HashSet<UserId>,
oc_controlled_bot_users: HashSet<UserId>,
diamond_membership_expiry_dates: HashMap<UserId, TimestampMillis>,
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1519](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1519-notifications)] - 2024-12-13

### Added

- Add an error log with http endpoint ([#6608](https://github.com/open-chat-labs/open-chat/pull/6608))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ fn post_upgrade(args: Args) {
let memory = get_upgrades_memory();
let reader = get_reader(&memory);

let (data, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>) = msgpack::deserialize(reader).unwrap();
let (data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
msgpack::deserialize(reader).unwrap();

// TODO: After release change this to
// let (data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) = msgpack::deserialize(reader).unwrap();
canister_logger::init_with_logs(data.test_mode, Vec::new(), logs, traces);
canister_logger::init_with_logs(data.test_mode, errors, logs, traces);

let env = init_env(data.rng_seed);
init_cycles_dispenser_client(data.cycles_dispenser_canister_id, data.test_mode);
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/notifications_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1518](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1518-notifications_index)] - 2024-12-13

### Added

- Add an error log with http endpoint ([#6608](https://github.com/open-chat-labs/open-chat/pull/6608))
Expand Down
Loading

0 comments on commit 196d8a7

Please sign in to comment.