Skip to content

Get storage at block number#2

Open
m-kus wants to merge 6 commits intomainfrom
get-storage-at-block-number
Open

Get storage at block number#2
m-kus wants to merge 6 commits intomainfrom
get-storage-at-block-number

Conversation

@m-kus
Copy link
Copy Markdown
Collaborator

@m-kus m-kus commented Mar 7, 2026

Summary

  • Switch starknet-rs dependencies from crates.io starknet-rust-* v0.17.0 to
    m-kus/starknet-rs fork (pinned at 20b1ddeb) which adds
    StorageResponseFlag and StorageResult types
  • Add optional response_flags parameter to starknet_getStorageAt per starknet-specs PR
    #370
    (v0.10.1-rc.3)
  • When INCLUDE_LAST_UPDATE_BLOCK is passed, the response becomes {"value": "0x...", "last_update_block": N} instead of a plain felt — the block number is found by scanning state
    diffs in reverse
  • Without the flag, behavior is unchanged (returns plain felt)

Motivation

The discovery service needs to know which block last modified a storage slot to efficiently
traverse transaction history backwards. This avoids scanning every block sequentially.

Changes

File What
Cargo.toml starknet-rs deps → git fork
emitted_event.rs Compat: default transaction_index/event_index to 0 (fields absent in
upstream starknet-rs)
endpoints_ws.rs Compat: default commitment/count fields for origin block headers
models/mod.rs response_flags: Option<Vec<StorageResponseFlag>> on GetStorageInput
json_rpc_response.rs StorageResult variant on StarknetResponse
starknet/mod.rs find_last_storage_update_block() — reverse scan of num_to_hash +
hash_to_state_diff
json_rpc_handler.rs Pass response_flags through dispatch
endpoints.rs Branch on flag: return StorageResult or Felt

Test plan

  • cargo check — compiles cleanly
  • cargo test -p starknet-devnet-server — 70 tests pass (includes new deserialization tests
    for response_flags)
  • cargo test -p starknet-devnet-core — 116 tests pass
  • Integration test: deploy contract → write storage → call with/without flags → verify
    response
  • Manual: start devnet, send tx, curl starknet_getStorageAt with response_flags: ["INCLUDE_LAST_UPDATE_BLOCK"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant