mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 06:41:02 +00:00
Rococo/Westend Coretime Runtime
New runtimes for the Coretime Chain (a.k.a. "Broker Chain") described in RFC-1. Replaces https://github.com/paritytech/cumulus/pull/2889 - [x] Add Agile Coretime pallet https://github.com/paritytech/substrate/pull/14568 - [x] Generate chain specs for local and testnets - [x] Deploy parachain on Rococo - Done: [rococo-coretime-rpc.polkadot.io](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frococo-coretime-rpc.polkadot.io#/explorer) DevOps issue for Aura keygen: https://github.com/paritytech/devops/issues/2725 Edit (Dónal): This PR is mainly for Rococo, the Westend runtime is a shell with no `Broker` pallet. The Rococo runtime has the broker calls filtered for initial deployment. --------- Co-authored-by: Dónal Murray <donal.murray@parity.io> Co-authored-by: 0xmovses <r.v.melkonian@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Marcin S. <marcin@realemail.net> Co-authored-by: Bastian Köcher <info@kchr.de> Co-authored-by: command-bot <> Co-authored-by: Branislav Kontur <bkontur@gmail.com>
This commit is contained in:
@@ -30,7 +30,10 @@ use frame_support::{
|
||||
use frame_system::{EnsureRoot, EnsureSignedBy};
|
||||
use sp_arithmetic::Perbill;
|
||||
use sp_core::{ConstU32, ConstU64};
|
||||
use sp_runtime::{traits::Identity, BuildStorage, Saturating};
|
||||
use sp_runtime::{
|
||||
traits::{BlockNumberProvider, Identity},
|
||||
BuildStorage, Saturating,
|
||||
};
|
||||
use sp_std::collections::btree_map::BTreeMap;
|
||||
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
@@ -75,18 +78,20 @@ pub struct TestCoretimeProvider;
|
||||
impl CoretimeInterface for TestCoretimeProvider {
|
||||
type AccountId = u64;
|
||||
type Balance = u64;
|
||||
type BlockNumber = u32;
|
||||
fn latest() -> Self::BlockNumber {
|
||||
System::block_number() as u32
|
||||
}
|
||||
type RealyChainBlockNumberProvider = System;
|
||||
fn request_core_count(count: CoreIndex) {
|
||||
NotifyCoreCount::mutate(|s| s.insert(0, count));
|
||||
}
|
||||
fn request_revenue_info_at(when: Self::BlockNumber) {
|
||||
if when > Self::latest() {
|
||||
panic!("Asking for revenue info in the future {:?} {:?}", when, Self::latest());
|
||||
fn request_revenue_info_at(when: RCBlockNumberOf<Self>) {
|
||||
if when > RCBlockNumberProviderOf::<Self>::current_block_number() {
|
||||
panic!(
|
||||
"Asking for revenue info in the future {:?} {:?}",
|
||||
when,
|
||||
RCBlockNumberProviderOf::<Self>::current_block_number()
|
||||
);
|
||||
}
|
||||
|
||||
let when = when as u32;
|
||||
let mut total = 0;
|
||||
CoretimeSpending::mutate(|s| {
|
||||
s.retain(|(n, a)| {
|
||||
@@ -105,27 +110,35 @@ impl CoretimeInterface for TestCoretimeProvider {
|
||||
}
|
||||
fn assign_core(
|
||||
core: CoreIndex,
|
||||
begin: Self::BlockNumber,
|
||||
begin: RCBlockNumberOf<Self>,
|
||||
assignment: Vec<(CoreAssignment, PartsOf57600)>,
|
||||
end_hint: Option<Self::BlockNumber>,
|
||||
end_hint: Option<RCBlockNumberOf<Self>>,
|
||||
) {
|
||||
CoretimeWorkplan::mutate(|p| p.insert((begin, core), assignment.clone()));
|
||||
let item = (Self::latest(), AssignCore { core, begin, assignment, end_hint });
|
||||
CoretimeWorkplan::mutate(|p| p.insert((begin as u32, core), assignment.clone()));
|
||||
let item = (
|
||||
RCBlockNumberProviderOf::<Self>::current_block_number() as u32,
|
||||
AssignCore {
|
||||
core,
|
||||
begin: begin as u32,
|
||||
assignment,
|
||||
end_hint: end_hint.map(|v| v as u32),
|
||||
},
|
||||
);
|
||||
CoretimeTrace::mutate(|v| v.push(item));
|
||||
}
|
||||
fn check_notify_core_count() -> Option<u16> {
|
||||
NotifyCoreCount::mutate(|s| s.pop())
|
||||
}
|
||||
fn check_notify_revenue_info() -> Option<(Self::BlockNumber, Self::Balance)> {
|
||||
NotifyRevenueInfo::mutate(|s| s.pop())
|
||||
fn check_notify_revenue_info() -> Option<(RCBlockNumberOf<Self>, Self::Balance)> {
|
||||
NotifyRevenueInfo::mutate(|s| s.pop()).map(|v| (v.0 as _, v.1))
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn ensure_notify_core_count(count: u16) {
|
||||
NotifyCoreCount::mutate(|s| s.insert(0, count));
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn ensure_notify_revenue_info(when: Self::BlockNumber, revenue: Self::Balance) {
|
||||
NotifyRevenueInfo::mutate(|s| s.push((when, revenue)));
|
||||
fn ensure_notify_revenue_info(when: RCBlockNumberOf<Self>, revenue: Self::Balance) {
|
||||
NotifyRevenueInfo::mutate(|s| s.push((when as u32, revenue)));
|
||||
}
|
||||
}
|
||||
impl TestCoretimeProvider {
|
||||
@@ -134,14 +147,16 @@ impl TestCoretimeProvider {
|
||||
ensure!(CoretimeInPool::get() > 0, ());
|
||||
c.insert(who, c.get(&who).ok_or(())?.checked_sub(price).ok_or(())?);
|
||||
CoretimeCredit::set(c);
|
||||
CoretimeSpending::mutate(|v| v.push((Self::latest(), price)));
|
||||
CoretimeSpending::mutate(|v| {
|
||||
v.push((RCBlockNumberProviderOf::<Self>::current_block_number() as u32, price))
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
pub fn bump() {
|
||||
let mut pool_size = CoretimeInPool::get();
|
||||
let mut workplan = CoretimeWorkplan::get();
|
||||
let mut usage = CoretimeUsage::get();
|
||||
let now = Self::latest();
|
||||
let now = RCBlockNumberProviderOf::<Self>::current_block_number() as u32;
|
||||
workplan.retain(|(when, core), assignment| {
|
||||
if *when <= now {
|
||||
if let Some(old_assignment) = usage.get(core) {
|
||||
@@ -184,7 +199,7 @@ impl crate::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Currency = ItemOf<TestFungibles<(), u64, (), ConstU64<0>, ()>, (), u64>;
|
||||
type OnRevenue = IntoZero;
|
||||
type TimeslicePeriod = ConstU32<2>;
|
||||
type TimeslicePeriod = ConstU64<2>;
|
||||
type MaxLeasedCores = ConstU32<5>;
|
||||
type MaxReservedCores = ConstU32<5>;
|
||||
type Coretime = TestCoretimeProvider;
|
||||
@@ -240,7 +255,7 @@ impl TestExt {
|
||||
}
|
||||
|
||||
pub fn advance_notice(mut self, advance_notice: Timeslice) -> Self {
|
||||
self.0.advance_notice = advance_notice;
|
||||
self.0.advance_notice = advance_notice as u64;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user