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

[GraphQL][DotMove][3/n] Adds External resolver #18798

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

manolisliolios
Copy link
Contributor

@manolisliolios manolisliolios commented Jul 25, 2024

Description

Introduces the external resolution, which requests "names" from a different graphql node.

In reality, that'll be a mainnet RPC endpoint being used.

Test plan

e2e tests updated to start a secondary service that utilizes external resolution, and depend on that:

cargo nextest run --package sui-graphql-rpc --test dot_move_e2e --features pg_integration

Stack


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):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

Copy link

vercel bot commented Jul 25, 2024

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 Aug 29, 2024 1:11pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2024 1:11pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2024 1:11pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2024 1:11pm

Copy link
Contributor

@amnn amnn left a comment

Choose a reason for hiding this comment

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

Very nice -- main comment here is related to distancing ourselves from the idea that external resolution always talks to mainnet.

crates/sui-graphql-rpc/src/types/dot_move/data_loader.rs Outdated Show resolved Hide resolved
crates/sui-graphql-rpc/src/types/dot_move/data_loader.rs Outdated Show resolved Hide resolved
crates/sui-graphql-rpc/src/types/dot_move/data_loader.rs Outdated Show resolved Hide resolved
crates/sui-graphql-rpc/src/types/dot_move/data_loader.rs Outdated Show resolved Hide resolved
crates/sui-graphql-rpc/src/types/dot_move/data_loader.rs Outdated Show resolved Hide resolved
crates/sui-graphql-rpc/src/types/dot_move/data_loader.rs Outdated Show resolved Hide resolved
crates/sui-types/src/collection_types.rs Show resolved Hide resolved
crates/sui-types/src/collection_types.rs Outdated Show resolved Hide resolved
crates/sui-graphql-rpc/src/types/dot_move/data_loader.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@amnn amnn left a comment

Choose a reason for hiding this comment

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

This is good to go modulo nits, thanks @manolisliolios !

Comment on lines 131 to 149
for k in mapping.keys() {
// SAFETY: we inserted the keys in the mapping before.
let idx = mapping.get(k).unwrap();

let Some(Some(bcs)) = names.get(&fetch_key(idx)) else {
continue;
};

let Some(bytes) = Base64::from_str(&bcs.value.bcs).ok() else {
continue;
};

let Some(app_record) = bcs::from_bytes::<AppRecord>(&bytes.0).ok() else {
continue;
};

// only insert the record if it is a valid `app_record`
results.insert(k.clone(), app_record);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's a more compact way to do this:

Suggested change
for k in mapping.keys() {
// SAFETY: we inserted the keys in the mapping before.
let idx = mapping.get(k).unwrap();
let Some(Some(bcs)) = names.get(&fetch_key(idx)) else {
continue;
};
let Some(bytes) = Base64::from_str(&bcs.value.bcs).ok() else {
continue;
};
let Some(app_record) = bcs::from_bytes::<AppRecord>(&bytes.0).ok() else {
continue;
};
// only insert the record if it is a valid `app_record`
results.insert(k.clone(), app_record);
}
let results = HashMap::from_iter(
mapping
.into_iter()
.filter_map(|k, idx| {
let bcs = names.get(&fetch_key(idx))??;
let Base64(bytes) = Base64::from_str(&bcs.value.bcs).ok()?;
let app_record: AppRecord = bcs::from_bytes(&bytes).ok()?;
Some((k, app_record))
})
);

Although I wonder whether if some of these steps fail, you should be producing an error instead, rather than dropping the value? Not sure -- that only works if the error can't be triggered by user input (i.e. it's an internal error of some kind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, love the more compact approach.

We'll error out when we try to populate things in the "controllers". Since this data loader is doing a bulk operation here (so it's likely that it is serving multiple requests), I didn't want irrelevant requests to error out that's why we ignore singular name errors on this layer.

It's a different story for full request errors, there we indeed do error out.

crates/sui-graphql-rpc/tests/dot_move_e2e.rs Outdated Show resolved Hide resolved
crates/sui-graphql-rpc/src/server/builder.rs Show resolved Hide resolved
@amnn
Copy link
Contributor

amnn commented Aug 27, 2024

(But do take a look at the thing about using write! instead of .push_str(&format!(...))).

@manolisliolios manolisliolios force-pushed the ml/dot-move-2-n branch 3 times, most recently from bf2b163 to 6e4390a Compare August 29, 2024 11:41
Base automatically changed from ml/dot-move-2-n to ml/dot-move-1-n August 29, 2024 12:03
@manolisliolios manolisliolios merged commit 03d1dcb into ml/dot-move-1-n Aug 29, 2024
42 of 45 checks passed
@manolisliolios manolisliolios deleted the ml/dot-move-3-n branch August 29, 2024 13:48
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