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

Capitalized the C in Relay Chain #1472

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ cargo run --features with-mandala-runtime --features try-runtime -- try-runtime
cargo run --features with-mandala-runtime --features try-runtime -- try-runtime --wasm-execution=compiled --block-at=0x9def608d5674f6d16574f53849218fe13d80ec1042ef7c2d4de7d4c50abab806 --url="wss://karura.api.onfinality.io/public-ws" offchain-worker snap -s snapshot.bin
```

# 8. Run local testnet with `Relaychain` and `Parachain`
Build Relaychain and Parachain local testnet to develop.
# 8. Run local testnet with `RelayChain` and `Parachain`
Build RelayChain and Parachain local testnet to develop.

```bash
cd launch
Expand Down
4 changes: 2 additions & 2 deletions modules/homa-lite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ For Karura network:
* Liquid currency: LKSM

## Test
Homa-lite uses XCM transfer to upload Staking currency into the Relaychain. Therefore a setup that allows successful XCM transfer to the relaychain is required for full end-to-end test of the Homa-lite module.
Homa-lite uses XCM transfer to upload Staking currency into the RelayChain. Therefore a setup that allows successful XCM transfer to the relaychain is required for full end-to-end test of the Homa-lite module.

### Local node
1. Pull the Master branch of the Acala codebase
2. Follow the README.md to setup local Relaychain and parachains.
2. Follow the README.md to setup local RelayChain and parachains.

This should launch some local test nodes running Karura(parachain) and Rococo(relaychain)
3. Open a new web browser, go to `https://polkadot.js.org/apps/#/explorer`
Expand Down
42 changes: 21 additions & 21 deletions modules/homa-lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub use weights::WeightInfo;
pub mod module {
use super::*;

pub type RelaychainBlockNumberOf<T> = <<T as Config>::RelaychainBlockNumber as BlockNumberProvider>::BlockNumber;
pub type RelayChainBlockNumberOf<T> = <<T as Config>::RelayChainBlockNumber as BlockNumberProvider>::BlockNumber;
pub(crate) type AmountOf<T> =
<<T as Config>::Currency as MultiCurrencyExtended<<T as frame_system::Config>::AccountId>>::Amount;

Expand Down Expand Up @@ -88,8 +88,8 @@ pub mod module {
/// The interface to Cross-chain transfer.
type XcmTransfer: XcmTransfer<Self::AccountId, Balance, CurrencyId>;

/// The Call builder for communicating with Relaychain via XCM messaging.
type RelaychainCallBuilder: CallBuilder<AccountId = Self::AccountId, Balance = Balance>;
/// The Call builder for communicating with RelayChain via XCM messaging.
type RelayChainCallBuilder: CallBuilder<AccountId = Self::AccountId, Balance = Balance>;

/// The MultiLocation of the sovereign sub-account for where the staking currencies are sent
/// to.
Expand All @@ -112,7 +112,7 @@ pub mod module {
#[pallet::constant]
type MintFee: Get<Balance>;

/// Equivalent to the loss of % staking reward from unbonding on the Relaychain.
/// Equivalent to the loss of % staking reward from unbonding on the RelayChain.
#[pallet::constant]
type BaseWithdrawFee: Get<Permill>;

Expand All @@ -121,7 +121,7 @@ pub mod module {
type XcmUnbondFee: Get<Balance>;

/// Block number provider for the relaychain.
type RelaychainBlockNumber: BlockNumberProvider<BlockNumber = Self::BlockNumber>;
type RelayChainBlockNumber: BlockNumberProvider<BlockNumber = Self::BlockNumber>;

/// The account ID to redeem from on the relaychain.
#[pallet::constant]
Expand All @@ -133,7 +133,7 @@ pub mod module {

/// Unbonding slashing spans for unbonding on the relaychain.
#[pallet::constant]
type RelaychainUnbondingSlashingSpans: Get<u32>;
type RelayChainUnbondingSlashingSpans: Get<u32>;

/// Maximum number of scheduled unbonds allowed
#[pallet::constant]
Expand Down Expand Up @@ -162,7 +162,7 @@ pub mod module {

#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
#[pallet::metadata(T::AccountId = "AccountId", RelaychainBlockNumberOf<T> = "RelaychainBlockNumner")]
#[pallet::metadata(T::AccountId = "AccountId", RelayChainBlockNumberOf<T> = "RelayChainBlockNumner")]
xlc marked this conversation as resolved.
Show resolved Hide resolved
pub enum Event<T: Config> {
/// The user has Staked some currencies to mint Liquid Currency.
/// \[user, amount_staked, amount_minted\]
Expand Down Expand Up @@ -192,12 +192,12 @@ pub mod module {

/// A new Unbond request added to the schedule.
/// \[staking_amount, relaychain_blocknumber\]
ScheduledUnbondAdded(Balance, RelaychainBlockNumberOf<T>),
ScheduledUnbondAdded(Balance, RelayChainBlockNumberOf<T>),

/// The ScheduledUnbond has been replaced.
ScheduledUnbondReplaced,

/// The scheduled Unbond has been withdrew from the Relaychain.
/// The scheduled Unbond has been withdrew from the RelayChain.
///\[staking_amount_added\]
ScheduledUnbondWithdrew(Balance),
}
Expand Down Expand Up @@ -234,11 +234,11 @@ pub mod module {
pub type AvailableStakingBalance<T: Config> = StorageValue<_, Balance, ValueQuery>;

/// Funds that will be unbonded in the future
/// ScheduledUnbond: Vec<(staking_amount: Balance, unbond_at: RelaychainBlockNumber>
/// ScheduledUnbond: Vec<(staking_amount: Balance, unbond_at: RelayChainBlockNumber>
#[pallet::storage]
#[pallet::getter(fn scheduled_unbond)]
pub type ScheduledUnbond<T: Config> =
StorageValue<_, BoundedVec<(Balance, RelaychainBlockNumberOf<T>), T::MaxScheduledUnbonds>, ValueQuery>;
StorageValue<_, BoundedVec<(Balance, RelayChainBlockNumberOf<T>), T::MaxScheduledUnbonds>, ValueQuery>;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand All @@ -252,7 +252,7 @@ pub mod module {
let mut scheduled_unbond = Self::scheduled_unbond();
if !scheduled_unbond.is_empty() {
let (staking_amount, block_number) = scheduled_unbond[0];
if T::RelaychainBlockNumber::current_block_number() >= block_number {
if T::RelayChainBlockNumber::current_block_number() >= block_number {
let res = Self::process_scheduled_unbond(staking_amount);
log::debug!("{:?}", res);
debug_assert!(res.is_ok());
Expand Down Expand Up @@ -492,7 +492,7 @@ pub mod module {
Ok(())
}

/// Request staking currencies to be unbonded from the Relaychain.
/// Request staking currencies to be unbonded from the RelayChain.
///
/// Requires `T::GovernanceOrigin`
///
Expand All @@ -504,7 +504,7 @@ pub mod module {
pub fn schedule_unbond(
origin: OriginFor<T>,
#[pallet::compact] staking_amount: Balance,
unbond_block: RelaychainBlockNumberOf<T>,
unbond_block: RelayChainBlockNumberOf<T>,
) -> DispatchResult {
T::GovernanceOrigin::ensure_origin(origin)?;

Expand All @@ -531,7 +531,7 @@ pub mod module {
#[transactional]
pub fn replace_schedule_unbond(
origin: OriginFor<T>,
new_unbonds: Vec<(Balance, RelaychainBlockNumberOf<T>)>,
new_unbonds: Vec<(Balance, RelayChainBlockNumberOf<T>)>,
) -> DispatchResult {
T::GovernanceOrigin::ensure_origin(origin)?;

Expand Down Expand Up @@ -648,7 +648,7 @@ pub mod module {
/// Mint some Liquid currency, by locking up the given amount of Staking currency.
/// The redeem requests given in `requests` are prioritized to be matched. All other redeem
/// requests are matched after. The remaining amount is minted through Staking on the
/// Relaychain (via XCM).
/// RelayChain (via XCM).
///
/// Parameters:
/// - `amount`: The amount of Staking currency to be exchanged.
Expand Down Expand Up @@ -847,14 +847,14 @@ pub mod module {

/// Construct a XCM message
pub fn construct_xcm_unreserve_message(parachain_account: T::AccountId, amount: Balance) -> Xcm<()> {
let xcm_message = T::RelaychainCallBuilder::utility_as_derivative_call(
T::RelaychainCallBuilder::utility_batch_call(vec![
T::RelaychainCallBuilder::staking_withdraw_unbonded(T::RelaychainUnbondingSlashingSpans::get()),
T::RelaychainCallBuilder::balances_transfer_keep_alive(parachain_account, amount),
let xcm_message = T::RelayChainCallBuilder::utility_as_derivative_call(
T::RelayChainCallBuilder::utility_batch_call(vec![
T::RelayChainCallBuilder::staking_withdraw_unbonded(T::RelayChainUnbondingSlashingSpans::get()),
T::RelayChainCallBuilder::balances_transfer_keep_alive(parachain_account, amount),
]),
T::SubAccountIndex::get(),
);
T::RelaychainCallBuilder::finalize_call_into_xcm_message(
T::RelayChainCallBuilder::finalize_call_into_xcm_message(
xcm_message,
T::XcmUnbondFee::get(),
Self::xcm_dest_weight(),
Expand Down
10 changes: 5 additions & 5 deletions modules/homa-lite/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
pub use super::*;
pub use frame_support::{ord_parameter_types, parameter_types, traits::Everything};
pub use frame_system::{EnsureRoot, EnsureSignedBy, RawOrigin};
pub use module_relaychain::RelaychainCallBuilder;
pub use module_relaychain::RelayChainCallBuilder;
pub use module_support::mocks::MockAddressMapping;
pub use orml_traits::{parameter_type_with_key, XcmTransfer};
pub use primitives::{Amount, TokenSymbol};
Expand Down Expand Up @@ -258,7 +258,7 @@ parameter_types! {
pub const ParachainAccount: AccountId = ROOT;
pub const MaximumRedeemRequestMatchesForMint: u32 = 2;
pub static MockRelayBlockNumberProvider: u64 = 0;
pub const RelaychainUnbondingSlashingSpans: u32 = 5;
pub const RelayChainUnbondingSlashingSpans: u32 = 5;
pub const MaxScheduledUnbonds: u32 = 14;
pub const SubAccountIndex: u16 = 0;
pub ParachainId: ParaId = ParaId::from(PARACHAIN_ID);
Expand Down Expand Up @@ -290,13 +290,13 @@ impl Config for Runtime {
type DefaultExchangeRate = DefaultExchangeRate;
type MaxRewardPerEra = MaxRewardPerEra;
type MintFee = MintFee;
type RelaychainCallBuilder = RelaychainCallBuilder<Runtime, ParachainId>;
type RelayChainCallBuilder = RelayChainCallBuilder<Runtime, ParachainId>;
type BaseWithdrawFee = BaseWithdrawFee;
type XcmUnbondFee = XcmUnbondFee;
type RelaychainBlockNumber = MockRelayBlockNumberProvider;
type RelayChainBlockNumber = MockRelayBlockNumberProvider;
type ParachainAccount = ParachainAccount;
type MaximumRedeemRequestMatchesForMint = MaximumRedeemRequestMatchesForMint;
type RelaychainUnbondingSlashingSpans = RelaychainUnbondingSlashingSpans;
type RelayChainUnbondingSlashingSpans = RelayChainUnbondingSlashingSpans;
type MaxScheduledUnbonds = MaxScheduledUnbonds;
}

Expand Down
38 changes: 19 additions & 19 deletions modules/relaychain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! # Module Relaychain
//! # Module RelayChain
//!
//! This module is in charge of handling relaychain related utilities and business logic.

Expand All @@ -43,11 +43,11 @@ pub enum BalancesCall<T: Config> {
}

#[derive(Encode, Decode, RuntimeDebug)]
pub enum UtilityCall<RelaychainCall> {
pub enum UtilityCall<RelayChainCall> {
#[codec(index = 1)]
AsDerivative(u16, RelaychainCall),
AsDerivative(u16, RelayChainCall),
#[codec(index = 2)]
BatchAll(Vec<RelaychainCall>),
BatchAll(Vec<RelayChainCall>),
}

#[derive(Encode, Decode, RuntimeDebug)]
Expand All @@ -62,7 +62,7 @@ mod kusama {
/// The encoded index correspondes to Kusama's Runtime module configuration.
/// https://github.com/paritytech/polkadot/blob/444e96ae34bcec8362f0f947a07bd912b32ca48f/runtime/kusama/src/lib.rs#L1379
#[derive(Encode, Decode, RuntimeDebug)]
pub enum RelaychainCall<T: Config> {
pub enum RelayChainCall<T: Config> {
#[codec(index = 4)]
Balances(BalancesCall<T>),
#[codec(index = 6)]
Expand All @@ -78,7 +78,7 @@ mod polkadot {
/// The encoded index correspondes to Polkadot's Runtime module configuration.
/// https://github.com/paritytech/polkadot/blob/84a3962e76151ac5ed3afa4ef1e0af829531ab42/runtime/polkadot/src/lib.rs#L1040
#[derive(Encode, Decode, RuntimeDebug)]
pub enum RelaychainCall<T: Config> {
pub enum RelayChainCall<T: Config> {
#[codec(index = 5)]
Balances(BalancesCall<T>),
#[codec(index = 7)]
Expand All @@ -94,35 +94,35 @@ pub use kusama::*;
#[cfg(feature = "polkadot")]
pub use polkadot::*;

pub struct RelaychainCallBuilder<T: Config, ParachainId: Get<ParaId>>(PhantomData<(T, ParachainId)>);
pub struct RelayChainCallBuilder<T: Config, ParachainId: Get<ParaId>>(PhantomData<(T, ParachainId)>);

impl<T: Config, ParachainId: Get<ParaId>> CallBuilder for RelaychainCallBuilder<T, ParachainId>
impl<T: Config, ParachainId: Get<ParaId>> CallBuilder for RelayChainCallBuilder<T, ParachainId>
where
T::AccountId: FullCodec,
RelaychainCall<T>: FullCodec,
RelayChainCall<T>: FullCodec,
{
type AccountId = T::AccountId;
type Balance = Balance;
type RelaychainCall = RelaychainCall<T>;
type RelayChainCall = RelayChainCall<T>;

fn utility_batch_call(calls: Vec<Self::RelaychainCall>) -> Self::RelaychainCall {
RelaychainCall::Utility(Box::new(UtilityCall::BatchAll(calls)))
fn utility_batch_call(calls: Vec<Self::RelayChainCall>) -> Self::RelayChainCall {
RelayChainCall::Utility(Box::new(UtilityCall::BatchAll(calls)))
}

fn utility_as_derivative_call(call: Self::RelaychainCall, index: u16) -> Self::RelaychainCall {
RelaychainCall::Utility(Box::new(UtilityCall::AsDerivative(index, call)))
fn utility_as_derivative_call(call: Self::RelayChainCall, index: u16) -> Self::RelayChainCall {
RelayChainCall::Utility(Box::new(UtilityCall::AsDerivative(index, call)))
}

fn staking_withdraw_unbonded(num_slashing_spans: u32) -> Self::RelaychainCall {
RelaychainCall::Staking(StakingCall::WithdrawUnbonded(num_slashing_spans))
fn staking_withdraw_unbonded(num_slashing_spans: u32) -> Self::RelayChainCall {
RelayChainCall::Staking(StakingCall::WithdrawUnbonded(num_slashing_spans))
}

fn balances_transfer_keep_alive(to: Self::AccountId, amount: Self::Balance) -> Self::RelaychainCall {
RelaychainCall::Balances(BalancesCall::TransferKeepAlive(T::Lookup::unlookup(to), amount))
fn balances_transfer_keep_alive(to: Self::AccountId, amount: Self::Balance) -> Self::RelayChainCall {
RelayChainCall::Balances(BalancesCall::TransferKeepAlive(T::Lookup::unlookup(to), amount))
}

fn finalize_call_into_xcm_message(
call: Self::RelaychainCall,
call: Self::RelayChainCall,
extra_fee: Self::Balance,
weight: Weight,
debt: Weight,
Expand Down
12 changes: 6 additions & 6 deletions modules/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,29 +568,29 @@ pub trait CompoundCashTrait<Balance, Moment> {
pub trait CallBuilder {
type AccountId: FullCodec;
type Balance: FullCodec;
type RelaychainCall: FullCodec;
type RelayChainCall: FullCodec;

/// Execute multiple calls in a batch.
/// Param:
/// - calls: List of calls to be executed
fn utility_batch_call(calls: Vec<Self::RelaychainCall>) -> Self::RelaychainCall;
fn utility_batch_call(calls: Vec<Self::RelayChainCall>) -> Self::RelayChainCall;

/// Execute a call, replacing the `Origin` with a sub-account.
/// params:
/// - call: The call to be executed. Can be nested with `utility_batch_call`
/// - index: The index of sub-account to be used as the new origin.
fn utility_as_derivative_call(call: Self::RelaychainCall, index: u16) -> Self::RelaychainCall;
fn utility_as_derivative_call(call: Self::RelayChainCall, index: u16) -> Self::RelayChainCall;

/// Withdraw unbonded staking on the relay-chain.
/// params:
/// - num_slashing_spans: The number of slashing spans to withdraw from.
fn staking_withdraw_unbonded(num_slashing_spans: u32) -> Self::RelaychainCall;
fn staking_withdraw_unbonded(num_slashing_spans: u32) -> Self::RelayChainCall;

/// Transfer Staking currency to another account, disallowing "death".
/// params:
/// - to: The destination for the transfer
/// - amount: The amount of staking currency to be transferred.
fn balances_transfer_keep_alive(to: Self::AccountId, amount: Self::Balance) -> Self::RelaychainCall;
fn balances_transfer_keep_alive(to: Self::AccountId, amount: Self::Balance) -> Self::RelayChainCall;

/// Wrap the final calls into the Xcm format.
/// params:
Expand All @@ -599,7 +599,7 @@ pub trait CallBuilder {
/// - weight: the weight limit used for XCM.
/// - debt: the weight limit used to process the `call`.
fn finalize_call_into_xcm_message(
call: Self::RelaychainCall,
call: Self::RelayChainCall,
extra_fee: Self::Balance,
weight: Weight,
debt: Weight,
Expand Down
6 changes: 3 additions & 3 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub use runtime_common::{
EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate, FinancialCouncilInstance,
FinancialCouncilMembershipInstance, GasToWeight, GeneralCouncilInstance, GeneralCouncilMembershipInstance,
HomaCouncilInstance, HomaCouncilMembershipInstance, OffchainSolutionWeightLimit, OperatorMembershipInstanceAcala,
OperatorMembershipInstanceBand, Price, ProxyType, Rate, Ratio, RelaychainBlockNumberProvider, RuntimeBlockLength,
OperatorMembershipInstanceBand, Price, ProxyType, Rate, Ratio, RelayChainBlockNumberProvider, RuntimeBlockLength,
RuntimeBlockWeights, SystemContractsFilter, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance,
TimeStampedPrice, ACA, AUSD, DOT, LDOT, RENBTC,
};
Expand Down Expand Up @@ -862,7 +862,7 @@ impl orml_vesting::Config for Runtime {
type VestedTransferOrigin = EnsureRootOrTreasury;
type WeightInfo = weights::orml_vesting::WeightInfo<Runtime>;
type MaxVestingSchedules = MaxVestingSchedules;
type BlockNumberProvider = RelaychainBlockNumberProvider<Runtime>;
type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -1221,7 +1221,7 @@ impl module_homa_validator_list::Config for Runtime {
type WeightInfo = ();
type OnIncreaseGuarantee = ();
type OnDecreaseGuarantee = ();
type BlockNumberProvider = RelaychainBlockNumberProvider<Runtime>;
type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
}

parameter_types! {
Expand Down
6 changes: 3 additions & 3 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ pub fn microcent(currency_id: CurrencyId) -> Balance {
millicent(currency_id) / 1000
}

pub struct RelaychainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);
pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);

impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider for RelaychainBlockNumberProvider<T> {
impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider for RelayChainBlockNumberProvider<T> {
type BlockNumber = BlockNumber;

fn current_block_number() -> Self::BlockNumber {
Expand Down Expand Up @@ -337,7 +337,7 @@ impl Default for ProxyType {
}

#[repr(u16)]
pub enum RelaychainSubAccountId {
pub enum RelayChainSubAccountId {
HomaLite = 0,
}

Expand Down
Loading