-
Notifications
You must be signed in to change notification settings - Fork 991
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
refactor state crate #2606
refactor state crate #2606
Conversation
3afe3de
to
2d4d95f
Compare
4f4803b
to
4ec74dd
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2606 +/- ##
==========================================
+ Coverage 53.38% 53.46% +0.08%
==========================================
Files 302 307 +5
Lines 103403 102898 -505
==========================================
- Hits 55198 55012 -186
+ Misses 48205 47886 -319 ☔ View full report in Codecov by Sentry. |
4ec74dd
to
bc29e16
Compare
2293352
to
b3cdf30
Compare
* tomas/refactor-state: changelog: add #2606 benches: update for new state API test/wasm: update for new state API tests: update for new state API test/PoS: update for new state API apps: update for new state API namada: update for new state API, refactor tx and VP host envs sdk: update for new state API eth_bridge: update for new state API ibc: update for new state API state: refactor everything
there's an issue with loading merkle tree after node restart, looking into it |
fixed in 1519e71 |
0c98d6d
to
daffb53
Compare
* tomas/refactor-state: changelog: add #2606 benches: update for new state API test/wasm: update for new state API tests: update for new state API test/PoS: update for new state API apps: update for new state API namada: update for new state API, refactor tx and VP host envs sdk: update for new state API eth_bridge: update for new state API ibc: update for new state API state: refactor everything
Describe your changes
closes #2486
High-level
struct State
tostruct InMemory
and removed its fielddb: D
together withD
type paramState
that were using thedb
are moved totrait State
and prefixed withdb_
(e.g.State::read
becomesState::db_read
)struct WlStorage
,struct TempWlStorage
andtrait WriteLogAndStorage
trait State
generic over DB and hasher, comprised of a write log, DB andInMemory
state.struct FullAccessState
(implsState
,StorageRead
andStorageWrite
) - this is owned by shell which has full access to everything (DB, write log andInMemory
state)struct WlState
(implsState
,StorageRead
andStorageWrite
) - DB is read only, write/delete can only be done via write logstruct TempWlState
(implsState
,StorageRead
andStorageWrite
) - replacesTempWlStorage
- for prepare and process proposal and dry-run txs which use a temporary write logstruct VpHostEnvState
(implsState
andStorageRead
) - state for VP exec, everything is read-only (except for gas meter which is held in aRefCell
to allow mutation in immutable methods)struct TxHostEnvState
(implsState
,StorageRead
andStorageWrite
) - state for tx exec, can only write to write log, cannot modify in-memory state. Includes gas accounting (gas meter also in aRefCell
).struct TxCtx
now hold reference to a generic mutableState
'static
lifetime so anything that contains a non-static reference is a no-go. Instead, theTxCtx
now has astate()
method, which returns aTxHostEnvState
that allows to useStorageRead + StorageWrite
in host env with gas accounting included (replaces temporary implementation we've added for IBC tx workaround)'static
to be able to use them inwasm_imports
struct VpCtx
andnative_vp::Ctx
now hold a reference to a generic immutableState
VpCtx
has astate()
method that returnsVpHostEnvState
struct TestWlStorage
bytype TestState = FullAccessState<MockDB, Sha256Hasher>
Usage
FullAccessState::restrict_writes_to_write_log
- returns&mut WlState
for transactions and other state changes in a blockFullAccessState::read_only
- returns&WlState
for VPs and queriestrait State
components accessState::write_log()
,State::write_log_mut()
,State::db()
,State::in_mem()
(InMemory
state)State::split_borrow
to use all 3 at the same timetrait State
in place ofWlStorage
to simplify the verbose bounds:Next steps
For sub-system modules envisioned in #2111 we'll want to replace the usage of
WlStorage
/WlState
/State
with the more abstractStorageRead + StorageWrite
with additional traits that add access to individual parts of the state that are being used but not covered byStorageRead
orStorageWrite
(e.g. things fromInMemory
state - for shielded token we havetrait WithConversionState
that provides mutable access to conversion state (in the concreteFullAccessState
this is held instruct InMemory
). The only places that directly use the state will be:These are
governance
,ethereum_bridge
andibc
.TODOs
StorageRead
andStorageWrite
impl forTxCtx
incrates/namada/src/vm/host_env.rs
with a impl provided by the state crate (must account for gas)Indicate on which release or other PRs this topic is based on
#2507 - diff https://github.com/anoma/namada/pull/2606/files/d44bf1e2c242e076ca96e23c1e27dfba663c12b2..daffb53860531bf589f00259c3e12d4e5ee3b395
Checklist before merging to
draft