Skip to content

Commit 50242a6

Browse files
rococo-runtime: RococoGenesisExt removed (#1490)
[`RococoGenesisExt`](https://github.com/paritytech/polkadot-sdk/blob/a414ea7515c9cdc81f1d12410e646afc148250e8/polkadot/node/service/src/chain_spec.rs#L152-L171) is removed. It was the hack to allow overwriting `EpochDurationInBlocks`. Removal of `RococGenesisExt` prevents from manipulating the state to change the runtime constants. Changes: - Environment variable which controls the `time::EpochDurationInBlocks` value was added: `ROCOCO_EPOCH_DURATION` (epoch duration will be set to the value of env), - `10,100,600` versions of rococo-runtime are built in CI and put into `polkadot-debug` docker image. `rococo-runtime` building examples: - to build runtime for `versi_staging_testnet` which had EpochDurationInBlocks set to 100: ``` ROCOCO_EPOCH_DURATION=100 cargo build --features=fast-runtime -p rococo-runtime ``` - to build runtime for `wococo_development` ``` ROCOCO_EPOCH_DURATION=10 cargo build --features=fast-runtime -p rococo-runtime ``` - to build `versi-staging` chain spec: ``` ROCOCO_EPOCH_DURATION=100 cargo run -p polkadot --features=fast-runtime -- build-spec --chain versi-staging --raw ``` - to build `wococo-dev` chain spec: ``` ROCOCO_EPOCH_DURATION=10 cargo run -p polkadot --features=fast-runtime -- build-spec --chain wococo-dev --raw ``` It is also possible to change the epoch duration by replacing the `code` field in the chain spec with the hex dump of pre-built runtime wasm blob (because the epoch duration is hard-coded into wasm blob). --------- Co-authored-by: Bastian Köcher <[email protected]>
1 parent c1eb342 commit 50242a6

10 files changed

Lines changed: 46 additions & 75 deletions

File tree

.gitlab/pipeline/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ build-linux-stable:
1919
RUN_UI_TESTS: 1
2020
script:
2121
- time cargo build --locked --profile testnet --features pyroscope,fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker
22+
- time ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-10/
23+
- time ROCOCO_EPOCH_DURATION=100 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-100/
24+
- time ROCOCO_EPOCH_DURATION=600 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-600/
25+
- pwd
26+
- ls -alR runtimes
2227
# pack artifacts
2328
- mkdir -p ./artifacts
2429
- VERSION="${CI_COMMIT_REF_NAME}" # will be tag or branch name
2530
- mv ./target/testnet/polkadot ./artifacts/.
2631
- mv ./target/testnet/polkadot-prepare-worker ./artifacts/.
2732
- mv ./target/testnet/polkadot-execute-worker ./artifacts/.
33+
- mv ./runtimes/ ./artifacts/.
2834
- pushd artifacts
2935
- sha256sum polkadot | tee polkadot.sha256
3036
- shasum -c polkadot.sha256

docker/dockerfiles/polkadot/polkadot_injected_debug.Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ RUN apt-get update && \
2828
find /var/lib/apt/lists/ -type f -not -name lock -delete; \
2929
# add user and link ~/.local/share/polkadot to /data
3030
useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \
31-
mkdir -p /data /polkadot/.local/share && \
31+
mkdir -p /data /polkadot/.local/share /polkdot/runtimes && \
3232
chown -R polkadot:polkadot /data && \
3333
ln -s /data /polkadot/.local/share/polkadot
3434

3535
# add polkadot binaries to docker image
3636
COPY ./artifacts/polkadot ./artifacts/polkadot-execute-worker ./artifacts/polkadot-prepare-worker /usr/local/bin
3737

38+
# add runtime binaries to docker image
39+
COPY ./artifacts/runtimes /polkadot/runtimes/
40+
3841
USER polkadot
3942

4043
# check if executable works in this container

polkadot/node/service/src/chain_spec.rs

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub type WestendChainSpec = GenericChainSpec;
8484

8585
/// The `ChainSpec` parameterized for the rococo runtime.
8686
#[cfg(feature = "rococo-native")]
87-
pub type RococoChainSpec = service::GenericChainSpec<RococoGenesisExt, Extensions>;
87+
pub type RococoChainSpec = service::GenericChainSpec<rococo::RuntimeGenesisConfig, Extensions>;
8888

8989
/// The `ChainSpec` parameterized for the `versi` runtime.
9090
///
@@ -96,30 +96,6 @@ pub type VersiChainSpec = RococoChainSpec;
9696
#[cfg(not(feature = "rococo-native"))]
9797
pub type RococoChainSpec = GenericChainSpec;
9898

99-
/// Extension for the Rococo genesis config to support a custom changes to the genesis state.
100-
#[derive(serde::Serialize, serde::Deserialize)]
101-
#[cfg(feature = "rococo-native")]
102-
pub struct RococoGenesisExt {
103-
/// The runtime genesis config.
104-
runtime_genesis_config: rococo::RuntimeGenesisConfig,
105-
/// The session length in blocks.
106-
///
107-
/// If `None` is supplied, the default value is used.
108-
session_length_in_blocks: Option<u32>,
109-
}
110-
111-
#[cfg(feature = "rococo-native")]
112-
impl sp_runtime::BuildStorage for RococoGenesisExt {
113-
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
114-
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
115-
if let Some(length) = self.session_length_in_blocks.as_ref() {
116-
rococo_runtime_constants::time::EpochDurationInBlocks::set(length);
117-
}
118-
});
119-
self.runtime_genesis_config.assimilate_storage(storage)
120-
}
121-
}
122-
12399
pub fn polkadot_config() -> Result<GenericChainSpec, String> {
124100
GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..])
125101
}
@@ -780,10 +756,7 @@ pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
780756
"Rococo Staging Testnet",
781757
"rococo_staging_testnet",
782758
ChainType::Live,
783-
move || RococoGenesisExt {
784-
runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary),
785-
session_length_in_blocks: None,
786-
},
759+
move || rococo_staging_testnet_config_genesis(wasm_binary),
787760
boot_nodes,
788761
Some(
789762
TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)])
@@ -817,10 +790,7 @@ pub fn versi_staging_testnet_config() -> Result<RococoChainSpec, String> {
817790
"Versi Staging Testnet",
818791
"versi_staging_testnet",
819792
ChainType::Live,
820-
move || RococoGenesisExt {
821-
runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary),
822-
session_length_in_blocks: Some(100),
823-
},
793+
move || rococo_staging_testnet_config_genesis(wasm_binary),
824794
boot_nodes,
825795
Some(
826796
TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)])
@@ -1130,11 +1100,7 @@ pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
11301100
"Development",
11311101
"rococo_dev",
11321102
ChainType::Development,
1133-
move || RococoGenesisExt {
1134-
runtime_genesis_config: rococo_development_config_genesis(wasm_binary),
1135-
// Use 1 minute session length.
1136-
session_length_in_blocks: Some(10),
1137-
},
1103+
move || rococo_development_config_genesis(wasm_binary),
11381104
vec![],
11391105
None,
11401106
Some(DEFAULT_PROTOCOL_ID),
@@ -1153,11 +1119,7 @@ pub fn versi_development_config() -> Result<RococoChainSpec, String> {
11531119
"Development",
11541120
"versi_dev",
11551121
ChainType::Development,
1156-
move || RococoGenesisExt {
1157-
runtime_genesis_config: rococo_development_config_genesis(wasm_binary),
1158-
// Use 1 minute session length.
1159-
session_length_in_blocks: Some(10),
1160-
},
1122+
move || rococo_development_config_genesis(wasm_binary),
11611123
vec![],
11621124
None,
11631125
Some("versi"),
@@ -1177,11 +1139,7 @@ pub fn wococo_development_config() -> Result<RococoChainSpec, String> {
11771139
"Development",
11781140
"wococo_dev",
11791141
ChainType::Development,
1180-
move || RococoGenesisExt {
1181-
runtime_genesis_config: rococo_development_config_genesis(wasm_binary),
1182-
// Use 1 minute session length.
1183-
session_length_in_blocks: Some(10),
1184-
},
1142+
move || rococo_development_config_genesis(wasm_binary),
11851143
vec![],
11861144
None,
11871145
Some(WOCOCO_DEV_PROTOCOL_ID),
@@ -1239,11 +1197,7 @@ pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
12391197
"Rococo Local Testnet",
12401198
"rococo_local_testnet",
12411199
ChainType::Local,
1242-
move || RococoGenesisExt {
1243-
runtime_genesis_config: rococo_local_testnet_genesis(wasm_binary),
1244-
// Use 1 minute session length.
1245-
session_length_in_blocks: Some(10),
1246-
},
1200+
move || rococo_local_testnet_genesis(wasm_binary),
12471201
vec![],
12481202
None,
12491203
Some(DEFAULT_PROTOCOL_ID),
@@ -1278,11 +1232,7 @@ pub fn wococo_local_testnet_config() -> Result<RococoChainSpec, String> {
12781232
"Wococo Local Testnet",
12791233
"wococo_local_testnet",
12801234
ChainType::Local,
1281-
move || RococoGenesisExt {
1282-
runtime_genesis_config: wococo_local_testnet_genesis(wasm_binary),
1283-
// Use 1 minute session length.
1284-
session_length_in_blocks: Some(10),
1285-
},
1235+
move || wococo_local_testnet_genesis(wasm_binary),
12861236
vec![],
12871237
None,
12881238
Some(DEFAULT_PROTOCOL_ID),
@@ -1317,11 +1267,7 @@ pub fn versi_local_testnet_config() -> Result<RococoChainSpec, String> {
13171267
"Versi Local Testnet",
13181268
"versi_local_testnet",
13191269
ChainType::Local,
1320-
move || RococoGenesisExt {
1321-
runtime_genesis_config: versi_local_testnet_genesis(wasm_binary),
1322-
// Use 1 minute session length.
1323-
session_length_in_blocks: Some(10),
1324-
},
1270+
move || versi_local_testnet_genesis(wasm_binary),
13251271
vec![],
13261272
None,
13271273
Some("versi"),

polkadot/runtime/rococo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ sp-tracing = { path = "../../../substrate/primitives/tracing", default-features
110110
tokio = { version = "1.24.2", features = ["macros"] }
111111

112112
[build-dependencies]
113-
substrate-wasm-builder = { path = "../../../substrate/utils/wasm-builder" }
113+
substrate-wasm-builder = { path = "../../../substrate/utils/wasm-builder", optional = true }
114114

115115
[features]
116116
default = [ "std" ]
@@ -196,6 +196,7 @@ std = [
196196
"sp-storage/std",
197197
"sp-tracing/std",
198198
"sp-version/std",
199+
"substrate-wasm-builder",
199200
"tx-pool-api/std",
200201
"xcm-builder/std",
201202
"xcm-executor/std",

polkadot/runtime/rococo/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Rococo is a testnet runtime with no stability guarantees.
44

5+
## How to build `rococo` runtime
6+
`EpochDurationInBlocks` parameter is configurable via `ROCOCO_EPOCH_DURATION` environment variable. To build wasm
7+
runtime blob with customized epoch duration the following command shall be exectuted:
8+
```bash
9+
ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime /path/to/output/directory/
10+
```
11+
512
## How to run `rococo-local`
613

714
The [Cumulus Tutorial](https://docs.substrate.io/tutorials/v3/cumulus/start-relay/) details building, starting, and

polkadot/runtime/rococo/build.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use substrate_wasm_builder::WasmBuilder;
18-
17+
#[cfg(feature = "std")]
1918
fn main() {
20-
WasmBuilder::new()
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+
22+
substrate_wasm_builder::WasmBuilder::new()
2123
.with_current_project()
2224
.import_memory()
2325
.export_heap_base()
24-
.build()
26+
.build();
27+
28+
println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV);
2529
}
30+
31+
#[cfg(not(feature = "std"))]
32+
fn main() {}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ pub mod currency {
3838
/// Time and blocks.
3939
pub mod time {
4040
use primitives::{BlockNumber, Moment};
41-
use runtime_common::prod_or_fast;
4241
pub const MILLISECS_PER_BLOCK: Moment = 6000;
4342
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
44-
pub const DEFAULT_EPOCH_DURATION: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES);
43+
4544
frame_support::parameter_types! {
46-
pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION;
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);
4748
}
4849

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

polkadot/zombienet_tests/functional/0002-parachains-disputes.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[settings]
22
timeout = 1000
33

4-
[relaychain.genesis.runtime.runtime_genesis_config.configuration.config]
4+
[relaychain.genesis.runtime.configuration.config]
55
max_validators_per_core = 5
66
needed_approvals = 8
77

polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
timeout = 1000
33
bootnode = true
44

5-
[relaychain.genesis.runtime.runtime_genesis_config.configuration.config]
5+
[relaychain.genesis.runtime.configuration.config]
66
max_validators_per_core = 1
77
needed_approvals = 2
88

polkadot/zombienet_tests/misc/0001-paritydb.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
timeout = 1000
33
bootnode = true
44

5-
[relaychain.genesis.runtime.runtime_genesis_config.configuration.config]
5+
[relaychain.genesis.runtime.configuration.config]
66
max_validators_per_core = 1
77
needed_approvals = 3
88

0 commit comments

Comments
 (0)