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

indexer-alt: sum_coin_balances pipeline #20070

Merged
merged 2 commits into from
Oct 29, 2024
Merged

indexer-alt: sum_coin_balances pipeline #20070

merged 2 commits into from
Oct 29, 2024

Conversation

amnn
Copy link
Contributor

@amnn amnn commented Oct 29, 2024

Description

Similar to sum_obj_types in that it is tracking the live object set,
but this index only covers coin objects owned by addresses, and it
orders them by balance, which allows queries to return them in
decreasing balance order.

Test plan

Manually run the indexer on the first 100,000 checkpoints:

sui$ cargo run -p sui-indexer-alt --release --                                   \
  --database-url "postgres://postgres:postgrespw@localhost:5432/sui_indexer_alt" \
  --remote-store-url https://checkpoints.mainnet.sui.io/                         \
  --last-checkpoint 100000

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

@amnn amnn self-assigned this Oct 29, 2024
Copy link

vercel bot commented Oct 29, 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 Oct 29, 2024 8:39pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Oct 29, 2024 8:39pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Oct 29, 2024 8:39pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Oct 29, 2024 8:39pm

@amnn amnn changed the title index-alt: sum_coin_balances pipeline indexer-alt: sum_coin_balances pipeline Oct 29, 2024
@amnn amnn force-pushed the amnn/idx-sum-coin-balances branch from d7f7b19 to 3885b1d Compare October 29, 2024 18:12
@amnn amnn force-pushed the amnn/idx-sum-coin-balances branch from 3885b1d to 7abbac0 Compare October 29, 2024 18:49
Base automatically changed from amnn/idx-params to main October 29, 2024 18:49
## Description

The `sum_coin_balances` pipeline also needs to represent object updates,
so this change factors out a type that can represent an update to an
object (at a particular version), or a deletion at that version.

## Test plan

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

@gegaowp gegaowp 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!

--
-- This can be used to paginate the coin balances of a given address at an
-- instant in time, returning coins in descending balance order.
CREATE TABLE IF NOT EXISTS sum_coin_balances
Copy link
Contributor

Choose a reason for hiding this comment

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

naive q, why sum_ instead of just coin_balances?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sum stands for "summary", it's the equivalent of the "_snapshot" from "objects_snapshot". There will be an additional "wal_coin_balances" that is like the old "objects_history".


/// Each insert or update will include at most this many rows -- the size is chosen to maximize the
/// rows without hitting the limit on bind parameters.
const UPDATE_CHUNK_ROWS: usize = i16::MAX as usize / 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, good to read 5 from schema

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 go back over and provide some automation to calculate the number of fields based on model types, using a procedural macro:

https://linear.app/mysten-labs/issue/DVX-447/automatically-calculate-field-count


// Deleted and wrapped coins
for change in tx.effects.object_changes() {
// The object is not deleted/wrapped, or if it is it was unwrapped in the same
Copy link
Contributor

Choose a reason for hiding this comment

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

if it is it was ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the current comment is grammatically correct:

The object is not deleted/wrapped, or if it is (deleted or wrapped) it was unwrapped in the same transaction

let serialized = bcs::to_bytes(&coin_type)
.map_err(|_| anyhow!("Failed to serialize type for {}", object.id()))?;

coin_types.insert(object.id(), serialized);
Copy link
Contributor

Choose a reason for hiding this comment

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

assumption check, does coin_type never change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An object's type cannot currently change, but we aren't using that fact here, right? The reason why we include the coin type here is to make filtering by the coin type efficient.

Copy link
Contributor

Choose a reason for hiding this comment

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

if the type can change, one object ID is likely mapped to multiple types on different versions, then we will get type for each (id, version) instead of id only to be correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This table is keyed by id, and it only tracks the latest version of each object, so it's not going to have multiple versions of any given object.

## Description

Similar to `sum_obj_types` in that it is tracking the live object set,
but this index only covers coin objects owned by addresses, and it
orders them by balance, which allows queries to return them in
decreasing balance order.

## Test plan

Manually run the indexer on the first 100,000 checkpoints:

```
sui$ cargo run -p sui-indexer-alt --release --                                   \
  --database-url "postgres://postgres:postgrespw@localhost:5432/sui_indexer_alt" \
  --remote-store-url https://checkpoints.mainnet.sui.io                          \
  --last-checkpoint 100000
```
@amnn amnn force-pushed the amnn/idx-sum-coin-balances branch from 7a9525d to 6f3c2c5 Compare October 29, 2024 20:37
@amnn amnn merged commit b2700da into main Oct 29, 2024
52 checks passed
@amnn amnn deleted the amnn/idx-sum-coin-balances branch October 29, 2024 22:24
@amnn amnn mentioned this pull request Oct 30, 2024
8 tasks
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