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 <git@kchr.de>
This commit is contained in:
Michal Kucharczyk
2023-09-28 18:29:12 +02:00
committed by GitHub
parent c1eb342b14
commit 50242a61d7
10 changed files with 46 additions and 75 deletions
+6
View File
@@ -19,12 +19,18 @@ build-linux-stable:
RUN_UI_TESTS: 1
script:
- time cargo build --locked --profile testnet --features pyroscope,fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker
- time ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-10/
- time ROCOCO_EPOCH_DURATION=100 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-100/
- time ROCOCO_EPOCH_DURATION=600 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-600/
- pwd
- ls -alR runtimes
# pack artifacts
- mkdir -p ./artifacts
- VERSION="${CI_COMMIT_REF_NAME}" # will be tag or branch name
- mv ./target/testnet/polkadot ./artifacts/.
- mv ./target/testnet/polkadot-prepare-worker ./artifacts/.
- mv ./target/testnet/polkadot-execute-worker ./artifacts/.
- mv ./runtimes/ ./artifacts/.
- pushd artifacts
- sha256sum polkadot | tee polkadot.sha256
- shasum -c polkadot.sha256
@@ -28,13 +28,16 @@ RUN apt-get update && \
find /var/lib/apt/lists/ -type f -not -name lock -delete; \
# add user and link ~/.local/share/polkadot to /data
useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \
mkdir -p /data /polkadot/.local/share && \
mkdir -p /data /polkadot/.local/share /polkdot/runtimes && \
chown -R polkadot:polkadot /data && \
ln -s /data /polkadot/.local/share/polkadot
# add polkadot binaries to docker image
COPY ./artifacts/polkadot ./artifacts/polkadot-execute-worker ./artifacts/polkadot-prepare-worker /usr/local/bin
# add runtime binaries to docker image
COPY ./artifacts/runtimes /polkadot/runtimes/
USER polkadot
# check if executable works in this container
+9 -63
View File
@@ -84,7 +84,7 @@ pub type WestendChainSpec = GenericChainSpec;
/// The `ChainSpec` parameterized for the rococo runtime.
#[cfg(feature = "rococo-native")]
pub type RococoChainSpec = service::GenericChainSpec<RococoGenesisExt, Extensions>;
pub type RococoChainSpec = service::GenericChainSpec<rococo::RuntimeGenesisConfig, Extensions>;
/// The `ChainSpec` parameterized for the `versi` runtime.
///
@@ -96,30 +96,6 @@ pub type VersiChainSpec = RococoChainSpec;
#[cfg(not(feature = "rococo-native"))]
pub type RococoChainSpec = GenericChainSpec;
/// Extension for the Rococo genesis config to support a custom changes to the genesis state.
#[derive(serde::Serialize, serde::Deserialize)]
#[cfg(feature = "rococo-native")]
pub struct RococoGenesisExt {
/// The runtime genesis config.
runtime_genesis_config: rococo::RuntimeGenesisConfig,
/// The session length in blocks.
///
/// If `None` is supplied, the default value is used.
session_length_in_blocks: Option<u32>,
}
#[cfg(feature = "rococo-native")]
impl sp_runtime::BuildStorage for RococoGenesisExt {
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
if let Some(length) = self.session_length_in_blocks.as_ref() {
rococo_runtime_constants::time::EpochDurationInBlocks::set(length);
}
});
self.runtime_genesis_config.assimilate_storage(storage)
}
}
pub fn polkadot_config() -> Result<GenericChainSpec, String> {
GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..])
}
@@ -780,10 +756,7 @@ pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
"Rococo Staging Testnet",
"rococo_staging_testnet",
ChainType::Live,
move || RococoGenesisExt {
runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary),
session_length_in_blocks: None,
},
move || rococo_staging_testnet_config_genesis(wasm_binary),
boot_nodes,
Some(
TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)])
@@ -817,10 +790,7 @@ pub fn versi_staging_testnet_config() -> Result<RococoChainSpec, String> {
"Versi Staging Testnet",
"versi_staging_testnet",
ChainType::Live,
move || RococoGenesisExt {
runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary),
session_length_in_blocks: Some(100),
},
move || rococo_staging_testnet_config_genesis(wasm_binary),
boot_nodes,
Some(
TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)])
@@ -1130,11 +1100,7 @@ pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
"Development",
"rococo_dev",
ChainType::Development,
move || RococoGenesisExt {
runtime_genesis_config: rococo_development_config_genesis(wasm_binary),
// Use 1 minute session length.
session_length_in_blocks: Some(10),
},
move || rococo_development_config_genesis(wasm_binary),
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
@@ -1153,11 +1119,7 @@ pub fn versi_development_config() -> Result<RococoChainSpec, String> {
"Development",
"versi_dev",
ChainType::Development,
move || RococoGenesisExt {
runtime_genesis_config: rococo_development_config_genesis(wasm_binary),
// Use 1 minute session length.
session_length_in_blocks: Some(10),
},
move || rococo_development_config_genesis(wasm_binary),
vec![],
None,
Some("versi"),
@@ -1177,11 +1139,7 @@ pub fn wococo_development_config() -> Result<RococoChainSpec, String> {
"Development",
"wococo_dev",
ChainType::Development,
move || RococoGenesisExt {
runtime_genesis_config: rococo_development_config_genesis(wasm_binary),
// Use 1 minute session length.
session_length_in_blocks: Some(10),
},
move || rococo_development_config_genesis(wasm_binary),
vec![],
None,
Some(WOCOCO_DEV_PROTOCOL_ID),
@@ -1239,11 +1197,7 @@ pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
"Rococo Local Testnet",
"rococo_local_testnet",
ChainType::Local,
move || RococoGenesisExt {
runtime_genesis_config: rococo_local_testnet_genesis(wasm_binary),
// Use 1 minute session length.
session_length_in_blocks: Some(10),
},
move || rococo_local_testnet_genesis(wasm_binary),
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
@@ -1278,11 +1232,7 @@ pub fn wococo_local_testnet_config() -> Result<RococoChainSpec, String> {
"Wococo Local Testnet",
"wococo_local_testnet",
ChainType::Local,
move || RococoGenesisExt {
runtime_genesis_config: wococo_local_testnet_genesis(wasm_binary),
// Use 1 minute session length.
session_length_in_blocks: Some(10),
},
move || wococo_local_testnet_genesis(wasm_binary),
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
@@ -1317,11 +1267,7 @@ pub fn versi_local_testnet_config() -> Result<RococoChainSpec, String> {
"Versi Local Testnet",
"versi_local_testnet",
ChainType::Local,
move || RococoGenesisExt {
runtime_genesis_config: versi_local_testnet_genesis(wasm_binary),
// Use 1 minute session length.
session_length_in_blocks: Some(10),
},
move || versi_local_testnet_genesis(wasm_binary),
vec![],
None,
Some("versi"),
+2 -1
View File
@@ -110,7 +110,7 @@ sp-tracing = { path = "../../../substrate/primitives/tracing", default-features
tokio = { version = "1.24.2", features = ["macros"] }
[build-dependencies]
substrate-wasm-builder = { path = "../../../substrate/utils/wasm-builder" }
substrate-wasm-builder = { path = "../../../substrate/utils/wasm-builder", optional = true }
[features]
default = [ "std" ]
@@ -196,6 +196,7 @@ std = [
"sp-storage/std",
"sp-tracing/std",
"sp-version/std",
"substrate-wasm-builder",
"tx-pool-api/std",
"xcm-builder/std",
"xcm-executor/std",
+7
View File
@@ -2,6 +2,13 @@
Rococo is a testnet runtime with no stability guarantees.
## How to build `rococo` runtime
`EpochDurationInBlocks` parameter is configurable via `ROCOCO_EPOCH_DURATION` environment variable. To build wasm
runtime blob with customized epoch duration the following command shall be exectuted:
```bash
ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime /path/to/output/directory/
```
## How to run `rococo-local`
The [Cumulus Tutorial](https://docs.substrate.io/tutorials/v3/cumulus/start-relay/) details building, starting, and
+11 -4
View File
@@ -14,12 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use substrate_wasm_builder::WasmBuilder;
#[cfg(feature = "std")]
fn main() {
WasmBuilder::new()
// note: needs to be synced with rococo-runtime-constants::time hard-coded string literal
const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION";
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.import_memory()
.export_heap_base()
.build()
.build();
println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV);
}
#[cfg(not(feature = "std"))]
fn main() {}
+4 -3
View File
@@ -38,12 +38,13 @@ pub mod currency {
/// Time and blocks.
pub mod time {
use primitives::{BlockNumber, Moment};
use runtime_common::prod_or_fast;
pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
pub const DEFAULT_EPOCH_DURATION: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES);
frame_support::parameter_types! {
pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION;
pub storage EpochDurationInBlocks: BlockNumber = option_env!("ROCOCO_EPOCH_DURATION")
.map(|s| s.parse().expect("`ROCOCO_EPOCH_DURATION` is not a valid `BlockNumber`"))
.unwrap_or(1 * MINUTES);
}
// These time units are defined in number of blocks.
@@ -1,7 +1,7 @@
[settings]
timeout = 1000
[relaychain.genesis.runtime.runtime_genesis_config.configuration.config]
[relaychain.genesis.runtime.configuration.config]
max_validators_per_core = 5
needed_approvals = 8
@@ -2,7 +2,7 @@
timeout = 1000
bootnode = true
[relaychain.genesis.runtime.runtime_genesis_config.configuration.config]
[relaychain.genesis.runtime.configuration.config]
max_validators_per_core = 1
needed_approvals = 2
@@ -2,7 +2,7 @@
timeout = 1000
bootnode = true
[relaychain.genesis.runtime.runtime_genesis_config.configuration.config]
[relaychain.genesis.runtime.configuration.config]
max_validators_per_core = 1
needed_approvals = 3