Skip to content

Commit

Permalink
Introduces DotMove service [1/3] - internal package resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
manolisliolios committed Aug 28, 2024
1 parent 1dd99f9 commit b845f77
Show file tree
Hide file tree
Showing 28 changed files with 1,373 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
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
8 changes: 8 additions & 0 deletions crates/sui-graphql-rpc/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,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 @@ -3343,6 +3347,10 @@ type Query {
"""
resolveSuinsAddress(domain: String!): Address
"""
Fetch a package by its name (using dot move service)
"""
packageByName(name: String!): MovePackage
"""
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
5 changes: 5 additions & 0 deletions crates/sui-graphql-rpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use async_graphql_axum::GraphQLResponse;
use sui_indexer::errors::IndexerError;
use sui_json_rpc::name_service::NameServiceError;

use crate::types::dot_move::error::MoveRegistryError;

/// Error codes for the `extensions.code` field of a GraphQL error that originates from outside
/// GraphQL.
/// `<https://www.apollographql.com/docs/apollo-server/data/errors/#built-in-error-codes>`
Expand Down Expand Up @@ -76,12 +78,15 @@ pub enum Error {
Client(String),
#[error("Internal error occurred while processing request: {0}")]
Internal(String),
#[error(transparent)]
MoveNameRegistry(#[from] MoveRegistryError),
}

impl ErrorExtensions for Error {
fn extend(&self) -> async_graphql::Error {
async_graphql::Error::new(format!("{}", self)).extend_with(|_err, e| match self {
Error::NameService(_)
| Error::MoveNameRegistry(_)
| Error::CursorNoFirstLast
| Error::PageTooLarge(_, _)
| Error::ProtocolVersionUnsupported(_, _)
Expand Down
5 changes: 5 additions & 0 deletions crates/sui-graphql-rpc/src/functional_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub(crate) enum FunctionalGroup {
/// Aspects that affect the running of the system that are managed by the
/// validators either directly, or through system transactions.
SystemState,

/// Named packages service (utilizing dotmove package registry).
MoveRegistry,
}

impl FunctionalGroup {
Expand All @@ -51,6 +54,7 @@ impl FunctionalGroup {
G::NameService,
G::Subscriptions,
G::SystemState,
G::MoveRegistry,
];
ALL
}
Expand Down Expand Up @@ -96,6 +100,7 @@ fn functional_groups() -> &'static BTreeMap<(&'static str, &'static str), Functi
(("Query", "networkMetrics"), G::Analytics),
(("Query", "protocolConfig"), G::SystemState),
(("Query", "resolveSuinsAddress"), G::NameService),
(("Query", "packageByName"), G::MoveRegistry),
(("Subscription", "events"), G::Subscriptions),
(("Subscription", "transactions"), G::Subscriptions),
(("SystemStateSummary", "safeMode"), G::SystemState),
Expand Down
5 changes: 4 additions & 1 deletion crates/sui-graphql-rpc/src/server/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ impl ServerBuilder {
let mut builder = ServerBuilder::new(state);

let name_service_config = config.service.name_service.clone();
let move_registry_config = config.service.move_registry.clone();
let zklogin_config = config.service.zklogin.clone();
let reader = PgManager::reader_with_config(
config.connection.db_url.clone(),
Expand Down Expand Up @@ -465,7 +466,8 @@ impl ServerBuilder {
.context_data(name_service_config)
.context_data(zklogin_config)
.context_data(metrics.clone())
.context_data(config.clone());
.context_data(config.clone())
.context_data(move_registry_config.clone());

if config.internal_features.feature_gate {
builder = builder.extension(FeatureGate);
Expand Down Expand Up @@ -536,6 +538,7 @@ async fn graphql_handler(

req.data.insert(Watermark::new(watermark_lock).await);
req.data.insert(chain_identifier_lock.read().await);
req.data.insert(chain_identifier_lock.read().await);

let result = schema.execute(req).await;

Expand Down
Loading

0 comments on commit b845f77

Please sign in to comment.