Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make extrinsics #[transactional] #576

Merged
merged 8 commits into from
May 14, 2022
Merged
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
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
1 change: 1 addition & 0 deletions zrml/liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(T::WeightInfo::set_per_block_distribution())]
// MARK(non-transactional): `set_per_block_distribution` is infallible.
pub fn set_per_block_distribution(
origin: OriginFor<T>,
#[pallet::compact] 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 @@ -63,6 +63,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 @@ -107,6 +108,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
23 changes: 19 additions & 4 deletions zrml/prediction-markets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mod pallet {
T::MaxCategories::get().into()
))
)]
#[transactional]
pub fn admin_destroy_market(
origin: OriginFor<T>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -224,6 +225,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>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -255,6 +257,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>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand All @@ -281,6 +284,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>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -384,6 +388,7 @@ mod pallet {
}

#[pallet::weight(T::WeightInfo::create_categorical_market())]
#[transactional]
pub fn create_categorical_market(
origin: OriginFor<T>,
oracle: T::AccountId,
Expand All @@ -404,8 +409,11 @@ mod pallet {
Self::ensure_market_start_is_in_time(&period)?;
}

// Require sha3-384 as multihash.
let MultiHash::Sha3_384(multihash) = metadata;
// Require sha3-384 as multihash. TODO(#608) The irrefutable `if let` is a workaround
// for a compiler error. Link an issue for this!
#[allow(irrefutable_let_patterns)]
let multihash =
if let MultiHash::Sha3_384(multihash) = metadata { multihash } else { [0u8; 50] };
ensure!(multihash[0] == 0x15 && multihash[1] == 0x30, <Error<T>>::InvalidMultihash);

let status: MarketStatus = match creation {
Expand Down Expand Up @@ -566,6 +574,7 @@ mod pallet {
}

#[pallet::weight(T::WeightInfo::create_scalar_market())]
#[transactional]
pub fn create_scalar_market(
origin: OriginFor<T>,
oracle: T::AccountId,
Expand All @@ -585,8 +594,11 @@ mod pallet {
Self::ensure_market_start_is_in_time(&period)?;
}

// Require sha3-384 as multihash.
let MultiHash::Sha3_384(multihash) = metadata;
// Require sha3-384 as multihash. TODO(#608) The irrefutable `if let` is a workaround
// for a compiler error. Link an issue for this!
#[allow(irrefutable_let_patterns)]
let multihash =
if let MultiHash::Sha3_384(multihash) = metadata { multihash } else { [0u8; 50] };
ensure!(multihash[0] == 0x15 && multihash[1] == 0x30, <Error<T>>::InvalidMultihash);

let status: MarketStatus = match creation {
Expand Down Expand Up @@ -788,6 +800,7 @@ mod pallet {
#[pallet::weight(T::WeightInfo::redeem_shares_categorical()
.max(T::WeightInfo::redeem_shares_scalar())
)]
#[transactional]
pub fn redeem_shares(
origin: OriginFor<T>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -917,6 +930,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>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -1006,6 +1020,7 @@ mod pallet {
#[pallet::weight(
T::WeightInfo::sell_complete_set(T::MaxCategories::get().into())
)]
#[transactional]
pub fn sell_complete_set(
origin: OriginFor<T>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down
21 changes: 12 additions & 9 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,
transactional, Blake2_128Concat, PalletId, Twox64Concat,
};
use frame_system::{ensure_root, ensure_signed, pallet_prelude::OriginFor};
use orml_traits::{BalanceStatus, MultiCurrency, MultiReservableCurrency};
Expand Down Expand Up @@ -86,7 +86,7 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(T::WeightInfo::admin_set_pool_to_stale())]
#[frame_support::transactional]
#[transactional]
pub fn admin_set_pool_to_stale(
origin: OriginFor<T>,
#[pallet::compact] market_id: <<T as Config>::MarketCommons as MarketCommonsPalletApi>::MarketId,
Expand Down Expand Up @@ -117,7 +117,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>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -168,6 +168,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>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -258,6 +259,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.
maltekliemann marked this conversation as resolved.
Show resolved Hide resolved
pub fn pool_exit_with_exact_asset_amount(
origin: OriginFor<T>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -290,7 +292,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>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -358,7 +360,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>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -402,7 +404,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())]
#[frame_support::transactional]
#[transactional]
pub fn pool_join_subsidy(
origin: OriginFor<T>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -466,6 +468,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 @@ -499,7 +502,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>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -563,7 +566,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>,
#[pallet::compact] pool_id: PoolId,
Expand Down Expand Up @@ -600,7 +603,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>,
#[pallet::compact] pool_id: PoolId,
Expand Down