Skip to content

Commit

Permalink
[GraphQL][DotMove] Introduces DotMove resolution (#18774)
Browse files Browse the repository at this point in the history
## Description 

Introduces the logic for querying packages & types by name. 
Works for both internal & external resolution mode.

Important: There's not yet an officially supported package for this 
functionality on mainnet. There'll be a follow-up PR to address this.

## Test plan 

There are both unit tests on name parsing, and e2e tests for package
resolution.
I test package upgrades, and resolution both with "latest", as well as
on given fixed versions.

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


## Stack

- #18770 
---

## 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: 
- [x] GraphQL: Introduces `.move` name resolution (internal & external) for GraphQL. Only supported on a non-mainnet environment for the time being. 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
manolisliolios authored Aug 29, 2024
1 parent 339b8eb commit aebab3c
Show file tree
Hide file tree
Showing 34 changed files with 1,939 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ jobs:
- run: sleep 5
- name: tests-requiring-postgres
run: |
cargo nextest run --test-threads 1 --package sui-graphql-rpc --test e2e_tests --test examples_validation_tests --features pg_integration
cargo nextest run --test-threads 1 --package sui-graphql-rpc --test e2e_tests --test examples_validation_tests --test dot_move_e2e --features pg_integration
cargo nextest run --test-threads 1 --package sui-graphql-rpc --lib --features pg_integration -- test_query_cost
cargo nextest run --test-threads 4 --package sui-graphql-e2e-tests --features pg_integration
cargo nextest run --test-threads 1 --package sui-cluster-test --test local_cluster_test --features pg_integration
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/sui-cluster-test/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::net::SocketAddr;
use std::path::Path;
use sui_config::Config;
use sui_config::{PersistedConfig, SUI_KEYSTORE_FILENAME, SUI_NETWORK_CONFIG};
use sui_graphql_rpc::config::ConnectionConfig;
use sui_graphql_rpc::config::{ConnectionConfig, ServiceConfig};
use sui_graphql_rpc::test_infra::cluster::start_graphql_server_with_fn_rpc;
use sui_indexer::test_utils::{start_test_indexer, ReaderWriterConfig};
use sui_keys::keystore::{AccountKeystore, FileBasedKeystore, Keystore};
Expand Down Expand Up @@ -260,6 +260,7 @@ impl Cluster for LocalNewCluster {
graphql_connection_config.clone(),
Some(fullnode_url.clone()),
/* cancellation_token */ None,
ServiceConfig::test_defaults(),
)
.await;
}
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-graphql-rpc-client/src/simple_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ impl SimpleClient {
.await?;
Ok(())
}

pub fn url(&self) -> String {
self.url.clone()
}
}

#[allow(clippy::type_complexity)]
Expand Down
1 change: 1 addition & 0 deletions crates/sui-graphql-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ serde_json.workspace = true
sui-framework.workspace = true
tower.workspace = true
sui-test-transaction-builder.workspace = true
sui-move-build.workspace = true

[features]
default = []
Expand Down
12 changes: 12 additions & 0 deletions crates/sui-graphql-rpc/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,10 @@ enum Feature {
validators either directly, or through system transactions.
"""
SYSTEM_STATE
"""
Named packages service (utilizing dotmove package registry).
"""
MOVE_REGISTRY
}


Expand Down Expand Up @@ -3347,6 +3351,14 @@ type Query {
"""
resolveSuinsAddress(domain: String!): Address
"""
Fetch a package by its name (using dot move service)
"""
packageByName(name: String!): MovePackage
"""
Fetch a type that includes dot move service names in it.
"""
typeByName(name: String!): MoveType!
"""
The coin metadata associated with the given coin type.
"""
coinMetadata(coinType: String!): CoinMetadata
Expand Down
95 changes: 95 additions & 0 deletions crates/sui-graphql-rpc/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
use std::str::FromStr;

use crate::functional_group::FunctionalGroup;
use async_graphql::*;
use fastcrypto_zkp::bn254::zk_login_api::ZkLoginEnv;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeSet, fmt::Display, time::Duration};
use sui_graphql_config::GraphQLConfig;
use sui_json_rpc::name_service::NameServiceConfig;
use sui_types::base_types::{ObjectID, SuiAddress};

pub(crate) const RPC_TIMEOUT_ERR_SLEEP_RETRY_PERIOD: Duration = Duration::from_millis(10_000);
pub(crate) const MAX_CONCURRENT_REQUESTS: usize = 1_000;

// Move Registry constants
pub(crate) const MOVE_REGISTRY_MODULE: &IdentStr = ident_str!("name");
pub(crate) const MOVE_REGISTRY_TYPE: &IdentStr = ident_str!("Name");
// TODO(manos): Replace with actual package id on mainnet.
const MOVE_REGISTRY_PACKAGE: &str =
"0x1a841abe817c38221596856bc975b3b84f2f68692191e9247e185213d3d02fd8";
// TODO(manos): Replace with actual registry table id on mainnet.
const MOVE_REGISTRY_TABLE_ID: &str =
"0x250b60446b8e7b8d9d7251600a7228dbfda84ccb4b23a56a700d833e221fae4f";
const DEFAULT_PAGE_LIMIT: u16 = 50;

/// The combination of all configurations for the GraphQL service.
#[GraphQLConfig]
#[derive(Default)]
Expand Down Expand Up @@ -52,6 +67,7 @@ pub struct ServiceConfig {
pub(crate) name_service: NameServiceConfig,
pub(crate) background_tasks: BackgroundTasksConfig,
pub(crate) zklogin: ZkLoginConfig,
pub(crate) move_registry: MoveRegistryConfig,
}

#[GraphQLConfig]
Expand Down Expand Up @@ -106,6 +122,22 @@ pub struct BackgroundTasksConfig {
pub watermark_update_ms: u64,
}

#[GraphQLConfig]
#[derive(Clone)]
pub(crate) struct MoveRegistryConfig {
pub(crate) external_api_url: Option<String>,
pub(crate) resolution_type: ResolutionType,
pub(crate) page_limit: u16,
pub(crate) package_address: SuiAddress,
pub(crate) registry_id: ObjectID,
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub(crate) enum ResolutionType {
Internal,
External,
}

/// The Version of the service. `year.month` represents the major release.
/// New `patch` versions represent backwards compatible fixes for their major release.
/// The `full` version is `year.month.patch-sha`.
Expand Down Expand Up @@ -360,6 +392,14 @@ impl ConnectionConfig {
pub fn server_address(&self) -> String {
format!("{}:{}", self.host, self.port)
}

pub fn host(&self) -> String {
self.host.clone()
}

pub fn port(&self) -> u16 {
self.port
}
}

impl ServiceConfig {
Expand All @@ -376,6 +416,29 @@ impl ServiceConfig {
..Default::default()
}
}

pub fn dot_move_test_defaults(
external: bool,
endpoint: Option<String>,
pkg_address: Option<SuiAddress>,
object_id: Option<ObjectID>,
page_limit: Option<u16>,
) -> Self {
Self {
move_registry: MoveRegistryConfig {
resolution_type: if external {
ResolutionType::External
} else {
ResolutionType::Internal
},
external_api_url: endpoint,
package_address: pkg_address.unwrap_or_default(),
registry_id: object_id.unwrap_or(ObjectID::random()),
page_limit: page_limit.unwrap_or(50),
},
..Self::test_defaults()
}
}
}

impl Limits {
Expand Down Expand Up @@ -406,6 +469,24 @@ impl BackgroundTasksConfig {
}
}

impl MoveRegistryConfig {
pub(crate) fn new(
resolution_type: ResolutionType,
external_api_url: Option<String>,
page_limit: u16,
package_address: SuiAddress,
registry_id: ObjectID,
) -> Self {
Self {
resolution_type,
external_api_url,
page_limit,
package_address,
registry_id,
}
}
}

impl Default for Versions {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -504,6 +585,20 @@ impl Display for Version {
}
}

// TODO: Keeping the values as is, because we'll remove the default getters
// when we refactor to use `[GraphqlConfig]` macro.
impl Default for MoveRegistryConfig {
fn default() -> Self {
Self::new(
ResolutionType::Internal,
None,
DEFAULT_PAGE_LIMIT,
SuiAddress::from_str(MOVE_REGISTRY_PACKAGE).unwrap(),
ObjectID::from_str(MOVE_REGISTRY_TABLE_ID).unwrap(),
)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions crates/sui-graphql-rpc/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

pub(crate) mod apys;
pub(crate) mod move_registry_data_loader;
pub(crate) mod package_resolver;
pub(crate) mod pg;

Expand Down
Loading

0 comments on commit aebab3c

Please sign in to comment.