owned this note
owned this note
Published
Linked with GitHub
# Runtime OCW Burn-in example
## WTF are we doing here?
> We're breaking the fundamental assumption of the chian, by *tweaking the runtime*'s code in a *controlled* way, and then makinng a new binary (**without** bumping the spec version -- as you would normally do).
You can always compile a new polkadot node with a different runtime and sync the chain. This is okay, as long as your spec version is honest. In reality, this new `burn-in` polkadot binary will have a bumped spec version, and we always use the canonical wasm code from the chain state instead, so it really doesn't matter what is the native runtime.
In this type of burn-in, we want to trick the system. We want to change the runtime code, but we won't bump the spec version. This will trick the binary to actually execute the *native* runtime (i.e. your modified runtime), not the one stored on-chain.
Note that we **only** do this if we know that the changes that we are placing in the new runtime do not have any state effect. Otherwise you would come up to a state-mismatch, and if you are a validator, you'd author incorrect blocks and you lose money. For example, this is suicidal if you change the logic of any pallet, add or remote storage etc, as you would surely get a state root mismatch.
In this case, we only teak the OCW code, so the state root will never change. All in all, be very careful with this, and only deploy on as little as possible number of validators, as you could casue slashing.
## Example
For PR https://github.com/paritytech/substrate/pull/7976
=
- Polkadot: Checkout to `2f84569930a4ae86a3ecd60fff3488753ab79aa6`, **latest release**
- Make branch `kiz-staking-OCW-rerun-dryrun-polkadot`
```
gich -B kiz-staking-OCW-rerun-dryrun-polkadot 2f84569930a4ae86a3ecd60fff3488753ab79aa6
```
- Substrate: checkout to `8c3b3fb1b0c858cc603444eafab4032caf6795ce`
- Make branch `kiz-staking-OCW-rerun-dryrun`
> This is the substrate commit that is pinned to polkadot at `2f84569930a4ae86a3ecd60fff3488753ab79aa6`.
```
gich -B kiz-staking-OCW-rerun-dryrun 8c3b3fb1b0c858cc603444eafab4032caf6795ce
```
- apply all the commits from the PR:
```
git log origin/master..kiz-staking-OCW-rerun --oneline --reverse --pretty=format:"%h" | xargs -n 1 git cherry-pick --strategy-option=ours
```
> Note that this luckily errors out on the commits that are merging something from master, and skips them. ideally, the `git log` should be configured to filter them out. **We don't want to add the commits that merged master into this PR to be included in the patch!**. Do a `git log` to verify this.
> Probably easier to do this with creating a `.patch` file and applying that.
- Make it compile. All tests pass. Push.
- Polkadot, replace all `git = "https://github.com/paritytech/substrate", branch = "whatever"` wiht `git = "https://github.com/paritytech/substrate", branch = "kiz-staking-OCW-rerun-dryrun "`
- Make it compile as well. All tests pass. Push.
Branch `kiz-staking-OCW-rerun-dryrun-polkadot` of polkadot should now be ready for burin.
## Automation
Script available at https://gist.github.com/coriolinus/4c25daf5aa3e331fb6341a568250bf96