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

rpc-alt: showBalanceChanges for getTransactionBlock #20944

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

amnn
Copy link
Member

@amnn amnn commented Jan 22, 2025

Description

Implement showBalanceChanges for getTransactionBlock. Data is fetched using a data loader, and the response logic has changed slightly so that the output corresponding to each response option gets its own function (rather than handling everything in one function).

This refactoring was done to handle the fact that if balance changes are requested we:

  • Want to perform an extra DB load, which we ideally want to do concurrently with fetching the transaction.

  • Want to use the presence or absence of an Option<StoredTxBalanceChange> to decide whether to add the corresponding output, rather than the flag from the option.

Test plan

New E2E test:

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

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 added 3 commits January 23, 2025 00:36
## Description

Add an index on `tx_digests` from digest to sequence number (the reverse
of the primary key index). This is to make it easier to look up balance
changes (keyed by sequence number in the database) based on their digest
(the key we use for the KV store).

The alternative was to make `tx_balances` keyed on digest, but in that
case we would still need to retain the sequence number, because it is
used for pruning.

## Test plan
CI (Ran `./generate_schema.sh`)
## Description
Rather than implementing the `StoredTransaction` DataLoader directly on
`TransactionDigest` as the key type, introduce a new type wrapping the
digest. This is so that we can implement other data loaders that use
`TransactionDigest` as the key.

## Test plan
CI
## Description

Implement showBalanceChanges for getTransactionBlock. Data is fetched
using a data loader, and the response logic has changed slightly so that
the output corresponding to each response option gets its own function
(rather than handling everything in one function).

This refactoring was done to handle the fact that if balance changes are
requested we:

- Want to perform an extra DB load, which we ideally want to do
  concurrently with fetching the transaction.

- Want to use the presence or absence of an
  `Option<StoredTxBalanceChange>` to decide whether to add the
  corresponding output, rather than the flag from the option.

## Test plan
New E2E test:

```
sui$ cargo nextest run -p sui-indexer-alt-e2e-tests
```
@amnn amnn requested review from lxfind, emmazzz, gegaowp and wlmyng January 22, 2025 19:10
@amnn amnn self-assigned this Jan 22, 2025
Copy link

vercel bot commented Jan 22, 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 Jan 22, 2025 7:10pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Jan 22, 2025 7:10pm
sui-kiosk ⬜️ Ignored (Inspect) Jan 22, 2025 7:10pm

Copy link
Member Author

Choose a reason for hiding this comment

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

Will need to run these operations proactively before landing this PR -- I'll hold off on landing until I am back and can coordinate that with our various races etc.

response(ctx, &stored, &options)
.await
.map_err(internal_error)
// Balance changes might not be present because of pruning, in which case we return
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this the right behaviour w.r.t. pruning or should we produce an error if this happens? This behaviour matches what we do for GraphQL (just don't return the field that was pruned), but we do that mainly because we don't want the absence of one field to ruin the entire query. In JSON-RPC, we don't really have compound queries in the same way, but "options" are kind of analogous, so it seems to fit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems easier for callers to handle this way, they can do some additional filtering on the response side, as opposed to sending two requests in case the first requesting balance changes fails

Copy link
Member Author

Choose a reason for hiding this comment

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

I flip-flopped on this. Here I opted for nulling out the field, but then when I started implementing showObjectChanges, I realised I couldn't do it so cleanly there, because I could end up with one (historical) object having been pruned, but everything else existing, it seemed strange to react to that by nulling out just the object changes field, so I introduced a new error for when some requested data was pruned. Maybe we can discuss the pro's/con's on Monday.

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.

i like that we've split out the stored -> rpc conversion for each field out into its own fn

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