Skip to content

Commit 31bae49

Browse files
committed
fix: node-side panics after refactoring (#718)
Fixes KILTprotocol/ticket#3596 and fixes KILTprotocol/ticket#3598.
1 parent 8257350 commit 31bae49

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# this container builds the kilt-parachain binary from source files and the runtime library
22
# pinned the version to avoid build cache invalidation
33

4-
FROM paritytech/ci-unified:bullseye-1.70.0 as builder
4+
FROM paritytech/ci-unified:bullseye-1.74.0 as builder
55

66
WORKDIR /build
77

@@ -32,5 +32,7 @@ VOLUME ["/data"]
3232

3333
COPY ./chainspecs /node/chainspecs
3434

35+
ENV CHAINSPECS_FOLDER=/node/chainspecs
36+
3537
ENTRYPOINT ["/usr/local/bin/node-executable"]
3638
CMD ["--help"]

nodes/parachain/src/chain_spec/utils.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,29 @@ pub(crate) fn load_spec(id: &str) -> Result<Box<dyn sc_service::ChainSpec>, Stri
8686
}
8787
}
8888

89+
// Compile-time env variable used when running the binary with cargo or via
90+
// cargo (after `cargo build`).
8991
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
90-
const CHAINSPECS_FOLDER: &str = "chainspecs";
92+
// Name of the runtime-time env variable that can be used to configure the
93+
// chainspecs folder path, useful especially when running the binary in a Docker
94+
// container.
95+
const CHAINSPECS_FOLDER_VAR_NAME: &str = "CHAINSPECS_FOLDER";
9196

92-
// Prepends the given path with the `<workspace_root>/chainspecs` path.
9397
fn get_chainspec_full_path(path: &str) -> PathBuf {
94-
Path::new(MANIFEST_DIR)
95-
.join("..")
96-
.join("..")
97-
.join(CHAINSPECS_FOLDER)
98+
// Use the provided env variable, if present at runtime, or else uses the
99+
// compile-time `CARGO_MANIFEST_DIR` variable (e.g., if the binary is run via
100+
// cargo instead of in a Docker container).
101+
let chainspecs_root = match std::env::var(CHAINSPECS_FOLDER_VAR_NAME) {
102+
Ok(chainspecs_folder_name) => chainspecs_folder_name.to_owned(),
103+
Err(_) => Path::new(MANIFEST_DIR)
104+
.join("..")
105+
.join("..")
106+
.join("chainspecs")
107+
.to_string_lossy()
108+
.into_owned(),
109+
};
110+
111+
Path::new(chainspecs_root.as_str())
98112
.join(path)
99113
.canonicalize()
100114
.expect("Invalid path provided.")

runtimes/kestrel/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sp-api = { workspace = true }
5858
sp-block-builder = { workspace = true }
5959
sp-consensus-aura = { workspace = true }
6060
sp-core = { workspace = true }
61+
sp-genesis-builder = { workspace = true }
6162
sp-inherents = { workspace = true }
6263
sp-offchain = { workspace = true }
6364
sp-runtime = { workspace = true }
@@ -138,6 +139,7 @@ std = [
138139
"sp-block-builder/std",
139140
"sp-consensus-aura/std",
140141
"sp-core/std",
142+
"sp-genesis-builder/std",
141143
"sp-inherents/std",
142144
"sp-offchain/std",
143145
"sp-runtime/std",

runtimes/kestrel/src/lib.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
2929

3030
use frame_support::{
31-
construct_runtime, parameter_types,
31+
construct_runtime,
32+
genesis_builder_helper::{build_config, create_default_config},
33+
parameter_types,
3234
traits::{Everything, InstanceFilter},
3335
weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee, Weight},
3436
};
@@ -1158,6 +1160,17 @@ impl_runtime_apis! {
11581160
}
11591161
}
11601162

1163+
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1164+
1165+
fn create_default_config() -> Vec<u8> {
1166+
create_default_config::<RuntimeGenesisConfig>()
1167+
}
1168+
1169+
fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {
1170+
build_config::<RuntimeGenesisConfig>(config)
1171+
}
1172+
}
1173+
11611174

11621175
#[cfg(feature = "try-runtime")]
11631176
impl frame_try_runtime::TryRuntime<Block> for Runtime {

0 commit comments

Comments
 (0)