0xMiden / 0xMiden/node

Vault lookup can omit live assets when tombstones consume the SQL row limit

未关闭
#2,574 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
104
派生
138
平均合并
1 天 13 小时
30 天内合并 PR
56

描述

### Version

next at 4c211fc555e121d061a92d03cb1ddfc46710d416 (miden-node-store 0.16.0-rc.5)

### Other packages versions

Not applicable.

### What happened?

select_account_vault_at_block() applies LIMIT MAX_RETURN_ENTRIES + 1 before filtering deletion tombstones represented by NULL assets.

The query in crates/store/src/db/models/queries/accounts.rs is:

SELECT asset FROM account_vault_assets WHERE account_id = ?1 AND block_num <= ?2 AND valid_until > ?2 LIMIT ?3

The returned rows are then filtered in Rust with entries.into_iter().flatten().

If tombstone rows consume the SQL limit before a live asset is reached, the live asset is omitted. The post-query filtering removes the tombstones and can return an empty or incomplete vault without reporting LimitExceeded.

### What should have happened?

Deletion tombstones should not consume the limit used for live vault assets. Every live asset valid at the requested block should be returned when the number of live assets is within AccountVaultDetails::MAX_RETURN_ENTRIES.

If the number of live assets exceeds the limit, the caller should receive the existing LimitExceeded result rather than a silently incomplete vault.

### How can this be reproduced?

Create an in-memory SQLite database using the production account_vault_assets schema and insert:

- 1,001 rows for the same account with asset = NULL and valid_until = i64::MAX;
- one additional live row with asset = "LIVE" and a vault key ordered after the tombstone keys.

Run the production query with block number 2 and limit 1001:

SELECT asset FROM account_vault_assets WHERE account_id = ?1 AND block_num <= ?2 AND valid_until > ?2 LIMIT ?3

The query returns 1,001 rows, all containing NULL. After Rust applies .flatten(), the result is empty and the live asset is missing.

Running the equivalent query with AND asset IS NOT NULL before LIMIT returns the live asset.

### Relevant log output

```shell
rows_returned: 1001
non_null_returned: 0
filtered_assets:
- LIVE
query_plan:
SEARCH account_vault_assets USING PRIMARY KEY (account_id=? AND block_num

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。