Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

use stack of contexts to implement snapshot revert #399

Merged
merged 7 commits into from
Aug 10, 2021

Conversation

yihuang
Copy link
Contributor

@yihuang yihuang commented Aug 5, 2021

Closes: #338

Description


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@yihuang
Copy link
Contributor Author

yihuang commented Aug 5, 2021

the integration tests are verified manually, not sure if it's get picked up in CI.

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

I like this approach and PR. I think we should move the cached context struct into a new file and implement it as a stack. We should also add more comprehensive comments (especially on RevertToSnapshot and Snapshot) so that people know how this actually works and the motivation behind this approach.

x/evm/keeper/keeper.go Outdated Show resolved Hide resolved
x/evm/keeper/keeper.go Outdated Show resolved Hide resolved
x/evm/keeper/keeper.go Outdated Show resolved Hide resolved
x/evm/keeper/keeper.go Outdated Show resolved Hide resolved
x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
x/evm/keeper/statedb_test.go Outdated Show resolved Hide resolved
x/evm/keeper/statedb.go Show resolved Hide resolved
x/evm/keeper/statedb.go Outdated Show resolved Hide resolved
x/evm/keeper/keeper.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 6, 2021

Codecov Report

Merging #399 (23e2ee9) into main (9632845) will decrease coverage by 0.04%.
The diff coverage is 76.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #399      +/-   ##
==========================================
- Coverage   50.74%   50.69%   -0.05%     
==========================================
  Files          48       49       +1     
  Lines        4846     4872      +26     
==========================================
+ Hits         2459     2470      +11     
- Misses       2288     2298      +10     
- Partials       99      104       +5     
Impacted Files Coverage Δ
x/evm/keeper/state_transition.go 58.10% <46.15%> (-5.69%) ⬇️
x/evm/keeper/grpc_query.go 70.88% <80.00%> (-0.23%) ⬇️
x/evm/keeper/context_stack.go 81.08% <81.08%> (ø)
x/evm/keeper/statedb.go 84.76% <83.87%> (+0.03%) ⬆️
x/evm/keeper/keeper.go 70.52% <84.00%> (+0.63%) ⬆️

@thomas-nguy
Copy link
Contributor

beside some naming convention, lgtm

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

Left another round of comments. I think we should explicitly test the cache stack by ensuring that creating a cacheCtx from another cacheCtx works fine

x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

Nice! A final round of comments, mostly test cases

x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
x/evm/keeper/statedb_test.go Outdated Show resolved Hide resolved
x/evm/keeper/statedb_test.go Outdated Show resolved Hide resolved
x/evm/keeper/statedb_test.go Outdated Show resolved Hide resolved
x/evm/keeper/statedb_test.go Show resolved Hide resolved
@yihuang yihuang force-pushed the snapshot branch 2 times, most recently from 13352da to 92fabd1 Compare August 9, 2021 07:20
Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK. 2 Minor suggestions. can you add a breaking change entry on the changelog?

x/evm/keeper/statedb_test.go Outdated Show resolved Hide resolved
x/evm/keeper/context_stack.go Outdated Show resolved Hide resolved
@yihuang
Copy link
Contributor Author

yihuang commented Aug 9, 2021

ACK. 2 Minor suggestions. can you add a breaking change entry on the changelog?

changelog added.

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK. Pending panic on nil commit function

CHANGELOG.md Outdated Show resolved Hide resolved
@fedekunze fedekunze mentioned this pull request Aug 9, 2021
11 tasks
Closes #338

add exception revert test case

verify partial revert

mutate state after the reverted subcall

polish

update comments

name the module after the type name

remove the unnecessary Snapshot in outer layer

and add snapshot unit test

assert context stack is clean after tx processing

cleanups

fix context revert

fix comments

update comments

it's ok to commit in failed case too

Update x/evm/keeper/context_stack.go

Co-authored-by: Federico Kunze Küllmer <[email protected]>

Update x/evm/keeper/context_stack.go

Co-authored-by: Federico Kunze Küllmer <[email protected]>

Update x/evm/keeper/context_stack.go

Co-authored-by: Federico Kunze Küllmer <[email protected]>

update comment and error message

add comment to cacheContext

k -> cs

Update x/evm/keeper/context_stack.go

Co-authored-by: Federico Kunze Küllmer <[email protected]>

evm can handle state revert

renames and unit tests
@evmos evmos deleted a comment from netlify bot Aug 10, 2021
@fedekunze fedekunze enabled auto-merge (squash) August 10, 2021 07:14
@fedekunze fedekunze merged commit 9227e78 into evmos:main Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C:x/evm EVM module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

state is not reverted when exception get recovered in smart contract
4 participants