-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the EventRelay canister (#5334)
- Loading branch information
Showing
40 changed files
with
461 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "event_relay_canister" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
candid = { workspace = true } | ||
candid_gen = { path = "../../../libraries/candid_gen" } | ||
serde = { workspace = true } | ||
types = { path = "../../../libraries/types" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
service : { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![allow(unused_imports)] | ||
|
||
mod lifecycle; | ||
mod queries; | ||
mod updates; | ||
|
||
pub use lifecycle::*; | ||
pub use queries::*; | ||
pub use updates::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use candid::{CandidType, Principal}; | ||
use serde::{Deserialize, Serialize}; | ||
use types::{BuildVersion, CanisterId}; | ||
|
||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub struct Args { | ||
pub push_events_whitelist: Vec<Principal>, | ||
pub cycles_dispenser_canister_id: CanisterId, | ||
pub wasm_version: BuildVersion, | ||
pub test_mode: bool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod init; | ||
pub mod post_upgrade; |
8 changes: 8 additions & 0 deletions
8
backend/canisters/event_relay/api/src/lifecycle/post_upgrade.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use candid::CandidType; | ||
use serde::{Deserialize, Serialize}; | ||
use types::BuildVersion; | ||
|
||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub struct Args { | ||
pub wasm_version: BuildVersion, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
candid::export_service!(); | ||
std::print!("{}", __export_service()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "event_relay_canister_impl" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
candid = { workspace = true } | ||
canister_logger = { path = "../../../libraries/canister_logger" } | ||
canister_state_macros = { path = "../../../libraries/canister_state_macros" } | ||
canister_tracing_macros = { path = "../../../libraries/canister_tracing_macros" } | ||
event_relay_canister = { path = "../api" } | ||
http_request = { path = "../../../libraries/http_request" } | ||
ic-cdk = { workspace = true } | ||
ic-cdk-macros = { workspace = true } | ||
ic-cdk-timers = { workspace = true } | ||
ic-stable-structures = { workspace = true } | ||
rand = { workspace = true } | ||
serde = { workspace = true } | ||
serializer = { path = "../../../libraries/serializer" } | ||
stable_memory = { path = "../../../libraries/stable_memory" } | ||
tracing = { workspace = true } | ||
types = { path = "../../../libraries/types" } | ||
utils = { path = "../../../libraries/utils" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use candid::Principal; | ||
use canister_state_macros::canister_state; | ||
use serde::{Deserialize, Serialize}; | ||
use std::cell::RefCell; | ||
use std::collections::HashSet; | ||
use types::{BuildVersion, CanisterId, Cycles, TimestampMillis, Timestamped}; | ||
use utils::env::Environment; | ||
|
||
mod lifecycle; | ||
mod memory; | ||
mod model; | ||
mod queries; | ||
mod updates; | ||
|
||
thread_local! { | ||
static WASM_VERSION: RefCell<Timestamped<BuildVersion>> = RefCell::default(); | ||
} | ||
|
||
canister_state!(RuntimeState); | ||
|
||
struct RuntimeState { | ||
pub env: Box<dyn Environment>, | ||
pub data: Data, | ||
} | ||
|
||
impl RuntimeState { | ||
pub fn new(env: Box<dyn Environment>, data: Data) -> RuntimeState { | ||
RuntimeState { env, data } | ||
} | ||
|
||
pub fn metrics(&self) -> Metrics { | ||
Metrics { | ||
memory_used: utils::memory::used(), | ||
now: self.env.now(), | ||
cycles_balance: self.env.cycles_balance(), | ||
wasm_version: WASM_VERSION.with_borrow(|v| **v), | ||
git_commit_id: utils::git::git_commit_id().to_string(), | ||
push_events_whitelist: self.data.push_events_whitelist.iter().copied().collect(), | ||
canister_ids: CanisterIds { | ||
cycles_dispenser: self.data.cycles_dispenser_canister_id, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
struct Data { | ||
pub push_events_whitelist: HashSet<Principal>, | ||
pub cycles_dispenser_canister_id: CanisterId, | ||
pub rng_seed: [u8; 32], | ||
pub test_mode: bool, | ||
} | ||
|
||
impl Data { | ||
pub fn new(push_events_whitelist: HashSet<Principal>, cycles_dispenser_canister_id: CanisterId, test_mode: bool) -> Data { | ||
Data { | ||
push_events_whitelist, | ||
cycles_dispenser_canister_id, | ||
rng_seed: [0; 32], | ||
test_mode, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
pub struct Metrics { | ||
pub now: TimestampMillis, | ||
pub memory_used: u64, | ||
pub cycles_balance: Cycles, | ||
pub wasm_version: BuildVersion, | ||
pub git_commit_id: String, | ||
pub push_events_whitelist: Vec<Principal>, | ||
pub canister_ids: CanisterIds, | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
pub struct CanisterIds { | ||
pub cycles_dispenser: CanisterId, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::lifecycle::{init_env, init_state}; | ||
use crate::Data; | ||
use canister_tracing_macros::trace; | ||
use event_relay_canister::init::Args; | ||
use ic_cdk_macros::init; | ||
use tracing::info; | ||
use utils::cycles::init_cycles_dispenser_client; | ||
|
||
#[init] | ||
#[trace] | ||
fn init(args: Args) { | ||
canister_logger::init(args.test_mode); | ||
init_cycles_dispenser_client(args.cycles_dispenser_canister_id, args.test_mode); | ||
|
||
let env = init_env([0; 32]); | ||
let data = Data::new( | ||
args.push_events_whitelist.into_iter().collect(), | ||
args.cycles_dispenser_canister_id, | ||
args.test_mode, | ||
); | ||
|
||
init_state(env, data, args.wasm_version); | ||
|
||
info!(version = %args.wasm_version, "Initialization complete"); | ||
} |
Oops, something went wrong.