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

Fix(standalone): Do not eagerly commit transactions to the DB #825

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

birchmd
Copy link
Member

@birchmd birchmd commented Aug 21, 2023

Description

The Borealis refiner was experiencing a performance issue where it would become very slow at processing blocks. Profiling revealed the reason was increasing time to look up the ENGINE_STATE key when replaying transactions (this replay is necessary to correctly process batch transactions on Near). After some investigation, we realized the cause of this slow lookup was due to that key being constantly written and deleted by every transaction. The reason for this churn is because the Engine logic was changed to automatically migrate its state, but of course old transactions did not have that logic and therefore the replay would compute an incorrect state diff relative to what is reported in the Near block. In such cases the replay changes to the DB are deleted and the correct diff from the Near block is used instead.

To avoid this DB churn, this PR changes the standalone engine so that it will not commit to the DB right away when consuming a block. Instead it is now up to clients of the standalone engine to commit the changes themselves (after performing any validation). A PR on Borealis Refiner will make that change there after this PR is merged.

Note this does not address the larger issue of replay accuracy. In theory the Borealis Refiner should use the code that existed at the time when replaying an old transaction. However, this is not so easy to accomplish which is why we are proposing this solution instead. It is an immediate fix to the performance issue that can keep the Refiner running while we address the more fundamental problem.

Performance / NEAR gas cost considerations

No impact to on-chain Aurora contract; changes to standalone only.

Testing

Updates to existing tests

@birchmd birchmd added C-enhancement Category: New feature or request A-standalone Area: the standalone engine EVM labels Aug 21, 2023
@birchmd birchmd requested a review from aleksuss August 21, 2023 14:02
Copy link
Contributor

@RomanHodulak RomanHodulak left a comment

Choose a reason for hiding this comment

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

I don't think it's the subject of the PR but I like the changes from EngineStateAccess to generic I: IO + Copy, it improves the abstraction.

@birchmd birchmd added this pull request to the merge queue Aug 23, 2023
Merged via the queue into develop with commit 3a544df Aug 23, 2023
20 checks passed
@birchmd birchmd deleted the fix/birchmd/separate-standalone-commit branch August 23, 2023 15:39
birchmd added a commit that referenced this pull request Aug 23, 2023
## Description

The [Borealis
refiner](https://github.com/aurora-is-near/borealis-engine-lib/tree/main/refiner-lib)
was experiencing a performance issue where it would become very slow at
processing blocks. Profiling revealed the reason was increasing time to
look up the `ENGINE_STATE` key when replaying transactions (this replay
is necessary to correctly process batch transactions on Near). After
some investigation, we realized the cause of this slow lookup was due to
that key being constantly written and deleted by every transaction. The
reason for this churn is because the Engine logic was changed to
automatically migrate its state, but of course old transactions did not
have that logic and therefore the replay would compute an incorrect
state diff relative to what is reported in the Near block. In such cases
the replay changes to the DB are deleted and the correct diff from the
Near block is used instead.

To avoid this DB churn, this PR changes the standalone engine so that it
will not commit to the DB right away when consuming a block. Instead it
is now up to clients of the standalone engine to commit the changes
themselves (after performing any validation). A PR on Borealis Refiner
will make that change there after this PR is merged.

Note this does not address the larger issue of replay accuracy. In
theory the Borealis Refiner should use the code that existed at the time
when replaying an old transaction. However, this is not so easy to
accomplish which is why we are proposing this solution instead. It is an
immediate fix to the performance issue that can keep the Refiner running
while we address the more fundamental problem.

## Performance / NEAR gas cost considerations

No impact to on-chain Aurora contract; changes to standalone only.

## Testing

Updates to existing tests
@birchmd birchmd mentioned this pull request Aug 23, 2023
birchmd added a commit that referenced this pull request Aug 25, 2023
### Fixes

- Updated sputnikvm dependency with bugfix in the `returndatacopy`
implementation and a performance improvement in accessing EVM memory.
(#826)

### Changes

- BREAKING: `engine-standalone-storage` no longer automatically writes
to the DB when `consume_message` is called. It is up to downstream users
of the library to commit the diff (after doing any validation for
correctness). (#825)

### Additions

- New crate for the so-called "hashchain" implementation. It will enable
verification of Aurora blocks by light clients in the future. (#816)

---------

Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>
aleksuss pushed a commit that referenced this pull request Aug 30, 2023
## Description

The [Borealis
refiner](https://github.com/aurora-is-near/borealis-engine-lib/tree/main/refiner-lib)
was experiencing a performance issue where it would become very slow at
processing blocks. Profiling revealed the reason was increasing time to
look up the `ENGINE_STATE` key when replaying transactions (this replay
is necessary to correctly process batch transactions on Near). After
some investigation, we realized the cause of this slow lookup was due to
that key being constantly written and deleted by every transaction. The
reason for this churn is because the Engine logic was changed to
automatically migrate its state, but of course old transactions did not
have that logic and therefore the replay would compute an incorrect
state diff relative to what is reported in the Near block. In such cases
the replay changes to the DB are deleted and the correct diff from the
Near block is used instead.

To avoid this DB churn, this PR changes the standalone engine so that it
will not commit to the DB right away when consuming a block. Instead it
is now up to clients of the standalone engine to commit the changes
themselves (after performing any validation). A PR on Borealis Refiner
will make that change there after this PR is merged.

Note this does not address the larger issue of replay accuracy. In
theory the Borealis Refiner should use the code that existed at the time
when replaying an old transaction. However, this is not so easy to
accomplish which is why we are proposing this solution instead. It is an
immediate fix to the performance issue that can keep the Refiner running
while we address the more fundamental problem.

## Performance / NEAR gas cost considerations

No impact to on-chain Aurora contract; changes to standalone only.

## Testing

Updates to existing tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-standalone Area: the standalone engine EVM C-enhancement Category: New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants