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

Fixes storage_hash caching issue and enables better caching for Cumulus #8518

Merged
merged 4 commits into from
Apr 2, 2021

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Apr 2, 2021

There was a caching issue with storage_hash that resulted in not
reverting cached storage hashes when required. In Cumulus this resulted
in nodes failing to import new blocks after a runtime upgrade, because
they were using the old runtime version.

Besides that, this pr optimizes for the Cumulus use case. In particular
that we always import blocks first as non-best blocks and enact them
later. In current version of the caching that would mean we would always
throw away the complete cache of the latest imported block. Now, we
always update the cache for the first block of a new block height. This
enables us to use the cache if this block will enacted as best block
later. If there is a fork and that is enacted as best, we revert all the
changes to the cache.

…ulus

There was a caching issue with `storage_hash` that resulted in not
reverting cached storage hashes when required. In Cumulus this resulted
in nodes failing to import new blocks after a runtime upgrade, because
they were using the old runtime version.

Besides that, this pr optimizes for the Cumulus use case. In particular
that we always import blocks first as non-best blocks and enact them
later. In current version of the caching that would mean we would always
throw away the complete cache of the latest imported block. Now, we
always update the cache for the first block of a new block height. This
enables us to use the cache if this block will enacted as best block
later. If there is a fork and that is enacted as best, we revert all the
changes to the cache.
@bkchr bkchr added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Apr 2, 2021
@bkchr bkchr requested a review from arkpar April 2, 2021 12:17
///
/// If there already exists a modification for a higher block height, `false` is returned.
fn is_first_modification_at_block_height(&self, number: NumberFor<B>) -> bool {
self.modifications.get(0).map(|c| c.number < number).unwrap_or(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather call it has_no_modification_at_block_height. is_ implies that condition is applied to self, rather than the argument.

bkchr and others added 2 commits April 2, 2021 16:14
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
@bkchr bkchr merged commit 2789fed into master Apr 2, 2021
@bkchr bkchr deleted the bkchr-fix-storage-hash-caching-issue branch April 2, 2021 21:58
bkchr added a commit that referenced this pull request Apr 3, 2021
…ulus (#8518)

* Fixes `storage_hash` caching issue and enables better caching for Cumulus

There was a caching issue with `storage_hash` that resulted in not
reverting cached storage hashes when required. In Cumulus this resulted
in nodes failing to import new blocks after a runtime upgrade, because
they were using the old runtime version.

Besides that, this pr optimizes for the Cumulus use case. In particular
that we always import blocks first as non-best blocks and enact them
later. In current version of the caching that would mean we would always
throw away the complete cache of the latest imported block. Now, we
always update the cache for the first block of a new block height. This
enables us to use the cache if this block will enacted as best block
later. If there is a fork and that is enacted as best, we revert all the
changes to the cache.

* Apply suggestions from code review

Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>

* Indentation

* Update client/db/src/storage_cache.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
arkpar added a commit that referenced this pull request Apr 6, 2021
bkchr pushed a commit that referenced this pull request Apr 6, 2021
* Revert "Fixes `storage_hash` caching issue and enables better caching for Cumulus (#8518)"

This reverts commit 85eef08.

* Fix reverting storage_hash

* Restore test
bkchr pushed a commit that referenced this pull request Apr 6, 2021
* Revert "Fixes `storage_hash` caching issue and enables better caching for Cumulus (#8518)"

This reverts commit 85eef08.

* Fix reverting storage_hash

* Restore test
hirschenberger pushed a commit to hirschenberger/substrate that referenced this pull request Apr 14, 2021
…ulus (paritytech#8518)

* Fixes `storage_hash` caching issue and enables better caching for Cumulus

There was a caching issue with `storage_hash` that resulted in not
reverting cached storage hashes when required. In Cumulus this resulted
in nodes failing to import new blocks after a runtime upgrade, because
they were using the old runtime version.

Besides that, this pr optimizes for the Cumulus use case. In particular
that we always import blocks first as non-best blocks and enact them
later. In current version of the caching that would mean we would always
throw away the complete cache of the latest imported block. Now, we
always update the cache for the first block of a new block height. This
enables us to use the cache if this block will enacted as best block
later. If there is a fork and that is enacted as best, we revert all the
changes to the cache.

* Apply suggestions from code review

Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>

* Indentation

* Update client/db/src/storage_cache.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
hirschenberger pushed a commit to hirschenberger/substrate that referenced this pull request Apr 14, 2021
* Revert "Fixes `storage_hash` caching issue and enables better caching for Cumulus (paritytech#8518)"

This reverts commit 85eef08.

* Fix reverting storage_hash

* Restore test
KalitaAlexey pushed a commit to KalitaAlexey/substrate that referenced this pull request Jul 9, 2021
* Revert "Fixes `storage_hash` caching issue and enables better caching for Cumulus (paritytech#8518)"

This reverts commit 85eef08.

* Fix reverting storage_hash

* Restore test
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. B0-silent Changes should not be mentioned in any release notes 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.

3 participants