Skip to content

Commit

Permalink
Make extrinsics #[transactional]
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann committed Apr 20, 2022
1 parent f1d45f6 commit 69c4c3a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
9 changes: 3 additions & 6 deletions zrml/court/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
// `transactional` attribute is not used simply because
// `remove_juror_from_all_courts_of_all_markets` is infallible.
// MARK(non-transactional): `remove_juror_from_all_courts_of_all_markets` is infallible.
#[pallet::weight(T::WeightInfo::exit_court())]
pub fn exit_court(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand All @@ -87,8 +86,7 @@ mod pallet {
Ok(())
}

// `transactional` attribute is not used here because once `reserve_named` is
// successful, `insert` won't fail.
// MARK(non-transactional): Once `reserve_named` is successful, `insert` won't fail.
#[pallet::weight(T::WeightInfo::join_court())]
pub fn join_court(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand All @@ -105,8 +103,7 @@ mod pallet {
Ok(())
}

// `transactional` attribute is not used here because no fallible storage operation
// is performed.
// MARK(non-transactional): No fallible storage operation is performed.
#[pallet::weight(T::WeightInfo::vote())]
pub fn vote(
origin: OriginFor<T>,
Expand Down
3 changes: 2 additions & 1 deletion zrml/liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod pallet {
traits::{
Currency, ExistenceRequirement, Get, Hooks, IsType, StorageVersion, WithdrawReasons,
},
Blake2_128Concat, PalletId, Twox64Concat,
transactional, Blake2_128Concat, PalletId, Twox64Concat,
};
use frame_system::{ensure_root, pallet_prelude::OriginFor};
use sp_runtime::{
Expand All @@ -78,6 +78,7 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(T::WeightInfo::set_per_block_distribution())]
#[transactional]
pub fn set_per_block_distribution(
origin: OriginFor<T>,
per_block_distribution: BalanceOf<T>,
Expand Down
2 changes: 2 additions & 0 deletions zrml/orderbook-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod pallet {
#[pallet::weight(
T::WeightInfo::cancel_order_ask().max(T::WeightInfo::cancel_order_bid())
)]
#[transactional]
pub fn cancel_order(
origin: OriginFor<T>,
asset: Asset<T::MarketId>,
Expand Down Expand Up @@ -109,6 +110,7 @@ mod pallet {
#[pallet::weight(
T::WeightInfo::fill_order_ask().max(T::WeightInfo::fill_order_bid())
)]
#[transactional]
pub fn fill_order(origin: OriginFor<T>, order_hash: T::Hash) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
let mut bid = true;
Expand Down
11 changes: 11 additions & 0 deletions zrml/prediction-markets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ mod pallet {
T::MaxCategories::get().into()
))
)]
#[transactional]
pub fn admin_destroy_market(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -191,6 +192,7 @@ mod pallet {
// Within the same block, operations that interact with the activeness of the same
// market will behave differently before and after this call.
#[pallet::weight(T::WeightInfo::admin_move_market_to_closed())]
#[transactional]
pub fn admin_move_market_to_closed(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -222,6 +224,7 @@ mod pallet {
T::MaxCategories::get().into()
).saturating_sub(T::WeightInfo::internal_resolve_scalar_reported())
))]
#[transactional]
pub fn admin_move_market_to_resolved(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand All @@ -248,6 +251,7 @@ mod pallet {
/// NOTE: Can only be called by the `ApprovalOrigin`.
///
#[pallet::weight(T::WeightInfo::approve_market())]
#[transactional]
pub fn approve_market(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -355,6 +359,7 @@ mod pallet {
/// See also: Polkadot Treasury
///
#[pallet::weight(T::WeightInfo::cancel_pending_market())]
#[transactional]
pub fn cancel_pending_market(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand All @@ -376,6 +381,7 @@ mod pallet {
}

#[pallet::weight(T::WeightInfo::create_categorical_market())]
#[transactional]
pub fn create_categorical_market(
origin: OriginFor<T>,
oracle: T::AccountId,
Expand Down Expand Up @@ -557,6 +563,7 @@ mod pallet {
}

#[pallet::weight(T::WeightInfo::create_scalar_market())]
#[transactional]
pub fn create_scalar_market(
origin: OriginFor<T>,
oracle: T::AccountId,
Expand Down Expand Up @@ -778,6 +785,7 @@ mod pallet {
/// NOTE: Requires the market to be already disputed `MaxDisputes` amount of times.
///
#[pallet::weight(10_000_000)]
#[transactional]
pub fn global_dispute(origin: OriginFor<T>, market_id: MarketIdOf<T>) -> DispatchResult {
let _sender = ensure_signed(origin)?;
let _market = T::MarketCommons::market(&market_id)?;
Expand All @@ -790,6 +798,7 @@ mod pallet {
#[pallet::weight(T::WeightInfo::redeem_shares_categorical()
.max(T::WeightInfo::redeem_shares_scalar())
)]
#[transactional]
pub fn redeem_shares(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -919,6 +928,7 @@ mod pallet {

/// Rejects a market that is waiting for approval from the advisory committee.
#[pallet::weight(T::WeightInfo::reject_market())]
#[transactional]
pub fn reject_market(origin: OriginFor<T>, market_id: MarketIdOf<T>) -> DispatchResult {
T::ApprovalOrigin::ensure_origin(origin)?;

Expand Down Expand Up @@ -1005,6 +1015,7 @@ mod pallet {
#[pallet::weight(
T::WeightInfo::sell_complete_set(T::MaxCategories::get().into())
)]
#[transactional]
pub fn sell_complete_set(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand Down
20 changes: 12 additions & 8 deletions zrml/swaps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod pallet {
pallet_prelude::{StorageDoubleMap, StorageMap, StorageValue, ValueQuery},
storage::{with_transaction, TransactionOutcome},
traits::{Get, IsType, StorageVersion},
Blake2_128Concat, PalletId, Twox64Concat,
Blake2_128Concat, PalletId, Twox64Concat, transactional
};
use frame_system::{ensure_root, ensure_signed, pallet_prelude::OriginFor};
use orml_traits::{BalanceStatus, MultiCurrency, MultiReservableCurrency};
Expand Down Expand Up @@ -85,7 +85,7 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(T::WeightInfo::admin_set_pool_as_stale())]
#[frame_support::transactional]
#[transactional]
pub fn admin_set_pool_as_stale(
origin: OriginFor<T>,
market_type: MarketType,
Expand Down Expand Up @@ -115,7 +115,7 @@ mod pallet {
/// * `min_assets_out`: List of asset lower bounds. No asset should be lower than the
/// provided values.
#[pallet::weight(T::WeightInfo::pool_exit(min_assets_out.len() as u32))]
#[frame_support::transactional]
#[transactional]
pub fn pool_exit(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -166,6 +166,7 @@ mod pallet {
/// * `pool_id`: Unique pool identifier.
/// * `amount`: The amount of base currency that should be removed from subsidy.
#[pallet::weight(T::WeightInfo::pool_exit_subsidy())]
#[transactional]
pub fn pool_exit_subsidy(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -250,6 +251,7 @@ mod pallet {
/// * `max_pool_amount`: The calculated amount of assets for the pool must be equal or
/// greater than the given value.
#[pallet::weight(T::WeightInfo::pool_exit_with_exact_asset_amount())]
// MARK(non-transactional): Immediately calls and returns a transactional.
pub fn pool_exit_with_exact_asset_amount(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -282,7 +284,7 @@ mod pallet {
/// * `min_asset_amount`: The calculated amount for the asset must the equal or less
/// than the given value.
#[pallet::weight(T::WeightInfo::pool_exit_with_exact_pool_amount())]
#[frame_support::transactional]
#[transactional]
pub fn pool_exit_with_exact_pool_amount(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -350,7 +352,7 @@ mod pallet {
/// * `max_assets_in`: List of asset upper bounds. No asset should be greater than the
/// provided values.
#[pallet::weight(T::WeightInfo::pool_join(max_assets_in.len() as u32))]
#[frame_support::transactional]
#[transactional]
pub fn pool_join(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -394,6 +396,7 @@ mod pallet {
/// * `pool_id`: Unique pool identifier.
/// * `amount`: The amount of base currency that should be added to subsidy.
#[pallet::weight(T::WeightInfo::pool_join_subsidy())]
#[transactional]
pub fn pool_join_subsidy(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -445,6 +448,7 @@ mod pallet {
/// * `asset_amount`: Asset amount that is entering the pool.
/// * `min_pool_amount`: The calculated amount for the pool must be equal or greater
/// than the given value.
// MARK(non-transactional): Immediately calls and returns a transactional.
#[pallet::weight(T::WeightInfo::pool_join_with_exact_asset_amount())]
pub fn pool_join_with_exact_asset_amount(
origin: OriginFor<T>,
Expand Down Expand Up @@ -478,7 +482,7 @@ mod pallet {
/// * `max_asset_amount`: The calculated amount of assets for the pool must be equal or
/// less than the given value.
#[pallet::weight(T::WeightInfo::pool_join_with_exact_pool_amount())]
#[frame_support::transactional]
#[transactional]
pub fn pool_join_with_exact_pool_amount(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -542,7 +546,7 @@ mod pallet {
/// * `min_asset_amount_out`: Minimum asset amount that can leave the pool.
/// * `max_price`: Market price must be equal or less than the provided value.
#[pallet::weight(T::WeightInfo::swap_exact_amount_in_rikiddo(T::MaxAssets::get().into()))]
#[frame_support::transactional]
#[transactional]
pub fn swap_exact_amount_in(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down Expand Up @@ -579,7 +583,7 @@ mod pallet {
/// * `asset_amount_out`: Amount that will be transferred from the pool to the provider.
/// * `max_price`: Market price must be equal or less than the provided value.
#[pallet::weight(T::WeightInfo::swap_exact_amount_out_rikiddo(T::MaxAssets::get().into()))]
#[frame_support::transactional]
#[transactional]
pub fn swap_exact_amount_out(
origin: OriginFor<T>,
pool_id: PoolId,
Expand Down

0 comments on commit 69c4c3a

Please sign in to comment.