Conditional compilation for the runtime proposals parameters.#5
Conditional compilation for the runtime proposals parameters.#5shamil-gadelshin wants to merge 6 commits intoproposals_update4from
Conversation
|
This certainly looks very promising! Did you review other options beyond environment variable approach? I hope you did not presume that I had looked into it as the best approach. |
I considered other options as well:
"JSON via enviroment variable" approach was chosen because it has at least basic library support and provides type-safety for the main (default parameters) path. Other options are less convinient for both configuring and using or more dangerous because of lacking type safety. |
|
There is a way to do a conditional compilation in rust: It also could be used as key-value pairs: for examples, We have three problems:
C-like "cfg" option helps to solve (A) in a convenient way. But (B) and (C) lead to a very verbose format of both specifying and parsing eight parameters for a dozen proposals. The environment variable also solves (A). One of the first considered approaches was to use "ENV" as an indicator that JSON (B) should be loaded whether from a predefined path or path derived from this/another ENV (C). rust --cfg is typically used as switch in code branches rather than for configuration-rich purposes. JSON was chosen as (B) as a widely used format that has perfect support in JS integration tests environment. Also, it allows to define similar parameter structure for different proposal and avoid Cartesian product (CROSS JOIN) of proposals and parameters, unlike the "cfg" or "env-var per parameter" approach. Having JSON in a separate file would make 'JSON-path' (C) to be part of the "configuration interface" which is unnecessary let alone that filesystem IO could lead to such rare problems as file access permissions. So, this how "environment-variable JSON" approach was selected. |
|
Isn't this, at runtime, reading a JSON object via an environment variable and attempting to decode all parameters from it? If so, then parameters are not set at compile time. You could run the same binary multiple times with a different set of input values, or put differently, I could run my full node, and if something corrupted my json file, then I would be out of consensus. |
|
|
This looks good. I'm happy with the selection of env variable to pass in the custom configuration, especially when considering building docker images of the joystream node. I think there might be issues with the From what I can tell that yes the "static" section: ensures this initial value is set at compile time, not dynamically at runtime. I would prefer that all parameter properties would be required and not optional (being overridden with default when omitted) this helps to ensure the users customizing the parameters does not mistakenly omit a value, although I appreciate the that it makes it easier on the testing framework. However I think if make all parameters required and I will try to build and test from this branch to ensure in native and wasm builds of the runtime the env variable does indeed work as designed. But initially my gut tells me we might have to consider how build.rs and the wasm builder https://github.com/Joystream/joystream/blob/b2057380b50ba23be278b7e87b557f19dd9dba4e/runtime/build.rs#L20 behave to ensure env variable changes do indeed trigger a re-bulid of the runtime (since no source files are touched) |
|
Just a clarification on the point regarding re-triggering of the runtime build. My concern is running cargo build which results in a node binary where the native runtime does not match the wasm blob runtime, but would have the same runtime version which results in a binary that will break from consensus as a result. This is not an issue when cleaning the cargo build artifacts before running a build, or make a clean docker image build (without caching of cargo artifacts) Its also possible that an env var change doesn't even trigger a rebuild of native code for that matter. |
|
|
Great.
Is this silent error advisable? Seems to be worth failing more loudly during building. It will take next to nothing to get such an input file corrupted in some way. |
|
Our current use case is to set only |
|
I added 'panic' for the corrupted JSON env. It could panic only if the env-var set on compilation time, so it is safe by default. |
So this is a non-issue because of how the macro works in:
The macros added in b29aaa7 are great to easily add the additional proposals 👍 Code builds, but there are some cargo-fmt changes needed. I can't seem to get the build to panic when passing invalid JSON like this:
|
|
I pushed the code formatting commit.
It won't panic during the build, because it just creates a string during the compilation. It will panic later during the execution (during the string parsing). |
Thanks I was able to force the panic, as you suggested when the Interestingly the node keeps producing blocks, but they don't get finalized. On the client side the error is also propagated: |
|
With these values I'm still getting Also an observation/question. since But I'm not able to test and confirm this because the JSON is not being validated. |
|
The JSON you provided is invalid indeed near the beginning
Currently, there is no possibility to set None. But I will add this by converting 0(zero) to the None. Omitted fields are defaulted. |
I guess that is acceptable, but double check if lite-json can detect a Regarding that extra |
|
Silly me it was an issue with quotes, I needed to use single quotes around the json like this: Works. Tested using: #6 |
Olympia schema fix member by role
Fix min unstaking period test

Summary
We created a separate runtime module(file) In order to be able to pass the proposal parameter constants during the compilation time. The primary goal for the conditional compilation is integration tests. All parameters for the proposal could be set via
ALL_PROPOSALS_PARAMETERS_JSONenvironment variable. The value of the variable should be a valid JSON file (a sample file is included in the PR). The PR contains a migration of the single proposal parameter set for demo purposes.Comments
lite-jsoncrate as "no_std" option for parsing JSON recommended for Substrate.serde_jsonis not 'no_std' ready.serder_json_corelibrary is not working.ignore).