Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass a bound on StorageCountedMap::remove_all (similarly to StorageMap::removal_all) #294

Open
gui1117 opened this issue Dec 3, 2021 · 10 comments
Labels
I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework.

Comments

@gui1117
Copy link
Contributor

gui1117 commented Dec 3, 2021

StorageMap::remove_all take as argument the limit of key to remove from backend. This is useful when user want to remove all keys from a map but without using too much of the block weight.

StorageCountedMap::remove_all cannot implement this limit easily. Because when the runtime api clear_prefix return the number of key removed from backend, but we don't know how many keys were actually removed (some key are in the overlay and some are in both overlay and backend), so we can't update the counter.

One solution suggested by Shawn is to look at the value of the counter in the backend. and update the counter with: counter in the backend - number of key removed in the backend by this operation.
Maybe this is a way to implement the limit.

context:

@dharjeezy
Copy link
Contributor

Hello @thiolliere

I saw you mentioned the previous issue you closed(#10288) which I attempted on this current issue.
Can you elaborate the differences between that other issue(#10288) and this current issue you opened?
I am willing to pick this issue up but i need to understand what i am to do and the difference between what i attempted in my PR here(paritytech/substrate#10332) earlier?

@dharjeezy
Copy link
Contributor

you there @thiolliere ?

@gui1117
Copy link
Contributor Author

gui1117 commented Dec 20, 2021

you there @thiolliere ?

I didn't work last weekend why did you expect me to answer a low priority question ?

EDIT: I also find the tone of your sentence disrespectful.

@gui1117
Copy link
Contributor Author

gui1117 commented Dec 20, 2021

Hello @thiolliere

I saw you mentioned the previous issue you closed(#10288) which I attempted on this current issue. Can you elaborate the differences between that other issue(#10288) and this current issue you opened? I am willing to pick this issue up but i need to understand what i am to do and the difference between what i attempted in my PR here(#10332) earlier?

The solution I suggested in the issue paritytech/substrate#10288 doesn't work.
The goal of this issue is to enhance the the method remove_all for StorageCountedMap type.
We want to be able to give a limit on the number of key to remove from the backend (or both backend and overlay, the important point is to be able to give a limit), similarly to the method remove_all for StorageMap.

There might be a way found by Shawn that I explained in the top message. This consist of looking at the number of key in the backend by looking the value of the counter in the backend (maybe by using the parent block hash or something I don't know).

I don't have a precise idea about how to fetch the value of the counter in the backend. But if we have it then we can implement remove_all with some limit, and update the counter with the value: counter in backend minus number of key removed from backend. Because all keys are removed from overlay this should work.

@dharjeezy
Copy link
Contributor

dharjeezy commented Dec 24, 2021

you there @thiolliere ?

I didn't work last weekend why did you expect me to answer a low priority question ?

EDIT: I also find the tone of your sentence disrespectful.

@thiolliere I am sorry for the tone I used, never knew you'd get offended by it. I will do better next time.

@dharjeezy
Copy link
Contributor

Hello @thiolliere
I saw you mentioned the previous issue you closed(#10288) which I attempted on this current issue. Can you elaborate the differences between that other issue(#10288) and this current issue you opened? I am willing to pick this issue up but i need to understand what i am to do and the difference between what i attempted in my PR here(#10332) earlier?

The solution I suggested in the issue paritytech/substrate#10288 doesn't work. The goal of this issue is to enhance the the method remove_all for StorageCountedMap type. We want to be able to give a limit on the number of key to remove from the backend (or both backend and overlay, the important point is to be able to give a limit), similarly to the method remove_all for StorageMap.

There might be a way found by Shawn that I explained in the top message. This consist of looking at the number of key in the backend by looking the value of the counter in the backend (maybe by using the parent block hash or something I don't know).

I don't have a precise idea about how to fetch the value of the counter in the backend. But if we have it then we can implement remove_all with some limit, and update the counter with the value: counter in backend minus number of key removed from backend. Because all keys are removed from overlay this should work.

If i can get you correctly, we need to implement a limit on remove_all function CountedStorageMap right?

The caller of the function will definitely include the limit while calling this function right? or is the remove_all to determine the limit that is to be removed out of the box inside the function?

More so, will one implement a v2 for remove_all or modify the existing one?

@hirschenberger
Copy link
Contributor

hirschenberger commented Mar 2, 2022

Hey @thiolliere , I skimmed through the code and found this comment in the existing remove_all fn.

But it does not seem to be true anymore, as the sp_io::storage::clear_prefix fn does return a KillStorageResult.

Also the comment of sp_io::clear_prefix seems outdated as it mentiones a boolean return value.

So maybe this can now be implemented straight forward?

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 2, 2022

@hirschenberger

I think the comment in the code should be updated, it was a mistake from me to think that having the number of key deleted from overlay would be sufficient to implement this feature.

This comment should explain it paritytech/substrate#10288 (comment)

Basically we can have the same key in both overlay and backend. (when they are overriden for example). So even if we know that N and M keys are removed from overlay and backend we don't know how many key we actually deleted from the counted storage map.

@hirschenberger
Copy link
Contributor

Oh, I see. And the approach @shawntabrizi suggested is using a "counter" for the backend to determine how many backend operations happend during the removal and take this number into account for the limit.

What exactly is this counter, is it the read_write_count or usage_info functions. It seems they are more tailored towards bechmarking or telemetry and seem to be a fragile API?

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 8, 2022

Oh, I see. And the approach @shawntabrizi suggested is using a "counter" for the backend to determine how many backend operations happend during the removal and take this number into account for the limit.

What exactly is this counter, is it the read_write_count or usage_info functions. It seems they are more tailored towards bechmarking or telemetry and seem to be a fragile API?

Shawn solution was to fetch the value of the counter in the backend itself as it should hold as it shouldn't take into account the value added in the overlay. I don't think sp_io::storage provides a way to read this value. Maybe we would want to introduce sp_io::storage::get_backend which returns the value for a given key but using only the backend.
In general I don't really like having the backend/overlay architecture exposed in the sp_io::storage API, but clear_prefix is already exposing this architecture in the API.

@juangirini juangirini transferred this issue from paritytech/substrate Aug 24, 2023
@the-right-joyce the-right-joyce added I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework. and removed J0-enhancement labels Aug 25, 2023
helin6 pushed a commit to boolnetwork/polkadot-sdk that referenced this issue Feb 5, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
* changed log level from error to trace

* incomplete during submit != synced
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
* changed log level from error to trace

* incomplete during submit != synced
jonathanudd pushed a commit to jonathanudd/polkadot-sdk that referenced this issue Apr 10, 2024
* changed log level from error to trace

* incomplete during submit != synced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
Status: Backlog
Development

No branches or pull requests

5 participants