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

[FRAME] State Diff Guard #4204

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
29 changes: 29 additions & 0 deletions prdoc/pr_4204.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "`try-runtime`: Add `StateDiffGuard` to record state difference and guard against unexpected storage changes"

doc:
- audience: Runtime Dev
description: |
This PR adds a `StateDiffGuard` helper struct that records the state difference between
its initialization and drop. It can be used to guard against unexpected storage changes
and also for recording the state difference for testing, debugging, and other purposes.

Example:
```rust
let _guard = StateDiffGuardBuilder::default()
.must_change(StoragePrefix{
pallet_name: b"Balances",
storage_name: b"TotalIssuance",
})
.build();

// do something that may change the storage

// the guard will panic if the storage is changed unexpectedly at the end of the scope
```

crates:
- name: frame-support
bump: minor
1 change: 1 addition & 0 deletions substrate/frame/support/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub mod child;
pub mod generator;
pub mod hashed;
pub mod migration;
pub mod state_diff_guard;
pub mod storage_noop_guard;
mod stream_iter;
pub mod transactional;
Expand Down
Loading
Loading