Expand description
State Diff Engine: field-level change tracking.
Captures before/after snapshots of account data and computes diffs. Use cases:
- Audit trails
- Test assertions
- Post-mutation invariant verification
- Debugging state transitions
§Usage
ⓘ
// Capture before state
let snap = StateSnapshot::<256>::capture(account_data);
// ... mutations happen ...
// Compute diff
let diff = snap.diff(account_data);
if diff.has_changes() {
let regions = diff.changed_regions::<8>();
let mut i = 0;
while i < regions.len() {
if let Some(r) = regions.get(i) {
// r.offset, r.length
}
i += 1;
}
}§Design
Snapshots are stack-allocated using const generics. The maximum snapshot
size is a compile-time parameter. For accounts larger than the snapshot
buffer, only the first N bytes are captured. Use was_truncated() to
detect this.
Structs§
- Changed
Region - A contiguous region of changed bytes.
- Changed
Region Iter - Iterator over changed regions.
- Changed
Regions - Stack-allocated list of changed regions.
- State
Diff - A diff between two states of account data.
- State
Snapshot - A stack-allocated snapshot of account data.
Functions§
- field_
diff_ mask - Build a field-level diff report for a known layout.