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

core: event sending module relocation #19672

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions crates/sui-cluster-test/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,12 @@ impl Cluster for LocalNewCluster {

// Start the graphql service
let graphql_address = graphql_address.parse::<SocketAddr>()?;
let graphql_connection_config = ConnectionConfig::new(
Some(graphql_address.port()),
Some(graphql_address.ip().to_string()),
Some(pg_address),
None,
None,
None,
);
let graphql_connection_config = ConnectionConfig {
port: graphql_address.port(),
host: graphql_address.ip().to_string(),
db_url: pg_address,
..Default::default()
};

start_graphql_server_with_fn_rpc(
graphql_connection_config.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
processed 6 tasks

init:
A: object(0,0)

task 1, lines 6-11:
//# publish --upgradeable --sender A
created: object(1,0), object(1,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 5327600, storage_rebate: 0, non_refundable_storage_fee: 0

task 2, lines 13-28:
//# upgrade --package P --upgrade-capability 1,1 --sender A
created: object(2,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 6802000, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 3, line 30:
//# run P::M1::emit --sender A
events: Event { package_id: P, transaction_module: Identifier("M1"), sender: A, type_: StructTag { address: fake(1,0), module: Identifier("M0"), name: Identifier("Event"), type_params: [] }, contents: [42, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4, line 32:
//# create-checkpoint
Checkpoint created: 1

task 5, lines 34-44:
//# run-graphql
Response: {
"data": {
"events": {
"nodes": [
{
"sendingModule": {
"package": {
"address": "0xf847f63b795fdbc978a23fc181ea5180f55755e446fae1f1ce7865234cac7984"
},
"name": "M1"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --protocol-version 62 --addresses P=0x0 --accounts A --simulator

//# publish --upgradeable --sender A
module P::M0 {
public struct Event has copy, drop {
value: u64
}
}

//# upgrade --package P --upgrade-capability 1,1 --sender A
module P::M0 {
public struct Event has copy, drop {
value: u64
}

public fun emit() {
sui::event::emit(Event { value: 42 })
}
}

module P::M1 {
public fun emit() {
P::M0::emit()
}
}

//# run P::M1::emit --sender A

//# create-checkpoint

//# run-graphql
{
events {
nodes {
sendingModule {
package { address }
name
}
}
}
}
33 changes: 9 additions & 24 deletions crates/sui-graphql-rpc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use clap::*;
use std::path::PathBuf;

use crate::config::{ConnectionConfig, Ide, TxExecFullNodeConfig};

#[derive(Parser)]
#[clap(
name = "sui-graphql-rpc",
Expand All @@ -21,34 +23,17 @@ pub enum Command {
},

StartServer {
/// The title to display at the top of the page
#[clap(short, long)]
ide_title: Option<String>,
/// DB URL for data fetching
#[clap(short, long)]
db_url: Option<String>,
/// Pool size for DB connections
#[clap(long)]
db_pool_size: Option<u32>,
/// Port to bind the server to
#[clap(short, long)]
port: Option<u16>,
/// Host to bind the server to
#[clap(long)]
host: Option<String>,
/// Port to bind the prom server to
#[clap(long)]
prom_port: Option<u16>,
/// Host to bind the prom server to
#[clap(long)]
prom_host: Option<String>,
#[clap(flatten)]
ide: Ide,

#[clap(flatten)]
connection: ConnectionConfig,

/// Path to TOML file containing configuration for service.
#[clap(short, long)]
config: Option<PathBuf>,

/// RPC url to the Node for tx execution
#[clap(long)]
node_rpc_url: Option<String>,
#[clap(flatten)]
tx_exec_full_node: TxExecFullNodeConfig,
},
}
56 changes: 24 additions & 32 deletions crates/sui-graphql-rpc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,30 @@ pub struct ServerConfig {
/// specific connections between this service and other services, and might differ from instance to
/// instance of the GraphQL service.
#[GraphQLConfig]
#[derive(Clone, Eq, PartialEq)]
#[derive(clap::Args, Clone, Eq, PartialEq)]
pub struct ConnectionConfig {
/// Port to bind the server to
#[clap(short, long, default_value_t = ConnectionConfig::default().port)]
pub port: u16,
/// Host to bind the server to
#[clap(long, default_value_t = ConnectionConfig::default().host)]
pub host: String,
/// DB URL for data fetching
#[clap(short, long, default_value_t = ConnectionConfig::default().db_url)]
pub db_url: String,
/// Pool size for DB connections
#[clap(long, default_value_t = ConnectionConfig::default().db_pool_size)]
pub db_pool_size: u32,
pub prom_url: String,
/// Host to bind the prom server to
#[clap(long, default_value_t = ConnectionConfig::default().prom_host)]
pub prom_host: String,
/// Port to bind the prom server to
#[clap(long, default_value_t = ConnectionConfig::default().prom_port)]
pub prom_port: u16,
/// Skip checking whether the service is compatible with the DB it is about to connect to, on
/// start-up.
#[clap(long, default_value_t = ConnectionConfig::default().skip_migration_consistency_check)]
pub skip_migration_consistency_check: bool,
}

/// Configuration on features supported by the GraphQL service, passed in a TOML-based file. These
Expand Down Expand Up @@ -172,8 +186,11 @@ impl Version {
}

#[GraphQLConfig]
#[derive(clap::Args)]
pub struct Ide {
pub(crate) ide_title: String,
/// The title to display at the top of the web-based GraphiQL IDE.
#[clap(short, long, default_value_t = Ide::default().ide_title)]
pub ide_title: String,
}

#[GraphQLConfig]
Expand All @@ -199,8 +216,9 @@ pub struct InternalFeatureConfig {
}

#[GraphQLConfig]
#[derive(Default)]
#[derive(clap::Args, Default)]
pub struct TxExecFullNodeConfig {
/// RPC URL for the fullnode to send transactions to execute and dry-run.
pub(crate) node_rpc_url: Option<String>,
}

Expand Down Expand Up @@ -337,25 +355,6 @@ impl TxExecFullNodeConfig {
}

impl ConnectionConfig {
pub fn new(
port: Option<u16>,
host: Option<String>,
db_url: Option<String>,
db_pool_size: Option<u32>,
prom_url: Option<String>,
prom_port: Option<u16>,
) -> Self {
let default = Self::default();
Self {
port: port.unwrap_or(default.port),
host: host.unwrap_or(default.host),
db_url: db_url.unwrap_or(default.db_url),
db_pool_size: db_pool_size.unwrap_or(default.db_pool_size),
prom_url: prom_url.unwrap_or(default.prom_url),
prom_port: prom_port.unwrap_or(default.prom_port),
}
}

pub fn db_name(&self) -> String {
self.db_url.split('/').last().unwrap().to_string()
}
Expand Down Expand Up @@ -432,14 +431,6 @@ impl Limits {
}
}

impl Ide {
pub fn new(ide_title: Option<String>) -> Self {
ide_title
.map(|ide_title| Ide { ide_title })
.unwrap_or_default()
}
}

impl BackgroundTasksConfig {
pub fn test_defaults() -> Self {
Self {
Expand Down Expand Up @@ -481,8 +472,9 @@ impl Default for ConnectionConfig {
host: "127.0.0.1".to_string(),
db_url: "postgres://postgres:postgrespw@localhost:5432/sui_indexer".to_string(),
db_pool_size: 10,
prom_url: "0.0.0.0".to_string(),
prom_host: "0.0.0.0".to_string(),
prom_port: 9184,
skip_migration_consistency_check: false,
}
}
}
Expand Down
21 changes: 6 additions & 15 deletions crates/sui-graphql-rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use std::path::PathBuf;

use clap::Parser;
use sui_graphql_rpc::commands::Command;
use sui_graphql_rpc::config::{
ConnectionConfig, Ide, ServerConfig, ServiceConfig, TxExecFullNodeConfig, Version,
};
use sui_graphql_rpc::config::{ServerConfig, ServiceConfig, Version};
use sui_graphql_rpc::server::graphiql_server::start_graphiql_server;
use tokio_util::sync::CancellationToken;
use tokio_util::task::TaskTracker;
Expand Down Expand Up @@ -51,18 +49,11 @@ async fn main() {
}

Command::StartServer {
ide_title,
db_url,
db_pool_size,
port,
host,
ide,
connection,
config,
node_rpc_url,
prom_host,
prom_port,
tx_exec_full_node,
} => {
let connection =
ConnectionConfig::new(port, host, db_url, db_pool_size, prom_host, prom_port);
let service_config = service_config(config);
let _guard = telemetry_subscribers::TelemetryConfig::new()
.with_env()
Expand All @@ -74,8 +65,8 @@ async fn main() {
let server_config = ServerConfig {
connection,
service: service_config,
ide: Ide::new(ide_title),
tx_exec_full_node: TxExecFullNodeConfig::new(node_rpc_url),
ide,
tx_exec_full_node,
..ServerConfig::default()
};

Expand Down
Loading
Loading