Skip to content

Commit e4f5f3c

Browse files
authored
Rococo: Build two versions of the wasm binary (#2229)
One for local networks with `fast-runtime` feature activated (1 minute sessions) and one without the feature activated that will be the default that runs with 1 hour long sessions.
1 parent 3f7c743 commit e4f5f3c

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

polkadot/node/service/src/chain_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ fn rococo_local_testnet_genesis() -> serde_json::Value {
10681068
#[cfg(feature = "rococo-native")]
10691069
pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
10701070
Ok(RococoChainSpec::builder(
1071-
rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?,
1071+
rococo::fast_runtime_binary::WASM_BINARY.ok_or("Rococo development wasm not available")?,
10721072
Default::default(),
10731073
)
10741074
.with_name("Rococo Local Testnet")

polkadot/runtime/rococo/build.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616

1717
#[cfg(feature = "std")]
1818
fn main() {
19-
// note: needs to be synced with rococo-runtime-constants::time hard-coded string literal
20-
const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION";
21-
2219
substrate_wasm_builder::WasmBuilder::new()
2320
.with_current_project()
2421
.import_memory()
2522
.export_heap_base()
2623
.build();
2724

28-
println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV);
25+
substrate_wasm_builder::WasmBuilder::new()
26+
.with_current_project()
27+
.set_file_name("fast_runtime_binary.rs")
28+
.enable_feature("fast-runtime")
29+
.import_memory()
30+
.export_heap_base()
31+
.build();
2932
}
3033

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

polkadot/runtime/rococo/constants/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ pub mod currency {
3737

3838
/// Time and blocks.
3939
pub mod time {
40+
use runtime_common::prod_or_fast;
41+
4042
use primitives::{BlockNumber, Moment};
4143
pub const MILLISECS_PER_BLOCK: Moment = 6000;
4244
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
4345

4446
frame_support::parameter_types! {
45-
pub storage EpochDurationInBlocks: BlockNumber = option_env!("ROCOCO_EPOCH_DURATION")
46-
.map(|s| s.parse().expect("`ROCOCO_EPOCH_DURATION` is not a valid `BlockNumber`"))
47-
.unwrap_or(1 * MINUTES);
47+
pub EpochDurationInBlocks: BlockNumber =
48+
prod_or_fast!(1 * HOURS, 1 * MINUTES, "ROCOCO_EPOCH_DURATION");
4849
}
4950

5051
// These time units are defined in number of blocks.

polkadot/runtime/rococo/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ impl_runtime_weights!(rococo_runtime_constants);
131131
#[cfg(feature = "std")]
132132
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
133133

134+
/// Provides the `WASM_BINARY` build with `fast-runtime` feature enabled.
135+
///
136+
/// This is for example useful for local test chains.
137+
#[cfg(feature = "std")]
138+
pub mod fast_runtime_binary {
139+
include!(concat!(env!("OUT_DIR"), "/fast_runtime_binary.rs"));
140+
}
141+
134142
/// Runtime version (Rococo).
135143
#[sp_version::runtime_version]
136144
pub const VERSION: RuntimeVersion = RuntimeVersion {

0 commit comments

Comments
 (0)