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

StateDB cleanup #1890

Merged
merged 6 commits into from
Apr 30, 2024
Merged

StateDB cleanup #1890

merged 6 commits into from
Apr 30, 2024

Conversation

tudor-malene
Copy link
Collaborator

@tudor-malene tudor-malene commented Apr 29, 2024

Why this change is needed

Under load, the enclave spends time creating StateDB instances.
This PR started as an attempt to cache the head statedb so it can be used by all requests, but that's not possible because of the internal implementation of the stated.

The PR also tweaks the setup of the stateDb, because the caching values passed in were too low.

What changes were made as part of this PR

  • route all "CreateStateDB" calls through the batch registry
  • tweak setup

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

@@ -444,7 +447,7 @@ func (executor *batchExecutor) processTransactions(
} else {
// Exclude all errors
excludedTransactions = append(excludedTransactions, tx.Tx)
executor.logger.Info("Excluding transaction from batch", log.TxKey, tx.Tx.Hash(), log.BatchHashKey, batch.Hash(), "cause", result)
executor.logger.Debug("Excluding transaction from batch", log.TxKey, tx.Tx.Hash(), log.BatchHashKey, batch.Hash(), "cause", result)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is unrelated, but it has to be done because this entry is too verbose

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we need to prioritise the issues that leaves tx stuck in the mempool forever and then re-enable this. Because I think this failure has no feedback if it's got this far, so user will just see spinning forever waiting for receipt and this sometimes gave us visibility on them.

@tudor-malene tudor-malene changed the title WIP - cache statedb StateDB fixers Apr 30, 2024
@tudor-malene tudor-malene changed the title StateDB fixers StateDB fixes Apr 30, 2024
@tudor-malene tudor-malene changed the title StateDB fixes StateDB cleanup Apr 30, 2024
if err != nil {
return nil, syserr.NewInternalError(fmt.Errorf("could not create state DB for %s. Cause: %w", batch.Header.Root, err))
return nil, fmt.Errorf("could not create state DB for %s. Cause: %w", batch.Header.Root, err)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this might not be a system error, depending on the rpc request

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

Minor comments


func getBatchStateAtSeq(ctx context.Context, storage storage.Storage, seqNo uint64) (*state.StateDB, error) {
// We retrieve the batch of interest.
batch, err := storage.FetchBatchBySeqNo(ctx, seqNo)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Possible I'm missing something here, but it looks like both the places that call this already had the batch. If it's the batch hash we need rather than the seq number maybe they can pass that in to save the look up?

@@ -444,7 +447,7 @@ func (executor *batchExecutor) processTransactions(
} else {
// Exclude all errors
excludedTransactions = append(excludedTransactions, tx.Tx)
executor.logger.Info("Excluding transaction from batch", log.TxKey, tx.Tx.Hash(), log.BatchHashKey, batch.Hash(), "cause", result)
executor.logger.Debug("Excluding transaction from batch", log.TxKey, tx.Tx.Hash(), log.BatchHashKey, batch.Hash(), "cause", result)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we need to prioritise the issues that leaves tx stuck in the mempool forever and then re-enable this. Because I think this failure has no feedback if it's got this far, so user will just see spinning forever waiting for receipt and this sometimes gave us visibility on them.

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

lgtm

@tudor-malene tudor-malene merged commit ce8d274 into main Apr 30, 2024
2 checks passed
@tudor-malene tudor-malene deleted the tudor/cache_current_state branch April 30, 2024 09:32
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