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

[GraphQL Client] Fix digests #59

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

stefan-mysten
Copy link
Collaborator

This PR fixes digests to use the respective types. One thing that is confusing is the difference between CheckpointDigest and CheckpointContentsDigest.

@@ -643,7 +646,7 @@ impl Client {
/// provided, it will use the last known checkpoint id.
pub async fn checkpoint(
&self,
digest: Option<Digest>,
digest: Option<CheckpointContentsDigest>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this probably should be CheckpointDigest and not Contents given the return type here

Copy link
Collaborator Author

@stefan-mysten stefan-mysten Nov 14, 2024

Choose a reason for hiding this comment

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

The thing that confuses me is that, if I want to get the total transaction blocks in a checkpoint by digest after using this checkpoint function to get the checkpoint data, I have to pass in the CheckpointContentsDigest because that's what's content_digest type is.

    pub content_digest: CheckpointContentsDigest,
    pub previous_digest: Option<CheckpointDigest>,

So I would have to convert CheckpointContentsDigest to CheckpointDigest.

Not sure I fully follow why we need to have this separation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should take a look at the checkpoint types in the sdk types crate to familiarize yourself for what the differences are. The CheckpointDigest is the digest of a CheckpointSummary while the CheckpointContentsDigest is the digest of the "contents" or the CheckpointContents type which contains the list of txn digests and user signatures

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's what I gathered as well, but I think then we're missing a digest field in the CheckpointSummary type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I am confused.

Comment on lines 2143 to +2146
let digest = chckp.unwrap().unwrap().content_digest;
let chckp_digest = CheckpointDigest::from_bytes(digest.inner()).unwrap();
let total_transaction_blocks = client
.total_transaction_blocks_by_digest(digest.into())
.await;
assert!(total_transaction_blocks.is_ok());
assert!(total_transaction_blocks.unwrap().is_some_and(|tx| tx > 0));
.total_transaction_blocks_by_digest(chckp_digest)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is...odd...and seems inaccurate. total_transaction_blocks_by_digest should take a CheckpointDigest and not use the contents digest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this. CheckpointSummary has a previous_digest and content_digest field, but no digest field which I would expect would return the checkpoint's digest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pub content_digest: CheckpointContentsDigest,
pub previous_digest: Option<CheckpointDigest>,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In GraphQL schema, the digest of Checkpoint is

	"""
	A 32-byte hash that uniquely identifies the checkpoint contents, encoded in Base58. This
	hash can be used to verify checkpoint contents by checking signatures against the committee,
	Hashing contents to match digest, and checking that the previous checkpoint digest matches.
	"""
	digest: String!

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's because it needs to be calculated, its a hash over the type, its not a field on the actual type. Although graphql likely exposes the digest as a field

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it, thank you!
Yes, indeed, in GraphQL it's exposed as a field - following where it's being computed, I think this is the code.
https://github.com/stefan-mysten/sui/blob/2cf6f86853604a1ba8c34cc2dc3b54dba47e402f/crates/sui-types/src/messages_checkpoint.rs?plain=1#L194-L201

@stefan-mysten
Copy link
Collaborator Author

A proper fix for the Checkpoint data is in #62.

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