Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix state_subscribeRuntimeVersion for parachains #9617

Merged
merged 1 commit into from
Aug 25, 2021

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Aug 24, 2021

The old implementation was listening for storage changes and every time
a block changed the CODE storage field, it checked if the runtime
version changed. It used the best block to compare against the latest
known runtime version. It could happen that you processed the storage
notification of block Y and checked the runtime version of block X (the
current best block). This is also what happened on parachains.
Parachains import blocks and set the new best block in a later step.
This means we imported the block that changed the code, got notified and
checked the runtime version of the current best block (which would still
be the parent of the block that changed the runtime). As the parent did
not changed the runtime, the runtime version also did not changed and we
never notified the subscribers.

The new implementation now switches to listen for best imported blocks.
Every time we import a new best block, we check its runtime version
against the latest known runtime version. As we also send a notification
when the parachains sets a block as new best block, we will trigger this
code path correctly. It moves some computation from checking if the key
was modified to getting the runtime version. As fetching the runtime
version is a rather common pattern, it should not make any big
difference performancewise.

Fixes: paritytech/cumulus#574

The old implementation was listening for storage changes and every time
a block changed the `CODE` storage field, it checked if the runtime
version changed. It used the best block to compare against the latest
known runtime version. It could happen that you processed the storage
notification of block Y and checked the runtime version of block X (the
current best block). This is also what happened on parachains.
Parachains import blocks and set the new best block in a later step.
This means we imported the block that changed the code, got notified and
checked the runtime version of the current best block (which would still
be the parent of the block that changed the runtime). As the parent did
not changed the runtime, the runtime version also did not changed and we
never notified the subscribers.

The new implementation now switches to listen for best imported blocks.
Every time we import a new best block, we check its runtime version
against the latest known runtime version. As we also send a notification
when the parachains sets a block as new best block, we will trigger this
code path correctly. It moves some computation from checking if the key
was modified to getting the runtime version. As fetching the runtime
version is a rather common pattern, it should not make any big
difference performancewise.
@bkchr bkchr added A0-please_review Pull request needs code review. B5-clientnoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Aug 24, 2021
@bkchr bkchr requested review from dvdplm and niklasad1 August 24, 2021 14:32
@bkchr bkchr merged commit 87b6266 into master Aug 25, 2021
@bkchr bkchr deleted the bkchr-fix-subscribe-runtime-version branch August 25, 2021 07:13
Wizdave97 pushed a commit to Wizdave97/substrate that referenced this pull request Aug 25, 2021
The old implementation was listening for storage changes and every time
a block changed the `CODE` storage field, it checked if the runtime
version changed. It used the best block to compare against the latest
known runtime version. It could happen that you processed the storage
notification of block Y and checked the runtime version of block X (the
current best block). This is also what happened on parachains.
Parachains import blocks and set the new best block in a later step.
This means we imported the block that changed the code, got notified and
checked the runtime version of the current best block (which would still
be the parent of the block that changed the runtime). As the parent did
not changed the runtime, the runtime version also did not changed and we
never notified the subscribers.

The new implementation now switches to listen for best imported blocks.
Every time we import a new best block, we check its runtime version
against the latest known runtime version. As we also send a notification
when the parachains sets a block as new best block, we will trigger this
code path correctly. It moves some computation from checking if the key
was modified to getting the runtime version. As fetching the runtime
version is a rather common pattern, it should not make any big
difference performancewise.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

state_subscribeRuntimeVersion doesn't work for parachains
3 participants