Skip to content

Commit

Permalink
Update canisters post release
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Dec 19, 2024
1 parent eeb62fb commit 95666f0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 127 deletions.
2 changes: 2 additions & 0 deletions backend/canisters/community/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.1540](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1540-community)] - 2024-12-19

### Fixed

- Fix community `RoleChanged` event deserialization ([#7098](https://github.com/open-chat-labs/open-chat/pull/7098))
Expand Down
10 changes: 1 addition & 9 deletions backend/canisters/community/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use ic_cdk::post_upgrade;
use instruction_counts_log::InstructionCountFunctionId;
use stable_memory::get_reader;
use tracing::info;
use utils::env::Environment;

#[post_upgrade]
#[trace]
Expand All @@ -19,19 +18,12 @@ fn post_upgrade(args: Args) {
let memory = get_upgrades_memory();
let reader = get_reader(&memory);

let (mut data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
let (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.events.fix_role_changed_events();

let env = init_env(data.rng_seed);
let now = env.now();
for channel in data.channels.iter_mut() {
channel.chat.events.remove_spurious_video_call_in_progress(now);
}

init_state(env, data, args.wasm_version);

let completed_imports = read_state(|state| state.data.groups_being_imported.completed_imports());
Expand Down
105 changes: 4 additions & 101 deletions backend/canisters/community/impl/src/model/events.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::model::events::stable_memory::EventsStableStorage;
use chat_events::GroupGateUpdatedInternal;
use serde::{Deserialize, Serialize};
use tracing::info;
use types::{
AvatarChanged, BannerChanged, BotAdded, BotRemoved, BotUpdated, ChannelDeleted, ChannelId, ChatId, CommunityMembersRemoved,
CommunityPermissionsChanged, CommunityRole, CommunityUsersBlocked, CommunityVisibilityChanged, EventIndex,
CommunityPermissionsChanged, CommunityRoleChanged, CommunityUsersBlocked, CommunityVisibilityChanged, EventIndex,
EventWrapperInternal, GroupCreated, GroupDescriptionChanged, GroupFrozen, GroupInviteCodeChanged, GroupNameChanged,
GroupUnfrozen, PrimaryLanguageChanged, TimestampMillis, UserId, UsersInvited, UsersUnblocked,
GroupRulesChanged, GroupUnfrozen, PrimaryLanguageChanged, TimestampMillis, UserId, UsersInvited, UsersUnblocked,
};
use user_canister::token_swap_status::CandidType;

Check warning on line 10 in backend/canisters/community/impl/src/model/events.rs

View workflow job for this annotation

GitHub Actions / run unit tests

unused import: `user_canister::token_swap_status::CandidType`

Check failure on line 10 in backend/canisters/community/impl/src/model/events.rs

View workflow job for this annotation

GitHub Actions / run clippy

unused import: `user_canister::token_swap_status::CandidType`

Expand All @@ -19,56 +18,6 @@ pub struct CommunityEvents {
latest_event_timestamp: TimestampMillis,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum CommunityEventInternalOld {
#[serde(rename = "cr", alias = "Created")]
Created(Box<GroupCreated>),
#[serde(rename = "nc", alias = "NameChanged")]
NameChanged(Box<GroupNameChanged>),
#[serde(rename = "dc", alias = "DescriptionChanged")]
DescriptionChanged(Box<GroupDescriptionChanged>),
#[serde(rename = "rc", alias = "RulesChanged")]
RulesChangedOrRoleChanged(Box<RulesChangedOrRoleChanged>),
#[serde(rename = "ac", alias = "AvatarChanged")]
AvatarChanged(Box<AvatarChanged>),
#[serde(rename = "bc", alias = "BannerChanged")]
BannerChanged(Box<BannerChanged>),
#[serde(rename = "ui", alias = "UsersInvited")]
UsersInvited(Box<UsersInvited>),
#[serde(rename = "mr", alias = "MembersRemoved")]
MembersRemoved(Box<CommunityMembersRemoved>),
#[serde(rename = "rl", alias = "RoleChanged")]
RoleChanged(Box<types::CommunityRoleChanged>),
#[serde(rename = "ub", alias = "UsersBlocked")]
UsersBlocked(Box<CommunityUsersBlocked>),
#[serde(rename = "uu", alias = "UsersUnblocked")]
UsersUnblocked(Box<UsersUnblocked>),
#[serde(rename = "pc", alias = "PermissionsChanged")]
PermissionsChanged(Box<CommunityPermissionsChanged>),
#[serde(rename = "vc", alias = "VisibilityChanged")]
VisibilityChanged(Box<CommunityVisibilityChanged>),
#[serde(rename = "ic", alias = "InviteCodeChanged")]
InviteCodeChanged(Box<GroupInviteCodeChanged>),
#[serde(rename = "fr", alias = "Frozen")]
Frozen(Box<GroupFrozen>),
#[serde(rename = "uf", alias = "Unfrozen")]
Unfrozen(Box<GroupUnfrozen>),
#[serde(rename = "gu", alias = "GateUpdated")]
GateUpdated(Box<GroupGateUpdatedInternal>),
#[serde(rename = "cd", alias = "ChannelDeleted")]
ChannelDeleted(Box<ChannelDeleted>),
#[serde(rename = "pl", alias = "PrimaryLanguageChanged")]
PrimaryLanguageChanged(Box<PrimaryLanguageChanged>),
#[serde(rename = "gi", alias = "GroupImported")]
GroupImported(Box<GroupImportedInternal>),
#[serde(rename = "ba")]
BotAdded(Box<BotAdded>),
#[serde(rename = "br")]
BotRemoved(Box<BotRemoved>),
#[serde(rename = "bu")]
BotUpdated(Box<BotUpdated>),
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum CommunityEventInternal {
#[serde(rename = "cr", alias = "Created")]
Expand All @@ -78,7 +27,7 @@ pub enum CommunityEventInternal {
#[serde(rename = "dc", alias = "DescriptionChanged")]
DescriptionChanged(Box<GroupDescriptionChanged>),
#[serde(rename = "rc", alias = "RulesChanged")]
RulesChanged(Box<types::GroupRulesChanged>),
RulesChanged(Box<GroupRulesChanged>),
#[serde(rename = "ac", alias = "AvatarChanged")]
AvatarChanged(Box<AvatarChanged>),
#[serde(rename = "bc", alias = "BannerChanged")]
Expand All @@ -88,7 +37,7 @@ pub enum CommunityEventInternal {
#[serde(rename = "mr", alias = "MembersRemoved")]
MembersRemoved(Box<CommunityMembersRemoved>),
#[serde(rename = "rl", alias = "RoleChanged")]
RoleChanged(Box<types::CommunityRoleChanged>),
RoleChanged(Box<CommunityRoleChanged>),
#[serde(rename = "ub", alias = "UsersBlocked")]
UsersBlocked(Box<CommunityUsersBlocked>),
#[serde(rename = "uu", alias = "UsersUnblocked")]
Expand Down Expand Up @@ -119,53 +68,7 @@ pub enum CommunityEventInternal {
BotUpdated(Box<BotUpdated>),
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(untagged)]
pub enum RulesChangedOrRoleChanged {
RulesChanged(GroupRulesChanged),
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;
for event_wrapper in self.stable_events_map.read_all() {
if let CommunityEventInternalOld::RulesChangedOrRoleChanged(r) = event_wrapper.event {
if let RulesChangedOrRoleChanged::RoleChanged(role) = *r {
self.stable_events_map.insert(EventWrapperInternal {
index: event_wrapper.index,
timestamp: event_wrapper.timestamp,
correlation_id: 0,
expires_at: event_wrapper.expires_at,
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;
}
}
}
info!(count_updated, "Fixed community events");
}

pub fn new(name: String, description: String, created_by: UserId, now: TimestampMillis) -> CommunityEvents {
let event_index = EventIndex::default();
let event = EventWrapperInternal {
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.1541](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1541-group_index)] - 2024-12-19

### Changed

- Handle retry attempts when adding a new LocalGroupIndex ([#7091](https://github.com/open-chat-labs/open-chat/pull/7091))
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/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.1542](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1542-user_index)] - 2024-12-19

### Changed

- Add logging + skip steps that have already been completed ([#7093](https://github.com/open-chat-labs/open-chat/pull/7093))
Expand Down
17 changes: 0 additions & 17 deletions backend/libraries/types/src/canister_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,12 @@ pub enum UpgradeChunkedCanisterWasmResponse {
}

#[derive(CandidType, Serialize, Deserialize, Clone, Default)]
#[serde(from = "ChunkedCanisterWasmPrevious")]
pub struct ChunkedCanisterWasm {
pub wasm: CanisterWasm,
pub chunks: Vec<Hash>,
pub wasm_hash: Hash,
}

#[derive(Deserialize)]
pub struct ChunkedCanisterWasmPrevious {
pub wasm: CanisterWasm,
pub chunks: Vec<Hash>,
}

impl From<ChunkedCanisterWasmPrevious> for ChunkedCanisterWasm {
fn from(value: ChunkedCanisterWasmPrevious) -> Self {
ChunkedCanisterWasm {
wasm_hash: value.wasm.module.hash(),
wasm: value.wasm,
chunks: value.chunks,
}
}
}

impl From<CanisterWasm> for ChunkedCanisterWasm {
fn from(value: CanisterWasm) -> Self {
ChunkedCanisterWasm {
Expand Down

0 comments on commit 95666f0

Please sign in to comment.