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

[bridge-indexer] Progress saving policy #19243

Merged
merged 1 commit into from
Sep 7, 2024
Merged

Conversation

longbowlu
Copy link
Contributor

@longbowlu longbowlu commented Sep 6, 2024

Description

This PR introduces ProgressSavingPolicy to deal with two problems:

  1. The current implementation has a bug on Sui side - checkpoints data arrive out-of-order (e.g. checkpoint 10 may be processed earlier than checkpoint 9), so existing save_process may cause us to miss blocks.
  2. In current implementation we need to write progress to DB for every call to save_process. This can be optimized to cache progresses in memory and flush them periodically or conditionally.

We add two types of ProgressSavingPolicy, SaveAfterDuration and OutOfOrderSaveAfterDuration:

  • SaveAfterDuration only flushes the progress to DB after a period of time
  • OutOfOrderSaveAfterDuration assumes the data is out of order, and will only write height N when it makes sure everything before N has been received.

Test plan

unit tests and production deployment.


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

@longbowlu longbowlu marked this pull request as ready for review September 6, 2024 05:35
Base automatically changed from split-out-storage to main September 6, 2024 21:43
Copy link
Contributor

@dariorussi dariorussi left a comment

Choose a reason for hiding this comment

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

It looks good to me.
Do you think we need all the customization provided?
I feel an in memory story with all DB updates done with some interval (interval in checkpoints and not time) would be best.
Maybe that is what we do, but I am getting a bit lost in the level of abstraction provided by our indexer.

One question: is this affecting the deepbook indexer?

@longbowlu
Copy link
Contributor Author

It looks good to me. Do you think we need all the customization provided? I feel an in memory story with all DB updates done with some interval (interval in checkpoints and not time) would be best. Maybe that is what we do, but I am getting a bit lost in the level of abstraction provided by our indexer.

One question: is this affecting the deepbook indexer?

These two basic policies are what we need for Sui ingestion and Eth ingestion:

  • SaveAfterDuration does what you described in time. I think we can also do in checkpoints but then we need to allow custom value for checkpoint length cuz it may vary based on chains. We will use this for Eth, because eth data always comes in strict order.
  • OutOfOrderSaveAfterDuration is made for sui because when the data may come out of order from data ingestion framework. It means we need to re-order the data to make sure nothing is missed.
    To summarize these two policies are tailored to what we need today for bridge indexer.

@longbowlu
Copy link
Contributor Author

longbowlu commented Sep 7, 2024

One question: is this affecting the deepbook indexer?

@dariorussi I was wrong about what i commented earlier, in fact this PR's impact to deepbook indexer is very small: it changes the interface of async fn save_progress of IndexerProgressStore. The policy thing is only relevant to bridge indexer

@longbowlu longbowlu enabled auto-merge (squash) September 7, 2024 05:55
@longbowlu longbowlu merged commit 2e41207 into main Sep 7, 2024
49 checks passed
@longbowlu longbowlu deleted the progress-saving-policy branch September 7, 2024 06:12
suiwombat pushed a commit that referenced this pull request Sep 16, 2024
## Description 

This PR introduces `ProgressSavingPolicy` to deal with two problems:
1. The current implementation has a bug on Sui side - checkpoints data
arrive out-of-order (e.g. checkpoint 10 may be processed earlier than
checkpoint 9), so existing `save_process` may cause us to miss blocks.
2. In current implementation we need to write progress to DB for every
call to `save_process`. This can be optimized to cache progresses in
memory and flush them periodically or conditionally.

We add two types of `ProgressSavingPolicy`, `SaveAfterDuration` and
`OutOfOrderSaveAfterDuration`:
* `SaveAfterDuration` only flushes the progress to DB after a period of
time
* `OutOfOrderSaveAfterDuration` assumes the data is out of order, and
will only write height N when it makes sure everything before N has been
received.
* 

## Test plan 

unit tests and production deployment.

---

## 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:
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