Skip to content

Commit f77adcb

Browse files
committed
node: pull types from primitives
1 parent 9c764b3 commit f77adcb

File tree

14 files changed

+295
-300
lines changed

14 files changed

+295
-300
lines changed

Cargo.lock

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

sugondat-chain/node/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ serde_json = "1.0.108"
2020

2121
# Local
2222
sugondat-test-runtime = { path = "../runtimes/test" }
23+
sugondat-kusama-runtime = { path = "../runtimes/sugondat-kusama" }
24+
sugondat-primitives = { path = "../primitives" }
2325

2426
# Substrate
2527
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
@@ -49,7 +51,9 @@ sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "releas
4951
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
5052
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
5153
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
54+
sp-session = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
5255
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
56+
sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
5357
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
5458
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
5559
try-runtime-cli = { git = "https://github.com/paritytech/polkadot-sdk", optional = true , branch = "release-polkadot-v1.2.0" }

sugondat-chain/node/src/chain_spec/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use sc_service::ChainType;
44
use serde::{Deserialize, Serialize};
55
use sp_core::{sr25519, Pair, Public};
66
use sp_runtime::traits::{IdentifyAccount, Verify};
7-
use sugondat_test_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT};
7+
use sugondat_primitives::{AccountId, AuraId, Signature};
8+
use sugondat_test_runtime::EXISTENTIAL_DEPOSIT as TEST_EXISTENTIAL_DEPOSIT;
89

910
/// Specialized `ChainSpec` for the normal parachain runtime.
1011
pub type ChainSpec =
@@ -205,7 +206,7 @@ fn testnet_genesis(
205206
},
206207
collator_selection: sugondat_test_runtime::CollatorSelectionConfig {
207208
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
208-
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
209+
candidacy_bond: TEST_EXISTENTIAL_DEPOSIT * 16,
209210
..Default::default()
210211
},
211212
session: sugondat_test_runtime::SessionConfig {

sugondat-chain/node/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use sc_cli::{
99
};
1010
use sc_service::config::{BasePath, PrometheusConfig};
1111
use sp_runtime::traits::AccountIdConversion;
12-
use sugondat_test_runtime::Block;
12+
use sugondat_primitives::opaque::Block;
1313

1414
use crate::{
1515
chain_spec,

sugondat-chain/node/src/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use std::sync::Arc;
99

10-
use sugondat_test_runtime::{opaque::Block, AccountId, Balance, Nonce};
10+
use sugondat_primitives::{opaque::Block, AccountId, Balance, Nonce};
1111

1212
use sc_client_api::AuxStore;
1313
pub use sc_rpc::DenyUnsafe;

sugondat-chain/node/src/service.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
use std::{sync::Arc, time::Duration};
55

66
use cumulus_client_cli::CollatorOptions;
7-
// Local Runtime Types
8-
use sugondat_test_runtime::{
9-
opaque::{Block, Hash},
10-
RuntimeApi,
11-
};
7+
use sugondat_primitives::opaque::{Block, Hash};
128

139
// Cumulus Imports
1410
use cumulus_client_collator::service::CollatorService;
@@ -25,9 +21,7 @@ use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
2521
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
2622
use sc_client_api::Backend;
2723
use sc_consensus::ImportQueue;
28-
use sc_executor::{
29-
HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY,
30-
};
24+
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
3125
use sc_network::NetworkBlock;
3226
use sc_network_sync::SyncingService;
3327
use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager};
@@ -36,24 +30,29 @@ use sc_transaction_pool_api::OffchainTransactionPoolFactory;
3630
use sp_keystore::KeystorePtr;
3731
use substrate_prometheus_endpoint::Registry;
3832

39-
/// Native executor type.
40-
pub struct ParachainNativeExecutor;
41-
42-
impl sc_executor::NativeExecutionDispatch for ParachainNativeExecutor {
43-
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
44-
45-
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
46-
sugondat_test_runtime::api::dispatch(method, data)
47-
}
48-
49-
fn native_version() -> sc_executor::NativeVersion {
50-
sugondat_test_runtime::native_version()
51-
}
52-
}
53-
54-
type ParachainExecutor = NativeElseWasmExecutor<ParachainNativeExecutor>;
55-
56-
type ParachainClient = TFullClient<Block, RuntimeApi, ParachainExecutor>;
33+
// This is fine, even for the Kusama and Polkadot parachains.
34+
//
35+
// Runtime API invocations are one of the dumbest things in Substrate:
36+
//
37+
// Traits are auto-implemented for a struct based on an `impl_runtime_apis!` macro in the runtime code we're linking to,
38+
// but the implementation always calls into the underlying code executor because there is no guarantee that the
39+
// current runtime code on-chain is the same version as what we built this against.
40+
//
41+
// Basically, it's OK to always use the same Runtime API struct here, because the end result is that we always call
42+
// into the runtime. This could become a problem if some of the runtimes implement different runtime APIs from each other,
43+
// but that's not very likely for this use-case.
44+
type RuntimeApi = sugondat_test_runtime::RuntimeApi;
45+
46+
#[cfg(not(feature = "runtime-benchmarks"))]
47+
type HostFunctions = sp_io::SubstrateHostFunctions;
48+
49+
#[cfg(feature = "runtime-benchmarks")]
50+
type HostFunctions = (
51+
sp_io::SubstrateHostFunctions,
52+
frame_benchmarking::benchmarking::HostFunctions,
53+
);
54+
55+
type ParachainClient = TFullClient<Block, RuntimeApi, WasmExecutor<HostFunctions>>;
5756

5857
type ParachainBackend = TFullBackend<Block>;
5958

@@ -97,16 +96,14 @@ pub fn new_partial(
9796
extra_pages: h as _,
9897
});
9998

100-
let wasm = WasmExecutor::builder()
99+
let executor = WasmExecutor::<HostFunctions>::builder()
101100
.with_execution_method(config.wasm_method)
102101
.with_onchain_heap_alloc_strategy(heap_pages)
103102
.with_offchain_heap_alloc_strategy(heap_pages)
104103
.with_max_runtime_instances(config.max_runtime_instances)
105104
.with_runtime_cache_size(config.runtime_cache_size)
106105
.build();
107106

108-
let executor = ParachainExecutor::new_with_wasm_executor(wasm);
109-
110107
let (client, backend, keystore_container, task_manager) =
111108
sc_service::new_full_parts::<Block, RuntimeApi, _>(
112109
config,

sugondat-chain/primitives/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ license = "MIT OR Apache-2.0"
99
[dependencies]
1010
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.2.0" }
1111
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.2.0" }
12+
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.2.0" }
13+
14+
[features]
15+
default = ["std"]
16+
std = ["sp-runtime/std", "sp-core/std", "sp-consensus-aura/std"]

sugondat-chain/primitives/src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
12

3+
use sp_runtime::{
4+
traits::{IdentifyAccount, Verify},
5+
MultiSignature,
6+
};
7+
8+
/// An index to a block.
9+
pub type BlockNumber = u32;
10+
11+
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
12+
pub type Signature = MultiSignature;
13+
14+
/// Some way of identifying an account on the chain. We intentionally make it equivalent
15+
/// to the public key of our transaction signing scheme.
16+
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
17+
18+
/// Balance of an account.
19+
pub type Balance = u128;
20+
21+
/// Index of a transaction in the chain.
22+
pub type Nonce = u32;
23+
24+
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
25+
26+
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
27+
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
28+
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
29+
/// to even the core data structures.
30+
pub mod opaque {
31+
use super::*;
32+
use sp_runtime::{
33+
generic,
34+
traits::{BlakeTwo256, Hash as HashT},
35+
};
36+
37+
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
38+
/// Opaque block header type.
39+
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
40+
/// Opaque block type.
41+
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
42+
/// Opaque block identifier type.
43+
pub type BlockId = generic::BlockId<Block>;
44+
/// Opaque block hash type.
45+
pub type Hash = <BlakeTwo256 as HashT>::Output;
46+
}

sugondat-chain/runtimes/sugondat-kusama/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ smallvec = "1.10.0"
2222

2323
# Local
2424
pallet-sugondat-blobs = { path = "../../pallets/blobs", default-features = false }
25+
sugondat-primitives = { path = "../../primitives", default-features = false }
2526

2627
# Substrate
2728
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, optional = true, branch = "release-polkadot-v1.2.0" }
@@ -76,9 +77,6 @@ cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk
7677
pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false }
7778
parachain-info = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false }
7879

79-
sugondat-primitives = { path = "../../primitives" }
80-
81-
8280
[features]
8381
default = [ "std" ]
8482
std = [

0 commit comments

Comments
 (0)