Skip to content

Commit

Permalink
Store proposals_bot_canister_id in user canisters (#4485)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Oct 3, 2023
1 parent 1a1f650 commit ceb321b
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backend/canister_installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ async fn install_service_canisters_impl(
local_user_index_canister_wasm: CanisterWasm::default(),
group_index_canister_id: canister_ids.group_index,
notifications_index_canister_id: canister_ids.notifications_index,
proposals_bot_canister_id: canister_ids.proposals_bot,
storage_index_canister_id: canister_ids.storage_index,
proposals_bot_user_id: canister_ids.proposals_bot.into(),
cycles_dispenser_canister_id: canister_ids.cycles_dispenser,
internet_identity_canister_id: canister_ids.nns_internet_identity,
wasm_version: version,
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Store `proposals_bot_canister_id` in user canisters ([#4485](https://github.com/open-chat-labs/open-chat/pull/4485))

## [[2.0.860](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.860-local_user_index)] - 2023-09-26

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Args {
pub user_index_canister_id: CanisterId,
pub group_index_canister_id: CanisterId,
pub notifications_canister_id: CanisterId,
pub proposals_bot_canister_id: CanisterId,
pub cycles_dispenser_canister_id: CanisterId,
pub internet_identity_canister_id: CanisterId,
pub test_mode: bool,
Expand Down
10 changes: 10 additions & 0 deletions backend/canisters/local_user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl RuntimeState {
user_index: self.data.user_index_canister_id,
group_index: self.data.group_index_canister_id,
notifications: self.data.notifications_canister_id,
proposals_bot: self.data.proposals_bot_canister_id,
cycles_dispenser: self.data.cycles_dispenser_canister_id,
},
}
Expand All @@ -190,6 +191,8 @@ struct Data {
pub user_index_canister_id: CanisterId,
pub group_index_canister_id: CanisterId,
pub notifications_canister_id: CanisterId,
#[serde(default = "proposals_bot_canister_id")]
pub proposals_bot_canister_id: CanisterId,
pub cycles_dispenser_canister_id: CanisterId,
pub internet_identity_canister_id: CanisterId,
pub canisters_requiring_upgrade: CanistersRequiringUpgrade,
Expand All @@ -206,6 +209,10 @@ struct Data {
pub btc_miami_payments_queue: BtcMiamiPaymentsQueue,
}

fn proposals_bot_canister_id() -> CanisterId {
CanisterId::from_text("iywa7-ayaaa-aaaaf-aemga-cai").unwrap()
}

#[derive(Serialize, Deserialize)]
pub struct FailedMessageUsers {
pub sender: UserId,
Expand All @@ -219,6 +226,7 @@ impl Data {
user_index_canister_id: CanisterId,
group_index_canister_id: CanisterId,
notifications_canister_id: CanisterId,
proposals_bot_canister_id: CanisterId,
cycles_dispenser_canister_id: CanisterId,
internet_identity_canister_id: CanisterId,
canister_pool_target_size: u16,
Expand All @@ -232,6 +240,7 @@ impl Data {
user_index_canister_id,
group_index_canister_id,
notifications_canister_id,
proposals_bot_canister_id,
cycles_dispenser_canister_id,
internet_identity_canister_id,
canisters_requiring_upgrade: CanistersRequiringUpgrade::default(),
Expand Down Expand Up @@ -278,5 +287,6 @@ pub struct CanisterIds {
pub user_index: CanisterId,
pub group_index: CanisterId,
pub notifications: CanisterId,
pub proposals_bot: CanisterId,
pub cycles_dispenser: CanisterId,
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn init(args: Args) {
args.user_index_canister_id,
args.group_index_canister_id,
args.notifications_canister_id,
args.proposals_bot_canister_id,
args.cycles_dispenser_canister_id,
args.internet_identity_canister_id,
canister_pool_target_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ fn prepare(args: &Args, state: &mut RuntimeState) -> Result<PrepareOk, Response>
user_index_canister_id: state.data.user_index_canister_id,
local_user_index_canister_id: state.env.canister_id(),
notifications_canister_id: state.data.notifications_canister_id,
proposals_bot_canister_id: state.data.proposals_bot_canister_id,
wasm_version: canister_wasm.version,
username: args.username.clone(),
display_name: args.display_name.clone(),
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Support prize messages in any token by getting fee from original transfer ([#4470](https://github.com/open-chat-labs/open-chat/pull/4470))
- Prevent transfers to yourself ([#4471](https://github.com/open-chat-labs/open-chat/pull/4471))
- Retry sending tip if c2c call fails ([#4482](https://github.com/open-chat-labs/open-chat/pull/4482))
- Store `proposals_bot_canister_id` in user canisters ([#4485](https://github.com/open-chat-labs/open-chat/pull/4485))

## [[2.0.867](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.867-user)] - 2023-09-27

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user/api/src/lifecycle/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Args {
pub user_index_canister_id: CanisterId,
pub local_user_index_canister_id: CanisterId,
pub notifications_canister_id: CanisterId,
pub proposals_bot_canister_id: CanisterId,
pub wasm_version: BuildVersion,
pub username: String,
pub display_name: Option<String>,
Expand Down
10 changes: 10 additions & 0 deletions backend/canisters/user/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl RuntimeState {
group_index: self.data.group_index_canister_id,
local_user_index: self.data.local_user_index_canister_id,
notifications: self.data.notifications_canister_id,
proposals_bot: self.data.proposals_bot_canister_id,
icp_ledger: Cryptocurrency::InternetComputer.ledger_canister_id().unwrap(),
},
}
Expand All @@ -156,6 +157,8 @@ struct Data {
pub local_user_index_canister_id: CanisterId,
pub group_index_canister_id: CanisterId,
pub notifications_canister_id: CanisterId,
#[serde(default = "proposals_bot_canister_id")]
pub proposals_bot_canister_id: CanisterId,
pub avatar: Timestamped<Option<Document>>,
pub test_mode: bool,
pub is_platform_moderator: bool,
Expand All @@ -179,6 +182,10 @@ struct Data {
pub next_event_expiry: Option<TimestampMillis>,
}

fn proposals_bot_canister_id() -> CanisterId {
CanisterId::from_text("iywa7-ayaaa-aaaaf-aemga-cai").unwrap()
}

impl Data {
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand All @@ -187,6 +194,7 @@ impl Data {
local_user_index_canister_id: CanisterId,
group_index_canister_id: CanisterId,
notifications_canister_id: CanisterId,
proposals_bot_canister_id: CanisterId,
username: String,
display_name: Option<String>,
test_mode: bool,
Expand All @@ -203,6 +211,7 @@ impl Data {
local_user_index_canister_id,
group_index_canister_id,
notifications_canister_id,
proposals_bot_canister_id,
avatar: Timestamped::default(),
test_mode,
is_platform_moderator: false,
Expand Down Expand Up @@ -291,5 +300,6 @@ pub struct CanisterIds {
pub group_index: CanisterId,
pub local_user_index: CanisterId,
pub notifications: CanisterId,
pub proposals_bot: CanisterId,
pub icp_ledger: CanisterId,
}
1 change: 1 addition & 0 deletions backend/canisters/user/impl/src/lifecycle/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn init(args: Args) {
args.local_user_index_canister_id,
args.group_index_canister_id,
args.notifications_canister_id,
args.proposals_bot_canister_id,
args.username,
args.display_name,
args.test_mode,
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Store `proposals_bot_canister_id` in user canisters ([#4485](https://github.com/open-chat-labs/open-chat/pull/4485))

## [[2.0.861](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.861-user_index)] - 2023-09-26

### Changed
Expand Down
4 changes: 2 additions & 2 deletions backend/canisters/user_index/api/src/lifecycle/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};
use types::{BuildVersion, CanisterId, CanisterWasm, UserId};
use types::{BuildVersion, CanisterId, CanisterWasm};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
Expand All @@ -11,9 +11,9 @@ pub struct Args {
pub local_user_index_canister_wasm: CanisterWasm,
pub group_index_canister_id: CanisterId,
pub notifications_index_canister_id: CanisterId,
pub proposals_bot_canister_id: CanisterId,
pub cycles_dispenser_canister_id: CanisterId,
pub storage_index_canister_id: CanisterId,
pub proposals_bot_user_id: UserId,
pub internet_identity_canister_id: CanisterId,
pub wasm_version: BuildVersion,
pub test_mode: bool,
Expand Down
16 changes: 13 additions & 3 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl RuntimeState {
canister_ids: CanisterIds {
group_index: self.data.group_index_canister_id,
notifications_index: self.data.notifications_index_canister_id,
proposals_bot: self.data.proposals_bot_canister_id,
cycles_dispenser: self.data.cycles_dispenser_canister_id,
internet_identity: self.data.internet_identity_canister_id,
},
Expand All @@ -165,6 +166,8 @@ struct Data {
pub local_user_index_canister_wasm_for_upgrades: CanisterWasm,
pub group_index_canister_id: CanisterId,
pub notifications_index_canister_id: CanisterId,
#[serde(default = "proposals_bot_canister_id")]
pub proposals_bot_canister_id: CanisterId,
pub canisters_requiring_upgrade: CanistersRequiringUpgrade,
pub total_cycles_spent_on_canisters: Cycles,
pub cycles_dispenser_canister_id: CanisterId,
Expand All @@ -186,6 +189,10 @@ struct Data {
pub platform_moderators_group: Option<ChatId>,
}

fn proposals_bot_canister_id() -> CanisterId {
CanisterId::from_text("iywa7-ayaaa-aaaaf-aemga-cai").unwrap()
}

impl Data {
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand All @@ -194,9 +201,9 @@ impl Data {
local_user_index_canister_wasm: CanisterWasm,
group_index_canister_id: CanisterId,
notifications_index_canister_id: CanisterId,
proposals_bot_canister_id: CanisterId,
cycles_dispenser_canister_id: CanisterId,
storage_index_canister_id: CanisterId,
proposals_bot_user_id: UserId,
internet_identity_canister_id: CanisterId,
test_mode: bool,
) -> Self {
Expand All @@ -208,6 +215,7 @@ impl Data {
local_user_index_canister_wasm_for_upgrades: local_user_index_canister_wasm,
group_index_canister_id,
notifications_index_canister_id,
proposals_bot_canister_id,
cycles_dispenser_canister_id,
canisters_requiring_upgrade: CanistersRequiringUpgrade::default(),
total_cycles_spent_on_canisters: 0,
Expand All @@ -231,8 +239,8 @@ impl Data {

// Register the ProposalsBot
data.users.register(
proposals_bot_user_id.into(),
proposals_bot_user_id,
proposals_bot_canister_id,
proposals_bot_canister_id.into(),
"ProposalsBot".to_string(),
None,
0,
Expand All @@ -255,6 +263,7 @@ impl Default for Data {
local_user_index_canister_wasm_for_upgrades: CanisterWasm::default(),
group_index_canister_id: Principal::anonymous(),
notifications_index_canister_id: Principal::anonymous(),
proposals_bot_canister_id: Principal::anonymous(),
canisters_requiring_upgrade: CanistersRequiringUpgrade::default(),
cycles_dispenser_canister_id: Principal::anonymous(),
total_cycles_spent_on_canisters: 0,
Expand Down Expand Up @@ -328,6 +337,7 @@ pub struct DiamondMembershipPaymentMetrics {
pub struct CanisterIds {
pub group_index: CanisterId,
pub notifications_index: CanisterId,
pub proposals_bot: CanisterId,
pub cycles_dispenser: CanisterId,
pub internet_identity: CanisterId,
}
2 changes: 1 addition & 1 deletion backend/canisters/user_index/impl/src/lifecycle/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fn init(args: Args) {
args.local_user_index_canister_wasm,
args.group_index_canister_id,
args.notifications_index_canister_id,
args.proposals_bot_canister_id,
args.cycles_dispenser_canister_id,
args.storage_index_canister_id,
args.proposals_bot_user_id,
args.internet_identity_canister_id,
args.test_mode,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn prepare(args: &Args, state: &RuntimeState) -> Result<PrepareResult, Response>
user_index_canister_id: state.env.canister_id(),
group_index_canister_id: state.data.group_index_canister_id,
notifications_canister_id: args.notifications_canister_id,
proposals_bot_canister_id: state.data.proposals_bot_canister_id,
cycles_dispenser_canister_id: state.data.cycles_dispenser_canister_id,
internet_identity_canister_id: state.data.internet_identity_canister_id,
test_mode: state.data.test_mode,
Expand Down
2 changes: 1 addition & 1 deletion backend/integration_tests/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ fn install_canisters(env: &mut StateMachine, controller: Principal) -> CanisterI
local_user_index_canister_wasm,
group_index_canister_id,
notifications_index_canister_id,
proposals_bot_canister_id,
cycles_dispenser_canister_id,
storage_index_canister_id,
proposals_bot_user_id: proposals_bot_canister_id.into(),
internet_identity_canister_id: NNS_INTERNET_IDENTITY_CANISTER_ID,
wasm_version: BuildVersion::min(),
test_mode: true,
Expand Down

0 comments on commit ceb321b

Please sign in to comment.