Skip to content

Commit 2c63ccb

Browse files
authored
One node two runtimes (paritytech#191)
* One node two runtimes This enables the rococo-collator to run the normal and the contracts runtime. * Fix tests
1 parent 96da14c commit 2c63ccb

33 files changed

Lines changed: 1973 additions & 1481 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"rococo-parachains/contracts-runtime",
1010
"rococo-parachains/pallets/parachain-info",
1111
"rococo-parachains/pallets/token-dealer",
12+
"rococo-parachains/primitives",
1213
"rococo-parachains/runtime",
1314
"runtime",
1415
"service",

collator/src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -518,18 +518,17 @@ where
518518
Box::new(self.polkadot_network.clone()),
519519
)));
520520

521-
let follow =
522-
match cumulus_consensus::follow_polkadot(
523-
self.para_id,
524-
self.client,
525-
polkadot_client,
526-
self.announce_block.clone(),
527-
) {
528-
Ok(follow) => follow,
529-
Err(e) => {
530-
return Err(error!("Could not start following polkadot: {:?}", e));
531-
}
532-
};
521+
let follow = match cumulus_consensus::follow_polkadot(
522+
self.para_id,
523+
self.client,
524+
polkadot_client,
525+
self.announce_block.clone(),
526+
) {
527+
Ok(follow) => follow,
528+
Err(e) => {
529+
return Err(error!("Could not start following polkadot: {:?}", e));
530+
}
531+
};
533532

534533
self.spawner
535534
.spawn("cumulus-follow-polkadot", follow.map(|_| ()).boxed());

network/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ mod tests;
2323

2424
use sp_api::ProvideRuntimeApi;
2525
use sp_blockchain::{Error as ClientError, HeaderBackend};
26-
use sp_consensus::{block_validation::{BlockAnnounceValidator, Validation}, SyncOracle};
26+
use sp_consensus::{
27+
block_validation::{BlockAnnounceValidator, Validation},
28+
SyncOracle,
29+
};
2730
use sp_core::traits::SpawnNamed;
2831
use sp_runtime::{
2932
generic::BlockId,

network/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
use super::*;
1818
use cumulus_test_runtime::{Block, Header};
1919
use polkadot_primitives::v0::{
20-
AbridgedCandidateReceipt, Chain, CollatorId, DutyRoster, GlobalValidationData,
21-
Id as ParaId, LocalValidationData, ParachainHost, Retriable, SigningContext,
22-
ValidationCode, ValidatorId, Block as PBlock, Hash as PHash, Header as PHeader,
20+
AbridgedCandidateReceipt, Block as PBlock, Chain, CollatorId, DutyRoster, GlobalValidationData,
21+
Hash as PHash, Header as PHeader, Id as ParaId, LocalValidationData, ParachainHost, Retriable,
22+
SigningContext, ValidationCode, ValidatorId,
2323
};
2424
use polkadot_test_runtime_client::{
2525
DefaultTestClientBuilderExt, TestClient, TestClientBuilder, TestClientBuilderExt,

rococo-parachains/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ hex-literal = "0.2.1"
2525
# Parachain dependencies
2626
parachain-runtime = { package = "cumulus-test-parachain-runtime", path = "runtime" }
2727
parachain-contracts-runtime = { package = "cumulus-contracts-parachain-runtime", path = "contracts-runtime" }
28+
rococo-parachain-primitives = { path = "primitives" }
2829

2930
# Substrate dependencies
3031
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
3132
sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
3233
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
3334
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
3435
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
36+
sp-session = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
3537
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
3638
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
3739
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
@@ -42,11 +44,15 @@ sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch
4244
sc-network = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
4345
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", version = "0.8.0-rc5" }
4446
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
47+
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
48+
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
4549
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
4650
sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
4751
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
4852
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
4953
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
54+
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
55+
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
5056

5157
# RPC related dependencies
5258
cumulus-pallet-contracts-rpc = { path = "./pallets/contracts/rpc" }

rococo-parachains/contracts-runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.3.0", default-features =
1010

1111
cumulus-token-dealer = { path = "../pallets/token-dealer", default-features = false}
1212
parachain-info = { path = "../pallets/parachain-info", default-features = false}
13+
rococo-parachain-primitives = { path = "../primitives", default-features = false}
1314

1415
# Substrate dependencies
1516
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
@@ -79,6 +80,7 @@ std = [
7980
"pallet-sudo/std",
8081
"pallet-transaction-payment/std",
8182
"parachain-info/std",
83+
"rococo-parachain-primitives/std",
8284
"cumulus-runtime/std",
8385
"cumulus-parachain-upgrade/std",
8486
"cumulus-message-broker/std",

rococo-parachains/contracts-runtime/src/lib.rs

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
2424

2525
use cumulus_pallet_contracts_rpc_runtime_api::ContractExecResult;
26+
use rococo_parachain_primitives::*;
2627
use sp_api::impl_runtime_apis;
2728
use sp_core::OpaqueMetadata;
2829
use sp_runtime::{
2930
create_runtime_str, generic, impl_opaque_keys,
30-
traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Saturating, Verify},
31+
traits::{BlakeTwo256, Block as BlockT, IdentityLookup, Saturating},
3132
transaction_validity::{TransactionSource, TransactionValidity},
32-
ApplyExtrinsicResult, MultiSignature,
33+
ApplyExtrinsicResult,
3334
};
3435
use sp_std::prelude::*;
3536
#[cfg(feature = "std")]
@@ -49,61 +50,18 @@ pub use pallet_timestamp::Call as TimestampCall;
4950
pub use sp_runtime::BuildStorage;
5051
pub use sp_runtime::{Perbill, Permill};
5152

52-
/// An index to a block.
53-
pub type BlockNumber = u32;
53+
pub type SessionHandlers = ();
5454

55-
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
56-
pub type Signature = MultiSignature;
57-
58-
/// Some way of identifying an account on the chain. We intentionally make it equivalent
59-
/// to the public key of our transaction signing scheme.
60-
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
61-
62-
/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
63-
/// never know...
64-
pub type AccountIndex = u32;
65-
66-
/// Balance of an account.
67-
pub type Balance = u128;
68-
69-
/// Index of a transaction in the chain.
70-
pub type Index = u32;
71-
72-
/// A hash of some data used by the chain.
73-
pub type Hash = sp_core::H256;
74-
75-
/// Digest item type.
76-
pub type DigestItem = generic::DigestItem<Hash>;
77-
78-
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
79-
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
80-
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
81-
/// to even the core datastructures.
82-
pub mod opaque {
83-
use super::*;
84-
85-
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
86-
87-
/// Opaque block header type.
88-
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
89-
/// Opaque block type.
90-
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
91-
/// Opaque block identifier type.
92-
pub type BlockId = generic::BlockId<Block>;
93-
94-
pub type SessionHandlers = ();
95-
96-
impl_opaque_keys! {
97-
pub struct SessionKeys {}
98-
}
55+
impl_opaque_keys! {
56+
pub struct SessionKeys {}
9957
}
10058

10159
/// This runtime version.
10260
pub const VERSION: RuntimeVersion = RuntimeVersion {
10361
spec_name: create_runtime_str!("cumulus-contracts-parachain"),
10462
impl_name: create_runtime_str!("cumulus-contracts-parachain"),
10563
authoring_version: 1,
106-
spec_version: 1,
64+
spec_version: 2,
10765
impl_version: 1,
10866
apis: RUNTIME_API_VERSIONS,
10967
transaction_version: 1,
@@ -292,7 +250,7 @@ impl cumulus_pallet_contracts::Trait for Runtime {
292250
construct_runtime! {
293251
pub enum Runtime where
294252
Block = Block,
295-
NodeBlock = opaque::Block,
253+
NodeBlock = rococo_parachain_primitives::Block,
296254
UncheckedExtrinsic = UncheckedExtrinsic
297255
{
298256
System: frame_system::{Module, Call, Storage, Config, Event<T>},
@@ -405,11 +363,11 @@ impl_runtime_apis! {
405363
fn decode_session_keys(
406364
encoded: Vec<u8>,
407365
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
408-
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
366+
SessionKeys::decode_into_raw_public_keys(&encoded)
409367
}
410368

411369
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
412-
opaque::SessionKeys::generate(seed)
370+
SessionKeys::generate(seed)
413371
}
414372
}
415373

rococo-parachains/pallets/contracts/rpc/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
use std::sync::Arc;
2121

2222
use codec::Codec;
23+
use cumulus_pallet_contracts_primitives::RentProjection;
2324
use jsonrpc_core::{Error, ErrorCode, Result};
2425
use jsonrpc_derive::rpc;
25-
use cumulus_pallet_contracts_primitives::RentProjection;
2626
use serde::{Deserialize, Serialize};
2727
use sp_api::ProvideRuntimeApi;
2828
use sp_blockchain::HeaderBackend;
@@ -106,7 +106,11 @@ pub enum RpcContractExecResult {
106106
impl From<ContractExecResult> for RpcContractExecResult {
107107
fn from(r: ContractExecResult) -> Self {
108108
match r {
109-
ContractExecResult::Success { flags, data, gas_consumed } => RpcContractExecResult::Success {
109+
ContractExecResult::Success {
110+
flags,
111+
data,
112+
gas_consumed,
113+
} => RpcContractExecResult::Success {
110114
flags,
111115
data: data.into(),
112116
gas_consumed,
@@ -293,15 +297,18 @@ mod tests {
293297
#[test]
294298
fn call_request_should_serialize_deserialize_properly() {
295299
type Req = CallRequest<String, u128>;
296-
let req: Req = serde_json::from_str(r#"
300+
let req: Req = serde_json::from_str(
301+
r#"
297302
{
298303
"origin": "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL",
299304
"dest": "5DRakbLVnjVrW6niwLfHGW24EeCEvDAFGEXrtaYS5M4ynoom",
300305
"value": 0,
301306
"gasLimit": 1000000000000,
302307
"inputData": "0x8c97db39"
303308
}
304-
"#).unwrap();
309+
"#,
310+
)
311+
.unwrap();
305312
assert_eq!(req.gas_limit.into_u256(), U256::from(0xe8d4a51000u64));
306313
}
307314

rococo-parachains/pallets/contracts/src/account_db.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ use super::{
2121
TrieIdGenerator,
2222
};
2323
use crate::exec::StorageKey;
24-
use sp_std::cell::RefCell;
25-
use sp_std::collections::btree_map::{BTreeMap, Entry};
26-
use sp_std::prelude::*;
24+
use frame_support::{
25+
storage::unhashed as storage,
26+
traits::{Currency, Imbalance, SignedImbalance},
27+
StorageMap,
28+
};
29+
use frame_system;
2730
use sp_io::hashing::blake2_256;
2831
use sp_runtime::traits::{Bounded, Zero};
29-
use frame_support::traits::{Currency, Imbalance, SignedImbalance};
30-
use frame_support::{storage::unhashed as storage, StorageMap};
31-
use frame_system;
32+
use sp_std::{
33+
cell::RefCell,
34+
collections::btree_map::{BTreeMap, Entry},
35+
prelude::*,
36+
};
3237

3338
// Note: we don't provide Option<Contract> because we can't create
3439
// the trie_id in the overlay, thus we provide an overlay on the fields
@@ -133,8 +138,7 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {
133138
trie_id: Option<&TrieId>,
134139
location: &StorageKey,
135140
) -> Option<Vec<u8>> {
136-
trie_id
137-
.and_then(|id| storage::get_raw(&crate::prefixed_key(id, &blake2_256(location))))
141+
trie_id.and_then(|id| storage::get_raw(&crate::prefixed_key(id, &blake2_256(location))))
138142
}
139143
fn get_code_hash(&self, account: &T::AccountId) -> Option<CodeHash<T>> {
140144
<ContractInfoOf<T>>::get(account).and_then(|i| i.as_alive().map(|i| i.code_hash))
@@ -241,13 +245,13 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {
241245
if prev_value.is_empty() {
242246
new_info.empty_pair_count -= 1;
243247
}
244-
},
248+
}
245249
(None, Some(new_value)) => {
246250
new_info.total_pair_count += 1;
247251
if new_value.is_empty() {
248252
new_info.empty_pair_count += 1;
249253
}
250-
},
254+
}
251255
(Some(prev_value), Some(new_value)) => {
252256
if prev_value.is_empty() {
253257
new_info.empty_pair_count -= 1;

0 commit comments

Comments
 (0)