Skip to content

Conversation

@tpham-mysten
Copy link
Contributor

Description

Transactions that are output from simulation don't produce balance changes (because the usual path for returning balance changes involves looking them up in the database). This PR fixes that by loading the balance changes from the gRPC response.

Test plan

How did you test the new or updated feature?

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

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:
  • Indexing Framework:

@tpham-mysten tpham-mysten requested a review from a team as a code owner November 19, 2025 05:21
@tpham-mysten tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env November 19, 2025 05:21 — with GitHub Actions Inactive
@vercel
Copy link

vercel bot commented Nov 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sui-docs Ready Ready Preview Comment Nov 19, 2025 2:51pm
2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
multisig-toolkit Ignored Ignored Preview Nov 19, 2025 2:51pm
sui-kiosk Ignored Ignored Preview Nov 19, 2025 2:51pm

#[derive(Clone)]
/// Effects to the balance (sum of coin values per coin type) of addresses and objects.
#[derive(Clone, SimpleObject)]
pub(crate) struct BalanceChange {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this change, I have been thinking on a few options:

  1. Keep stored field and add a new constructor from_grpc(&GrpcBalanceChange) to convert GrpcBalanceChange to StoredBalanceChange. However, StoredBalanceChange is having owner type, where GrpcBalanceChange is just having address. We could overcome it by just using AddressOwner to wrap the address (as it will be unwrapped to address anyway), but that logic can be confusing to readers as they might think SuiAddress is always AddressOwner?
  2. Replace "stored: StoredBalanceChange" by the native BalanceChanges from sui-types. This works but requires extra conversion for both gpc::BalanceChange and stored::BalanceChange, making the flow more complex.
  3. [This approach] convert the gpc::BalanceChange and stored::BalanceChange directly to SimpleObject BalanceChange, which allows us to convert the BalanceChange directly to GraphQL type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach for this use case!

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.

Could we expose the balance changes through the transaction effects contents, rather than through the scope?

#[derive(Clone)]
/// Effects to the balance (sum of coin values per coin type) of addresses and objects.
#[derive(Clone, SimpleObject)]
pub(crate) struct BalanceChange {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach for this use case!


// Load balance changes from database using DataLoader
// First try to get balance changes from execution context (scope)
if let Some(grpc_balance_changes) = self.scope.balance_changes() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised to see this in the scope, as opposed to being exposed via the content, like for events -- why is that?

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.

3 participants