Skip to content

Commit

Permalink
[graphql/rpc] Protocol config impl (#13402)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxade authored Aug 15, 2023
1 parent 520a20e commit 587ae58
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 4 deletions.
13 changes: 10 additions & 3 deletions crates/sui-graphql-rpc/schema/draft_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,22 @@ type Epoch {

type ProtocolConfigs {
protocolVersion: Int!
configs: [ProtocolConfig]
config(key: String!): ProtocolConfig
featureFlags: [ProtocolConfigFeatureFlag]
configs: [ProtocolConfigAttr]
config(key: String!): ProtocolConfigAttr
featureFlag(key: String!): ProtocolConfigFeatureFlag
}

type ProtocolConfig {
type ProtocolConfigAttr {
key: String!
value: String!
}

type ProtocolConfigFeatureFlag {
key: String!
value: Boolean!
}

type SystemParameters {
durationMs: BigInt
stakeSubsidyStartEpoch: Int
Expand Down
38 changes: 38 additions & 0 deletions crates/sui-graphql-rpc/src/server/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use crate::types::base64::Base64;
use crate::types::big_int::BigInt;
use crate::types::object::ObjectFilter;
use crate::types::object::ObjectKind;
use crate::types::protocol_config::ProtocolConfigAttr;
use crate::types::protocol_config::ProtocolConfigFeatureFlag;
use crate::types::protocol_config::ProtocolConfigs;
use crate::types::transaction_block::TransactionBlock;
use crate::types::{object::Object, sui_address::SuiAddress};
use async_graphql::connection::{Connection, Edge};
Expand Down Expand Up @@ -172,6 +175,41 @@ pub(crate) async fn fetch_chain_id(cl: &SuiClient) -> Result<String> {
Ok(cl.read_api().get_chain_identifier().await?)
}

pub(crate) async fn fetch_protocol_config(
cl: &SuiClient,
version: Option<u64>,
) -> Result<ProtocolConfigs> {
let cfg = cl
.read_api()
.get_protocol_config(version.map(|x| x.into()))
.await?;

Ok(ProtocolConfigs {
configs: cfg
.attributes
.into_iter()
.map(|(k, v)| ProtocolConfigAttr {
key: k,
// TODO: what to return when value is None? nothing?
// TODO: do we want to return type info separately?
value: match v {
Some(q) => format!("{:?}", q),
None => "".to_string(),
},
})
.collect(),
feature_flags: cfg
.feature_flags
.into_iter()
.map(|x| ProtocolConfigFeatureFlag {
key: x.0,
value: x.1,
})
.collect(),
protocol_version: cfg.protocol_version.as_u64(),
})
}

fn convert_bal(b: sui_json_rpc_types::Balance) -> Balance {
Balance {
coin_object_count: b.coin_object_count as u64,
Expand Down
10 changes: 10 additions & 0 deletions crates/sui-graphql-rpc/src/types/display.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use async_graphql::*;

#[derive(Clone, Debug, PartialEq, Eq, SimpleObject)]
pub(crate) struct DisplayEntry {
pub key: String,
pub value: String,
}
29 changes: 29 additions & 0 deletions crates/sui-graphql-rpc/src/types/gas.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::types::object::Object;
use async_graphql::*;

use super::{address::Address, big_int::BigInt};

#[derive(Clone, Debug, PartialEq, Eq, SimpleObject)]
pub(crate) struct GasInput {
pub gas_sponsor: Option<Address>,
pub gas_payment: Option<Vec<Object>>,
pub gas_price: Option<BigInt>,
pub gas_budget: Option<BigInt>,
}

#[derive(Clone, Debug, PartialEq, Eq, SimpleObject)]
pub(crate) struct GasCostSummary {
pub computation_cost: Option<BigInt>,
pub storage_cost: Option<BigInt>,
pub storage_rebate: Option<BigInt>,
pub non_refundable_storage_fee: Option<BigInt>,
}

#[derive(Clone, Debug, PartialEq, Eq, SimpleObject)]
pub(crate) struct GasEffects {
pub gas_object: Option<Object>,
pub gas_summary: Option<GasCostSummary>,
}
3 changes: 3 additions & 0 deletions crates/sui-graphql-rpc/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ pub(crate) mod base64;
pub(crate) mod big_int;
pub(crate) mod coin;
pub(crate) mod date_time;
pub(crate) mod display;
pub(crate) mod gas;
pub(crate) mod name_service;
pub(crate) mod object;
pub(crate) mod owner;
pub(crate) mod protocol_config;
pub(crate) mod query;
pub(crate) mod stake;
pub(crate) mod sui_address;
Expand Down
1 change: 1 addition & 0 deletions crates/sui-graphql-rpc/src/types/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
types::base64::Base64,
};

#[derive(Clone, Eq, PartialEq, Debug)]
pub(crate) struct Object {
pub address: SuiAddress,
pub version: u64,
Expand Down
83 changes: 83 additions & 0 deletions crates/sui-graphql-rpc/src/types/protocol_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use async_graphql::*;

use crate::server::data_provider::fetch_protocol_config;

#[derive(Clone, Debug, PartialEq, Eq, SimpleObject)]
pub(crate) struct ProtocolConfigAttr {
pub key: String,
pub value: String,
}

#[derive(Clone, Debug, PartialEq, Eq, SimpleObject)]
pub(crate) struct ProtocolConfigFeatureFlag {
pub key: String,
pub value: bool,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct ProtocolConfigs {
pub configs: Vec<ProtocolConfigAttr>,
pub feature_flags: Vec<ProtocolConfigFeatureFlag>,
pub protocol_version: u64,
}

#[allow(unreachable_code)]
#[allow(unused_variables)]
#[Object]
impl ProtocolConfigs {
async fn configs(&self, ctx: &Context<'_>) -> Result<Option<Vec<ProtocolConfigAttr>>> {
Ok(Some(
fetch_protocol_config(ctx.data_unchecked::<sui_sdk::SuiClient>(), None)
.await?
.configs,
))
}

async fn feature_flags(
&self,
ctx: &Context<'_>,
) -> Result<Option<Vec<ProtocolConfigFeatureFlag>>> {
Ok(Some(
fetch_protocol_config(ctx.data_unchecked::<sui_sdk::SuiClient>(), None)
.await?
.feature_flags,
))
}

async fn protocol_version(&self, ctx: &Context<'_>) -> Result<u64> {
Ok(
fetch_protocol_config(ctx.data_unchecked::<sui_sdk::SuiClient>(), None)
.await?
.protocol_version,
)
}

async fn config(&self, ctx: &Context<'_>, key: String) -> Result<Option<ProtocolConfigAttr>> {
match self
.configs(ctx)
.await?
.map(|configs| configs.into_iter().find(|config| config.key == key))
{
Some(config) => Ok(config),
None => Ok(None),
}
}

async fn feature_flag(
&self,
ctx: &Context<'_>,
key: String,
) -> Result<Option<ProtocolConfigFeatureFlag>> {
match self
.feature_flags(ctx)
.await?
.map(|flags| flags.into_iter().find(|config| config.key == key))
{
Some(config) => Ok(config),
None => Ok(None),
}
}
}
14 changes: 13 additions & 1 deletion crates/sui-graphql-rpc/src/types/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

use async_graphql::*;

use super::{address::Address, object::Object, owner::ObjectOwner, sui_address::SuiAddress};
use super::{
address::Address, object::Object, owner::ObjectOwner, protocol_config::ProtocolConfigs,
sui_address::SuiAddress,
};
use crate::server::data_provider::fetch_chain_id;

pub(crate) struct Query;
Expand Down Expand Up @@ -38,4 +41,13 @@ impl Query {
async fn address(&self, address: SuiAddress) -> Option<Address> {
Some(Address { address })
}

async fn protocol_config(
&self,
ctx: &Context<'_>,
protocol_version: Option<u64>,
) -> Result<ProtocolConfigs> {
let cl = ctx.data_unchecked::<sui_sdk::SuiClient>();
crate::server::data_provider::fetch_protocol_config(cl, protocol_version).await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,30 @@ type PageInfo {
endCursor: String
}

type ProtocolConfigAttr {
key: String!
value: String!
}

type ProtocolConfigFeatureFlag {
key: String!
value: Boolean!
}

type ProtocolConfigs {
configs: [ProtocolConfigAttr!]
featureFlags: [ProtocolConfigFeatureFlag!]
protocolVersion: Int!
config(key: String!): ProtocolConfigAttr
featureFlag(key: String!): ProtocolConfigFeatureFlag
}

type Query {
chainIdentifier: String!
owner(address: SuiAddress!): ObjectOwner
object(address: SuiAddress!, version: Int): Object
address(address: SuiAddress!): Address
protocolConfig(protocolVersion: Int): ProtocolConfigs!
}

type StakeConnection {
Expand Down

2 comments on commit 587ae58

@vercel
Copy link

@vercel vercel bot commented on 587ae58 Aug 15, 2023

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

4 Validators 500/s Owned Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 600 | 600 | 0      | 19            | 8175          | 9063          | 422,499,744,000       | 25,349,984,640,000         |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 13  | 100 |

4 Validators 500/s Shared Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 510 | 510 | 0      | 20            | 8895          | 13383         | 435,817,116,000       | 26,149,026,960,000         |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 12  | 100 |

20 Validators 50/s Owned Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 200 | 200 | 0      | 21            | 65            | 124           | 156,418,560,000       | 9,385,113,600,000          |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 26  | 51  |

20 Validators 50/s Shared Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 193 | 193 | 0      | 65            | 1357          | 2035          | 177,522,034,800       | 10,651,322,088,000         |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 25  | 55  |

Narwhal Benchmark Results

 SUMMARY:
-----------------------------------------
 + CONFIG:
 Faults: 0 node(s)
 Committee size: 4 node(s)
 Worker(s) per node: 1 worker(s)
 Collocate primary and workers: True
 Input rate: 50,000 tx/s
 Transaction size: 512 B
 Execution time: 0 s

 Header number of batches threshold: 32 digests
 Header maximum number of batches: 1,000 digests
 Max header delay: 2,000 ms
 GC depth: 50 round(s)
 Sync retry delay: 10,000 ms
 Sync retry nodes: 3 node(s)
 batch size: 500,000 B
 Max batch delay: 200 ms
 Max concurrent requests: 500,000 

 + RESULTS:
 Batch creation avg latency: 202 ms
 Header creation avg latency: -1 ms
 	Batch to header avg latency: -1 ms
 Header to certificate avg latency: 1 ms
 	Request vote outbound avg latency: 0 ms
 Certificate commit avg latency: 695 ms

 Consensus TPS: 0 tx/s
 Consensus BPS: 0 B/s
 Consensus latency: 0 ms

 End-to-end TPS: 0 tx/s
 End-to-end BPS: 0 B/s
 End-to-end latency: 0 ms
-----------------------------------------

Please sign in to comment.