Skip to content

graphql-alt: Epoch #21997

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

Open
wants to merge 2 commits into
base: amnn/gql-vis
Choose a base branch
from
Open

graphql-alt: Epoch #21997

wants to merge 2 commits into from

Conversation

amnn
Copy link
Contributor

@amnn amnn commented Apr 28, 2025

Description

Add support for querying epochs (getting and multi-getting epochs by their IDs, and getting a checkpoint's epoch).

Test plan

sui$ cargo nextest run -p sui-indexer-alt-e2e-tests

Stack


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):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

@amnn amnn requested review from emmazzz, wlmyng and Copilot April 28, 2025 21:33
@amnn amnn self-assigned this Apr 28, 2025
Copy link

vercel bot commented Apr 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2025 4:16pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Apr 29, 2025 4:16pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Apr 29, 2025 4:16pm

@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env April 28, 2025 21:33 — with GitHub Actions Inactive
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for querying epochs by extending the schema, reader, and GraphQL API with new types and resolvers for single and multi-get epoch queries.

  • Added new Diesel schema and queryable types for epochs.
  • Implemented epoch data loaders in the reader and corresponding GraphQL types and resolvers.
  • Extended the API query to support fetching epochs and multiple epochs.

Reviewed Changes

Copilot reviewed 9 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/sui-indexer-alt-schema/src/epochs.rs Updated epoch schema types with Queryable derive to support queries.
crates/sui-indexer-alt-reader/src/lib.rs Exposed the new epochs module.
crates/sui-indexer-alt-reader/src/epochs.rs Added Loader implementations for EpochStartKey and EpochEndKey.
crates/sui-indexer-alt-graphql/src/api/types/mod.rs Included the new epoch module in the API types.
crates/sui-indexer-alt-graphql/src/api/types/epoch.rs Implemented GraphQL types and resolvers for epoch start and end details.
crates/sui-indexer-alt-graphql/src/api/types/checkpoint.rs Added a resolver for fetching the epoch related to a checkpoint.
crates/sui-indexer-alt-graphql/src/api/scalars/mod.rs Added the big_int scalar module required by the epoch types.
crates/sui-indexer-alt-graphql/src/api/scalars/big_int.rs Provided a BigInt scalar implementation used in the epoch GraphQL types.
crates/sui-indexer-alt-graphql/src/api/query.rs Introduced new query endpoints to fetch epochs, including multi-get epochs.
Files not reviewed (8)
  • crates/sui-indexer-alt-e2e-tests/tests/graphql/checkpoints/epoch.move: Language not supported
  • crates/sui-indexer-alt-e2e-tests/tests/graphql/checkpoints/epoch.snap: Language not supported
  • crates/sui-indexer-alt-e2e-tests/tests/graphql/epochs/query.move: Language not supported
  • crates/sui-indexer-alt-e2e-tests/tests/graphql/epochs/query.snap: Language not supported
  • crates/sui-indexer-alt-graphql/schema.graphql: Language not supported
  • crates/sui-indexer-alt-graphql/src/snapshots/sui_indexer_alt_graphql__tests__schema.graphql.snap: Language not supported
  • crates/sui-indexer-alt-graphql/src/snapshots/sui_indexer_alt_graphql__tests__staging.graphql.snap: Language not supported
  • crates/sui-indexer-alt-graphql/staging.graphql: Language not supported
Comments suppressed due to low confidence (1)

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

  • Typographical errors: 'guarnateed' should be 'guaranteed' and 'epocch' should be 'epoch'.
/// Returns a list of epochs that is guarnateed to be the same length as `keys`. If an epoch in `keys` could not be found in the store, its corresponding entry in the result will be `null'. This could be because the epocch does not exist yet, or because it was pruned.

@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env April 29, 2025 15:59 — with GitHub Actions Inactive
amnn added 2 commits April 29, 2025 17:06
## Description

Add support for query epochs (getting and multi-getting epochs by their
IDs, and getting a checkpoint's epoch).

## Test plan

```
sui$ cargo nextest run -p sui-indexer-alt-e2e-tests
```
Copy link
Contributor

@wlmyng wlmyng left a comment

Choose a reason for hiding this comment

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

looks good, lets advance this epoch

Comment on lines +4 to +16
//# init --protocol-version 70 --accounts A --simulator

//# create-checkpoint

//# advance-epoch

//# create-checkpoint

//# create-checkpoint

//# advance-epoch

//# create-checkpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

wheres c7 coming from?

e0
c0: init
c1: L6
c2: L8 advance-epoch

e1
c3 L10
c4 L12
c5 L14 advance epoch

and then c6 from L16

@@ -65,6 +74,22 @@ impl Query {
.collect())
}

/// Fetch epochs by their IDs.
///
/// Returns a list of epochs that is guarnateed to be the same length as `keys`. If an epoch in `keys` could not be found in the store, its corresponding entry in the result will be `null`. This could be because the epocch does not exist yet, or because it was pruned.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Returns a list of epochs that is guarnateed to be the same length as `keys`. If an epoch in `keys` could not be found in the store, its corresponding entry in the result will be `null`. This could be because the epocch does not exist yet, or because it was pruned.
/// Returns a list of epochs that is guaranteed to be the same length as `keys`. If an epoch in `keys` could not be found in the store, its corresponding entry in the result will be `null`. This could be because the epoch does not exist yet, or because it was pruned.

Comment on lines +70 to +80
let ids: Vec<_> = keys.iter().map(|e| e.0 as i64).collect();
let epochs: Vec<StoredEpochEnd> = conn
.results(e::kv_epoch_ends.filter(e::epoch.eq_any(ids)))
.await
.map_err(Arc::new)?;

Ok(epochs
.into_iter()
.map(|e| (EpochEndKey(e.epoch as u64), e))
.collect())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

feels weird to see a relatively simple diesel query after all the jazz from previous prs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can make it more complicated ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants