Skip to content

Commit

Permalink
Update polkadot v0.9.31 (#847)
Browse files Browse the repository at this point in the history
* claim_rewards should not create empty records (#835)

* refactor: make weight argument in xtokens transfers optional (#841)

* refactor: make weight argument in xtokens be of type WeightLimit

* refactor: rename dest_weight -> dest_weight_limit

* prevent nested DelayedOrigin (#845)

* prevent nested DelayedOrigin

* fix deps

* Update authority/src/tests.rs

Co-authored-by: zjb0807 <zjb0807@qq.com>

* allow nested DelayedOrigin

* update docstring

* typo fix

Co-authored-by: zjb0807 <zjb0807@qq.com>

* Add try-runtime feature for orml-payments (#846)

* Add try-runtime feature for orml-payments

* Add features

Co-authored-by: wangjj9219 <183318287@qq.com>
Co-authored-by: sander2 <sanderbosma@gmail.com>
Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
  • Loading branch information
4 people authored Nov 22, 2022
1 parent 4ab13d2 commit ce4d97a
Show file tree
Hide file tree
Showing 25 changed files with 526 additions and 281 deletions.
27 changes: 17 additions & 10 deletions asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ serde = { version = "1.0.136", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] }

# substrate
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }

# polkadot
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" }
Expand All @@ -29,9 +29,9 @@ orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = fa

[dev-dependencies]
# substrate
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }

# cumulus
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" }
Expand All @@ -47,30 +47,37 @@ xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "rele

# orml
orml-tokens = { path = "../tokens" }
orml-xtokens = { path = "../xtokens" }
orml-xcm = { path = "../xcm" }
orml-xcm-support = { path = "../xcm-support", default-features = false }
orml-xtokens = { path = "../xtokens" }

[features]
default = ["std"]
std = [
"serde",

"codec/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"frame-support/std",
"frame-system/std",
"orml-traits/std",
"pallet-xcm/std",
"xcm/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-xcm/try-runtime",
]
try-runtime = ["frame-support/try-runtime"]
8 changes: 4 additions & 4 deletions asset-registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn send_self_parachain_asset_to_sibling() {
)
.into()
),
40,
WeightLimit::Unlimited,
));

assert_eq!(ParaTokens::free_balance(CurrencyId::RegisteredAsset(1), &ALICE), 500);
Expand Down Expand Up @@ -204,7 +204,7 @@ fn send_sibling_asset_to_non_reserve_sibling() {
)
.into()
),
40
WeightLimit::Unlimited
));
assert_eq!(ParaTokens::free_balance(CurrencyId::RegisteredAsset(1), &ALICE), 500);
});
Expand Down Expand Up @@ -302,7 +302,7 @@ fn test_fixed_rate_asset_trader() {
)
.into()
),
40,
WeightLimit::Unlimited,
));
});

Expand Down Expand Up @@ -353,7 +353,7 @@ fn test_fixed_rate_asset_trader() {
)
.into()
),
40,
WeightLimit::Unlimited,
));
});

Expand Down
18 changes: 11 additions & 7 deletions auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ authors = ["Acala Developers"]
edition = "2021"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
serde = { version = "1.0.136", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }

sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }

orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false }

Expand All @@ -27,12 +27,16 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0
default = ["std"]
std = [
"serde",

"codec/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"frame-support/std",
"frame-system/std",
"orml-traits/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
28 changes: 17 additions & 11 deletions authority/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,42 @@ authors = ["Acala Developers"]
edition = "2021"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
serde = { version = "1.0.145", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }

sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }

[dev-dependencies]
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }

[features]
default = ["std"]
std = [
"serde",

"codec/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"sp-io/std",
"frame-support/std",
"frame-system/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
try-runtime = ["frame-support/try-runtime"]
74 changes: 67 additions & 7 deletions authority/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
//! Two functionalities are provided by this module:
//! - schedule a dispatchable
//! - dispatch method with on behalf of other origins
//!
//! NOTE:
//!
//! In order to derive a feasible max encoded len for `DelayedOrigin`, it is
//! assumed that there are no nested `DelayedOrigin` in `OriginCaller`.
//! In practice, this means there should not be nested `schedule_dispatch`.
//! Otherwise the proof size estimation may not be accurate.
#![cfg_attr(not(feature = "std"), no_std)]
// Disable the following three lints since they originate from an external macro
Expand All @@ -32,6 +39,7 @@ use frame_support::{
};
use frame_system::{pallet_prelude::*, EnsureRoot, EnsureSigned};
use scale_info::TypeInfo;
use sp_core::defer;
use sp_runtime::{
traits::{CheckedSub, Dispatchable, Hash, Saturating},
ArithmeticError, DispatchError, DispatchResult, Either, RuntimeDebug,
Expand All @@ -45,12 +53,64 @@ mod weights;
pub use weights::WeightInfo;

/// A delayed origin. Can only be dispatched via `dispatch_as` with a delay.
#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo)]
pub struct DelayedOrigin<BlockNumber, PalletsOrigin> {
/// Number of blocks that this call have been delayed.
pub delay: BlockNumber,
pub(crate) delay: BlockNumber,
/// The initial origin.
pub origin: Box<PalletsOrigin>,
pub(crate) origin: Box<PalletsOrigin>,
}

#[cfg(feature = "std")]
mod helper {
use std::cell::RefCell;

thread_local! {
static NESTED_MAX_ENCODED_LEN: RefCell<bool> = RefCell::new(false);
}

pub fn set_nested_max_encoded_len(val: bool) {
NESTED_MAX_ENCODED_LEN.with(|v| *v.borrow_mut() = val);
}

pub fn nested_max_encoded_len() -> bool {
NESTED_MAX_ENCODED_LEN.with(|v| *v.borrow())
}
}

#[cfg(not(feature = "std"))]
mod helper {
static mut NESTED_MAX_ENCODED_LEN: bool = false;

pub fn set_nested_max_encoded_len(val: bool) {
unsafe {
NESTED_MAX_ENCODED_LEN = val;
}
}

pub fn nested_max_encoded_len() -> bool {
unsafe { NESTED_MAX_ENCODED_LEN }
}
}

// Manual implementation to break recursive calls of `MaxEncodedLen` as the
// implementation of `PalletsOrigin::max_encoded_len` will also call
// `MaxEncodedLen` on `DelayedOrigin`. This is only safe if there are no nested
// `DelayedOrigin`. It is only possible to construct a `DelayedOrigin` via
// `schedule_dispatch` which is a protected call only accessible via governance.
impl<BlockNumber: MaxEncodedLen, PalletsOrigin: MaxEncodedLen> MaxEncodedLen
for DelayedOrigin<BlockNumber, PalletsOrigin>
{
fn max_encoded_len() -> usize {
if helper::nested_max_encoded_len() {
return 0;
}

helper::set_nested_max_encoded_len(true);
defer!(helper::set_nested_max_encoded_len(false));

BlockNumber::max_encoded_len() + PalletsOrigin::max_encoded_len()
}
}

/// Ensure the origin have a minimum amount of delay.
Expand Down Expand Up @@ -99,10 +159,10 @@ pub trait AuthorityConfig<Origin, PalletsOrigin, BlockNumber> {
new_delay: BlockNumber,
) -> DispatchResult;
/// Check if the `origin` is allow to delay a scheduled task that
/// initially created by `inital_origin`.
/// initially created by `initial_origin`.
fn check_delay_schedule(origin: Origin, initial_origin: &PalletsOrigin) -> DispatchResult;
/// Check if the `origin` is allow to cancel a scheduled task that
/// initially created by `inital_origin`.
/// initially created by `initial_origin`.
fn check_cancel_schedule(origin: Origin, initial_origin: &PalletsOrigin) -> DispatchResult;
}

Expand Down Expand Up @@ -396,12 +456,12 @@ pub mod module {

#[pallet::weight(T::WeightInfo::remove_authorized_call())]
pub fn remove_authorized_call(origin: OriginFor<T>, hash: T::Hash) -> DispatchResult {
let root_or_sigend =
let root_or_signed =
EitherOfDiverse::<EnsureRoot<T::AccountId>, EnsureSigned<T::AccountId>>::ensure_origin(origin)?;

SavedCalls::<T>::try_mutate_exists(hash, |maybe_call| {
let (_, maybe_caller) = maybe_call.take().ok_or(Error::<T>::CallNotAuthorized)?;
match root_or_sigend {
match root_or_signed {
Either::Left(_) => {} // root, do nothing
Either::Right(who) => {
// signed, ensure it's the caller
Expand Down
7 changes: 7 additions & 0 deletions authority/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![cfg(test)]

use super::*;
use codec::MaxEncodedLen;
use frame_support::{
assert_noop, assert_ok,
dispatch::DispatchErrorWithPostInfo,
Expand Down Expand Up @@ -691,3 +692,9 @@ fn trigger_old_call_should_be_free_and_operational() {
);
});
}

#[test]
fn origin_max_encoded_len_works() {
assert_eq!(DelayedOrigin::<u32, OriginCaller>::max_encoded_len(), 22);
assert_eq!(OriginCaller::max_encoded_len(), 27);
}
25 changes: 14 additions & 11 deletions benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ authors = ["Laminar Developers <hello@laminar.one>"]
edition = "2021"

[dependencies]
serde = { version = "1.0.136", optional = true }
paste = "1.0.7"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
log = { version = "0.4.17", default-features = false }
paste = "1.0.7"
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
serde = { version = "1.0.136", optional = true }

frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" }

[dev-dependencies]
hex-literal = "0.3.4"
Expand All @@ -32,13 +32,16 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk
default = [ "std" ]
std = [
"serde",

"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"log/std",
"scale-info/std",
"sp-api/std",
"sp-io/std",
"sp-runtime-interface/std",
"sp-runtime/std",
"sp-api/std",
"sp-std/std",
"frame-support/std",
"frame-benchmarking/std",
"log/std",
"sp-storage/std",
]
Loading

0 comments on commit ce4d97a

Please sign in to comment.