Skip to content

Commit

Permalink
Merge branch 'master' into crystalin-staking-period
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois committed Dec 2, 2021
2 parents a7e087a + 301ba00 commit 3afe74b
Show file tree
Hide file tree
Showing 54 changed files with 2,961 additions and 1,505 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
image_exists: ${{ steps.check-check-docker-image.outputs.image_exists }}
sha: ${{ steps.get-sha.outputs.sha }}
sha8: ${{ steps.get-sha.outputs.sha8 }}
polkadot_repo: ${{ steps.get-sha.outputs.polkadot_repo }}
polkadot_commit: ${{ steps.get-sha.outputs.polkadot_commit }}
steps:
- name: Check git ref
Expand All @@ -49,6 +50,7 @@ jobs:
run: |
echo ::set-output name=sha::$(git log -1 --format="%H")
echo ::set-output name=sha8::$(git log -1 --format="%H" | cut -c1-8)
echo ::set-output name=polkadot_repo::$(egrep -o 'https.*/polkadot' Cargo.lock | head -1)
echo ::set-output name=polkadot_commit::$(egrep -o '/polkadot.*#([^\"]*)' Cargo.lock | \
head -1 | sed 's/.*#//' | cut -c1-8)
- name: Check existing docker image
Expand Down Expand Up @@ -178,12 +180,13 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check & build polkadot docker image
run: |
POLKADOT_REPO=${{ needs.set-tags.outputs.polkadot_repo }}
POLKADOT_COMMIT=${{ needs.set-tags.outputs.polkadot_commit }}
DOCKER_TAG="purestake/moonbase-relay-testnet:sha-$POLKADOT_COMMIT"
POLKADOT_EXISTS=$(docker manifest inspect $DOCKER_TAG > /dev/null && \
echo "true" || echo "false")
if [[ "$POLKADOT_EXISTS" == "false" ]]; then
# $POLKADOT_COMMIT is used to build the relay image
# $POLKADOT_COMMIT and $POLKADOT_REPO is used to build the relay image
./scripts/build-alphanet-relay-image.sh
docker push $DOCKER_TAG
fi
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion moonbeam-types-bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ const TYPES_900_undefined_deprecated: RegistryTypes = {
},
};

const TYPES_POST_900: RegistryTypes = {
ProxyType: {
_enum: [
"Any",
"NonTransfer",
"Governance",
"Staking",
"CancelProxy",
"Balances",
"AuthorMapping",
],
},
};

export const moonbeamDefinitions = {
alias: moduleDefinitions,
rpc: rpcDefinitions,
Expand Down Expand Up @@ -445,7 +459,7 @@ export const moonbeamDefinitions = {
},
{
minmax: [900, undefined],
types: {},
types: TYPES_POST_900,
},
],
} as OverrideBundleDefinition;
Expand Down
8 changes: 7 additions & 1 deletion pallets/maintenance-mode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ frame-system = { git = "https://github.com/purestake/substrate", branch = "moonb
parity-scale-codec = { version = "2.2", default-features = false }
scale-info = { version = "1.0", default-features = false, features = [ "derive" ] }
sp-runtime = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.12", default-features = false }
sp-std = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.12", default-features = false }

cumulus-primitives-core = { git = "https://github.com/purestake/cumulus", branch = "moonbeam-polkadot-v0.9.12", optional = true, default-features = false }

[dev-dependencies]
sp-core = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.12" }
sp-io = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.12" }

[features]
default = [ "std" ]
default = [ "std", "xcm-support" ]
std = [
"cumulus-primitives-core/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
]
try-runtime = [ "frame-support/try-runtime" ]
xcm-support = [ "cumulus-primitives-core" ]
72 changes: 66 additions & 6 deletions pallets/maintenance-mode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
//! 4. Maintenance mode timeout. To avoid getting stuck in maintenance mode. It could automatically
//! switch back to normal mode after a pre-decided number of blocks. Maybe there could be an
//! extrinsic to extend the maintenance time.
//!
//! 5. Let the runtime developer configure which pallets' on_initialize and on_finalize hooks get
//! called. This would allow to determine whether eg staking elections should still occur and
//! democracy referenda still mature

#![allow(non_camel_case_types)]
#![cfg_attr(not(feature = "std"), no_std)]
Expand All @@ -49,16 +45,27 @@ mod mock;
#[cfg(test)]
mod tests;

mod types;
pub use types::*;

use frame_support::pallet;

pub use pallet::*;

#[pallet]
pub mod pallet {
#[cfg(feature = "xcm-support")]
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler,
};
#[cfg(feature = "xcm-support")]
use sp_std::vec::Vec;

use frame_support::pallet_prelude::*;
use frame_support::traits::{Contains, EnsureOrigin};
use frame_support::traits::{
Contains, EnsureOrigin, OffchainWorker, OnFinalize, OnIdle, OnInitialize, OnRuntimeUpgrade,
};
use frame_system::pallet_prelude::*;

/// Pallet for migrations
#[pallet::pallet]
#[pallet::generate_storage_info]
Expand All @@ -81,6 +88,32 @@ pub mod pallet {
/// able to return to normal mode. For example, if your MaintenanceOrigin is a council, make
/// sure that your councilors can still cast votes.
type MaintenanceOrigin: EnsureOrigin<Self::Origin>;
/// The DMP handler to be used in normal operating mode
#[cfg(feature = "xcm-support")]
type NormalDmpHandler: DmpMessageHandler;
/// The DMP handler to be used in maintenance mode
#[cfg(feature = "xcm-support")]
type MaintenanceDmpHandler: DmpMessageHandler;
/// The XCMP handler to be used in normal operating mode
#[cfg(feature = "xcm-support")]
type NormalXcmpHandler: XcmpMessageHandler;
/// The XCMP handler to be used in maintenance mode
#[cfg(feature = "xcm-support")]
type MaintenanceXcmpHandler: XcmpMessageHandler;
/// The executive hooks that will be used in normal operating mode
/// Important: Use AllPallets here if you dont want to modify the hooks behaviour
type NormalExecutiveHooks: OnRuntimeUpgrade
+ OnInitialize<Self::BlockNumber>
+ OnIdle<Self::BlockNumber>
+ OnFinalize<Self::BlockNumber>
+ OffchainWorker<Self::BlockNumber>;
/// The executive hooks that will be used in maintenance mode
/// Important: Use AllPallets here if you dont want to modify the hooks behaviour
type MaitenanceExecutiveHooks: OnRuntimeUpgrade
+ OnInitialize<Self::BlockNumber>
+ OnIdle<Self::BlockNumber>
+ OnFinalize<Self::BlockNumber>
+ OffchainWorker<Self::BlockNumber>;
}

#[pallet::event]
Expand Down Expand Up @@ -189,4 +222,31 @@ pub mod pallet {
}
}
}
#[cfg(feature = "xcm-support")]
impl<T: Config> DmpMessageHandler for Pallet<T> {
fn handle_dmp_messages(
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
limit: Weight,
) -> Weight {
if MaintenanceMode::<T>::get() {
T::MaintenanceDmpHandler::handle_dmp_messages(iter, limit)
} else {
T::NormalDmpHandler::handle_dmp_messages(iter, limit)
}
}
}

#[cfg(feature = "xcm-support")]
impl<T: Config> XcmpMessageHandler for Pallet<T> {
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
iter: I,
limit: Weight,
) -> Weight {
if MaintenanceMode::<T>::get() {
T::MaintenanceXcmpHandler::handle_xcmp_messages(iter, limit)
} else {
T::NormalXcmpHandler::handle_xcmp_messages(iter, limit)
}
}
}
}
Loading

0 comments on commit 3afe74b

Please sign in to comment.