0xMiden / 0xMiden/node

store: `apply_block` code does not correctly handle `StorageMapPatch::Remove` and `StorageMapPatch::Create` semantics

Đang mở
#2,328 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
store
Ngôn ngữ chính
Rust
Star
104
Fork
138
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
56

Mô tả

After the recent upgrade to `miden-protocol` `next` there were some semantic changes introduced with `AccountPatch`: explicit create and remove operations were added for storage slots and storage maps.

`StorageValuePatch::Remove` and `StorageMapPatch::Remove` now needs to be handled explicitly in our storage code. In particular, `StorageMapPatch::Remove` is _not_ handled correctly right now.

The account state forest code skips removes (because `StorageMapPatch::entries` returns `None` for `Remove`: https://github.com/0xMiden/node/blob/914ff72faf7a8c7a4798bfc352e6e6a4167397c0/crates/store/src/account_state_forest/mod.rs#L743).

The code applying account state changes to SQLite also seems to just skip `Remove`: https://github.com/0xMiden/node/blob/914ff72faf7a8c7a4798bfc352e6e6a4167397c0/crates/store/src/db/models/queries/accounts.rs#L1146

Similarly, `StorageMapPatch::merge()` can merge a `Remove, Create` operation pair into a single `StorageMapPatch::Create` operation, so it's entirely possible that we're getting a `StorageMapPatch::Create` patch for an _existing_ storage map. In that case all current entries should be removed first and then the new entries added.

Note that we don't have a good way of representing map value removals in SQLite. The current schema for storage maps is this:

```sql
CREATE TABLE account_storage_map_values (
account_id BLOB NOT NULL,
block_num BIGINT NOT NULL,
slot_name TEXT NOT NULL,
key BLOB NOT NULL,
value BLOB NOT NULL,
is_latest BOOLEAN NOT NULL,

PRIMARY KEY (account_id, block_num, slot_name, key),
FOREIGN KEY (account_id, block_num) REFERENCES accounts(account_id, block_num) ON DELETE CASCADE
) WITHOUT ROWID;
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.