This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
WIP removing native runtime #10872
Closed
Closed
WIP removing native runtime #10872
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
384c0a1
Started native runtime removal
arkpar 14ec4ae
Genesis built in the runtime
arkpar d3e357d
Cleanup
arkpar 67dd55f
Updated some tests
arkpar fcc794f
More fixes
arkpar 4b2aef8
Restore tests
arkpar 84990af
More test fixes
arkpar 11bba79
Additional test fixes
arkpar 0e478bf
Genesis builder does not care about host extensions
arkpar 5129d69
Removed chain-spec-builder
arkpar 0f503b1
Started runtiem extendable executor impl
arkpar 2e07b32
Sort out executor extensions
arkpar a9d61a8
Merge branch 'master' of github.com:paritytech/substrate into a-x-native
arkpar 987266f
Cleanup + formatting
arkpar 9744eab
Cleanup
arkpar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; | ||
use substrate_wasm_builder::WasmBuilder; | ||
|
||
fn main() { | ||
build_runtime(); | ||
generate_cargo_keys(); | ||
|
||
rerun_if_git_head_changed(); | ||
} | ||
|
||
fn build_runtime() { | ||
let mut path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
path.push("../runtime/Cargo.toml"); | ||
WasmBuilder::new() | ||
.with_project(path.canonicalize().unwrap()).unwrap() | ||
.export_heap_base() | ||
.import_memory() | ||
.build() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1,49 @@ | ||
use node_template_runtime::{ | ||
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig, | ||
SystemConfig, WASM_BINARY, | ||
}; | ||
use sc_service::ChainType; | ||
use sp_consensus_aura::sr25519::AuthorityId as AuraId; | ||
use sp_core::{sr25519, Pair, Public}; | ||
use sp_finality_grandpa::AuthorityId as GrandpaId; | ||
use sp_runtime::traits::{IdentifyAccount, Verify}; | ||
|
||
// The URL for the telemetry server. | ||
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; | ||
|
||
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. | ||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>; | ||
|
||
/// Generate a crypto pair from seed. | ||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { | ||
TPublic::Pair::from_string(&format!("//{}", seed), None) | ||
.expect("static values are valid; qed") | ||
.public() | ||
} | ||
|
||
type AccountPublic = <Signature as Verify>::Signer; | ||
|
||
/// Generate an account ID from seed. | ||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId | ||
where | ||
AccountPublic: From<<TPublic::Pair as Pair>::Public>, | ||
{ | ||
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account() | ||
mod runtime { | ||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); | ||
/// Wasm binary unwrapped. If built with `SKIP_WASM_BUILD`, the function panics. | ||
pub fn wasm_binary_unwrap() -> &'static [u8] { | ||
WASM_BINARY.expect( | ||
"Development wasm binary is not available. This means the client is built with \ | ||
`SKIP_WASM_BUILD` flag and it is only usable for production chains. Please rebuild with \ | ||
the flag disabled.", | ||
) | ||
} | ||
} | ||
|
||
/// Generate an Aura authority key. | ||
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { | ||
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s)) | ||
} | ||
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. | ||
pub type ChainSpec = sc_service::GenericChainSpec<()>; | ||
|
||
pub fn development_config() -> Result<ChainSpec, String> { | ||
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; | ||
|
||
Ok(ChainSpec::from_genesis( | ||
// Name | ||
Ok(ChainSpec::from_runtime( | ||
"Development", | ||
// ID | ||
"dev", | ||
ChainType::Development, | ||
move || { | ||
testnet_genesis( | ||
wasm_binary, | ||
// Initial PoA authorities | ||
vec![authority_keys_from_seed("Alice")], | ||
// Sudo account | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
], | ||
true, | ||
) | ||
}, | ||
// Bootnodes | ||
runtime::wasm_binary_unwrap(), | ||
"Genesis_build_dev", | ||
vec![], | ||
// Telemetry | ||
None, | ||
// Protocol ID | ||
None, | ||
None, | ||
// Properties | ||
None, | ||
// Extensions | ||
None, | ||
Default::default(), | ||
)) | ||
} | ||
|
||
pub fn local_testnet_config() -> Result<ChainSpec, String> { | ||
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; | ||
|
||
Ok(ChainSpec::from_genesis( | ||
// Name | ||
Ok(ChainSpec::from_runtime( | ||
"Local Testnet", | ||
// ID | ||
"local_testnet", | ||
ChainType::Local, | ||
move || { | ||
testnet_genesis( | ||
wasm_binary, | ||
// Initial PoA authorities | ||
vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], | ||
// Sudo account | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), | ||
], | ||
true, | ||
) | ||
}, | ||
// Bootnodes | ||
runtime::wasm_binary_unwrap(), | ||
"Genesis_build_genesis", | ||
vec![], | ||
// Telemetry | ||
None, | ||
// Protocol ID | ||
None, | ||
// Properties | ||
None, | ||
None, | ||
// Extensions | ||
None, | ||
Default::default(), | ||
)) | ||
} | ||
|
||
/// Configure initial storage state for FRAME modules. | ||
fn testnet_genesis( | ||
wasm_binary: &[u8], | ||
initial_authorities: Vec<(AuraId, GrandpaId)>, | ||
root_key: AccountId, | ||
endowed_accounts: Vec<AccountId>, | ||
_enable_println: bool, | ||
) -> GenesisConfig { | ||
GenesisConfig { | ||
system: SystemConfig { | ||
// Add Wasm runtime to storage. | ||
code: wasm_binary.to_vec(), | ||
}, | ||
balances: BalancesConfig { | ||
// Configure endowed accounts with initial balance of 1 << 60. | ||
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), | ||
}, | ||
aura: AuraConfig { | ||
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), | ||
}, | ||
grandpa: GrandpaConfig { | ||
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), | ||
}, | ||
sudo: SudoConfig { | ||
// Assign network admin rights. | ||
key: Some(root_key), | ||
}, | ||
transaction_payment: Default::default(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pepyakin Do we need
panic = "unwind"
for wasmtime?Otherwise, with no native runtime, we can switch to
panic = "abort"
and gain better performance and significantly reduced binary size.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you mean whether traps generated by wasm code in wasmtime require
unwind
, and the answer is no, it works via a setjmp/longjmp like approach.However, I think we should do this as a follow-up. The reason is, this requires some research to proof that we do not rely on this property somewhere else, because it was already there. I personally cannot recall any but it's better be safe than sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#10874