Skip to content

Commit c169c69

Browse files
authored
Merge pull request #5204 from Lezek123/mainnet-rpc-hotfix
Update mainnet RPC endpoint
2 parents b956002 + cc0425e commit c169c69

File tree

5 files changed

+206
-172
lines changed

5 files changed

+206
-172
lines changed

.github/workflows/joystream-node.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
FILES: |
6868
Cargo.lock
6969
Cargo.toml
70-
70+
7171
- name: Toolchains
7272
run: |
7373
./setup.sh
@@ -79,25 +79,25 @@ jobs:
7979
if: env.GIT_DIFF
8080
- name: Staging Runtime
8181
env:
82-
RUNTIME_PROFILE: "STAGING"
82+
RUNTIME_PROFILE: 'STAGING'
8383
run: |
8484
yarn cargo-checks && yarn cargo-build
8585
if: env.GIT_DIFF
8686
- name: Playground Runtime
8787
env:
88-
RUNTIME_PROFILE: "PLAYGROUND"
88+
RUNTIME_PROFILE: 'PLAYGROUND'
8989
run: |
9090
yarn cargo-checks && yarn cargo-build
9191
if: env.GIT_DIFF
9292
- name: Testing Runtime
9393
env:
94-
RUNTIME_PROFILE: "TESTING"
94+
RUNTIME_PROFILE: 'TESTING'
9595
run: |
9696
yarn cargo-checks && yarn cargo-build
9797
if: env.GIT_DIFF
9898
- name: Fast Production Runtime
9999
env:
100-
RUNTIME_PROFILE: "FAST-PROD"
100+
RUNTIME_PROFILE: 'FAST-PROD'
101101
run: |
102102
yarn cargo-checks && yarn cargo-build
103103
if: env.GIT_DIFF
@@ -133,7 +133,7 @@ jobs:
133133
--runtime ./target/release/wbuild/joystream-node-runtime/joystream_node_runtime.compact.compressed.wasm \
134134
on-runtime-upgrade \
135135
live \
136-
--uri wss://rpc.joystream.org:9944/
136+
--uri wss://rpc.joystream.org
137137
if: env.GIT_DIFF
138138
- name: run_migrations test
139139
run: |

RUNTIME-CONTRIBUTING.md

Lines changed: 68 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## Overview
2+
23
This readme covers some basic introduction to the concept of WASM runtime, with guidelines and recommended approaches for creating, testing, and verifying runtime upgrades.
34

45
## Target audiance
6+
57
This guide is targeted to developers, council members and any technical community member that wants to participate in the process of runtime upgrade of the chain.
68

79
It is expected you have some technical and coding background and some knowlege about substrate in general and joystream runtime specifically.
@@ -13,6 +15,7 @@ A key feature of the joystream network, and substrate based chains in general is
1315
The runtime is stored on chain, at a well known storage key, as an [WebAssembly](https://docs.substrate.io/reference/glossary/#webassembly-wasm) binary, or WASM for short. The WASM is produced by building the joystream [runtime](./runtime) source code, which is made up of substrate and joystream pallets or [rutime-modules](./runtime-modules).
1416

1517
## WASM compression
18+
1619
The raw compiled WASM is averaging ~5MB. This is too large to fit in transactions and blocks. So the build process compacts the original produce WASM and finally compresses it with the [Zstandard](https://facebook.github.io/zstd/) fast compression algorithm.
1720
Note a compressed runtime has a magic 8 byte pre-fix so to decompress we must first strip them.
1821

@@ -28,6 +31,7 @@ You can then decompress with following command:
2831
`dd if=compressed.wasm bs=512k | { dd bs=8 count=1 of=/dev/null; dd bs=512k; } | zstd -d -o uncompressed.wasm`
2932

3033
## Getting the current runtime from the chain
34+
3135
From a fully synced node we can download the runtime blob and get information about it.
3236

3337
### Using utils/api-scripts
@@ -51,18 +55,20 @@ node src/inspect-wasm-runtime-version.js ./runtime.wasm
5155
# Install subwasm
5256
cargo install --locked --git https://github.com/chevdor/subwasm --tag v0.18.0
5357
# Fetch the runtime and save it as runtime.wasm
54-
subwasm get wss://rpc.joystream.org:9944/ -o ./runtime.wasm
58+
subwasm get wss://rpc.joystream.org -o ./runtime.wasm
5559
# Get runtime version and hash
5660
subwasm info ./runtime.wasm
5761
```
5862

5963
### From polkadot-js-app
64+
6065
Visit https://polkadot.js.org/apps/#/chainstate/raw and make sure you are pointing at the joystream network.
6166

6267
Enter storage key: `0x3a636f6465`
6368
Copy hex string and use a tool to convert it to a binary file.
6469

65-
### From QueryNode
70+
### From QueryNode
71+
6672
It is best to use the approaches mentioned above as the most direct way to fetch the rutnime, but it can also be found in the query-node, if at least one runtime upgrade has been performed through governance.
6773

6874
```
@@ -75,6 +81,7 @@ Query the runtimeCode table by hash to fetch the wasm blob
7581
Reference code from [pioneer](https://github.com/Joystream/pioneer/blob/dev/packages/ui/src/proposals/hooks/useRuntimeBytecode.ts)
7682

7783
## Verifying runtime builds
84+
7885
By verification we mean that we can follow steps to get a guarantee that a specific runtime wasm blob was compiled/built from a given codebase.
7986

8087
For verification to be possible, it is an essential property of the build process to be [deterministic](https://docs.substrate.io/build/build-a-deterministic-runtime/).
@@ -85,6 +92,7 @@ We have chosen the approach of using docker with a fixed version of the rust too
8592
Polkadot adopts a similar approach and a generalized tool [`srtool`](https://docs.substrate.io/reference/command-line-tools/srtool/) exists for building runtimes. Perhaps we should be consider using that in future.
8693

8794
### Example - Verify onchain runtime
95+
8896
As a policy the master branch will be kept upto-date with the runtime used on mainnet
8997
Lets verify that this is the case.
9098

@@ -115,9 +123,10 @@ Compare results with the runtime you fetched from the chain in previous section.
115123
If you are verifying a proposed runtime then you will need to build it yourself from what the proposer claims is the git commit/branch for the new proposed runtime, and compare it with the proposed runtime.
116124

117125
The proposed WASM can also be downloaded from the proposal details page in pioneer.
118-
The hash of the propossed runtime should also be visible in pioneer.
126+
The hash of the propossed runtime should also be visible in pioneer.
119127

120128
#### Howto fetch the proposed runtime
129+
121130
If you don't want to rely on pioneer,
122131
another way to check the runtime proposed is with utility scripts provided.
123132

@@ -147,6 +156,7 @@ Then follow steps from previous section on how extract the wasm file from the im
147156
and inspect its hash and version information.
148157

149158
#### Reviewing code changes
159+
150160
Verifying the proposed runtime comes from a specific code base is only the first step ofcourse.
151161
There is no guarantee the proposed runtime is safe to use, implements changes or new features outlined by the proposer.
152162

@@ -164,13 +174,14 @@ git diff master -- runtime/ runtime-modules/ bin/ Cargo.toml Cargo.lock
164174
```
165175

166176
### Sharing code changes without using public repo
167-
A proposer may choose not to make changes public, they can be shared through more secure and private channels with the council members (who ultimately vote on the runtime upgrade proposal).
177+
178+
A proposer may choose not to make changes public, they can be shared through more secure and private channels with the council members (who ultimately vote on the runtime upgrade proposal).
168179

169180
The primary case where this might be a good idea is when fixing a bug, or security issue.
170181

171182
#### Using a patch file
172-
One approach would be to provide the code changes via a patch file produced from the proposers local changes. Lets say proposer has created a local branch based off master branch called fix-runtime:
173183

184+
One approach would be to provide the code changes via a patch file produced from the proposers local changes. Lets say proposer has created a local branch based off master branch called fix-runtime:
174185

175186
```sh
176187
git checkout fix-runtime
@@ -180,7 +191,7 @@ git diff master -- Cargo.lock Cargo.toml joystream-node.Dockerfile runtime/ runt
180191
This saves the code changes in a patch or diff file named fix-runtime.patch
181192
This should then be encrypted with council members' or other trusted community members that would be tasked with reviewing and testing the patch, and possibly providing council members with their assesment.
182193

183-
After decrypting the patch file it can be applied for review:
194+
After decrypting the patch file it can be applied for review:
184195

185196
```sh
186197
git checkout master
@@ -190,6 +201,7 @@ git diff
190201
```
191202

192203
#### Using a tarball
204+
193205
Alternatively all required files for building the runtime can be shared in an archive or 'tarball'
194206

195207
```sh
@@ -207,52 +219,58 @@ tar -czf joystream.tar.gz \
207219
## Implementing a new runtime
208220

209221
### General workflow
222+
210223
Although how actual runtime changes are not detailed here, there is a general set of steps that should
211224
be followed below:
212225

213226
#### Development cycle
214227

215-
1. Determine the "base" branch to bulid pn. This will typically be the master branch.
216-
1. Bump the `spec_version` component of the runtime `pub const VERSION` in `runtime/src/lib.rs`
217-
update the version of the cargo crates (Cargo.toml) for both the runtime and bin/node
218-
runtime `spec_name` should not be changed.
219-
If the runtime change is only an performance enhancement with no new state or state logic, then
220-
only the `impl_version` needs to be changed.
221-
1. Implement runtime changes, fixes, or new feature. This must includes benchmarking code and new unit tests as appropriate.
222-
1. Run `yarn cargo-checks` to run the linter, code formatting check and unit tests.
223-
1. Build the node with runtime benchmarks feature enabled, see `./scripts/cargo-build-with-benchmarks.sh`
224-
1. Generate weights for modified/new benchmark functions on reference machine, and checkin the changes of the weights.rs - helper script is available in scripts/generate-weights.sh
225-
1. Re run code formatting with `cargo fmt --all`
226-
1. Do another test build with modified benchmarks `yarn cargo-checks && yarn cargo-build`
227-
1. Extract the new runtime metadata `yarn update-chain-metadata`
228-
1. Build all npm packages: `yarn build`
229-
1. Add any new integration tests, query-node mappings that cover the changes implemented.
230-
1. Lint typescript `yarn lint`
231-
1. Build the testing runtime joystream/node docker image and run the full integration test suite (see Integration tests section below)
232-
1. Commit your changes and push new branch to your repo.
233-
1. Open a PR from your branch on upstream repo, targetting the current runtime release (master) so there is a clear code git diff showing the changes being implemented in the new runtime.
228+
1. Determine the "base" branch to bulid pn. This will typically be the master branch.
229+
1. Bump the `spec_version` component of the runtime `pub const VERSION` in `runtime/src/lib.rs`
230+
update the version of the cargo crates (Cargo.toml) for both the runtime and bin/node
231+
runtime `spec_name` should not be changed.
232+
If the runtime change is only an performance enhancement with no new state or state logic, then
233+
only the `impl_version` needs to be changed.
234+
1. Implement runtime changes, fixes, or new feature. This must includes benchmarking code and new unit tests as appropriate.
235+
1. Run `yarn cargo-checks` to run the linter, code formatting check and unit tests.
236+
1. Build the node with runtime benchmarks feature enabled, see `./scripts/cargo-build-with-benchmarks.sh`
237+
1. Generate weights for modified/new benchmark functions on reference machine, and checkin the changes of the weights.rs - helper script is available in scripts/generate-weights.sh
238+
1. Re run code formatting with `cargo fmt --all`
239+
1. Do another test build with modified benchmarks `yarn cargo-checks && yarn cargo-build`
240+
1. Extract the new runtime metadata `yarn update-chain-metadata`
241+
1. Build all npm packages: `yarn build`
242+
1. Add any new integration tests, query-node mappings that cover the changes implemented.
243+
1. Lint typescript `yarn lint`
244+
1. Build the testing runtime joystream/node docker image and run the full integration test suite (see Integration tests section below)
245+
1. Commit your changes and push new branch to your repo.
246+
1. Open a PR from your branch on upstream repo, targetting the current runtime release (master) so there is a clear code git diff showing the changes being implemented in the new runtime.
234247

235248
You should typically wait for community and core dev team to review before taking the next step of creating the runtime upgrade proposal, as that will require staking a substantial amount of tokens which are at risk of being slashed if the council rejects the proposal.
236249

237250
#### Creating the proposal
238-
1. Build the production joystream/node docker image.
239-
1. Extract the compressed wasm blob from the docker image image.
240-
1. Create a proposal in [pioneer](https://pioneerapp.xyz/#/proposals/current)
241-
Follow instructions, and provide reference to the Pull Request, and upload the compressed wasm file.
242-
251+
252+
1. Build the production joystream/node docker image.
253+
1. Extract the compressed wasm blob from the docker image image.
254+
1. Create a proposal in [pioneer](https://pioneerapp.xyz/#/proposals/current)
255+
Follow instructions, and provide reference to the Pull Request, and upload the compressed wasm file.
256+
243257
### General Points
258+
244259
Making runtime changes are very critical and there are lots of details to keep in mind, especially when the runtime is an upgrade of the current chain, as apposed to a new runtime for a genesis block.
245260
Below are some points to watch out for, what you can/cannot do.. and work arounds.
246261

247262
### Consensus algorithm
263+
248264
No changes should be made to the block interval.
249265

250266
### Runtime type changes
267+
251268
As much as possible avoid changing the types that are stord in state storage. If changes are made there must be either accompanying migration code, or custom decoding implementation for the type to ensure reading existing state from storage does not fail to decode. Adding new types and migrating state from old types is encouraged.
252269

253270
Ref: guide on how migrations can be done: https://docs.substrate.io/reference/how-to-guides/storage-migrations/basic-storage-migration/
254271

255272
### Runtime event types
273+
256274
It is generally not safe to modify runtime event type. The primary consumer of events is the query node,
257275
and the current implementation of they query node does not have a built in mechanism to correctly handle changing of the event type structure through runtime changes, and it should generally be avoided.
258276

@@ -261,9 +279,11 @@ If absolutely necessary the graphql schema and event handler must be aware of su
261279
The issue is being worked on: https://github.com/Joystream/joystream/issues/4650
262280

263281
### New Genesis configurable state storage
282+
264283
When introducing new state storage that is configurable at genesus, keep in mind that the genesis build function for the pallet will not be executed and will not be assigned. Initialing such values must be done in the `on_runtime_upgrade()` hook of the runtime.
265284

266285
### OnRuntimeUpgrade hook
286+
267287
A custom [OnRuntimeUpgrade](https://github.com/Joystream/joystream/blob/master/runtime/src/runtime_api.rs#L63) is executed once when the runtime upgrades to the new version.
268288

269289
This is where we can execute migration code, or any the logic such as setting new storage values if necessary.
@@ -273,31 +293,37 @@ On a related note, there is a new approach seen in substrate code where the pall
273293
This should be researched.
274294

275295
### Joystream fork of substrate
296+
276297
By inspecting Cargo.toml of runtime/, runtime-modules/ and bin/ you will note that the dependencies on substrate comes from:
277-
https://github.com/Joystream/substrate/tree/update-carthage-to-v0.9.24-1
298+
https://github.com/Joystream/substrate/tree/update-carthage-to-v0.9.24-1
278299

279300
It is important that the custom implementation of the vesting and staking be maintained to be compatible with joystream runtime.
280-
- [vesting pallet](https://github.com/Joystream/substrate/pull/7)
281-
- [staking bonding](https://github.com/Joystream/substrate/pull/8)
301+
302+
- [vesting pallet](https://github.com/Joystream/substrate/pull/7)
303+
- [staking bonding](https://github.com/Joystream/substrate/pull/8)
282304

283305
At time of writing the modifications for vesting pallet have been ported to newer versions of substrate upstream, but not the staking pallet.
284306

285307
This should be kept in mind when planning a runtime upgrade that also updates the core version of substrate.
286308

287309
### Running integration tests
310+
288311
The best experience for doing development and testing is on a linux/ubuntu amd64 architecture machine, especially when it comes to working with docker.
289312

290313
### Runtime profiles
314+
291315
The runtime can be compiled with several cargo feature flags, to produce slightly different configurations.
292316
The main difference between these configurations is around the council election periods lenghts, proposal periods (voting and gracing), and block production interval.
293317

294318
There are 4 profiles:
295-
- production: used in production mainnet (this is the default when no explicit feature flag is provided)
296-
- staging: used on long running staging testnets
297-
- playground: used when deploying simple shared development testnets
298-
- testing: used when running integration tests
319+
320+
- production: used in production mainnet (this is the default when no explicit feature flag is provided)
321+
- staging: used on long running staging testnets
322+
- playground: used when deploying simple shared development testnets
323+
- testing: used when running integration tests
299324

300325
### Integration tests
326+
301327
How they differ from rust/cargo unit tests.
302328
In addition to cargo unit tests for runtime features, over time we have developed a growing suite of integration tests. This is more of an end to end testing framework for testing proper functioning of the joystream platform as a whole. It involves running a scaled down joystream network on a local development machine and running through as many flows of interaction through extrinsics and testing that components such as the runtime, query-node and storage infrastructure behave as expected.
303329

@@ -309,6 +335,7 @@ tests/network-tests/run-tests.sh
309335
```
310336

311337
### Running a Testing playground
338+
312339
In addition to running automated test, it makes sense to also do some manual testing of apps, like polkadot-js, pioneer, and atlas.
313340
For you can conveniently run a local playground and point those apps to it:
314341

@@ -323,16 +350,20 @@ RUNTIME_PROFILE=PLAYGROUND ./start-multistorage.sh
323350
```
324351

325352
### Upgrade Testing
353+
326354
In addition to testing the new runtime in isolation, it is imperative that it be tested through performing an actual upgrade of the existing runtime. This would be done on a test network or playground. To make it practical the proposal needs to be executed in a short period in these test environments so using a testing profile or playground profile would be best.
327355

328356
Specific test scenario should be written to test for any state migration code performed after the upgrade, or for any custom decoding implemented for old types.
329357

330358
#### Automated runtime upgrade testing
359+
331360
There are some scripts in `tests/network-tests/run-migration-tests.sh` that are executed by github workflow to perform such tests,
332361
but they should also be executed locally.
333362

334363
### Additional Resources
364+
335365
Some tooling that would be useful to add to our node and runtime to improve testing capabilities:
366+
336367
- https://docs.substrate.io/reference/how-to-guides/tools/use-try-runtime/
337368
- https://docs.substrate.io/reference/command-line-tools/try-runtime/
338369

0 commit comments

Comments
 (0)