Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage): use the cached block height from the database at the time of creation of the view #2639

Merged
merged 5 commits into from
Jan 28, 2025

Conversation

rymnc
Copy link
Member

@rymnc rymnc commented Jan 28, 2025

Linked Issues/PRs

Description

This pull request includes several changes to the crates/fuel-core/src/database.rs and related files to enhance the handling of metadata within the GenericDatabase structure. The most important changes include the addition of metadata support, the modification of type definitions to incorporate height types, and updates to various database methods to utilize this new structure.

Enhancements to metadata handling:

Updates to type definitions:

  • crates/fuel-core/src/state.rs: Modified type definitions for IterableKeyValueView and KeyValueView to include height types, and updated the TransactableStorage trait to reflect these changes. [1] [2] [3]

Changes to database methods:

  • crates/fuel-core/src/database.rs: Updated methods such as latest_view, view_at_height, and in_memory to utilize the new metadata structure, ensuring consistent handling of metadata across different database operations. [1] [2] [3]

Refactoring and cleanup:

Updates to related files:

These changes collectively enhance the database's functionality by introducing metadata support and improving the handling of height types, leading to a more robust and flexible database structure.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification 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]

@rymnc rymnc marked this pull request as ready for review January 28, 2025 11:57
@rymnc rymnc requested a review from AurelienFT January 28, 2025 11:58
@rymnc rymnc self-assigned this Jan 28, 2025
@AurelienFT AurelienFT merged commit 68e845d into release/v0.40.4 Jan 28, 2025
38 checks passed
@AurelienFT AurelienFT deleted the fix/graphql-storage-read-for-height branch January 28, 2025 14:10
AurelienFT added a commit that referenced this pull request Jan 28, 2025
## Version 0.40.4

### Changed

- [2639](#2639): Refactor
fetching `latest_height` from `OnChainIterableKeyValueView` to instead
use height at the time of its creation.

### Fixed

- [2638](#2638): Optimize the
`cumulative_percent_change` function used in estimation of gas price,
convert multiple async functions to sync.
rymnc added a commit that referenced this pull request Feb 11, 2025
…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]>
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.

2 participants