Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jul 12, 2023
1 parent 62d0fb0 commit 71e2dd6
Show file tree
Hide file tree
Showing 34 changed files with 171 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repository = "https://github.com/AstarNetwork/Astar"
# General deps
# (wasm)
parity-scale-codec = { version = "3.4.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
log = { version = "0.4.17", default-features = false }
environmental = { version = "1.1.2", default-features = false }
sha3 = { version = "0.10.1", default-features = false }
Expand All @@ -67,7 +67,7 @@ bounded-collections = { version = "0.1.5", default-features = false }
array-bytes = "6.0.0"
smallvec = "1.9.0"
async-trait = "0.1.59"
clap = { version = "4.1.6", features = ["derive"] }
clap = { version = "4.2.5", features = ["derive"] }
futures = { version = "0.3.26" }
serde = { version = "1.0.151", features = ["derive"] }
serde_json = "1.0.92"
Expand Down
18 changes: 6 additions & 12 deletions bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ pub fn new_partial(
>,
ServiceError,
> {
if config.keystore_remote.is_some() {
return Err(ServiceError::Other(
"Remote Keystores are not supported.".to_string(),
));
}

let telemetry = config
.telemetry_endpoints
.clone()
Expand Down Expand Up @@ -368,7 +362,7 @@ pub fn start_node(
let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
keystore: keystore_container.sync_keystore(),
keystore: keystore_container.keystore(),
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
rpc_builder: rpc_extensions_builder,
Expand Down Expand Up @@ -411,7 +405,7 @@ pub fn start_node(
},
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
keystore: keystore_container.keystore(),
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
Expand All @@ -431,7 +425,7 @@ pub fn start_node(
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() {
Some(keystore_container.sync_keystore())
Some(keystore_container.keystore())
} else {
None
};
Expand Down Expand Up @@ -630,7 +624,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
keystore: keystore_container.sync_keystore(),
keystore: keystore_container.keystore(),
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
rpc_builder: rpc_extensions_builder,
Expand Down Expand Up @@ -673,7 +667,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
},
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
keystore: keystore_container.keystore(),
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
Expand All @@ -693,7 +687,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() {
Some(keystore_container.sync_keystore())
Some(keystore_container.keystore())
} else {
None
};
Expand Down
8 changes: 4 additions & 4 deletions bin/collator/src/parachain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ where
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
config: parachain_config,
keystore: params.keystore_container.sync_keystore(),
keystore: params.keystore_container.keystore(),
backend: backend.clone(),
network: network.clone(),
system_rpc_tx,
Expand Down Expand Up @@ -557,7 +557,7 @@ where
relay_chain_interface.clone(),
transaction_pool,
sync_service,
params.keystore_container.sync_keystore(),
params.keystore_container.keystore(),
force_authoring,
)?;

Expand Down Expand Up @@ -874,7 +874,7 @@ where
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
config: parachain_config,
keystore: params.keystore_container.sync_keystore(),
keystore: params.keystore_container.keystore(),
backend: backend.clone(),
network: network.clone(),
system_rpc_tx,
Expand Down Expand Up @@ -904,7 +904,7 @@ where
relay_chain_interface.clone(),
transaction_pool,
sync_service,
params.keystore_container.sync_keystore(),
params.keystore_container.keystore(),
force_authoring,
)?;

Expand Down
4 changes: 4 additions & 0 deletions pallets/block-reward/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl pallet_balances::Config for TestRuntime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

parameter_types! {
Expand Down
4 changes: 2 additions & 2 deletions pallets/contracts-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub mod pallet {
initial: old.initial,
maximum: old.maximum,
code: old.code,
determinism: Determinism::Deterministic,
determinism: pallet_contracts::Enforced,
})
});

Expand Down Expand Up @@ -297,7 +297,7 @@ pub mod pallet {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
for value in CodeStorage::<T>::iter_values() {
ensure!(
value.determinism == Determinism::Deterministic,
value.determinism == Determinism::Enforced,
"All pre-existing codes need to be deterministic."
);
}
Expand Down
4 changes: 4 additions & 0 deletions pallets/custom-signatures/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ impl pallet_balances::Config for Runtime {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

const MAGIC_NUMBER: u16 = 0xff50;
Expand Down
5 changes: 5 additions & 0 deletions pallets/dapps-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ impl pallet_balances::Config for TestRuntime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
// TODO: modify this properly, will need some freeze identifier
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

parameter_types! {
Expand Down
4 changes: 4 additions & 0 deletions pallets/ethereum-checked/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ impl pallet_balances::Config for TestRuntime {
type ExistentialDeposit = ConstU128<2>;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

impl pallet_timestamp::Config for TestRuntime {
Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ benchmarks! {
Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateSupportedVersion, Weight::zero());
}

force_suspension {}: _(RawOrigin::Root, true)

migrate_version_notifiers {
let old_version = XCM_VERSION - 1;
let loc = VersionedMultiLocation::from(MultiLocation::from(Parent));
Expand Down
46 changes: 41 additions & 5 deletions pallets/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use frame_system::pallet_prelude::*;
pub use pallet::*;
use xcm_executor::{
traits::{
ClaimAssets, DropAssets, MatchesFungible, OnResponse, VersionChangeNotifier, WeightBounds,
ClaimAssets, DropAssets, MatchesFungible, OnResponse, VersionChangeNotifier, WeightBounds, CheckSuspension,
},
Assets,
};
Expand All @@ -69,6 +69,7 @@ pub trait WeightInfo {
fn force_default_xcm_version() -> Weight;
fn force_subscribe_version_notify() -> Weight;
fn force_unsubscribe_version_notify() -> Weight;
fn force_suspension() -> Weight;
fn migrate_supported_version() -> Weight;
fn migrate_version_notifiers() -> Weight;
fn already_notified_target() -> Weight;
Expand Down Expand Up @@ -114,6 +115,10 @@ impl WeightInfo for TestWeightInfo {
Weight::from_parts(100_000_000, 0)
}

fn force_suspension() -> Weight {
Weight::from_parts(100_000_000, 0)
}

fn migrate_supported_version() -> Weight {
Weight::from_parts(100_000_000, 0)
}
Expand Down Expand Up @@ -257,6 +262,10 @@ pub mod pallet {
/// If `None`, the benchmarks that depend on a reachable destination will be skipped.
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest: Get<Option<MultiLocation>>;

/// The origin that is allowed to call privileged operations on the XCM pallet
type AdminOrigin: EnsureOrigin<<Self as SysConfig>::RuntimeOrigin>;

}

#[pallet::event]
Expand Down Expand Up @@ -623,6 +632,10 @@ pub mod pallet {
OptionQuery,
>;

/// Global suspension state of the XCM executor.
#[pallet::storage]
pub(super) type XcmExecutionSuspended<T: Config> = StorageValue<_, bool, ValueQuery>;

#[pallet::genesis_config]
pub struct GenesisConfig {
/// The default version to encode outgoing XCM messages with.
Expand Down Expand Up @@ -941,7 +954,7 @@ pub mod pallet {
location: Box<MultiLocation>,
xcm_version: XcmVersion,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
let location = *location;
SupportedVersion::<T>::insert(
XCM_VERSION,
Expand All @@ -963,7 +976,7 @@ pub mod pallet {
origin: OriginFor<T>,
maybe_xcm_version: Option<XcmVersion>,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
SafeXcmVersion::<T>::set(maybe_xcm_version);
Ok(())
}
Expand All @@ -978,7 +991,7 @@ pub mod pallet {
origin: OriginFor<T>,
location: Box<VersionedMultiLocation>,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
let location: MultiLocation = (*location)
.try_into()
.map_err(|()| Error::<T>::BadLocation)?;
Expand All @@ -1003,7 +1016,7 @@ pub mod pallet {
origin: OriginFor<T>,
location: Box<VersionedMultiLocation>,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
let location: MultiLocation = (*location)
.try_into()
.map_err(|()| Error::<T>::BadLocation)?;
Expand Down Expand Up @@ -1118,6 +1131,18 @@ pub mod pallet {
)
}

/// Set or unset the global suspension state of the XCM executor.
///
/// - `origin`: Must be an origin specified by AdminOrigin.
/// - `suspended`: `true` to suspend, `false` to resume.
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::force_suspension())]
pub fn force_suspension(origin: OriginFor<T>, suspended: bool) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
XcmExecutionSuspended::<T>::set(suspended);
Ok(())
}

/// Transfer some assets from sovereign account to reserve holder chain and
/// forward a notification XCM.
///
Expand Down Expand Up @@ -2364,6 +2389,17 @@ impl<T: Config> OnResponse for Pallet<T> {
}
}

impl<T: Config> CheckSuspension for Pallet<T> {
fn is_suspended<Call>(
_origin: &MultiLocation,
_instructions: &mut [Instruction<Call>],
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> bool {
XcmExecutionSuspended::<T>::get()
}
}

/// Ensure that the origin `o` represents an XCM (`Transact`) origin.
///
/// Returns `Ok` with the location of the XCM sender or an `Err` otherwise.
Expand Down
6 changes: 6 additions & 0 deletions pallets/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use frame_support::{
traits::{Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use parity_scale_codec::Encode;
use polkadot_parachain::primitives::Id as ParaId;
use polkadot_runtime_parachains::origin;
Expand Down Expand Up @@ -246,6 +247,10 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

parameter_types! {
Expand Down Expand Up @@ -346,6 +351,7 @@ impl pallet_xcm::Config for Test {
type WeightInfo = TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

impl origin::Config for Test {}
Expand Down
2 changes: 1 addition & 1 deletion pallets/pallet-xvm/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
None,
input,
false,
pallet_contracts::Determinism::Deterministic,
pallet_contracts::Determinism::Enforced,
);

log::trace!(
Expand Down
4 changes: 4 additions & 0 deletions pallets/xc-asset-config/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

type AssetId = u128;
Expand Down
4 changes: 4 additions & 0 deletions precompiles/assets-erc20/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

parameter_types! {
Expand Down
5 changes: 5 additions & 0 deletions precompiles/dapps-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ impl pallet_balances::Config for TestRuntime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
// TODO: set this properly
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

pub fn precompile_address() -> H160 {
Expand Down
4 changes: 4 additions & 0 deletions precompiles/sr25519/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

parameter_types! {
Expand Down
Loading

0 comments on commit 71e2dd6

Please sign in to comment.