-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Linter: Warn when storage can never be freed up #1431
Comments
I think this issue should be in ink!. This is where the lints live now :) |
You could also leave lints out of the compiler and move it to a specialised tool, just for that (just like rustc is not a linter and outsources that to |
@cmichi I suggest to split this into two lints:
The point is that the implementation of these lints seems to be different.
OTOH, What do you think? |
@jubnzv I think it makes a lot of sense.
I'm a bit torn on I'm torn because there's also legitimate use-cases for writing storage once and never freeing it up again. An example is our |
It seems that there is no such lint in clippy. I'll try to ask them, maybe it is possible to contribute a new lint to
That's a fair point, I agree. In some cases it is absolutely legit to write code that doesn't free storage. My suggestion here is to set What do you think? |
* feat(lint+test): add skeleton of storage_never_freed (#1431) * feat(lint): add utils and logic to collect `Vec`/`Mapping` types It reuses functions implemented in #1914, so we need to rebase and modify it when it is merged. * feat(lint): Make it pass simple tests * feat(lint): Support index operations (`vec[]`) * feat(lint): Ignore fields that has mutable unsafe pointers * chore(lint): Refactor * feat(test): Inserting in method arg * chore(test): Refactor * feat(test): Insert inside insert * chore(lint): Refactor * feat(lint): Support local type aliases * chore(lint): More accurate warning text * chore(lint): Refactor * feat(lint): Additional check for `self` * chore(lint+tests): Refactor; update tests output * chore: Update changelog * chore: fmt
Here's the issue in clippy regarding unnecessary |
pallet-contracts
uses storage deposit as a mechanism to counter state bloat. In short, the idea is that there is an economic incentive to free up space on the chain. When a user executes a contract function that writes to storage, the user has to put a deposit down for the amount of storage space used. Whoever frees up that storage at some later point gets the deposit back.For this to work, developers should whenever possible provide means for users to free up storage space again.
We could introduce a lint that checks in a simple manner:
Vec.push()
in the contract, then there also has to be aVec.pop()
.Mapping.insert()
in the contract, then there also has to be aMapping.remove()
.Option = Some(…)
in the contract, then there also has to be aOption = None
.There's surely contexts where it makes sense to ignore this rule, we could have something like
#[allow(ink::never_freed)]
to explicitly mark those.I'm a bit torn if this linter rule makes sense, I would like to hear opinions from others. My concern is that I'm not sure if it's realistic to have inverse methods on a general base and if we would not be causing more user friction this way, possibly resulting in people just always allowing
never_freed
for the entire contract.The text was updated successfully, but these errors were encountered: