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: exact epoch tx count #12395

Merged
merged 2 commits into from
Jun 9, 2023
Merged

Conversation

gegaowp
Copy link
Contributor

@gegaowp gegaowp commented Jun 7, 2023

Description

Before this PR, tx count was updated within an epoch. This is problematic on backfill when data racing happens, as a result, epoch tx count is not accurate.

Also removed the epoch updating on each checkpoint b/c it has caused constant DB commit errors like

2023-06-07T23:13:27.759942Z  INFO sui_indexer::store::pg_indexer_store: Persisting epoch 19
2023-06-07T23:13:36.865246Z  WARN sui_indexer::handlers::checkpoint_handler: Indexer epoch commit failed with error: PostgresWriteError("could not serialize access due to read/write dependencies among transactions"), retrying after 100 milli-secs...
2023-06-07T23:13:36.965945Z  INFO sui_indexer::store::pg_indexer_store: Persisting epoch 19
2023-06-07T23:13:46.059553Z  WARN sui_indexer::handlers::checkpoint_handler: Indexer epoch commit failed with error: PostgresWriteError("could not serialize access due to read/write dependencies among transactions"), retrying after 100 milli-secs...
2023-06-07T23:13:46.160704Z  INFO sui_indexer::store::pg_indexer_store: Persisting epoch 19

Test Plan

Build image and test with mainnet, verify in the DB.


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

@vercel
Copy link

vercel bot commented Jun 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
offline-signer-helper ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2023 11:25pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Jun 7, 2023 11:25pm
explorer-storybook ⬜️ Ignored (Inspect) Jun 7, 2023 11:25pm
sui-wallet-kit ⬜️ Ignored (Inspect) Jun 7, 2023 11:25pm
wallet-adapter ⬜️ Ignored (Inspect) Jun 7, 2023 11:25pm

@@ -235,6 +235,10 @@ pub trait IndexerStore {
) -> Result<(), IndexerError>;

async fn persist_epoch(&self, data: &TemporaryEpochStore) -> Result<(), IndexerError>;
async fn count_network_transaction_previous_epoch(
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 a function that counts transactions in epoch X makes more sense than in epoch X-1

Copy link
Contributor Author

@gegaowp gegaowp Jun 7, 2023

Choose a reason for hiding this comment

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

this is to fetch the last network_total_transactions value of previous epoch in checkpoints table, we cannot count the tx of current epoch yet, b/c the checkpoint is likely not committed yet.

the more I think, the more I want to move all epoch related calculation & DB commits to an async processor, such that this async processor will just wait until all checkpoints have been complete on the previous epoch and then start processing.

Copy link
Contributor

@longbowlu longbowlu Jun 9, 2023

Choose a reason for hiding this comment

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

I was suggesting:

fn count_network_transaction_in_epoch

and then call count_network_transaction_in_epoch(n-1)

will leave it up to you though

Copy link
Contributor Author

@gegaowp gegaowp Jun 9, 2023

Choose a reason for hiding this comment

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

yes, I saw what you meant, I wanted to calculate the total tx of current epoch based on

  • committed row of last checkpoint of previous epoch, where the network_total_tx is tx count since genesis;
  • the current checkpoint row in mem, which is the last row of the current epoch and may or may not committed

such that the difference is the tx count of current tx.

b/c the current checkpoint row might not have been committed, thus running query of count_network_transaction_in_epoch could generate an inaccurate result.
If we do that with an async processor, it would be this issue b/c we can always have triggering condition to make sure the all checkpoints have been committed before processing the epoch

crates/sui-indexer/src/store/pg_indexer_store.rs Outdated Show resolved Hide resolved
crates/sui-indexer/src/store/pg_indexer_store.rs Outdated Show resolved Hide resolved
@gegaowp gegaowp merged commit b29b1fe into MystenLabs:main Jun 9, 2023
@gegaowp gegaowp deleted the indexer-epoch-tx-count branch June 9, 2023 19:43
ebmifa pushed a commit that referenced this pull request Jun 14, 2023
## Description
Before this PR, tx count was updated within an epoch. This is
problematic on backfill when data racing happens, as a result, epoch tx
count is not accurate.

Also removed the epoch updating on each checkpoint b/c it has caused
constant DB commit errors like
```
2023-06-07T23:13:27.759942Z  INFO sui_indexer::store::pg_indexer_store: Persisting epoch 19
2023-06-07T23:13:36.865246Z  WARN sui_indexer::handlers::checkpoint_handler: Indexer epoch commit failed with error: PostgresWriteError("could not serialize access due to read/write dependencies among transactions"), retrying after 100 milli-secs...
2023-06-07T23:13:36.965945Z  INFO sui_indexer::store::pg_indexer_store: Persisting epoch 19
2023-06-07T23:13:46.059553Z  WARN sui_indexer::handlers::checkpoint_handler: Indexer epoch commit failed with error: PostgresWriteError("could not serialize access due to read/write dependencies among transactions"), retrying after 100 milli-secs...
2023-06-07T23:13:46.160704Z  INFO sui_indexer::store::pg_indexer_store: Persisting epoch 19
```

## Test Plan
Build image and test with mainnet, verify in the DB.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [x] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
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