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

Fix clear prefix check to avoid erasing child trie roots. #7848

Merged
4 commits merged into from
Jan 13, 2021

Conversation

cheme
Copy link
Contributor

@cheme cheme commented Jan 7, 2021

Checks on child storage root for clear prefix is incorrect, this changes it.

An alternative implementation would be to allow such clear prefix and skip the child storage root prefix from being deleted.

This is possibly breaking consensus but I know of no pallet that can delete a prefix containing child storage root, so from my point of view it should be fine to use.

@cheme cheme added A0-please_review Pull request needs code review. B7-runtimenoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Jan 7, 2021
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Could you add some test?

@cheme cheme added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Jan 8, 2021
@cheme
Copy link
Contributor Author

cheme commented Jan 8, 2021

Will do 👍

@cheme cheme added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jan 8, 2021
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Some last nitpicks, otherwise looks good.

@@ -1022,6 +1023,24 @@ mod tests {
ext.child_storage_hash(child_info, &[30]),
Some(Blake2Hasher::hash(&[31]).as_ref().to_vec()),
);

// check clear prefix is ignored on conflict
use sp_core::storage::well_known_keys;
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to make this an independent test.

Comment on lines 184 to 185
/// Whether a prefix potentially contains child storage keys.
pub fn can_contain_child_storage_key(prefix: &[u8]) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Whether a prefix potentially contains child storage keys.
pub fn can_contain_child_storage_key(prefix: &[u8]) -> bool {
/// Returns if the given `key` starts with [`CHILD_STORAGE_KEY_PREFIX`] or collides with it.
pub fn starts_with_child_storage_key(key: &[u8]) -> bool {

@bkchr bkchr requested a review from gui1117 January 12, 2021 13:18
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

good catch, looks good to me,

I wonder should a similar handling be done with next_storage_key ? like if next_storage_key goes into some CHILD_STORAGE_KEY_PREFIX space then it should be skipped ?

@cheme
Copy link
Contributor Author

cheme commented Jan 12, 2021

I would not bother to skip it, accessing root read only seems fine to me.

@gui1117
Copy link
Contributor

gui1117 commented Jan 12, 2021

Yes I agree

@cheme
Copy link
Contributor Author

cheme commented Jan 13, 2021

bot merge

@ghost
Copy link

ghost commented Jan 13, 2021

Trying merge.

@ghost ghost merged commit aa8b7db into paritytech:master Jan 13, 2021
drahnr pushed a commit that referenced this pull request Jan 13, 2021
* Fix clear prefix check to avoid erasing child trie roots.

* Renaming and extend existing test with check.

* last nitpicks.
drahnr added a commit that referenced this pull request Jan 13, 2021
* make helper error types generics

* avoid From<io::Error> dep in runner helper logic

* slip of the pen, bump futures to 0.3.9

* more generics

* generic var spaces

Co-authored-by: Andronik Ordian <write@reusable.software>

* network-gossip: add metric for number of local messages (#7871)

* network-gossip: add metric for number of local messages

* grandpa: fix GossipEngine missing metrics registry parameter

* network-gossip: increase known messages cache size

* network-gossip: fix tests

* grandpa: remove unnecessary clone

Co-authored-by: Max Inden <mail@max-inden.de>

* network-gossip: count registered and expired messages separately

* network-gossip: add comment on known messages cache size

* network-gossip: extend comment with cache size in memory

Co-authored-by: Max Inden <mail@max-inden.de>

* Clean-up pass in network/src/protocol.rs (#7889)

* Remove statistics system

* Remove ContextData struct

* Remove next_request_id

* Some TryFrom nit-picking

* Use constants for peer sets

* contracts: Don't read the previous value when overwriting a storage item (#7879)

* Add `len` function that can return the length of a storage item efficiently

* Make use of the new len function in contracts

* Fix benchmarks

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Remove unused imports

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>

* Fix clear prefix check to avoid erasing child trie roots. (#7848)

* Fix clear prefix check to avoid erasing child trie roots.

* Renaming and extend existing test with check.

* last nitpicks.

* use follow paths to std standarad components

* line width

Co-authored-by: Bernhard Schuster <bernhard@parity.io>
Co-authored-by: Andronik Ordian <write@reusable.software>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
This pull request was closed.
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.

3 participants