Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ree-cookie-canister/src/canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::{
memory::{
mutate_state, read_state, set_state, ADDRESS_PRINCIPLE_MAP, BLOCKS, GAMER, TX_RECORDS,
},
state::{ExchangeState, GameStatus, PoolState},
state::{ExchangeState, PoolState},
utils::{
calculate_premine_rune_amount, tweak_pubkey_with_empty, AddLiquidityInfo, RegisterInfo,
calculate_premine_rune_amount, tweak_pubkey_with_empty, AddLiquidityInfo, ExecuteTxGuard, RegisterInfo
},
ExchangeError, Seconds, MIN_BTC_VALUE,
};
Expand Down Expand Up @@ -291,6 +291,9 @@ pub async fn execute_tx(args: ExecuteTxArgs) -> ExecuteTxResponse {
output_coins,
} = intention;

let _guard = ExecuteTxGuard::new(pool_address.clone())
.ok_or(format!("Pool {0} Executing", pool_address).to_string())?;

read_state(|s| {
return s
.address
Expand Down
5 changes: 4 additions & 1 deletion ree-cookie-canister/src/memory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub(crate) use std::cell::RefCell;
use std::collections::HashSet;

use candid::Principal;
use ic_stable_structures::{
Expand Down Expand Up @@ -52,6 +53,8 @@ thread_local! {
MEMORY_MANAGER.with(|m| m.borrow().get(TX_RECORDS_MEMORY_ID)),
)
);

pub static EXECUTING_POOLS: RefCell<HashSet<String>> = RefCell::new(HashSet::new());

}

Expand Down Expand Up @@ -94,4 +97,4 @@ where
let state = get_state();
let r = f(&state);
r
}
}
1 change: 0 additions & 1 deletion ree-cookie-canister/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use ic_cdk::api::management_canister::bitcoin::Satoshi;
use ic_stable_structures::storable::Bound;
use ic_stable_structures::Storable;
use itertools::Itertools;
use ree_types::{CoinBalance, CoinId, InputCoin, OutputCoin};
use std::borrow::Cow;

Expand Down
28 changes: 27 additions & 1 deletion ree-cookie-canister/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
use ic_cdk::api::management_canister::bitcoin::{BitcoinNetwork, Satoshi};
use ree_types::bitcoin::key::{Secp256k1, TapTweak, TweakedPublicKey};

use crate::{memory::read_state, *};
use crate::{
memory::{read_state, EXECUTING_POOLS},
*,
};

#[must_use]
pub struct ExecuteTxGuard(String);

impl ExecuteTxGuard {
pub fn new(pool_address: String) -> Option<Self> {
EXECUTING_POOLS.with(|executing_pools| {
if executing_pools.borrow().contains(&pool_address) {
return None;
}
executing_pools.borrow_mut().insert(pool_address.clone());
return Some(ExecuteTxGuard(pool_address));
})
}
}

impl Drop for ExecuteTxGuard {
fn drop(&mut self) {
EXECUTING_POOLS.with_borrow_mut(|executing_pools| {
executing_pools.remove(&self.0);
});
}
}

pub(crate) fn tweak_pubkey_with_empty(untweaked: Pubkey) -> TweakedPublicKey {
let secp = Secp256k1::new();
Expand Down