Skip to content

Commit e30e641

Browse files
committed
graphql-alt: ProtocolConfigs
## Description Fetch protocol configs by protocol version, and by epoch. ## Test plan New E2E tests: ``` sui$ cargo nextest run \ -p sui-indexer-alt-e2e-tests \ -- graphql/epoch/protocol_configs ```
1 parent 5d95cd4 commit e30e641

File tree

11 files changed

+520
-2
lines changed

11 files changed

+520
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//# init --protocol-version 70 --accounts A --simulator
5+
6+
//# create-checkpoint
7+
8+
//# run-graphql
9+
{ # Protocol Configs that don't exist (because they haven't been used in the
10+
# chain being indexed) -- their config lists will be empty.
11+
before: protocolConfigs(version: 69) {
12+
protocolVersion
13+
configs { key value }
14+
}
15+
16+
after: protocolConfigs(version: 71) {
17+
protocolVersion
18+
configs { key value }
19+
}
20+
}
21+
22+
//# run-graphql
23+
{
24+
protocolConfigs(version: 70) {
25+
config(key: "max_move_object_size") { key value }
26+
featureFlag(key: "enable_effects_v2") { key value }
27+
}
28+
}
29+
30+
//# run-graphql
31+
{ # Fetch protocol config version via epoch
32+
epoch(epochId: 0) { protocolConfigs { protocolVersion } }
33+
34+
# Fetch protocol config via version
35+
protocolConfigs(version: 70) { protocolVersion }
36+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
3+
---
4+
processed 5 tasks
5+
6+
init:
7+
A: object(0,0)
8+
9+
task 1, line 6:
10+
//# create-checkpoint
11+
Checkpoint created: 1
12+
13+
task 2, lines 8-20:
14+
//# run-graphql
15+
Response: {
16+
"data": {
17+
"before": {
18+
"protocolVersion": 69,
19+
"configs": []
20+
},
21+
"after": {
22+
"protocolVersion": 71,
23+
"configs": []
24+
}
25+
}
26+
}
27+
28+
task 3, lines 22-28:
29+
//# run-graphql
30+
Response: {
31+
"data": {
32+
"protocolConfigs": {
33+
"config": {
34+
"key": "max_move_object_size",
35+
"value": "256000"
36+
},
37+
"featureFlag": {
38+
"key": "enable_effects_v2",
39+
"value": true
40+
}
41+
}
42+
}
43+
}
44+
45+
task 4, lines 30-36:
46+
//# run-graphql
47+
Response: {
48+
"data": {
49+
"epoch": {
50+
"protocolConfigs": {
51+
"protocolVersion": 70
52+
}
53+
},
54+
"protocolConfigs": {
55+
"protocolVersion": 70
56+
}
57+
}
58+
}

crates/sui-indexer-alt-graphql/schema.graphql

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type Epoch {
6161
"""
6262
epochId: UInt53!
6363
"""
64+
The epoch's corresponding protocol configuration, including the feature flags and the configuration options.
65+
"""
66+
protocolConfigs: ProtocolConfigs
67+
"""
6468
The minimum gas price that a quorum of validators are guaranteed to sign a transaction for in this epoch.
6569
"""
6670
referenceGasPrice: BigInt
@@ -74,6 +78,20 @@ type Epoch {
7478
endTimestamp: DateTime
7579
}
7680

81+
"""
82+
A boolean protocol configuration.
83+
"""
84+
type FeatureFlag {
85+
"""
86+
Feature flag name.
87+
"""
88+
key: String!
89+
"""
90+
Feature flag value.
91+
"""
92+
value: Boolean!
93+
}
94+
7795

7896
"""
7997
Interface implemented by GraphQL types representing entities that are identified by an address.
@@ -298,6 +316,45 @@ type PageInfo {
298316
endCursor: String
299317
}
300318

319+
"""
320+
A protocol configuration that can hold an arbitrary value (or no value at all).
321+
"""
322+
type ProtocolConfig {
323+
"""
324+
Configuration name.
325+
"""
326+
key: String!
327+
"""
328+
Configuration value.
329+
"""
330+
value: String
331+
}
332+
333+
"""
334+
Constants that control how the chain operates.
335+
336+
These can only change during protocol upgrades which happen on epoch boundaries. Configuration is split into feature flags (which are just booleans), and configs which can take any value (including no value at all), and will be represented by a string.
337+
"""
338+
type ProtocolConfigs {
339+
protocolVersion: UInt53!
340+
"""
341+
Query for the value of the configuration with name `key`.
342+
"""
343+
config(key: String!): ProtocolConfig
344+
"""
345+
List all available configurations and their values.
346+
"""
347+
configs: [ProtocolConfig!]!
348+
"""
349+
Query for the state of the feature flag with name `key`.
350+
"""
351+
featureFlag(key: String!): FeatureFlag
352+
"""
353+
List all available feature flags and their values.
354+
"""
355+
featureFlags: [FeatureFlag!]!
356+
}
357+
301358
type Query {
302359
"""
303360
First four bytes of the network's genesis checkpoint digest (uniquely identifies the network), hex-encoded.
@@ -386,6 +443,10 @@ type Query {
386443
"""
387444
package(address: SuiAddress!, version: UInt53, atCheckpoint: UInt53): MovePackage
388445
"""
446+
Fetch the protocol config by protocol version.
447+
"""
448+
protocolConfigs(version: UInt53!): ProtocolConfigs
449+
"""
389450
Configuration for this RPC service.
390451
"""
391452
serviceConfig: ServiceConfig!

crates/sui-indexer-alt-graphql/src/api/query.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use super::{
1414
epoch::Epoch,
1515
move_package::{self, MovePackage, PackageKey},
1616
object::{self, Object, ObjectKey},
17+
protocol_configs::ProtocolConfigs,
1718
service_config::ServiceConfig,
1819
transaction::Transaction,
1920
transaction_effects::TransactionEffects,
@@ -222,6 +223,11 @@ impl Query {
222223
.await
223224
}
224225

226+
/// Fetch the protocol config by protocol version.
227+
async fn protocol_configs(&self, version: UInt53) -> Option<ProtocolConfigs> {
228+
Some(ProtocolConfigs::with_protocol_version(version.into()))
229+
}
230+
225231
/// Configuration for this RPC service.
226232
async fn service_config(&self) -> ServiceConfig {
227233
ServiceConfig

crates/sui-indexer-alt-graphql/src/api/types/epoch.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use crate::{
1717
scope::Scope,
1818
};
1919

20+
use super::protocol_configs::ProtocolConfigs;
21+
2022
pub(crate) struct Epoch {
2123
pub(crate) epoch_id: u64,
2224
pub(crate) scope: Scope,
@@ -63,6 +65,17 @@ impl Epoch {
6365

6466
#[Object]
6567
impl EpochStart {
68+
/// The epoch's corresponding protocol configuration, including the feature flags and the configuration options.
69+
async fn protocol_configs(&self) -> Option<ProtocolConfigs> {
70+
let Some(contents) = &self.contents else {
71+
return None;
72+
};
73+
74+
Some(ProtocolConfigs::with_protocol_version(
75+
contents.protocol_version as u64,
76+
))
77+
}
78+
6679
/// The minimum gas price that a quorum of validators are guaranteed to sign a transaction for in this epoch.
6780
async fn reference_gas_price(&self) -> Option<BigInt> {
6881
let Some(contents) = &self.contents else {

crates/sui-indexer-alt-graphql/src/api/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub(crate) mod epoch;
77
pub(crate) mod move_package;
88
pub(crate) mod object;
99
pub(crate) mod object_change;
10+
pub(crate) mod protocol_configs;
1011
pub(crate) mod service_config;
1112
pub(crate) mod transaction;
1213
pub(crate) mod transaction_effects;

0 commit comments

Comments
 (0)