Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port(storage): use the cached block height from the database at the t…
…ime of creation of the view (#2646) ## Linked Issues/PRs <!-- List of related issues/PRs --> - same as #2639, but for master ## Description <!-- List of detailed changes --> The most important changes include adding metadata support to the `GenericDatabase`, modifying type definitions to include height metadata, and updating various methods to use the new database structure. ### Database Structure Improvements: * [`crates/fuel-core/src/database.rs`](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898R28): Added metadata support to the `GenericDatabase` and updated type definitions to include height metadata. This includes changes to methods such as `new`, `in_memory`, and `latest_view`. [[1]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898R28) [[2]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898R64-L73) [[3]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898R83-R89) [[4]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L129-R138) [[5]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L144-R152) [[6]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L179-R190) [[7]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L190-R209) [[8]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L238-R259) [[9]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L257-R274) [[10]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L270-R290) [[11]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898R346-R369) [[12]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L344-R378) [[13]](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L354-R396) * [`crates/fuel-core/src/state.rs`](diffhunk://#diff-386ccf4eb5acb74a927c8c9849dfcc59aa78bcf800d9fd89f4e1a6e30f7199f0R33-R51): Updated type definitions for `IterableKeyValueView` and `KeyValueView` to include height metadata. Modified the `TransactableStorage` trait to use the new types. [[1]](diffhunk://#diff-386ccf4eb5acb74a927c8c9849dfcc59aa78bcf800d9fd89f4e1a6e30f7199f0R33-R51) [[2]](diffhunk://#diff-386ccf4eb5acb74a927c8c9849dfcc59aa78bcf800d9fd89f4e1a6e30f7199f0L64-R68) [[3]](diffhunk://#diff-386ccf4eb5acb74a927c8c9849dfcc59aa78bcf800d9fd89f4e1a6e30f7199f0L82-L89) ### Code Refactoring: * [`crates/fuel-core/src/state/generic_database.rs`](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L31-R60): Refactored the `GenericDatabase` struct to include metadata and updated various trait implementations to support the new structure. [[1]](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L31-R60) [[2]](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L67-R76) [[3]](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L77-R86) [[4]](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L96-R106) [[5]](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L106-R116) [[6]](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L139-R149) [[7]](diffhunk://#diff-304688e42224bb543ff683ccd9bc78e6432eea2e2868da28fc91ca441e38ea17L165-R202) ### Performance Improvements: * [`crates/fuel-core/src/database.rs`](diffhunk://#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898L144-R152): Improved the `latest_height` method to use metadata for fetching the latest height, enhancing performance. ### Test Updates: * [`crates/fuel-core/src/service/genesis/importer/import_task.rs`](diffhunk://#diff-954b9280f787dd90eda70a58c77f53b3543e8286462d498dcda45536ca7a175fL581-R587): Updated tests to use the new `KeyValueView` and `IterableKeyValueView` types with height metadata. ## Checklist - [ ] Breaking changes are clearly marked as such in the PR description and changelog - [ ] New behavior is reflected in tests - [ ] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [ ] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else? --------- Co-authored-by: Green Baneling <[email protected]> Co-authored-by: Andrea Cerone <[email protected]>
- Loading branch information