Skip to content

refactor: move HistoryLastUpdateBlock logic to the state#3486

Merged
MaksymMalicki merged 22 commits intomainfrom
thiagodeev/move-history-func-to-state
Mar 20, 2026
Merged

refactor: move HistoryLastUpdateBlock logic to the state#3486
MaksymMalicki merged 22 commits intomainfrom
thiagodeev/move-history-func-to-state

Conversation

@thiagodeev
Copy link
Copy Markdown
Contributor

@thiagodeev thiagodeev commented Mar 16, 2026

Follow-up PR for the #3470 feat.

Summary

  • Moves HistoryLastUpdateBlock logic from the db package into the state layer, replacing it with a ContractStorageLastUpdatedBlock(addr, key *felt.Felt) (uint64, bool, error) method added to the StateReader interface
  • Implements ContractStorageLastUpdatedBlock on all state types: DeprecatedState, deprecatedStateHistory, State, stateHistory, and PendingState
  • PendingState returns the pending block number when the key is present in the pending diff, otherwise delegates to the head state
  • Updates rpc/v10/storage.go to call ContractStorageLastUpdatedBlock through the StateReader interface instead of going directly to the db package
  • Removes db.HistoryLastUpdateBlock and db/schema_test.go; test coverage is migrated into each state package

@thiagodeev thiagodeev added disable-deploy-test We don't want to run deploy tests with this PR because it might affect our development environment. and removed disable-deploy-test We don't want to run deploy tests with this PR because it might affect our development environment. labels Mar 17, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 64.00000% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.78%. Comparing base (9385a88) to head (dcbc081).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
core/state.go 66.66% 8 Missing and 3 partials ⚠️
core/state/state.go 66.66% 6 Missing and 3 partials ⚠️
core/pending_state.go 64.70% 5 Missing and 1 partial ⚠️
core/state/history.go 20.00% 3 Missing and 1 partial ⚠️
core/history.go 40.00% 3 Missing ⚠️
rpc/v10/storage.go 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3486      +/-   ##
==========================================
- Coverage   75.05%   73.78%   -1.27%     
==========================================
  Files         385      385              
  Lines       34950    35168     +218     
==========================================
- Hits        26231    25949     -282     
- Misses       6762     6944     +182     
- Partials     1957     2275     +318     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thiagodeev thiagodeev marked this pull request as ready for review March 17, 2026 22:36
@thiagodeev thiagodeev marked this pull request as draft March 18, 2026 14:59
@thiagodeev thiagodeev marked this pull request as ready for review March 18, 2026 15:32
Copy link
Copy Markdown
Contributor

@rodrodros rodrodros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good – some stylistic changes

Comment thread core/state/state.go Outdated
Comment thread core/state/history.go Outdated
Comment thread core/history.go Outdated
Comment thread core/state/state.go Outdated
Comment thread core/pending_state.go Outdated
Comment thread core/pending_state.go Outdated
Comment thread core/pending_state_test.go Outdated
Comment thread core/state.go Outdated
Comment thread core/state.go Outdated
Comment thread core/state_interfaces.go Outdated
Comment thread core/state/history_test.go Outdated
Comment thread core/state/history_test.go Outdated
Comment thread core/pending_state_test.go
Comment thread rpc/v10/storage.go Outdated
Comment thread core/history_test.go
Comment thread core/state_test.go Outdated
Comment thread rpc/v10/storage_test.go Outdated
… felt.Address type

- Changed address parameter types in ContractStorageLastUpdatedBlock and related methods to felt.Address.
- Updated tests to reflect changes in address handling, ensuring compatibility with new address type.
- Enhanced clarity in comments regarding the behavior of ContractStorageLastUpdatedBlock.

[no ci]
…r clarity + remove feltOne global variable

[no ci]
@thiagodeev thiagodeev force-pushed the thiagodeev/move-history-func-to-state branch from d8e6e7a to 4645467 Compare March 19, 2026 15:52
@thiagodeev thiagodeev marked this pull request as draft March 20, 2026 11:28
@thiagodeev thiagodeev marked this pull request as ready for review March 20, 2026 11:48
@MaksymMalicki MaksymMalicki merged commit 30f35d1 into main Mar 20, 2026
23 checks passed
@MaksymMalicki MaksymMalicki deleted the thiagodeev/move-history-func-to-state branch March 20, 2026 14:50
brbrr pushed a commit that referenced this pull request Mar 20, 2026
* refactor: move the HistoryLastUpdateBlock logic to the DeprecatedState + deprecatedStateHistory types

* refactor: update StorageAt method to use the new ContractStorageLastUpdatedBlock method + update tests

* feat: add the ContractStorageLastUpdatedBlock logic to the State + stateHistory types

* feat: add pending block number and ContractStorageLastUpdatedBlock method for the  PendingState type

* chore: regenerate mocks

[no ci]

* test: implement ContractStorageLastUpdatedBlock tests across various state types

[no ci]

* ci: fix linter

* chore: rename param to 'pendingBlockNumber' in the NewPendingState func

* test: refactor TestPendingState

* test: fix TestStorageAt test

* test: fix Pending tests

* feat: add case for deployed contract with unchanged storage key in PendingState

* fix: avoid contract not found errors for new contracts in pre_confirmed block + enhance PendingState tests

* refactor: update address handling in state and history methods to use felt.Address type

- Changed address parameter types in ContractStorageLastUpdatedBlock and related methods to felt.Address.
- Updated tests to reflect changes in address handling, ensuring compatibility with new address type.
- Enhanced clarity in comments regarding the behavior of ContractStorageLastUpdatedBlock.

[no ci]

* refactor: rename pendingBlockNumber to blockNumber in PendingState for clarity + remove feltOne global variable

[no ci]

* test: use local stateDiff variable in the TestStorageAt instead of a single shared var

[no ci]

* test: add new test case for deployment height retrieval in state history

* ci: fix linter

* test: fix TestStorageAt due to the address parameter being a felt.Address now

* ci: fix linter

* refactor: remove unused return flag in the  ContractStorageLastUpdatedBlock method

---------

Co-authored-by: MaksymMalicki <81577596+MaksymMalicki@users.noreply.github.com>
brbrr pushed a commit that referenced this pull request Mar 20, 2026
* refactor: move the HistoryLastUpdateBlock logic to the DeprecatedState + deprecatedStateHistory types

* refactor: update StorageAt method to use the new ContractStorageLastUpdatedBlock method + update tests

* feat: add the ContractStorageLastUpdatedBlock logic to the State + stateHistory types

* feat: add pending block number and ContractStorageLastUpdatedBlock method for the  PendingState type

* chore: regenerate mocks

* test: implement ContractStorageLastUpdatedBlock tests across various state types

* ci: fix linter

* chore: rename param to 'pendingBlockNumber' in the NewPendingState func

* test: refactor TestPendingState

* test: fix TestStorageAt test

* test: fix Pending tests

* feat: add case for deployed contract with unchanged storage key in PendingState

* fix: avoid contract not found errors for new contracts in pre_confirmed block + enhance PendingState tests

* refactor: update address handling in state and history methods to use felt.Address type

- Changed address parameter types in ContractStorageLastUpdatedBlock and related methods to felt.Address.
- Updated tests to reflect changes in address handling, ensuring compatibility with new address type.
- Enhanced clarity in comments regarding the behavior of ContractStorageLastUpdatedBlock.

* refactor: rename pendingBlockNumber to blockNumber in PendingState for clarity + remove feltOne global variable

* test: use local stateDiff variable in the TestStorageAt instead of a single shared var

* test: add new test case for deployment height retrieval in state history

* ci: fix linter

* test: fix TestStorageAt due to the address parameter being a felt.Address now

* ci: fix linter

* refactor: remove unused return flag in the  ContractStorageLastUpdatedBlock method

---------

Co-authored-by: MaksymMalicki <81577596+MaksymMalicki@users.noreply.github.com>
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.

3 participants