Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit ca602a1

Browse files
authored
Merge branch 'master' into nv-assign-db-weights
2 parents cab044e + 31a62f2 commit ca602a1

23 files changed

Lines changed: 624 additions & 385 deletions

File tree

Cargo.lock

Lines changed: 188 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collator/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ pub trait Network: Send + Sync {
8383
/// The returned stream will not terminate, so it is required to make sure that the stream is
8484
/// dropped when it is not required anymore. Otherwise, it will stick around in memory
8585
/// infinitely.
86-
fn checked_statements(&self, relay_parent: Hash) -> Pin<Box<dyn Stream<Item=SignedStatement>>>;
86+
fn checked_statements(&self, relay_parent: Hash) -> Pin<Box<dyn Stream<Item=SignedStatement> + Send>>;
8787
}
8888

8989
impl Network for polkadot_network::protocol::Service {
90-
fn checked_statements(&self, relay_parent: Hash) -> Pin<Box<dyn Stream<Item=SignedStatement>>> {
91-
polkadot_network::protocol::Service::checked_statements(self, relay_parent)
90+
fn checked_statements(&self, relay_parent: Hash) -> Pin<Box<dyn Stream<Item=SignedStatement> + Send>> {
91+
polkadot_network::protocol::Service::checked_statements(self, relay_parent).boxed()
9292
}
9393
}
9494

@@ -241,12 +241,14 @@ fn build_collator_service<S, P, Extrinsic>(
241241
let (service, handles) = service;
242242
let spawner = service.spawn_task_handle();
243243

244-
let polkadot_network = match handles.polkadot_network {
245-
None => return Err(
246-
"Collator cannot run when Polkadot-specific networking has not been started".into()
247-
),
248-
Some(n) => n,
249-
};
244+
let polkadot_network = handles.polkadot_network
245+
.ok_or_else(|| "Collator cannot run when Polkadot-specific networking has not been started")?;
246+
247+
// We don't require this here, but we need to make sure that the validation service is started.
248+
// This service makes sure the collator is joining the correct gossip topics and receives the appropiate
249+
// messages.
250+
handles.validation_service_handle
251+
.ok_or_else(|| "Collator cannot run when validation networking has not been started")?;
250252

251253
let client = service.client();
252254

network/src/protocol/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ impl<N: NetworkServiceOps> Service<N> {
13751375
/// Take care to drop the stream, as the sending side will not be cleaned
13761376
/// up until it is.
13771377
pub fn checked_statements(&self, relay_parent: Hash)
1378-
-> Pin<Box<dyn Stream<Item = SignedStatement>>> {
1378+
-> impl Stream<Item = SignedStatement> + Send {
13791379
let (tx, rx) = oneshot::channel();
13801380
let mut sender = self.sender.clone();
13811381

@@ -1400,7 +1400,6 @@ impl<N: NetworkServiceOps> Service<N> {
14001400
}
14011401
})
14021402
.flatten_stream()
1403-
.boxed()
14041403
}
14051404
}
14061405

network/test/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "mas
1919
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
2020
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
2121
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
22-
env_logger = "0.7.0"
2322
polkadot-test-runtime-client = { path = "../../runtime/test-runtime/client" }

network/test/src/block_import.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ use super::*;
2727

2828
fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>) {
2929
let mut client = polkadot_test_runtime_client::new();
30-
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
30+
let mut builder = client.new_block(Default::default()).unwrap();
31+
32+
let extrinsics = polkadot_test_runtime_client::needed_extrinsics(vec![]);
33+
34+
for extrinsic in &extrinsics {
35+
builder.push(extrinsic.clone()).unwrap();
36+
}
37+
38+
let block = builder.build().unwrap().block;
3139
client.import(BlockOrigin::File, block).unwrap();
3240

3341
let (hash, number) = (client.block_hash(1).unwrap().unwrap(), 1);
@@ -37,7 +45,7 @@ fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>)
3745
(client, hash, number, peer_id.clone(), IncomingBlock {
3846
hash,
3947
header,
40-
body: Some(Vec::new()),
48+
body: Some(extrinsics),
4149
justification,
4250
origin: Some(peer_id.clone()),
4351
allow_missing_state: false,

parachain/src/wasm_executor/mod.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
use std::any::{TypeId, Any};
2424
use crate::primitives::{ValidationParams, ValidationResult, UpwardMessage};
2525
use codec::{Decode, Encode};
26-
use sp_core::storage::{ChildStorageKey, ChildInfo};
26+
use sp_core::storage::ChildInfo;
2727
use sp_core::traits::CallInWasm;
2828
use sp_wasm_interface::HostFunctions as _;
29+
use sp_externalities::Extensions;
2930

3031
#[cfg(not(target_os = "unknown"))]
3132
pub use validation_host::{run_worker, ValidationPool, EXECUTION_TIMEOUT_SEC};
@@ -171,7 +172,11 @@ pub fn validate_candidate_internal<E: Externalities + 'static>(
171172
encoded_call_data: &[u8],
172173
externalities: E,
173174
) -> Result<ValidationResult, Error> {
174-
let mut ext = ValidationExternalities(ParachainExt::new(externalities));
175+
let mut extensions = Extensions::new();
176+
extensions.register(ParachainExt::new(externalities));
177+
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));
178+
179+
let mut ext = ValidationExternalities(extensions);
175180

176181
let executor = sc_executor::WasmExecutor::new(
177182
sc_executor::WasmExecutionMethod::Interpreted,
@@ -194,7 +199,7 @@ pub fn validate_candidate_internal<E: Externalities + 'static>(
194199

195200
/// The validation externalities that will panic on any storage related access. They just provide
196201
/// access to the parachain extension.
197-
struct ValidationExternalities(ParachainExt);
202+
struct ValidationExternalities(Extensions);
198203

199204
impl sp_externalities::Externalities for ValidationExternalities {
200205
fn storage(&self, _: &[u8]) -> Option<Vec<u8>> {
@@ -205,31 +210,31 @@ impl sp_externalities::Externalities for ValidationExternalities {
205210
panic!("storage_hash: unsupported feature for parachain validation")
206211
}
207212

208-
fn child_storage_hash(&self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
213+
fn child_storage_hash(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
209214
panic!("child_storage_hash: unsupported feature for parachain validation")
210215
}
211216

212-
fn child_storage(&self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
217+
fn child_storage(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
213218
panic!("child_storage: unsupported feature for parachain validation")
214219
}
215220

216-
fn kill_child_storage(&mut self, _: ChildStorageKey, _: ChildInfo) {
221+
fn kill_child_storage(&mut self, _: &ChildInfo) {
217222
panic!("kill_child_storage: unsupported feature for parachain validation")
218223
}
219224

220225
fn clear_prefix(&mut self, _: &[u8]) {
221226
panic!("clear_prefix: unsupported feature for parachain validation")
222227
}
223228

224-
fn clear_child_prefix(&mut self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) {
229+
fn clear_child_prefix(&mut self, _: &ChildInfo, _: &[u8]) {
225230
panic!("clear_child_prefix: unsupported feature for parachain validation")
226231
}
227232

228233
fn place_storage(&mut self, _: Vec<u8>, _: Option<Vec<u8>>) {
229234
panic!("place_storage: unsupported feature for parachain validation")
230235
}
231236

232-
fn place_child_storage(&mut self, _: ChildStorageKey, _: ChildInfo, _: Vec<u8>, _: Option<Vec<u8>>) {
237+
fn place_child_storage(&mut self, _: &ChildInfo, _: Vec<u8>, _: Option<Vec<u8>>) {
233238
panic!("place_child_storage: unsupported feature for parachain validation")
234239
}
235240

@@ -241,15 +246,15 @@ impl sp_externalities::Externalities for ValidationExternalities {
241246
panic!("storage_root: unsupported feature for parachain validation")
242247
}
243248

244-
fn child_storage_root(&mut self, _: ChildStorageKey) -> Vec<u8> {
249+
fn child_storage_root(&mut self, _: &ChildInfo) -> Vec<u8> {
245250
panic!("child_storage_root: unsupported feature for parachain validation")
246251
}
247252

248253
fn storage_changes_root(&mut self, _: &[u8]) -> Result<Option<Vec<u8>>, ()> {
249254
panic!("storage_changes_root: unsupported feature for parachain validation")
250255
}
251256

252-
fn next_child_storage_key(&self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
257+
fn next_child_storage_key(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
253258
panic!("next_child_storage_key: unsupported feature for parachain validation")
254259
}
255260

@@ -268,25 +273,24 @@ impl sp_externalities::Externalities for ValidationExternalities {
268273

269274
impl sp_externalities::ExtensionStore for ValidationExternalities {
270275
fn extension_by_type_id(&mut self, type_id: TypeId) -> Option<&mut dyn Any> {
271-
if type_id == TypeId::of::<ParachainExt>() {
272-
Some(&mut self.0)
273-
} else {
274-
None
275-
}
276+
self.0.get_mut(type_id)
276277
}
277278

278279
fn register_extension_with_type_id(
279280
&mut self,
280-
_type_id: TypeId,
281-
_extension: Box<dyn sp_externalities::Extension>,
281+
type_id: TypeId,
282+
extension: Box<dyn sp_externalities::Extension>,
282283
) -> Result<(), sp_externalities::Error> {
283-
panic!("register_extension_with_type_id: unsupported feature for parachain validation")
284+
self.0.register_with_type_id(type_id, extension)
284285
}
285286

286287
fn deregister_extension_by_type_id(
287288
&mut self,
288-
_type_id: TypeId,
289+
type_id: TypeId,
289290
) -> Result<(), sp_externalities::Error> {
290-
panic!("deregister_extension_by_type_id: unsupported feature for parachain validation")
291+
match self.0.deregister(type_id) {
292+
Some(_) => Ok(()),
293+
None => Err(sp_externalities::Error::ExtensionIsNotRegistered(type_id))
294+
}
291295
}
292296
}

runtime/common/src/attestations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use frame_support::{
2525
decl_storage, decl_module, decl_error, ensure,
2626
dispatch::DispatchResult,
2727
traits::Get,
28-
weights::{MINIMUM_WEIGHT, SimpleDispatchInfo},
28+
weights::{MINIMUM_WEIGHT, DispatchClass},
2929
};
3030

3131
use primitives::{Hash, parachain::{AttestedCandidate, AbridgedCandidateReceipt, Id as ParaId}};
@@ -134,7 +134,7 @@ decl_module! {
134134
type Error = Error<T>;
135135

136136
/// Provide candidate receipts for parachains, in ascending order by id.
137-
#[weight = SimpleDispatchInfo::FixedMandatory(MINIMUM_WEIGHT)]
137+
#[weight = (MINIMUM_WEIGHT, DispatchClass::Mandatory)]
138138
fn more_attestations(origin, _more: MoreAttestations) -> DispatchResult {
139139
ensure_none(origin)?;
140140
ensure!(!DidUpdate::exists(), Error::<T>::TooManyAttestations);

runtime/common/src/claims.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use sp_std::prelude::*;
2020
use sp_io::{hashing::keccak_256, crypto::secp256k1_ecdsa_recover};
2121
use frame_support::{decl_event, decl_storage, decl_module, decl_error};
22-
use frame_support::weights::SimpleDispatchInfo;
2322
use frame_support::traits::{Currency, Get, VestingSchedule};
2423
use system::{ensure_root, ensure_none};
2524
use codec::{Encode, Decode};
@@ -184,7 +183,7 @@ decl_module! {
184183
///
185184
/// Total Complexity: O(1)
186185
/// </weight>
187-
#[weight = SimpleDispatchInfo::FixedNormal(1_000_000_000)]
186+
#[weight = 1_000_000_000]
188187
fn claim(origin, dest: T::AccountId, ethereum_signature: EcdsaSignature) {
189188
ensure_none(origin)?;
190189

@@ -231,7 +230,7 @@ decl_module! {
231230
///
232231
/// Total Complexity: O(1)
233232
/// </weight>
234-
#[weight = SimpleDispatchInfo::FixedNormal(30_000_000)]
233+
#[weight = 30_000_000]
235234
fn mint_claim(origin,
236235
who: EthereumAddress,
237236
value: BalanceOf<T>,

runtime/common/src/crowdfund.rs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use frame_support::{
7171
traits::{
7272
Currency, Get, OnUnbalanced, WithdrawReason, ExistenceRequirement::AllowDeath
7373
},
74-
weights::{MINIMUM_WEIGHT, SimpleDispatchInfo},
74+
weights::MINIMUM_WEIGHT,
7575
};
7676
use system::ensure_signed;
7777
use sp_runtime::{ModuleId,
@@ -80,7 +80,6 @@ use sp_runtime::{ModuleId,
8080
use crate::slots;
8181
use codec::{Encode, Decode};
8282
use sp_std::vec::Vec;
83-
use sp_core::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
8483
use primitives::parachain::{Id as ParaId, HeadData};
8584

8685
const MODULE_ID: ModuleId = ModuleId(*b"py/cfund");
@@ -251,7 +250,7 @@ decl_module! {
251250
fn deposit_event() = default;
252251

253252
/// Create a new crowdfunding campaign for a parachain slot deposit for the current auction.
254-
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
253+
#[weight = 100_000_000]
255254
fn create(origin,
256255
#[compact] cap: BalanceOf<T>,
257256
#[compact] first_slot: T::BlockNumber,
@@ -295,7 +294,7 @@ decl_module! {
295294
/// Contribute to a crowd sale. This will transfer some balance over to fund a parachain
296295
/// slot. It will be withdrawable in two instances: the parachain becomes retired; or the
297296
/// slot is unable to be purchased and the timeout expires.
298-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
297+
#[weight = MINIMUM_WEIGHT]
299298
fn contribute(origin, #[compact] index: FundIndex, #[compact] value: BalanceOf<T>) {
300299
let who = ensure_signed(origin)?;
301300

@@ -354,7 +353,7 @@ decl_module! {
354353
/// - `index` is the fund index that `origin` owns and whose deploy data will be set.
355354
/// - `code_hash` is the hash of the parachain's Wasm validation function.
356355
/// - `initial_head_data` is the parachain's initial head data.
357-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
356+
#[weight = MINIMUM_WEIGHT]
358357
fn fix_deploy_data(origin,
359358
#[compact] index: FundIndex,
360359
code_hash: T::Hash,
@@ -380,7 +379,7 @@ decl_module! {
380379
///
381380
/// - `index` is the fund index that `origin` owns and whose deploy data will be set.
382381
/// - `para_id` is the parachain index that this fund won.
383-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
382+
#[weight = MINIMUM_WEIGHT]
384383
fn onboard(origin,
385384
#[compact] index: FundIndex,
386385
#[compact] para_id: ParaId
@@ -409,7 +408,7 @@ decl_module! {
409408
}
410409

411410
/// Note that a successful fund has lost its parachain slot, and place it into retirement.
412-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
411+
#[weight = MINIMUM_WEIGHT]
413412
fn begin_retirement(origin, #[compact] index: FundIndex) {
414413
let _ = ensure_signed(origin)?;
415414

@@ -431,7 +430,7 @@ decl_module! {
431430
}
432431

433432
/// Withdraw full balance of a contributor to an unsuccessful or off-boarded fund.
434-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
433+
#[weight = MINIMUM_WEIGHT]
435434
fn withdraw(origin, #[compact] index: FundIndex) {
436435
let who = ensure_signed(origin)?;
437436

@@ -462,7 +461,7 @@ decl_module! {
462461
/// Remove a fund after either: it was unsuccessful and it timed out; or it was successful
463462
/// but it has been retired from its parachain slot. This places any deposits that were not
464463
/// withdrawn into the treasury.
465-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
464+
#[weight = MINIMUM_WEIGHT]
466465
fn dissolve(origin, #[compact] index: FundIndex) {
467466
let _ = ensure_signed(origin)?;
468467

@@ -529,46 +528,30 @@ impl<T: Trait> Module<T> {
529528
MODULE_ID.into_sub_account(index)
530529
}
531530

532-
pub fn id_from_index(index: FundIndex) -> Vec<u8> {
531+
pub fn id_from_index(index: FundIndex) -> child::ChildInfo {
533532
let mut buf = Vec::new();
534533
buf.extend_from_slice(b"crowdfund");
535534
buf.extend_from_slice(&index.to_le_bytes()[..]);
536-
537-
CHILD_STORAGE_KEY_PREFIX.into_iter()
538-
.chain(b"default:")
539-
.chain(T::Hashing::hash(&buf[..]).as_ref().into_iter())
540-
.cloned()
541-
.collect()
542-
}
543-
544-
/// Child trie unique id for a crowdfund is built from the hash part of the fund id.
545-
pub fn trie_unique_id(fund_id: &[u8]) -> child::ChildInfo {
546-
let start = CHILD_STORAGE_KEY_PREFIX.len() + b"default:".len();
547-
child::ChildInfo::new_default(&fund_id[start..])
535+
child::ChildInfo::new_default(T::Hashing::hash(&buf[..]).as_ref())
548536
}
549537

550538
pub fn contribution_put(index: FundIndex, who: &T::AccountId, balance: &BalanceOf<T>) {
551-
let id = Self::id_from_index(index);
552-
who.using_encoded(|b| child::put(id.as_ref(), Self::trie_unique_id(id.as_ref()), b, balance));
539+
who.using_encoded(|b| child::put(&Self::id_from_index(index), b, balance));
553540
}
554541

555542
pub fn contribution_get(index: FundIndex, who: &T::AccountId) -> BalanceOf<T> {
556-
let id = Self::id_from_index(index);
557543
who.using_encoded(|b| child::get_or_default::<BalanceOf<T>>(
558-
id.as_ref(),
559-
Self::trie_unique_id(id.as_ref()),
544+
&Self::id_from_index(index),
560545
b,
561546
))
562547
}
563548

564549
pub fn contribution_kill(index: FundIndex, who: &T::AccountId) {
565-
let id = Self::id_from_index(index);
566-
who.using_encoded(|b| child::kill(id.as_ref(), Self::trie_unique_id(id.as_ref()), b));
550+
who.using_encoded(|b| child::kill(&Self::id_from_index(index), b));
567551
}
568552

569553
pub fn crowdfund_kill(index: FundIndex) {
570-
let id = Self::id_from_index(index);
571-
child::kill_storage(id.as_ref(), Self::trie_unique_id(id.as_ref()));
554+
child::kill_storage(&Self::id_from_index(index));
572555
}
573556
}
574557

0 commit comments

Comments
 (0)