-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[rpc-alt] implement getCoinMetadata method #21315
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
85015ae
to
5a26504
Compare
@@ -160,7 +160,7 @@ pub(crate) async fn load_live( | |||
|
|||
// If the latest object info record has no owner, the object is not live (it is wrapped or | |||
// deleted). | |||
if obj_info.owner_id.is_none() { | |||
if obj_info.owner_kind.is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was pretty hard to find -- turns out owner_id
is None when the object is frozen or shared!
.filter(candidates!(owner_kind).eq(StoredOwnerKind::Address)) | ||
.filter(candidates!(owner_id).eq(owner.to_inner())); | ||
} else { | ||
query = query.filter(candidates!(owner_kind).is_not_null()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may work better to introduce a new data loader for singleton objects -- it would be keyed on TypeTag
, and it would run a query something like (my syntax might be a bit off):
SELECT DISTINCT ON (package, module, name, instantiation)
object_id,
owner_kind
FROM
obj_info
INNER JOIN (
VALUES
(...), ...
) types (package, module, name, instantiation)
USING (package, module, name, instantiation)
ORDER BY
package,
module,
name,
instantiation,
cp_sequence_number DESC
...and then it can filter out results where the owner_kind
is NULL
in memory, because there will be at most one for each input type.
Keeping singleton object queries separate lets us take advantage of the fact that they can be batched, and keeps the owned object filtering path simple as well.
At the moment, I'm concerned by this conditional -- we can do the work now to make sure that fetching coin metadata is efficient, but it implies that any combination of filters plus owner_kind IS NOT NULL
is going to be efficient, and I'm less sure about that, because it isn't exactly covered by one of our indices, and the only reason that's okay for CoinMetadata
is because we know that there should be at most one result for each type, which makes it cheap to filter that out with a scan -- this won't be true in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with separating out fetching singleton object and have done so in the new commit.
The query doesn't work though because, for a deleted object, not only is owner_kind
null, all the type fields are null too so we have to stick to the consistency query style. I didn't want to make this a data loader because dealing with multi fetching for a vector of types will be much harder than fetching for one type and I don't want this to become a blocker. I have added a TODO for it though.
@@ -160,7 +160,7 @@ pub(crate) async fn load_live( | |||
|
|||
// If the latest object info record has no owner, the object is not live (it is wrapped or | |||
// deleted). | |||
if obj_info.owner_id.is_none() { | |||
if obj_info.owner_kind.is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find!
5a26504
to
4be08af
Compare
Description
This PR implements the getCoinMetadata method.
It also fixes a subtle bug in
load_live
that prevented us from loading non-address-owned objects.Test plan
Added a test.
Release notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.