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

refactor(liveslots): minor improvements to prepare for upcoming changes #8752

Merged
merged 3 commits into from
Jan 17, 2024

Conversation

erights
Copy link
Member

@erights erights commented Jan 15, 2024

closes: #XXXX
refs: endojs/endo#1964 endojs/endo#1966

Description

Minor refactors to prepare for upcoming changes.

Some minor typing improvements. Mostly being explicit that cache.get(key) can return an answer or undefined, and then adding explicit assert(thing !== undefined); statements as suggested by the type checker. I believe in all cases where I added these, the undefined case would have caused an early enough error anyway, so the only behavioral change would be to make the error a bit clearer.

Reviewers, please look at all these potential behavioral changes to be sure my added assertions would not cause any buggy behavior. Also, are some of these cases that should always have handled the undefined case differently than just throwing an error?

As previously discussed with @FUDCo, cache.delete(key) now returns a boolean to say whether it actually deleted anything. The motivation for this was receiveRevoker which is disappearing endojs/endo#1964 , but this seems like a good change anyway. It is more consistent with other collection.delete(key) APIs.

The most significant are the simplifications of deleting makeContextProvider and makeContextProviderKit, and putting their context provider making code inline.

Security Considerations

none

Scaling Considerations

none

Documentation Considerations

none

Testing Considerations

none

Upgrade Considerations

none

Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

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

This all seems fine.

Having cache.delete(key) return a boolean seems like a strict improvement. It's information that's easily ignored if you don't care about it, but nice to have if you do care. Since pre-existing code was necessarily in the "don't care" category, there shouldn't be any backwards compatibility issues, which is the main thing I worry about when you change a return type.

@erights erights force-pushed the markm-minor-liveslots-refactor branch 2 times, most recently from ddc23a8 to 75212fc Compare January 16, 2024 19:42
@erights erights force-pushed the markm-minor-liveslots-refactor branch from 75212fc to 41ff168 Compare January 16, 2024 21:32
@erights erights added the automerge:squash Automatically squash merge label Jan 17, 2024
@mergify mergify bot merged commit 8ef62f4 into master Jan 17, 2024
74 checks passed
@mergify mergify bot deleted the markm-minor-liveslots-refactor branch January 17, 2024 02:38
anilhelvaci pushed a commit to Jorge-Lopes/agoric-sdk that referenced this pull request Feb 16, 2024
…es (Agoric#8752)

* refactor(liveslots): minor improvements to prepare for upcoming changes

* fix: use ClassContextProvider from endo Agoric#1966

* fix: adapt to endo types pre and post endo Agoric#1966
warner added a commit that referenced this pull request Jun 14, 2024
Liveslots uses an internal `Cache` utility to hold data about virtual
objects, backed by the vatstore. PR #8752 included a change to make
its `delete()` method return a "did exist" boolean, just like a
JavaScript `Map`. Unfortunately the cache does not know whether a key
is present/absent in the backing store, so `delete()` will return an
erroneous value. It would cost an extra DB query to make this behave
as expected, and liveslots does not have a need for it.

So this commit reverts that change, and makes `delete()` return void
as before.
@@ -17,7 +17,7 @@ import { Fail } from '@agoric/assert';
/**
* @callback CacheDelete
* @param {string} key
* @returns {void}
* @returns {boolean}
Copy link
Member

Choose a reason for hiding this comment

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

This won't work as expected (assuming that Map-like behavior is expected). The cache doesn't know whether a given key is present in the backing store or not, it only knows whether it was marked for deletion by a previous call to delete(). So the answer will depend upon the history of the cache as well as the backing store:

present in backing store cache operations expected result actual result
yes delete() true false
no delete() false false
yes get() + delete() true true
no get() + delete() false true

Liveslots doesn't have a need for a delete() return value, and it would cost an extra DB query to make this act like Map, so I'd suggest reverting this one piece.

The other change (get() can return undefined but the typedef didn't reflect that) is absolutely correct.

PR #9509 is for reverting this part.. my apologies for not reviewing this in a timely fashion.

warner added a commit that referenced this pull request Jun 14, 2024
Liveslots uses an internal `Cache` utility to hold data about virtual
objects, backed by the vatstore. PR #8752 included a change to make
its `delete()` method return a "did exist" boolean, just like a
JavaScript `Map`. Unfortunately the cache does not know whether a key
is present/absent in the backing store, so `delete()` will return an
erroneous value. It would cost an extra DB query to make this behave
as expected, and liveslots does not have a need for it.

So this commit reverts that change, and makes `delete()` return void
as before.
mergify bot added a commit that referenced this pull request Jun 14, 2024
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it.

So this commit reverts that change, and makes `delete()` return void as before.
mhofman pushed a commit that referenced this pull request Jun 20, 2024
Liveslots uses an internal `Cache` utility to hold data about virtual
objects, backed by the vatstore. PR #8752 included a change to make
its `delete()` method return a "did exist" boolean, just like a
JavaScript `Map`. Unfortunately the cache does not know whether a key
is present/absent in the backing store, so `delete()` will return an
erroneous value. It would cost an extra DB query to make this behave
as expected, and liveslots does not have a need for it.

So this commit reverts that change, and makes `delete()` return void
as before.
mhofman pushed a commit that referenced this pull request Jun 20, 2024
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it.

So this commit reverts that change, and makes `delete()` return void as before.
mhofman pushed a commit that referenced this pull request Jun 22, 2024
Liveslots uses an internal `Cache` utility to hold data about virtual
objects, backed by the vatstore. PR #8752 included a change to make
its `delete()` method return a "did exist" boolean, just like a
JavaScript `Map`. Unfortunately the cache does not know whether a key
is present/absent in the backing store, so `delete()` will return an
erroneous value. It would cost an extra DB query to make this behave
as expected, and liveslots does not have a need for it.

So this commit reverts that change, and makes `delete()` return void
as before.
mhofman pushed a commit that referenced this pull request Jun 22, 2024
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it.

So this commit reverts that change, and makes `delete()` return void as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:squash Automatically squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants