-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Use BlockHeight
as a primary key for the FuelsBlock
table
#1587
Merged
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
df6e1ae
Move storage traits implementation to the `fuel-core-storage` crate
xgreenx de82e25
Added comments to all newly added stuff. Made self-review and applied…
xgreenx 7ccc722
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx 33661bc
Updated CHANGELOG.md
xgreenx 1b8295a
Merge remote-tracking branch 'origin/feature/move-storage-implementat…
xgreenx 4c3f18c
Apply suggestions from the PR
xgreenx 0eaab98
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx 0cea5bb
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx c9977a4
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx b0ed3e9
Fixed compilation
xgreenx 541527e
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx d2b5504
Use `BlockHeight` as a primary key for the `FuelsBlock` table
xgreenx 1013f0e
Merge branch 'feature/move-storage-implementation-to-own-crate' into …
xgreenx 359192e
Updated CHANGELOG.md
xgreenx 34b5e6a
Merge remote-tracking branch 'origin/feature/block-height-as-primary-…
xgreenx e27996a
Fix compilation
xgreenx 452418c
Merge remote-tracking branch 'origin/feature/move-storage-implementat…
xgreenx 1fbc318
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx c5956a8
Use "blueprint" instead of "structure"
xgreenx cc9966c
Fix documents
xgreenx 0bbeea1
Merge branch 'feature/move-storage-implementation-to-own-crate' into …
xgreenx 2d3e471
Merge latest modifications from move storage PR
xgreenx f0df4f0
Merge branch 'master' into feature/block-height-as-primary-key
xgreenx 993aa84
Merge branch 'master' into feature/block-height-as-primary-key
xgreenx 36445b7
Merged master
xgreenx 0e2abad
Merge branch 'master' into feature/block-height-as-primary-key
xgreenx 6a503b9
Apply comments
xgreenx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,11 @@ use fuel_core_chain_config::{ | |
}; | ||
use fuel_core_storage::{ | ||
blueprint::Blueprint, | ||
codec::Decode, | ||
codec::{ | ||
Decode, | ||
Encode, | ||
Encoder, | ||
}, | ||
iter::IterDirection, | ||
kv_store::{ | ||
BatchOperations, | ||
|
@@ -253,18 +257,18 @@ impl BatchOperations for DataSource { | |
|
||
/// Read-only methods. | ||
impl Database { | ||
fn iter_all<M>( | ||
pub(crate) fn iter_all<M>( | ||
&self, | ||
direction: Option<IterDirection>, | ||
) -> impl Iterator<Item = StorageResult<(M::OwnedKey, M::OwnedValue)>> + '_ | ||
where | ||
M: Mappable + TableWithBlueprint, | ||
M::Blueprint: Blueprint<M, DataSource>, | ||
{ | ||
self.iter_all_filtered::<M, Vec<u8>, Vec<u8>>(None, None, direction) | ||
self.iter_all_filtered::<M, [u8; 0]>(None, None, direction) | ||
} | ||
|
||
fn iter_all_by_prefix<M, P>( | ||
pub(crate) fn iter_all_by_prefix<M, P>( | ||
&self, | ||
prefix: Option<P>, | ||
) -> impl Iterator<Item = StorageResult<(M::OwnedKey, M::OwnedValue)>> + '_ | ||
|
@@ -273,57 +277,64 @@ impl Database { | |
M::Blueprint: Blueprint<M, DataSource>, | ||
P: AsRef<[u8]>, | ||
{ | ||
self.iter_all_filtered::<M, P, [u8; 0]>(prefix, None, None) | ||
self.iter_all_filtered::<M, P>(prefix, None, None) | ||
} | ||
|
||
fn iter_all_by_start<M, S>( | ||
pub(crate) fn iter_all_by_start<M>( | ||
&self, | ||
start: Option<S>, | ||
start: Option<&M::Key>, | ||
direction: Option<IterDirection>, | ||
) -> impl Iterator<Item = StorageResult<(M::OwnedKey, M::OwnedValue)>> + '_ | ||
where | ||
M: Mappable + TableWithBlueprint, | ||
M::Blueprint: Blueprint<M, DataSource>, | ||
S: AsRef<[u8]>, | ||
{ | ||
self.iter_all_filtered::<M, [u8; 0], S>(None, start, direction) | ||
self.iter_all_filtered::<M, [u8; 0]>(None, start, direction) | ||
} | ||
|
||
fn iter_all_filtered<M, P, S>( | ||
pub(crate) fn iter_all_filtered<M, P>( | ||
&self, | ||
prefix: Option<P>, | ||
start: Option<S>, | ||
start: Option<&M::Key>, | ||
direction: Option<IterDirection>, | ||
) -> impl Iterator<Item = StorageResult<(M::OwnedKey, M::OwnedValue)>> + '_ | ||
where | ||
M: Mappable + TableWithBlueprint, | ||
M::Blueprint: Blueprint<M, DataSource>, | ||
P: AsRef<[u8]>, | ||
S: AsRef<[u8]>, | ||
{ | ||
self.data | ||
.as_ref() | ||
.iter_all( | ||
let iter = if let Some(start) = start { | ||
let encoder = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just map the start into the encoded value so we don't need an if-else to call the same function with a some vs a none? |
||
<M::Blueprint as Blueprint<M, DataSource>>::KeyCodec::encode(start); | ||
|
||
self.data.as_ref().iter_all( | ||
M::column(), | ||
prefix.as_ref().map(|p| p.as_ref()), | ||
start.as_ref().map(|s| s.as_ref()), | ||
Some(encoder.as_bytes().as_ref()), | ||
direction.unwrap_or_default(), | ||
) | ||
.map(|val| { | ||
val.and_then(|(key, value)| { | ||
let key = | ||
<M::Blueprint as Blueprint<M, DataSource>>::KeyCodec::decode( | ||
key.as_slice(), | ||
) | ||
.map_err(|e| StorageError::Codec(anyhow::anyhow!(e)))?; | ||
let value = | ||
<M::Blueprint as Blueprint<M, DataSource>>::ValueCodec::decode( | ||
value.as_slice(), | ||
) | ||
.map_err(|e| StorageError::Codec(anyhow::anyhow!(e)))?; | ||
Ok((key, value)) | ||
}) | ||
} else { | ||
self.data.as_ref().iter_all( | ||
M::column(), | ||
prefix.as_ref().map(|p| p.as_ref()), | ||
None, | ||
direction.unwrap_or_default(), | ||
) | ||
}; | ||
iter.map(|val| { | ||
val.and_then(|(key, value)| { | ||
let key = <M::Blueprint as Blueprint<M, DataSource>>::KeyCodec::decode( | ||
key.as_slice(), | ||
) | ||
.map_err(|e| StorageError::Codec(anyhow::anyhow!(e)))?; | ||
let value = | ||
<M::Blueprint as Blueprint<M, DataSource>>::ValueCodec::decode( | ||
value.as_slice(), | ||
) | ||
.map_err(|e| StorageError::Codec(anyhow::anyhow!(e)))?; | ||
Ok((key, value)) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
|
@@ -379,7 +390,7 @@ impl ChainConfigDb for Database { | |
} | ||
|
||
fn get_block_height(&self) -> StorageResult<BlockHeight> { | ||
Self::latest_height(self) | ||
self.latest_height() | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the encoder or the encoded value?