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 temporary values read #2735

Merged
merged 14 commits into from Apr 12, 2024
Merged

Fix temporary values read #2735

merged 14 commits into from Apr 12, 2024

Conversation

grarco
Copy link
Contributor

@grarco grarco commented Feb 27, 2024

Describe your changes

Closes #2683.

Fixes the has_key method provided to the vp env to not return an error on temporary write values (the read method was already fine).

Adds a new read_persistent method on WriteLog that ignore temporary writes and modifies the read and has_key implementation of impl_storage_read to call this new method.
Modifies tx_iter_next to skip temporary writes.
Refactors fetch_or_compile to call state.read (which should include possible updated in the write log of the wasm codes).

Updates write_temp in WriteLog to return an error when trying to overwrite a StorageModification::Write with a StorageModification::Temp.
Updates iter_prefix_post in WriteLog to iterate also on the precommit bucket.
Updates write, write_temp and delete in WriteLog to take the precommit bucket into account.

Indicate on which release or other PRs this topic is based on

v0.32.0

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 82.91139% with 27 lines in your changes are missing coverage. Please review.

Project coverage is 53.49%. Comparing base (5e0b162) to head (f588ec5).
Report is 4 commits behind head on main.

Files Patch % Lines
crates/namada/src/vm/wasm/run.rs 57.14% 12 Missing ⚠️
crates/namada/src/vm/host_env.rs 57.14% 6 Missing ⚠️
crates/state/src/write_log.rs 94.23% 6 Missing ⚠️
crates/namada/src/ledger/vp_host_fns.rs 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2735      +/-   ##
==========================================
+ Coverage   53.44%   53.49%   +0.05%     
==========================================
  Files         310      310              
  Lines      101574   101623      +49     
==========================================
+ Hits        54288    54368      +80     
+ Misses      47286    47255      -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grarco
Copy link
Contributor Author

grarco commented Feb 28, 2024

One thing I noticed is that here the type system doesn't really help us: the block_write_log will (and should) never contain a StorageModification::Temp because we filter them out, but since we are not using a different type this isn't enforced leading to some places in the code were we might match on a variant that doesn't really exist. We could think about coming up with a new type here

pub(crate) block_write_log: HashMap<storage::Key, StorageModification>,

@@ -188,7 +188,9 @@ where
Ok(false)
}
Some(&write_log::StorageModification::InitAccount { .. }) => Ok(true),
Some(&write_log::StorageModification::Temp { .. }) => Ok(true),
Some(&write_log::StorageModification::Temp { .. }) => {
Copy link
Contributor Author

@grarco grarco Feb 28, 2024

Choose a reason for hiding this comment

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

The API we provide to the VPs is different to the one we have in protocol or expose to transactions. For VPs we report an error whereas in protocol and for transactions we simply ignore temporary writes and try to look for other storage modifications or directly from storage. I tend to like the latter better but I can understand that returning an error might be more explicit. Should we try to unify the api and apply the same logic everywhere (either errors or read-through?)

Copy link
Member

Choose a reason for hiding this comment

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

I agree that the latter is better and I'm for unifying this in VPs. If a VP allows temp values, it has to read them explicitly so ignoring them for non-temp reads is fine

grarco added a commit that referenced this pull request Feb 28, 2024
@grarco grarco marked this pull request as ready for review February 28, 2024 16:19
grarco added a commit that referenced this pull request Feb 29, 2024
@tzemanovic
Copy link
Member

rebased on 0.32.0

tzemanovic added a commit that referenced this pull request Apr 1, 2024
* origin/grarco/fix-vps-api:
  Changelog #2735
  `read_persistent` returns a `PersistentStorageModification`
  Unit tests write log temp writes
  In write log `write`, `write_temp` and `delete` now take the precommit into account
  vp `read_temp` ignores non-temp values instead of error
  Unifies read interface of vps to that of txs and protocol
  Refactors `read` and `has_key` implementations in `impl_storage_read`
  Adds a new `read_persistent` method on `WriteLog`. Refactors `iter_prefix_post`
  Host fn iterator does not return temporary values
  Fixes check on address existence
  Fixes retrieval of wasm code in `fetch_or_compile`
  Ingores temporary writes in `impl_storage_read` macro
  Prevents a write log temp write after a write
  `has_key` host fns return error on temp write
tzemanovic added a commit that referenced this pull request Apr 10, 2024
* origin/grarco/fix-vps-api:
  Changelog #2735
  `read_persistent` returns a `PersistentStorageModification`
  Unit tests write log temp writes
  In write log `write`, `write_temp` and `delete` now take the precommit into account
  vp `read_temp` ignores non-temp values instead of error
  Unifies read interface of vps to that of txs and protocol
  Refactors `read` and `has_key` implementations in `impl_storage_read`
  Adds a new `read_persistent` method on `WriteLog`. Refactors `iter_prefix_post`
  Host fn iterator does not return temporary values
  Fixes check on address existence
  Fixes retrieval of wasm code in `fetch_or_compile`
  Ingores temporary writes in `impl_storage_read` macro
  Prevents a write log temp write after a write
  `has_key` host fns return error on temp write

# Conflicts:
#	crates/namada/src/vm/wasm/run.rs
@tzemanovic tzemanovic merged commit d6a9c77 into main Apr 12, 2024
16 of 19 checks passed
@tzemanovic tzemanovic deleted the grarco/fix-vps-api branch April 12, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong storage API in VPs
2 participants