Skip to content

Conversation

wlmyng
Copy link
Contributor

@wlmyng wlmyng commented Sep 5, 2024

Description

Extend the watermark task to also keep track of the min unpruned checkpoint and its min tx. The watermark task reads the min and max checkpoints from the checkpoints table, since this is the first table pruned by the pruner.

While checkpoint_viewed_at is inherited from a field's parent, the lower checkpoint bound will always be from the watermark, because any data < and potentially = to it must have been pruned from the db already.

Consequently, rather than the current assumption that the inclusive lower bound for transactions queries starts from zero if the caller did not specify a starting point, we instead use the min unpruned checkpoint and tx from the watermark task.

Returns an error if a caller tries to fetch data outside of the unpruned range (or should we return an empty response? I mirrored this off objects queries - if someone queries outside the available range, they will get an explicit error). At epoch boundary when we prune data, callers may receive an empty response instead of an error if the request was made before pruning but completed during or after pruning.

Later on, a dedicated watermarks table will simplify the query patterns needed to support the watermark task on graphql. And we should expose the unpruned range info on graphql api as well

Test plan

pruning/transactions.move


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:

Copy link

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

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.

Almost there, thanks @wlmyng ! Main thing is changing the error behaviour for transactions as per the suggestion from @lxfind.

hi_cp_timestamp_ms: 1,
epoch: 0,
lo_cp: 0,
lo_tx: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we record hi_tx as well? It would seem to be symmetric and we do need to use that for the transaction queries.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we care about the transaction upperbound for whatever the checkpoint upperbound is, so it doesn't really help to track hi_tx here.

Comment on lines 322 to 324
// If we've entered this function, we already fetched `checkpoint_viewed_at` from the
// `Watermark`, and so we must be able to retrieve `lo_cp` as well.
let Watermark { lo_cp, lo_tx, .. } = *ctx.data_unchecked();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: pull this out next to the other calls that fetch from the context.

Comment on lines 341 to 343
return Err(Error::Client(
"Requested data is pruned and no longer available".to_string(),
));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think @lxfind mentioned that it would be better to treat pruned data the same as if it had never existed -- that seems like a reasonable position for transactions given that the timeframe is measured in months rather than minutes.

That should simplify the logic here as well, because I think you can skip this check entirely.

Comment on lines +165 to +219
let tx_lo = match lo_record.1 {
Some(lo) => lo,
// Ostensibly this shouldn't happen in production, but should it occur, we can use
// `network_total_transactions` to exclude checkpoints < this one
None => lo_record.2,
} as u64;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make this an internal error -- I want to know if something should never happen in production, and yet it does.

// SAFETY: we can unwrap because of the `Some(checkpoint_viewed_at)
let cp_hi = min_option([cp_before_inclusive, cp_at, Some(checkpoint_viewed_at)]).unwrap();

// Read from the `checkpoints` table rather than the `pruner_cp_watermark` table, because
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an instance at which we read from pruner_cp_watermark? (In other words, can we get rid of that table?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it's used by the indexer, although just proposed a change in data platform channel that could allow us to get rid of this outright

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed that these are duplicate info between pruner_cp_watermark and checkpoints, and I was looking at the de-dup, but prob no longer relevant given indexer-alt.

@wlmyng
Copy link
Contributor Author

wlmyng commented Sep 19, 2024

@amnn I plan to wait for the watermarks table changes to land so graphql can read from that (and consequently simplify all the querying complexity in this PR), but if needed I can clean up this PR and get this merged first

…ark tracks lo and hi, because lo is not static - and won't be until we introduce watermarks table, we actually have to keep fetching the min cp no?
@gegaowp gegaowp mentioned this pull request Dec 5, 2024
8 tasks
gegaowp added a commit that referenced this pull request Dec 6, 2024
## Description 

- main changes from #19237 and
this is the only unknown blocker
- plus rebase, addressing comments and some testing changes.

## Test plan 

cargo nextest run --no-capture sui-graphql-e2e-tests::tests
run_test::stable/prune

---

## 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: 
- [X] GraphQL: graphql changes to enable pruning, mainly around
watermark
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
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