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

Implement pallet_xcm_core_buyer #452

Merged
merged 23 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7806893
Implement pallet_xcm_core_buyer
tmpolaczyk Feb 29, 2024
568562d
Add more validations and more tests
tmpolaczyk Mar 13, 2024
f05db9b
zepter & toml-maid
tmpolaczyk Mar 13, 2024
0aa4e38
Make benchmarks compile
tmpolaczyk Mar 13, 2024
fdc5f1e
Implement and run benchmarks
tmpolaczyk Mar 14, 2024
824ab4c
Change account derivation and store XCM weights in pallet storage
tmpolaczyk Mar 14, 2024
dd5f5ce
Add set_xcm_weights benchmark
tmpolaczyk Mar 15, 2024
396b791
typescript-api
tmpolaczyk Mar 15, 2024
2f36563
Merge remote-tracking branch 'origin/master' into tomasz-xcm-coretime
tmpolaczyk Mar 15, 2024
69cd633
toml-maid
tmpolaczyk Mar 15, 2024
4cc6262
Add docs, use XCM reanchor, use ParaId::into_account_truncating
tmpolaczyk Mar 18, 2024
d69e4f1
Merge remote-tracking branch 'origin/master' into tomasz-xcm-coretime
tmpolaczyk Mar 18, 2024
efff20f
PR comments
tmpolaczyk Mar 19, 2024
71a6dbd
Merge remote-tracking branch 'origin/master' into tomasz-xcm-coretime
tmpolaczyk Mar 19, 2024
8a09a2d
Add typescript tests
tmpolaczyk Mar 19, 2024
5623627
fmt
tmpolaczyk Mar 19, 2024
cfc4a3f
Create tanssi-relay-encoder crate
tmpolaczyk Mar 20, 2024
3bfce07
Merge remote-tracking branch 'origin/master' into tomasz-xcm-coretime
tmpolaczyk Mar 20, 2024
128bc1c
Add westend encoded call and allow configuring relay chain
tmpolaczyk Mar 20, 2024
efb6837
Merge remote-tracking branch 'origin/master' into tomasz-xcm-coretime
tmpolaczyk Mar 21, 2024
7c01f66
Fix unused import
tmpolaczyk Mar 21, 2024
00a4c51
Merge remote-tracking branch 'origin/master' into tomasz-xcm-coretime
tmpolaczyk Mar 22, 2024
e9db42a
typescript-api
tmpolaczyk Mar 22, 2024
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
392 changes: 221 additions & 171 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"primitives/*",
"runtime/dancebox",
"runtime/flashbox",
"runtime/relay-encoder",
]
resolver = "2"

Expand Down Expand Up @@ -61,6 +62,7 @@ pallet-registrar = { path = "pallets/registrar", default-features = false }
pallet-registrar-runtime-api = { path = "pallets/registrar/rpc/runtime-api", default-features = false }
pallet-services-payment = { path = "pallets/services-payment", default-features = false }
pallet-stream-payment = { path = "pallets/stream-payment", default-features = false }
pallet-xcm-core-buyer = { path = "pallets/xcm-core-buyer", default-features = false }

container-chain-template-frontier-runtime = { path = "container-chains/templates/frontier/runtime", default-features = false }
container-chain-template-simple-runtime = { path = "container-chains/templates/simple/runtime", default-features = false }
Expand All @@ -70,6 +72,7 @@ flashbox-runtime = { path = "runtime/flashbox", default-features = false }
manual-xcm-rpc = { path = "client/manual-xcm" }
node-common = { path = "client/node-common" }
runtime-common = { path = "runtime/common", default-features = false }
tanssi-relay-encoder = { path = "runtime/relay-encoder", default-features = false }
tc-consensus = { path = "client/consensus" }
tp-author-noting-inherent = { path = "primitives/author-noting-inherent", default-features = false }
tp-container-chain-genesis-data = { path = "primitives/container-chain-genesis-data", default-features = false }
Expand Down Expand Up @@ -210,6 +213,8 @@ polkadot-node-primitives = { git = "https://github.com/moondance-labs/polkadot-s
polkadot-parachain-primitives = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
polkadot-runtime-common = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
polkadot-runtime-parachains = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
rococo-runtime = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
rococo-runtime-constants = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
staging-xcm = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
staging-xcm-builder = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
staging-xcm-executor = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.6.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion pallets/data-preservers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod pallet {
/// Data preservers pallet.
#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet<T>(core::marker::PhantomData<T>);
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config {
Expand Down
2 changes: 1 addition & 1 deletion pallets/inflation-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod pallet {
/// Inflation rewards pallet.
#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet<T>(core::marker::PhantomData<T>);
pub struct Pallet<T>(PhantomData<T>);

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
Expand Down
14 changes: 0 additions & 14 deletions pallets/services-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

//! # Author Noting Pallet
//!
//! This pallet notes the author of the different containerChains that have registered:
//!
//! The set of container chains is retrieved thanks to the GetContainerChains trait
//! For each containerChain, we inspect the Header stored in the relayChain as
//! a generic header. This is the first requirement for containerChains.
//!
//! The second requirement is that an Aura digest with the slot number for the containerChains
//! needs to exist
//!
//! Using those two requirements we can select who the author was based on the collators assigned
//! to that containerChain, by simply assigning the slot position.

//! # Services Payment pallet
//!
//! This pallet allows for block creation services to be paid for by a
Expand Down
14 changes: 0 additions & 14 deletions pallets/services-payment/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

//! # Author Noting Pallet
//!
//! This pallet notes the author of the different containerChains that have registered:
//!
//! The set of container chains is retrieved thanks to the GetContainerChains trait
//! For each containerChain, we inspect the Header stored in the relayChain as
//! a generic header. This is the first requirement for containerChains.
//!
//! The second requirement is that an Aura digest with the slot number for the containerChains
//! needs to exist
//!
//! Using those two requirements we can select who the author was based on the collators assigned
//! to that containerChain, by simply assigning the slot position.

use {
crate::{
self as pallet_services_payment, ProvideBlockProductionCost, ProvideCollatorAssignmentCost,
Expand Down
14 changes: 0 additions & 14 deletions pallets/services-payment/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

//! # Author Noting Pallet
//!
//! This pallet notes the author of the different containerChains that have registered:
//!
//! The set of container chains is retrieved thanks to the GetContainerChains trait
//! For each containerChain, we inspect the Header stored in the relayChain as
//! a generic header. This is the first requirement for containerChains.
//!
//! The second requirement is that an Aura digest with the slot number for the containerChains
//! needs to exist
//!
//! Using those two requirements we can select who the author was based on the collators assigned
//! to that containerChain, by simply assigning the slot position.

use {
crate::{
mock::*, pallet as pallet_services_payment, BlockProductionCredits,
Expand Down
81 changes: 81 additions & 0 deletions pallets/xcm-core-buyer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[package]
name = "pallet-xcm-core-buyer"
authors = { workspace = true }
description = "Allows collators to buy parathread cores on demand"
edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]

[dependencies]

dp-core = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
tp-traits = { workspace = true }

# Polkadot
staging-xcm = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Nimbus
nimbus-primitives = { workspace = true }

[dev-dependencies]
bounded-collections = { workspace = true }
num-traits = { workspace = true }
pallet-balances = { workspace = true, features = [ "std" ] }
similar-asserts = { workspace = true }
sp-io = { workspace = true, features = [ "std" ] }

[features]
default = [ "std" ]
std = [
"bounded-collections/std",
"dp-core/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"nimbus-primitives/std",
"pallet-balances/std",
"parity-scale-codec/std",
"scale-info/std",
"serde",
"serde?/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"staging-xcm/std",
"tp-traits/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"nimbus-primitives/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"tp-traits/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"nimbus-primitives/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
100 changes: 100 additions & 0 deletions pallets/xcm-core-buyer/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

#![cfg(feature = "runtime-benchmarks")]

//! Benchmarking
use {
crate::{
Call, Config, GetParathreadCollators, GetParathreadParams, InFlightOrders, Pallet,
RelayChain, RelayXcmWeightConfig, RelayXcmWeightConfigInner,
},
core::marker::PhantomData,
frame_benchmarking::{account, v2::*},
frame_support::{assert_ok, pallet_prelude::Weight, BoundedBTreeSet},
frame_system::RawOrigin,
sp_std::{collections::btree_set::BTreeSet, vec},
tp_traits::{ParaId, ParathreadParams, SlotFrequency},
};

pub const BUY_EXECUTION_COST: u128 = 50_000_000;
pub const PLACE_ORDER_WEIGHT_AT_MOST: Weight = Weight::from_parts(1_000_000_000, 100_000);

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn force_buy_core(x: Linear<1, 99>) {
assert_ok!(Pallet::<T>::set_relay_xcm_weight_config(
RawOrigin::Root.into(),
Some(RelayXcmWeightConfigInner {
buy_execution_cost: BUY_EXECUTION_COST,
weight_at_most: PLACE_ORDER_WEIGHT_AT_MOST,
_phantom: PhantomData,
}),
));

let para_id = ParaId::from(x + 1);
assert_eq!(InFlightOrders::<T>::get(), BTreeSet::new());

// Mock `x` xcm messages already sent in this block
let bbs: BoundedBTreeSet<ParaId, _> = BTreeSet::from_iter((0..x).map(ParaId::from))
.try_into()
.expect("x is greater than MaxParathreads");
InFlightOrders::<T>::put(bbs);
assert!(!InFlightOrders::<T>::get().contains(&para_id));

// For the extrinsic to succeed, we need to ensure that:
// * the para_id is a parathread
// * it has assigned collators
T::GetParathreadParams::set_parathread_params(
para_id,
Some(ParathreadParams {
slot_frequency: SlotFrequency { min: 10, max: 10 },
}),
);
let author: T::AccountId = account("account id", 0u32, 0u32);
T::GetAssignedCollators::set_parathread_collators(para_id, vec![author]);

#[extrinsic_call]
Pallet::<T>::force_buy_core(RawOrigin::Root, para_id);

assert!(InFlightOrders::<T>::get().contains(&para_id));
}

#[benchmark]
fn set_relay_xcm_weight_config() {
let xcm_weights = RelayXcmWeightConfigInner {
buy_execution_cost: BUY_EXECUTION_COST,
weight_at_most: PLACE_ORDER_WEIGHT_AT_MOST,
_phantom: PhantomData,
};

#[extrinsic_call]
Pallet::<T>::set_relay_xcm_weight_config(RawOrigin::Root, Some(xcm_weights.clone()));

assert_eq!(RelayXcmWeightConfig::<T>::get(), Some(xcm_weights));
}

#[benchmark]
fn set_relay_chain() {
#[extrinsic_call]
Pallet::<T>::set_relay_chain(RawOrigin::Root, Some(T::RelayChain::default()));
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}
Loading
Loading