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

fix(sui-indexer): Fix StructTag conversion for suix_queryEvents Indexer-RPC method #20467

Merged
merged 2 commits into from
Nov 29, 2024

Conversation

samuel-rufi
Copy link
Contributor

@samuel-rufi samuel-rufi commented Nov 28, 2024

Description

Currently, there is a bug in the suix_queryEvents implementation when processing EventFilter::MoveEventType(struct_tag). Even if the user provides a struct_tag in its full canonical hex representation (including the necessary prefix), it is not converted correctly to the format expected by the database. Instead, the struct_tag is transformed into a simplified representation that does not align with the structure stored in the indexer database.

This mismatch causes the SQL query to fail in finding the relevant records, effectively preventing the retrieval of the desired event data, despite the user supplying the correct input.

While suix_queryEvents makes use of following string:

EventFilter::MoveEventType(struct_tag) => {
format!("event_type = '{}'", struct_tag)
}

The indexed event is stored makes use of the full canonical string (including the prefix):

event_type: event.type_.to_canonical_string(/* with_prefix */ true),

You can reproduce the issue by calling the suix_queryEvents RPC endpoint on a indexer instance as follows:

curl 'http://INDEXER_IP:INDEXER_PORT' \
  -H 'content-type: application/json' \
  --data-raw '{"jsonrpc":"2.0","id":4,"method":"suix_queryEvents","params":[{"MoveEventType":"0x00000000000000000000000000000003::validator_set::ValidatorEpochInfoEventV2"},null,8,true]}'

Inspired from this PR: iotaledger/iota#4289

Test plan

Please see the provided test.


Release notes

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer: Fix StructTag conversion for suix_queryEvents Indexer-RPC method
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

Copy link

vercel bot commented Nov 28, 2024

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 Nov 29, 2024 11:09am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2024 11:09am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2024 11:09am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2024 11:09am

Copy link
Contributor

@amnn amnn left a comment

Choose a reason for hiding this comment

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

Excellent PR, thanks @samuel-rufi! Love the detailed description, and the fact that you've added a test. I've made a suggestion for a small improvement in the fix, but everything else looks good here.

Comment on lines 1033 to 1034
let formatted_struct_tag = struct_tag.to_canonical_string(true);
format!("event_type = '{formatted_struct_tag}'")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a small tweak here -- we can use to_canonical_display to avoid materializing to an intermediate string.

Suggested change
let formatted_struct_tag = struct_tag.to_canonical_string(true);
format!("event_type = '{formatted_struct_tag}'")
format!(
"event_type = '{}'",
struct_tag.to_canonical_display(/* with_prefix */ true),
)

Copy link
Contributor Author

@samuel-rufi samuel-rufi Nov 29, 2024

Choose a reason for hiding this comment

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

Hey @amnn thanks very much for your response and suggestion, will keep this in mind! 🙏

Co-authored-by: Ashok Menon <amenon94@gmail.com>
@samuel-rufi samuel-rufi temporarily deployed to sui-typescript-aws-kms-test-env November 29, 2024 17:45 — with GitHub Actions Inactive
@amnn amnn merged commit 8d3fde6 into MystenLabs:main Nov 29, 2024
48 checks passed
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