Skip to content

Commit 4fdab49

Browse files
bkchrpepoviola
andauthored
Coretime Zombienet test (#2867)
This adds a Zombienet test for Coretime. Requires: #2862 --------- Co-authored-by: Javier Viola <[email protected]> Co-authored-by: Javier Viola <[email protected]>
1 parent 1914775 commit 4fdab49

File tree

11 files changed

+118
-71
lines changed

11 files changed

+118
-71
lines changed

.gitlab/pipeline/zombienet/polkadot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ zombienet-polkadot-smoke-0003-deregister-register-validator:
185185
--local-dir="${LOCAL_DIR}/smoke"
186186
--test="0003-deregister-register-validator-smoke.zndsl"
187187

188+
zombienet-polkadot-smoke-0004-coretime-smoke-test:
189+
extends:
190+
- .zombienet-polkadot-common
191+
script:
192+
- /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh
193+
--local-dir="${LOCAL_DIR}/smoke"
194+
--test="0004-coretime-smoke-test.zndsl"
195+
188196
zombienet-polkadot-misc-0001-parachains-paritydb:
189197
extends:
190198
- .zombienet-polkadot-common

cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,5 @@ try-runtime = [
194194
]
195195

196196
experimental = ["pallet-aura/experimental"]
197+
198+
fast-runtime = []

cumulus/parachains/runtimes/coretime/coretime-rococo/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ fn main() {
1919
.with_current_project()
2020
.export_heap_base()
2121
.import_memory()
22-
.build()
22+
.build();
23+
24+
substrate_wasm_builder::WasmBuilder::new()
25+
.with_current_project()
26+
.set_file_name("fast_runtime_binary.rs")
27+
.enable_feature("fast-runtime")
28+
.import_memory()
29+
.export_heap_base()
30+
.build();
2331
}
2432

2533
#[cfg(not(feature = "std"))]

cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use crate::*;
1818
use codec::{Decode, Encode};
1919
use cumulus_pallet_parachain_system::RelaychainDataProvider;
20+
use cumulus_primitives_core::relay_chain;
2021
use frame_support::{
2122
parameter_types,
2223
traits::{
@@ -51,11 +52,16 @@ enum CoretimeProviderCalls {
5152
#[codec(index = 1)]
5253
RequestCoreCount(CoreIndex),
5354
#[codec(index = 2)]
54-
RequestRevenueInfoAt(BlockNumber),
55+
RequestRevenueInfoAt(relay_chain::BlockNumber),
5556
#[codec(index = 3)]
5657
CreditAccount(AccountId, Balance),
5758
#[codec(index = 4)]
58-
AssignCore(CoreIndex, BlockNumber, Vec<(CoreAssignment, PartsOf57600)>, Option<BlockNumber>),
59+
AssignCore(
60+
CoreIndex,
61+
relay_chain::BlockNumber,
62+
Vec<(CoreAssignment, PartsOf57600)>,
63+
Option<relay_chain::BlockNumber>,
64+
),
5965
}
6066

6167
parameter_types! {
@@ -181,7 +187,7 @@ impl CoretimeInterface for CoretimeAllocator {
181187
},
182188
Instruction::Transact {
183189
origin_kind: OriginKind::Native,
184-
require_weight_at_most: Weight::from_parts(1000000000, 200000),
190+
require_weight_at_most: Weight::from_parts(1_000_000_000, 200000),
185191
call: assign_core_call.encode().into(),
186192
},
187193
]);
@@ -215,6 +221,9 @@ impl pallet_broker::Config for Runtime {
215221
type RuntimeEvent = RuntimeEvent;
216222
type Currency = Balances;
217223
type OnRevenue = CreditToCollatorPot;
224+
#[cfg(feature = "fast-runtime")]
225+
type TimeslicePeriod = ConstU32<10>;
226+
#[cfg(not(feature = "fast-runtime"))]
218227
type TimeslicePeriod = ConstU32<80>;
219228
type MaxLeasedCores = ConstU32<50>;
220229
type MaxReservedCores = ConstU32<10>;

cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
#[cfg(feature = "std")]
2222
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
2323

24+
/// Provides the `WASM_BINARY` build with `fast-runtime` feature enabled.
25+
///
26+
/// This is for example useful for local test chains.
27+
#[cfg(feature = "std")]
28+
pub mod fast_runtime_binary {
29+
include!(concat!(env!("OUT_DIR"), "/fast_runtime_binary.rs"));
30+
}
31+
2432
mod coretime;
2533
mod weights;
2634
pub mod xcm_config;

cumulus/polkadot-parachain/src/chain_spec/coretime.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use sc_chain_spec::{ChainSpec, ChainType};
2020
use std::{borrow::Cow, str::FromStr};
2121

2222
/// Collects all supported Coretime configurations.
23-
#[derive(Debug, PartialEq, Clone)]
23+
#[derive(Debug, PartialEq, Clone, Copy)]
2424
pub enum CoretimeRuntimeType {
2525
// Live
2626
Rococo,
@@ -85,13 +85,13 @@ impl CoretimeRuntimeType {
8585
&include_bytes!("../../../parachains/chain-specs/coretime-rococo.json")[..],
8686
)?)),
8787
CoretimeRuntimeType::RococoLocal =>
88-
Ok(Box::new(rococo::local_config(self, "rococo-local"))),
88+
Ok(Box::new(rococo::local_config(*self, "rococo-local"))),
8989
CoretimeRuntimeType::RococoDevelopment =>
90-
Ok(Box::new(rococo::local_config(self, "rococo-dev"))),
90+
Ok(Box::new(rococo::local_config(*self, "rococo-dev"))),
9191
CoretimeRuntimeType::WestendLocal =>
92-
Ok(Box::new(westend::local_config(self, "westend-local"))),
92+
Ok(Box::new(westend::local_config(*self, "westend-local"))),
9393
CoretimeRuntimeType::WestendDevelopment =>
94-
Ok(Box::new(westend::local_config(self, "westend-dev"))),
94+
Ok(Box::new(westend::local_config(*self, "westend-dev"))),
9595
}
9696
}
9797
}
@@ -114,31 +114,39 @@ pub mod rococo {
114114
get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION,
115115
};
116116
use parachains_common::{AccountId, AuraId, Balance};
117+
use sc_chain_spec::ChainType;
117118
use sp_core::sr25519;
118119

119120
pub(crate) const CORETIME_ROCOCO: &str = "coretime-rococo";
120121
pub(crate) const CORETIME_ROCOCO_LOCAL: &str = "coretime-rococo-local";
121122
pub(crate) const CORETIME_ROCOCO_DEVELOPMENT: &str = "coretime-rococo-dev";
122123
const CORETIME_ROCOCO_ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT;
123124

124-
pub fn local_config(runtime_type: &CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec {
125+
pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec {
125126
// Rococo defaults
126127
let mut properties = sc_chain_spec::Properties::new();
127128
properties.insert("ss58Format".into(), 42.into());
128129
properties.insert("tokenSymbol".into(), "ROC".into());
129130
properties.insert("tokenDecimals".into(), 12.into());
130131

131-
let chain_type = runtime_type.clone().into();
132+
let chain_type = runtime_type.into();
132133
let chain_name = format!("Coretime Rococo {}", chain_type_name(&chain_type));
133134
let para_id = super::CORETIME_PARA_ID;
134135

135-
GenericChainSpec::builder(
136+
let wasm_binary = if matches!(chain_type, ChainType::Local | ChainType::Development) {
137+
coretime_rococo_runtime::fast_runtime_binary::WASM_BINARY
138+
.expect("WASM binary was not built, please build it!")
139+
} else {
136140
coretime_rococo_runtime::WASM_BINARY
137-
.expect("WASM binary was not built, please build it!"),
141+
.expect("WASM binary was not built, please build it!")
142+
};
143+
144+
GenericChainSpec::builder(
145+
wasm_binary,
138146
Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() },
139147
)
140148
.with_name(&chain_name)
141-
.with_id(runtime_type.clone().into())
149+
.with_id(runtime_type.into())
142150
.with_chain_type(chain_type)
143151
.with_genesis_config_patch(genesis(
144152
// initial collators.
@@ -209,14 +217,14 @@ pub mod westend {
209217
pub(crate) const CORETIME_WESTEND_DEVELOPMENT: &str = "coretime-westend-dev";
210218
const CORETIME_WESTEND_ED: Balance = parachains_common::westend::currency::EXISTENTIAL_DEPOSIT;
211219

212-
pub fn local_config(runtime_type: &CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec {
220+
pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec {
213221
// westend defaults
214222
let mut properties = sc_chain_spec::Properties::new();
215223
properties.insert("ss58Format".into(), 42.into());
216224
properties.insert("tokenSymbol".into(), "WND".into());
217225
properties.insert("tokenDecimals".into(), 12.into());
218226

219-
let chain_type = runtime_type.clone().into();
227+
let chain_type = runtime_type.into();
220228
let chain_name = format!("Coretime Westend {}", chain_type_name(&chain_type));
221229
let para_id = super::CORETIME_PARA_ID;
222230

@@ -226,7 +234,7 @@ pub mod westend {
226234
Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() },
227235
)
228236
.with_name(&chain_name)
229-
.with_id(runtime_type.clone().into())
237+
.with_id(runtime_type.into())
230238
.with_chain_type(chain_type)
231239
.with_genesis_config_patch(genesis(
232240
// initial collators.

polkadot/runtime/parachains/src/coretime/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use pallet_broker::{CoreAssignment, CoreIndex as BrokerCoreIndex};
2727
use primitives::{CoreIndex, Id as ParaId};
2828
use sp_arithmetic::traits::SaturatedConversion;
2929
use xcm::v3::{
30-
send_xcm, Instruction, Junction, Junctions, MultiLocation, OriginKind, SendXcm, Xcm,
30+
send_xcm, Instruction, Junction, Junctions, MultiLocation, OriginKind, SendXcm, WeightLimit,
31+
Xcm,
3132
};
3233

3334
use crate::{
@@ -220,9 +221,13 @@ impl<T: Config> Pallet<T> {
220221
let new_core_count = notification.new_config.coretime_cores;
221222
if new_core_count != old_core_count {
222223
let core_count: u16 = new_core_count.saturated_into();
223-
let message = Xcm(vec![mk_coretime_call(
224-
crate::coretime::CoretimeCalls::NotifyCoreCount(core_count),
225-
)]);
224+
let message = Xcm(vec![
225+
Instruction::UnpaidExecution {
226+
weight_limit: WeightLimit::Unlimited,
227+
check_origin: None,
228+
},
229+
mk_coretime_call(crate::coretime::CoretimeCalls::NotifyCoreCount(core_count)),
230+
]);
226231
if let Err(err) = send_xcm::<T::SendXcm>(
227232
MultiLocation {
228233
parents: 0,
@@ -247,7 +252,7 @@ fn mk_coretime_call(call: crate::coretime::CoretimeCalls) -> Instruction<()> {
247252
origin_kind: OriginKind::Superuser,
248253
// Largest call is set_lease with 1526 byte:
249254
// Longest call is reserve() with 31_000_000
250-
require_weight_at_most: Weight::from_parts(100_000_000, 20_000),
255+
require_weight_at_most: Weight::from_parts(110_000_000, 20_000),
251256
call: BrokerRuntimePallets::Broker(call).encode().into(),
252257
}
253258
}

polkadot/zombienet_tests/smoke/0004-configure-broker.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@ async function run(nodeName, networkInfo, _jsArgs) {
1313
const calls = [
1414
// Default broker configuration
1515
api.tx.broker.configure({
16-
advanceNotice: 2,
16+
advanceNotice: 5,
1717
interludeLength: 1,
1818
leadinLength: 1,
19-
regionLength: 3,
19+
regionLength: 1,
2020
idealBulkProportion: 100,
2121
limitCoresOffered: null,
2222
renewalBump: 10,
2323
contributionTimeout: 5,
2424
}),
25-
// Make reservation for ParaId 100 (adder-a) every other block
26-
// and ParaId 101 (adder-b) every other block.
27-
api.tx.broker.reserve([
28-
{
29-
mask: [255, 0, 255, 0, 255, 0, 255, 0, 255, 0],
30-
assignment: { Task: 100 },
31-
},
32-
{
33-
mask: [0, 255, 0, 255, 0, 255, 0, 255, 0, 255],
34-
assignment: { Task: 101 },
35-
},
36-
]),
37-
// Start sale with 1 core starting at 1 planck
38-
api.tx.broker.startSales(1, 1),
25+
// We need MOARE cores.
26+
api.tx.broker.requestCoreCount(2),
27+
// Set a lease for the broker chain itself.
28+
api.tx.broker.setLease(
29+
1005,
30+
1000,
31+
),
32+
// Set a lease for parachain 100
33+
api.tx.broker.setLease(
34+
100,
35+
1000,
36+
),
37+
// Start sale to make the broker "work", but we don't offer any cores
38+
// as we have fixed leases only anyway.
39+
api.tx.broker.startSales(1, 0),
3940
];
4041
const sudo_batch = api.tx.sudo.sudo(api.tx.utility.batch(calls));
4142

polkadot/zombienet_tests/smoke/0004-configure-relay.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
const assert = require("assert");
22

33
async function run(nodeName, networkInfo, _jsArgs) {
4-
const { wsUri, userDefinedTypes } = networkInfo.nodesByName[nodeName];
4+
const init = networkInfo.nodesByName[nodeName];
5+
let wsUri = init.wsUri;
6+
let userDefinedTypes = init.userDefinedTypes;
57
const api = await zombie.connect(wsUri, userDefinedTypes);
68

9+
const sec = networkInfo.nodesByName["collator-para-100"];
10+
wsUri = sec.wsUri;
11+
userDefinedTypes = sec.userDefinedTypes;
12+
13+
const api_collator = await zombie.connect(wsUri, userDefinedTypes);
14+
715
await zombie.util.cryptoWaitReady();
816

17+
// Get the genesis header and the validation code of parachain 100
18+
const genesis_header = await api_collator.rpc.chain.getHeader();
19+
const validation_code = await api_collator.rpc.state.getStorage("0x3A636F6465");
20+
921
// account to submit tx
1022
const keyring = new zombie.Keyring({ type: "sr25519" });
1123
const alice = keyring.addFromUri("//Alice");
1224

1325
const calls = [
1426
api.tx.configuration.setCoretimeCores({ new: 1 }),
15-
api.tx.coretime.assignCore(0, 20,[[ { task: 1005 }, 57600 ]], null)
27+
api.tx.coretime.assignCore(0, 20,[[ { task: 1005 }, 57600 ]], null),
28+
api.tx.registrar.forceRegister(
29+
alice.address,
30+
0,
31+
100,
32+
genesis_header.toHex(),
33+
validation_code.toHex(),
34+
)
1635
];
1736
const sudo_batch = api.tx.sudo.sudo(api.tx.utility.batch(calls));
1837

polkadot/zombienet_tests/smoke/0004-coretime-smoke-test.toml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ command = "polkadot"
88

99
[[relaychain.nodes]]
1010
name = "alice"
11-
args = ["-lruntime=debug,parachain=trace" ]
11+
args = ["-lruntime=debug,xcm=trace" ]
1212

1313
[[relaychain.nodes]]
1414
name = "bob"
@@ -24,35 +24,18 @@ chain = "coretime-rococo-local"
2424

2525
[parachains.collator]
2626
name = "coretime-collator"
27-
image = "{{COL_IMAGE}}"
27+
image = "{{CUMULUS_IMAGE}}"
2828
command = "polkadot-parachain"
29-
args = [ "-lruntime=debug,parachain=trace" ]
29+
args = [ "-lruntime=debug,xcm=trace" ]
3030

3131
[[parachains]]
3232
id = 100
3333
add_to_genesis = false
34-
register_para = true
35-
onboard_as_parachain = false
36-
37-
[parachains.collator]
38-
name = "adder-a"
39-
image = "{{COL_IMAGE}}"
40-
command = "adder-collator"
41-
args = [ "-lruntime=debug,parachain=trace" ]
42-
43-
[[parachains]]
44-
id = 101
45-
add_to_genesis = false
46-
register_para = true
34+
register_para = false
4735
onboard_as_parachain = false
4836

4937
[parachains.collator]
50-
name = "adder-b"
51-
image = "{{COL_IMAGE}}"
52-
command = "adder-collator"
53-
args = [ "-lruntime=debug,parachain=trace" ]
54-
55-
[types.Header]
56-
number = "u64"
57-
parent_hash = "Hash"
58-
post_state = "Hash"
38+
name = "collator-para-100"
39+
image = "{{CUMULUS_IMAGE}}"
40+
command = "polkadot-parachain"
41+
args = ["-lruntime=debug,parachain=trace,aura=trace", "--force-authoring"]

0 commit comments

Comments
 (0)