Skip to content

Commit

Permalink
Add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed May 3, 2024
1 parent 33cd2cc commit 559e1c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions bounty/src/api/accept.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::state::{Contributor, BOUNTY_STATE};

pub fn accept_impl(contributor: Contributor, github_pr_id: i32) -> () {
// FIXME check contributor is the owner of the PR
BOUNTY_STATE.with(|state| {
if let Some(ref mut bounty_canister) = *state.borrow_mut() {
// Add the contributor to the interested contributors list
Expand Down
7 changes: 7 additions & 0 deletions bounty/src/api/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub struct Contributor {
}

// Define thread-local storage for the bounty canister state
// WASM is single-threaded by nature. [RefCell] and [thread_local!] are used despite being not totally safe primitives.
// This is to ensure that the canister state can be used throughout.
// Your other option here is to avoid [thread_local!] and use a [RefCell<RwLock/Mutex/Atomic>].
// Here we use [thread_local!] because it is simpler.
thread_local! {
// Currently, a single canister smart contract is limited to 4 GB of storage due to WebAssembly limitations.
// To ensure that our canister does not exceed this limit, we restrict memory usage to at most 2 GB because
// up to 2x memory may be needed for data serialization during canister upgrades.
pub static BOUNTY_STATE: std::cell::RefCell<Option<BountyState>> = std::cell::RefCell::new(None);
}

0 comments on commit 559e1c4

Please sign in to comment.