libplanet icon indicating copy to clipboard operation
libplanet copied to clipboard

Add `IAccountStateDelta.RemoveState()` to unset state after it's once set

Open dahlia opened this issue 4 years ago • 4 comments

States have been intended to be nullable, as they can be empty. I believe the nullability on that parameter was missing when I added #nullable enable to the source file.

See also the recent comment: https://github.com/planetarium/libplanet/issues/1383#issuecomment-1000046682.

dahlia avatar Jul 16 '21 04:07 dahlia

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar Sep 19 '21 01:09 stale[bot]

I changed the title, because an assumption/semantics of states that every state can be unset by filling it with null[^1] had been an undocumented specification only I (@dahlia) have been aware of. I leave some context for historical accuracy:

In early days, I (@dahlia) intended to let IAccountStateDelta.SetState() can take a null value to unset state. However, at that time IAccountStateDelta.cs did not enable null checker yet, and there has never been any mention about such behavior on docs.

Later, I enabled null checker on IAccountStateDelta.cs (context: #458), but I omitted give a question mark to type of IAccountStateDelta.SetState()'s second parameter by mistake. As a result, the meaning of the parameter changed from nullable IValue to non-nullable IValue. (The original description of this issue addressed this.)

When @moreal worked on MPT (ITrie, MerkleTrie, etc), he interpreted that states cannot be unset after once they are set. It was natural, because there was no clue at all both in code and docs. In the end, ITrie.Set() and so on are designed to disallow unset states and explicitly throw ArgumentNullException if null value is passed. This behavior is documented at least.

Lib9c, Libplanet's virtually only client code in production as of now, also never tries to unset states. They instead fill states with Bencodex.Types.Null.Value.

To sum up, our implementation, doc, and client code all assume that states cannot be unset after being set once. We could implement a feature to unset states in the future, it would be accomplished by adding a separate method like IAccountStateDelta.RemoveState(). This issue would be left for that work.

[^1]: It differs from Bencodex.Types.Null.Value.

dahlia avatar Dec 23 '21 05:12 dahlia

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar Mar 02 '22 09:03 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar Jul 31 '22 01:07 stale[bot]