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

[rpc-alt] implement getCoinMetadata method #21315

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

emmazzz
Copy link
Contributor

@emmazzz emmazzz commented Feb 22, 2025

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.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented Feb 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 25, 2025 9:58pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Feb 25, 2025 9:58pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Feb 25, 2025 9:58pm

@emmazzz emmazzz temporarily deployed to sui-typescript-aws-kms-test-env February 22, 2025 00:38 — with GitHub Actions Inactive
@emmazzz emmazzz force-pushed the emma/rpc-alt-coin-metadata branch from 85015ae to 5a26504 Compare February 22, 2025 00:41
@emmazzz emmazzz requested a review from amnn February 22, 2025 00:41
@emmazzz emmazzz temporarily deployed to sui-typescript-aws-kms-test-env February 22, 2025 00:41 — with GitHub Actions Inactive
@emmazzz emmazzz requested review from gegaowp and wlmyng February 22, 2025 00:41
@@ -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() {
Copy link
Contributor Author

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!

Base automatically changed from emma/rpc-all-balances to main February 22, 2025 01:07
.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());
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice find!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants