-
-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: metadata journal can rollback incorrectly (#3569)
this commit fixes an issue where multiple writes inside of a checkpoint lead to journal corruption on rollback. it ensures a call to `register_update()` when the metadata dict has already been updated inside of a given checkpoint. note this does not change any observed functionality in the compiler because writes to the metadata journal inside for loops only ever happen to be written once, but it prevents a bug in case we ever add multiple writes inside of the same checkpoint. chainsec june review 5.3 --------- Co-authored-by: tserg <8017125+tserg@users.noreply.github.com>
- Loading branch information
1 parent
a854929
commit 39a2313
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from vyper.ast.metadata import NodeMetadata | ||
from vyper.exceptions import VyperException | ||
|
||
|
||
def test_metadata_journal_basic(): | ||
m = NodeMetadata() | ||
|
||
m["x"] = 1 | ||
assert m["x"] == 1 | ||
|
||
|
||
def test_metadata_journal_commit(): | ||
m = NodeMetadata() | ||
|
||
with m.enter_typechecker_speculation(): | ||
m["x"] = 1 | ||
|
||
assert m["x"] == 1 | ||
|
||
|
||
def test_metadata_journal_exception(): | ||
m = NodeMetadata() | ||
|
||
m["x"] = 1 | ||
try: | ||
with m.enter_typechecker_speculation(): | ||
m["x"] = 2 | ||
m["x"] = 3 | ||
|
||
assert m["x"] == 3 | ||
raise VyperException("dummy exception") | ||
|
||
except VyperException: | ||
pass | ||
|
||
# rollback upon exception | ||
assert m["x"] == 1 | ||
|
||
|
||
def test_metadata_journal_rollback_inner(): | ||
m = NodeMetadata() | ||
|
||
m["x"] = 1 | ||
with m.enter_typechecker_speculation(): | ||
m["x"] = 2 | ||
|
||
try: | ||
with m.enter_typechecker_speculation(): | ||
m["x"] = 3 | ||
m["x"] = 4 # test multiple writes | ||
|
||
assert m["x"] == 4 | ||
raise VyperException("dummy exception") | ||
|
||
except VyperException: | ||
pass | ||
|
||
assert m["x"] == 2 | ||
|
||
|
||
def test_metadata_journal_rollback_outer(): | ||
m = NodeMetadata() | ||
|
||
m["x"] = 1 | ||
try: | ||
with m.enter_typechecker_speculation(): | ||
m["x"] = 2 | ||
|
||
with m.enter_typechecker_speculation(): | ||
m["x"] = 3 | ||
m["x"] = 4 # test multiple writes | ||
|
||
assert m["x"] == 4 | ||
|
||
m["x"] = 5 | ||
|
||
raise VyperException("dummy exception") | ||
|
||
except VyperException: | ||
pass | ||
|
||
assert m["x"] == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters